Skip to content

Commit

Permalink
Add document.open() for new Base URL behaviour and add test.
Browse files Browse the repository at this point in the history
This CL fixes the inheritance behavior for about:srcdoc urls opened
using document.open('', '') run in the context of an about:srcdoc
frame.

This CL also adds a WPT test to verify that changes to a parent's
baseURI don't affect an about:srcdoc child whose srcdoc attribute
hasn't been set.

Bug: 1356658
Change-Id: I2f9f79a4ce0d136361fcdd8ed19312c4bd9c249d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4209048
Reviewed-by: Dominic Farolino <dom@chromium.org>
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: James Maclean <wjmaclean@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1116439}
  • Loading branch information
W. James MacLean authored and pull[bot] committed Jun 26, 2023
1 parent 1bc985f commit 1171407
Showing 1 changed file with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>

<script>
// If document.open's behavior is modified to remove the url-rewriting behavior,
// then this test can be deleted (https://github.com/whatwg/html/issues/3989).
setup({ explicit_done: true });

window.start = childDocument => {
const grandchildDocument =
childDocument.querySelector('iframe').contentDocument;

test(t => {
// Clean up the iframe so that the dangling document.open() doesn't cause a
// harness timeout.
t.add_cleanup(() => {
document.querySelector('iframe').remove();
});

assert_equals(childDocument.URL, 'about:srcdoc',
'Child document starting URL');
assert_equals(grandchildDocument.URL, 'about:blank',
'Grandchild document starting URL');
const originalChildBaseURL = childDocument.baseURI;

grandchildDocument.open("", "");
// Verify that the document.open() trick worked: the grandchild should now
// have the same url as the child, and have inherited the child's base url.
assert_equals(grandchildDocument.URL, 'about:srcdoc',
'Grandchild document after document.open() trick');
assert_equals(grandchildDocument.baseURI, originalChildBaseURL,
'Grandchild base URL must match child base URL');

// Give child a new base URL.
const baseElement = childDocument.createElement('base');
baseElement.href = get_host_info().REMOTE_ORIGIN;
childDocument.head.append(baseElement);

// Verify that changing the child's base url succeeded and did not affect
// the grandchild's base url.
const newChildBaseURL = childDocument.baseURI;
assert_equals(grandchildDocument.URL, 'about:srcdoc',
'Grandchild document after child gets new base URL');
assert_not_equals(newChildBaseURL, originalChildBaseURL,
'Child base URL must change');
assert_equals(grandchildDocument.baseURI, originalChildBaseURL,
'Grandchild base URL must not change');
});

done();
};
</script>

<iframe srcdoc="<iframe></iframe><script>parent.start(document)</script>">
</iframe>

0 comments on commit 1171407

Please sign in to comment.