summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/infrastructure/urls/base-url/document-base-url-changes-about-srcdoc-2.https.html
blob: dab8d2122b64aea58bd9de3d5872a77b307218a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>

<iframe src='about:blank'></iframe>

<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 });

// This function is called by directly by the child iframe (above), with the
// child iframe's document. The child iframe's document contains an about:srcdoc iframe.
window.start = childDocument => {
  const grandchildDocument =
    childDocument.getElementById('foo').contentDocument;

  test(() => {
    assert_equals(childDocument.URL, 'about:blank',
      'Child document starting URL');
    assert_equals(grandchildDocument.URL, 'about:srcdoc',
      '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:blank',
      '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:blank',
      '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();
};

let subframe_doc = document.querySelector('iframe').contentDocument;
subframe_doc.body.innerHTML = '<iframe srcdoc="foo" id="foo"></iframe>';
promise_test(async t => {
  const grandchildIframe = subframe_doc.querySelector('iframe');
  await new Promise(resolve => {
    grandchildIframe.onload = resolve;
  });

  assert_equals(grandchildIframe.contentDocument.URL, 'about:srcdoc');

  let script = subframe_doc.createElement('script');
  script.innerHTML = 'parent.start(document);';
  subframe_doc.body.appendChild(script);
}, "wrapper promise test for timeout.");
</script>