Skip to content

Commit 2f56fd4

Browse files
committed
Update navigation actions when load finishes in a subframe
Fixes: QTBUG-81521 Change-Id: I8ca82224cd834b667471d1e96a44430164d3669e Reviewed-by: Allan Sandfeld Jensen <[email protected]>
1 parent 578f432 commit 2f56fd4

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

src/core/web_contents_delegate_qt.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,10 @@ void WebContentsDelegateQt::DidFinishLoad(content::RenderFrameHost* render_frame
409409
return;
410410
}
411411

412-
if (render_frame_host->GetParent())
412+
if (render_frame_host->GetParent()) {
413+
m_viewClient->updateNavigationActions();
413414
return;
415+
}
414416

415417
if (!m_faviconManager->hasCandidate())
416418
m_viewClient->iconChanged(QUrl());

tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,20 +1327,39 @@ void tst_QWebEnginePage::textEditing()
13271327
void tst_QWebEnginePage::backActionUpdate()
13281328
{
13291329
QWebEngineView view;
1330+
view.resize(640, 480);
1331+
view.show();
1332+
13301333
QWebEnginePage *page = view.page();
1334+
QSignalSpy loadSpy(page, &QWebEnginePage::loadFinished);
13311335
QAction *action = page->action(QWebEnginePage::Back);
13321336
QVERIFY(!action->isEnabled());
1333-
QSignalSpy loadSpy(page, SIGNAL(loadFinished(bool)));
1334-
QUrl url = QUrl("qrc:///resources/framedindex.html");
1335-
page->load(url);
1336-
QTRY_COMPARE(loadSpy.count(), 1);
1337+
1338+
page->load(QUrl("qrc:///resources/framedindex.html"));
1339+
QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 1, 20000);
13371340
QVERIFY(!action->isEnabled());
1338-
QTest::mouseClick(&view, Qt::LeftButton, 0, QPoint(10, 10));
1339-
QEXPECT_FAIL("", "Behavior change: Load signals are emitted only for the main frame in QtWebEngine.", Continue);
1340-
QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 2, 100);
13411341

1342-
QEXPECT_FAIL("", "FIXME: Mouse events aren't passed from the QWebEngineView down to the RWHVQtDelegateWidget", Continue);
1343-
QVERIFY(action->isEnabled());
1342+
auto firstAnchorCenterInFrame = [](QWebEnginePage *page, const QString &frameName) {
1343+
QVariantList rectList = evaluateJavaScriptSync(page,
1344+
"(function(){"
1345+
"var frame = document.getElementsByName('" + frameName + "')[0];"
1346+
"var anchor = frame.contentDocument.getElementsByTagName('a')[0];"
1347+
"var rect = anchor.getBoundingClientRect();"
1348+
"return [(rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2];"
1349+
"})()").toList();
1350+
1351+
if (rectList.count() != 2) {
1352+
qWarning("firstAnchorCenterInFrame failed.");
1353+
return QPoint();
1354+
}
1355+
1356+
return QPoint(rectList.at(0).toInt(), rectList.at(1).toInt());
1357+
};
1358+
1359+
QVERIFY(evaluateJavaScriptSync(page, "document.getElementsByName('frame_b')[0].contentDocument == undefined").toBool());
1360+
QTest::mouseClick(view.focusProxy(), Qt::LeftButton, 0, firstAnchorCenterInFrame(page, "frame_c"));
1361+
QTRY_VERIFY(evaluateJavaScriptSync(page, "document.getElementsByName('frame_b')[0].contentDocument != undefined").toBool());
1362+
QTRY_VERIFY(action->isEnabled());
13441363
}
13451364

13461365
#if defined(QWEBENGINEPAGE_SETTINGS)

0 commit comments

Comments
 (0)