Bug 1480648 [wpt PR 12290] - Add test for blocked iframe navigation, a=testonly

Automatic update from web-platform-testsAdd test for blocked iframe navigation (#12290)

* Add test for blocked iframe navigation

Step 2 of "process the iframe attributes" [1] reads:

> 2. If there exists an ancestor browsing context whose active
>    document's URL, ignoring fragments, is equal to url, then return.

Add tests for this behavior, verifying the absence of navigation through
the synchronously-fired `beforeunload` event.

[1] https://html.spec.whatwg.org/multipage/iframe-embed-object.html#otherwise-steps-for-iframe-or-frame-elements

--

wpt-commits: 6af1174b30fef90e711f8ef5c517b40d6f961e3a
wpt-pr: 12290
This commit is contained in:
jugglinmike 2018-08-16 21:55:15 +00:00 committed by moz-wptsync-bot
parent e2e95ab324
commit a570ef6939
2 changed files with 152 additions and 4 deletions

View File

@ -358504,6 +358504,12 @@
{}
]
],
"html/semantics/embedded-content/the-iframe-element/src-repeated-in-ancestor.html": [
[
"/html/semantics/embedded-content/the-iframe-element/src-repeated-in-ancestor.html",
{}
]
],
"html/semantics/embedded-content/the-img-element/Image-constructor.html": [
[
"/html/semantics/embedded-content/the-img-element/Image-constructor.html",
@ -599167,6 +599173,10 @@
"4e6293949a0d9a799e6b3bb627fa181e29fe0b2c",
"testharness"
],
"html/semantics/embedded-content/the-iframe-element/src-repeated-in-ancestor.html": [
"2f77dfe164df3737cbbabf4efce6e28028e62537",
"testharness"
],
"html/semantics/embedded-content/the-iframe-element/stash.py": [
"0b8693a901152cc7a7f21de1fbdd191dce6078c3",
"support"
@ -642660,7 +642670,7 @@
"support"
],
"tools/wptrunner/wptrunner/tests/test_wpttest.py": [
"ff7c260f9d4182a75de33e1e248d01781ee9197e",
"827244cda3c5cc94d2bdb8becad1fe5c5253828b",
"support"
],
"tools/wptrunner/wptrunner/update/__init__.py": [
@ -642728,7 +642738,7 @@
"support"
],
"tools/wptrunner/wptrunner/wptmanifest/parser.py": [
"9763670663f9198433f611cf76b5b2db1221d0e2",
"82aad5f61350795eb9e807ca33015762e1a9f581",
"support"
],
"tools/wptrunner/wptrunner/wptmanifest/serializer.py": [
@ -642744,11 +642754,11 @@
"support"
],
"tools/wptrunner/wptrunner/wptmanifest/tests/test_parser.py": [
"765c984f42f56d4b888a5a5eb8171474852ffbe3",
"87ddfeed891742519c59b33aa0806f635c16a5cc",
"support"
],
"tools/wptrunner/wptrunner/wptmanifest/tests/test_serializer.py": [
"6908ea4c1e020dd1aafdd8da14f387c7c48c000e",
"f7c3ca24c709f1b462700de45decf0a51de8949a",
"support"
],
"tools/wptrunner/wptrunner/wptmanifest/tests/test_static.py": [

View File

@ -0,0 +1,138 @@
<!doctype html>
<meta charset="utf-8">
<title>Navigation should not occur when `src` matches the location of a anscestor browsing context</title>
<script>
// Avoid recursion in non-conforming browsers
if (parent !== window && parent.title == window.title) {
window.stop();
}
</script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
/**
* This test uses the `beforeunload` event to detect navigation. Because that
* event is fired synchronously in response to "process the iframe attributes",
* a second "control" iframe may be used to verify cases where navigation
* should *not* occur. `Promise.race` ensures that tests complete as soon as
* possible.
*
* Although the specification dictates that the `beforeunload` event must be
* emitted synchronously during navigation, a number of user agents do not
* adhere to this requirement. WPT includes a dedicated test for synchronous
* emission of the event [1]. This test is authored to support non-standard
* behavior in order to avoid spuriously passing in those UAs.
*
* [1] https://github.com/web-platform-tests/wpt/pull/12343
*/
'use strict';
function when(target, eventName) {
return new Promise(function(resolve, reject) {
target.addEventListener(eventName, function() {
resolve();
}, { once: true });
target.addEventListener('error', function() {
reject(new Error('Error while waiting for ' + eventName));
}, { once: true });
});
}
function init(doc, t) {
var iframes = [doc.createElement('iframe'), doc.createElement('iframe')];
iframes.forEach(function(iframe) {
iframe.src = '/common/blank.html';
doc.body.appendChild(iframe);
t.add_cleanup(function() {
iframe.parentNode.removeChild(iframe);
});
});
return Promise.all([when(iframes[0], 'load'), when(iframes[1], 'load')])
.then(function() { return iframes; });
}
// This test verifies that navigation does occur; it is intended to validate
// the utility functions.
promise_test(function(t) {
return init(document, t)
.then(function(iframes) {
var subjectNavigation = when(iframes[0].contentWindow, 'beforeunload');
var controlNavigation = when(iframes[1].contentWindow, 'beforeunload');
iframes[0].src = '/common/blank.html?2';
iframes[1].src = '/common/blank.html?3';
return Promise.all([subjectNavigation, controlNavigation]);
});
}, 'different path name');
promise_test(function(t) {
return init(document, t)
.then(function(iframes) {
var subjectNavigation = when(iframes[0].contentWindow, 'beforeunload');
var controlNavigation = when(iframes[1].contentWindow, 'beforeunload');
iframes[0].src = location.href;
iframes[1].src = '/common/blank.html?4';
return Promise.race([
subjectNavigation.then(function() {
assert_unreached('Should not navigate');
}),
controlNavigation
]);
});
}, 'same path name, no document fragment');
promise_test(function(t) {
return init(document, t)
.then(function(iframes) {
var subjectNavigation = when(iframes[0].contentWindow, 'beforeunload');
var controlNavigation = when(iframes[1].contentWindow, 'beforeunload');
iframes[0].src = location.href + '#something-else';
iframes[1].src = '/common/blank.html?5';
return Promise.race([
subjectNavigation.then(function() {
assert_unreached('Should not navigate');
}),
controlNavigation
]);
});
}, 'same path name, different document fragment');
promise_test(function(t) {
var intermediate = document.createElement('iframe');
document.body.appendChild(intermediate);
t.add_cleanup(function() {
intermediate.parentNode.removeChild(intermediate);
});
intermediate.contentDocument.open();
intermediate.contentDocument.write('<body></body>');
intermediate.contentDocument.close();
return init(intermediate.contentDocument, t)
.then(function(iframes) {
var subjectNavigation = when(iframes[0].contentWindow, 'beforeunload');
var controlNavigation = when(iframes[1].contentWindow, 'beforeunload');
iframes[0].src = location.href;
iframes[1].src = '/common/blank.html?6';
return Promise.race([
subjectNavigation.then(function() {
assert_unreached('Should not navigate');
}),
controlNavigation
]);
});
}, 'same path name, no document fragement (intermediary browsing context)');
</script>
</body>