diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2017-07-19 14:12:54 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-09-11 17:25:32 +0000 |
commit | 7282fb4fb4861320539f2b7288f63e1d4f48749d (patch) | |
tree | 3fb62ed4d45875be975410b08c776888803748ec /tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp | |
parent | 82499104972d24027044acaff1136ea7d758efe2 (diff) |
Adaptations for Chromium 60
Change-Id: I536258e22c2ec143f2fd3f1cbda229e0611b6af4
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp')
-rw-r--r-- | tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp index c10ae2886..1a8110bb6 100644 --- a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp +++ b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp @@ -38,6 +38,7 @@ private Q_SLOTS: void webChannel_data(); void webChannel(); void noTransportWithoutWebChannel(); + void scriptsInNestedIframes(); }; void tst_QWebEngineScript::domEditing() @@ -246,6 +247,58 @@ void tst_QWebEngineScript::noTransportWithoutWebChannel() QCOMPARE(evaluateJavaScriptSync(&page, "qt.webChannelTransport"), QVariant(QVariant::Invalid)); } +void tst_QWebEngineScript::scriptsInNestedIframes() +{ + QWebEnginePage page; + QWebEngineView view; + view.setPage(&page); + QWebEngineScript s; + s.setInjectionPoint(QWebEngineScript::DocumentReady); + s.setWorldId(QWebEngineScript::ApplicationWorld); + + // Prepend a "Modified prefix" to every frame's div content. + s.setSourceCode("var elements = document.getElementsByTagName(\"div\");\ + var i;\ + for (i = 0; i < elements.length; i++) {\ + var content = elements[i].innerHTML;\ + elements[i].innerHTML = \"Modified \" + content;\ + }\ + "); + + // Make sure the script runs on all frames. + s.setRunsOnSubFrames(true); + page.scripts().insert(s); + + QSignalSpy spyFinished(&page, &QWebEnginePage::loadFinished); + page.load(QUrl("qrc:/resources/test_iframe_main.html")); + view.show(); + QVERIFY(spyFinished.wait()); + + // Check that main frame has modified content. + QCOMPARE( + evaluateJavaScriptSyncInWorld(&page, "document.getElementsByTagName(\"div\")[0].innerHTML", + QWebEngineScript::ApplicationWorld), + QVariant::fromValue(QStringLiteral("Modified Main text"))); + + // Check that outer frame has modified content. + QCOMPARE( + evaluateJavaScriptSyncInWorld(&page, + "var i = document.getElementById(\"outer\").contentDocument;\ + i.getElementsByTagName(\"div\")[0].innerHTML", + QWebEngineScript::ApplicationWorld), + QVariant::fromValue(QStringLiteral("Modified Outer text"))); + + + // Check that inner frame has modified content. + QCOMPARE( + evaluateJavaScriptSyncInWorld(&page, + "var i = document.getElementById(\"outer\").contentDocument;\ + var i2 = i.getElementById(\"inner\").contentDocument;\ + i2.getElementsByTagName(\"div\")[0].innerHTML", + QWebEngineScript::ApplicationWorld), + QVariant::fromValue(QStringLiteral("Modified Inner text"))); +} + QTEST_MAIN(tst_QWebEngineScript) #include "tst_qwebenginescript.moc" |