diff options
author | Michal Klocek <michal.klocek@qt.io> | 2022-08-25 12:25:46 +0200 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2022-12-09 07:11:03 +0000 |
commit | ffc09328c9774548e378a3187ea0d386cc31de3a (patch) | |
tree | baf122c2f43b68a8cb8756694d075d0d90ec4b01 /tests | |
parent | f393443d607a8c095334ffc5965e50871b260846 (diff) |
Reduce slowness and flakiness of tst_origin
This test runs very slow and it is flaky. Make it run faster by:
* instead of doing timeout checks for "cannotLoad", introduce
<image> element add use 'onload' and 'onerror' handlers before
doing actual <iframe> load, this dropps a need for hardcoded
delay/deadline for ifrme being loaded.
* do not evaluate JavaScript in try wait loop , use JavaScript
messages instead.
Note that using <img> or <script> element to perform the test (which
have onload and onerros handler unlike iframe) ie. loading cross origin
scripts or images instead of iframes is a dead-end as it has different
results and "canLoadButNotAccess" can not be tested as origin BAR can
load a script from origin FOO, but it still works in BAR‘s context.
Task-number: QTBUG-105342
Pick-to: 6.4
Change-Id: I180aea801cedb0f97b96cb90a54b793d0a7c1a7f
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/core/origins/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/core/origins/resources/mixedSchemes.html | 29 | ||||
-rw-r--r-- | tests/auto/core/origins/resources/mixedSchemes_frame.html | 9 | ||||
-rw-r--r-- | tests/auto/core/origins/resources/red.png | bin | 0 -> 146 bytes | |||
-rw-r--r-- | tests/auto/core/origins/tst_origins.cpp | 28 |
5 files changed, 45 insertions, 22 deletions
diff --git a/tests/auto/core/origins/CMakeLists.txt b/tests/auto/core/origins/CMakeLists.txt index 4a4219267..10a185f0a 100644 --- a/tests/auto/core/origins/CMakeLists.txt +++ b/tests/auto/core/origins/CMakeLists.txt @@ -32,6 +32,7 @@ set(tst_origins_resource_files "resources/viewSource.html" "resources/websocket.html" "resources/websocket2.html" + "resources/red.png" ) qt_internal_add_resource(tst_origins "tst_origins" diff --git a/tests/auto/core/origins/resources/mixedSchemes.html b/tests/auto/core/origins/resources/mixedSchemes.html index 53c8c83ff..3e50c2c3b 100644 --- a/tests/auto/core/origins/resources/mixedSchemes.html +++ b/tests/auto/core/origins/resources/mixedSchemes.html @@ -6,23 +6,34 @@ var result; var canary; - function setIFrameUrl(url) { + function setIFrameUrl(frameUrl,imgUrl) { result = undefined; canary = undefined; - document.getElementById("iframe").setAttribute("src", url); - // Early fire is OK unless the test is expecting cannotLoad. - // If timeout is too short then a false positive is possible. - setTimeout(() => { result = result || "cannotLoad"; }, 3000); + let img = document.createElement('img'); + img.onerror = function() { + console.log("TEST:cannotLoad"); + console.log("TEST:done"); + }; + img.onload = function() { + document.getElementById("iframe").setAttribute("src", frameUrl); + }; + img.src = imgUrl } addEventListener("load", function() { document.getElementById("iframe").addEventListener("load", function() { - if (canary && window[0].canary) - result = "canLoadAndAccess"; - else - result = "canLoadButNotAccess"; + if (canary && window[0].canary) { + console.log("TEST:canLoadAndAccess"); + console.log("TEST:done"); + } else { + console.log("TEST:canLoadButNotAccess"); + console.log("TEST:done"); + } }); }); + window.onerror = function(message, url, line, col, errorObj) { + return true; + }; </script> </head> <body> diff --git a/tests/auto/core/origins/resources/mixedSchemes_frame.html b/tests/auto/core/origins/resources/mixedSchemes_frame.html index 40ace2d2f..9499caa1f 100644 --- a/tests/auto/core/origins/resources/mixedSchemes_frame.html +++ b/tests/auto/core/origins/resources/mixedSchemes_frame.html @@ -3,9 +3,12 @@ <head> <title>Mixed - Frame</title> <script> - console.log('Frame Loaded'); - var canary = true; - parent.canary = true; + try{ + var canary = true; + parent.canary = true; + }catch(exception){ + }; + </script> </head> <body></body> diff --git a/tests/auto/core/origins/resources/red.png b/tests/auto/core/origins/resources/red.png Binary files differnew file mode 100644 index 000000000..5ae85192b --- /dev/null +++ b/tests/auto/core/origins/resources/red.png diff --git a/tests/auto/core/origins/tst_origins.cpp b/tests/auto/core/origins/tst_origins.cpp index 71285dcf0..2e58ed746 100644 --- a/tests/auto/core/origins/tst_origins.cpp +++ b/tests/auto/core/origins/tst_origins.cpp @@ -1005,9 +1005,14 @@ void tst_Origins::mixedContent() auto setIFrameUrl = [&] (const QString &scheme) { if (scheme == "data") - return QString("setIFrameUrl('data:,<script>var canary = true; parent.canary = true</script>')"); + return QString("setIFrameUrl('data:,<script>var canary = true; parent.canary = " + "true</script>','data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA" + "AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/" + "w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==')"); auto frameUrl = QString("%1:%2/resources/mixedSchemes_frame.html").arg(scheme).arg(scheme == "file" ? srcDir : ""); - return QString("setIFrameUrl('%1')").arg(frameUrl); + auto imgUrl = + QString("%1:%2/resources/red.png").arg(scheme).arg(scheme == "file" ? srcDir : ""); + return QString("setIFrameUrl('%1','%2')").arg(frameUrl).arg(imgUrl); }; m_page->messages.clear(); @@ -1019,15 +1024,18 @@ void tst_Origins::mixedContent() eval(setIFrameUrl(schemeTo)); - QTRY_COMPARE(eval(QSL("result !== undefined")), QVariant(true)); - auto result = eval(QSL("result")).toString(); - // Work-around some combinations missing JS loaded signals: - if (m_page->messages.size() > 0) { - if (m_page->messages[0] == QSL("Frame Loaded") && result == QSL("cannotLoad")) - result = QSL("canLoadButNotAccess"); - m_page->messages.clear(); + // wait for token in the log + QTRY_VERIFY(m_page->messages.contains("TEST:done")); + QString result; + // make sure we do not have some extra logs from blink + for (auto message : m_page->messages) { + QStringList s = message.split(':'); + if (s.size() > 1 && s[0] == "TEST") { + result = s[1]; + break; + } } - + m_page->messages.clear(); schemesTo.append(schemeTo.rightJustified(20)); results.append(result.rightJustified(20)); expected.append(expectedResult.rightJustified(20)); |