New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test for blocked iframe navigation #12290
Merged
bzbarsky
merged 3 commits into
web-platform-tests:master
from
bocoup:iframe-src-repeated
Aug 15, 2018
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
138 changes: 138 additions & 0 deletions
138
html/semantics/embedded-content/the-iframe-element/src-repeated-in-ancestor.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test doesn't have any test assertions. Is it just testing that loads generally work? If so, it's worth documenting that explicitly. But it's not very clear to me what this is trying to test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the other tests assert the same result, making me suspicious of test bugs. This test gives a little more confidence in the correctness of the utility functions. I'll add a comment explaining this.