summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/browsers/browsing-the-web/history-traversal/pageswap/pageswap-iframe.html
blob: 05ca1a942886a841852a6afdc9fba460eae950fd (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
<!DOCTYPE HTML>
<title>Tests pageswap dispatch on iframe Documents</title>
<link rel="author" title="Khushal Sagar"  href="mailto:khushalsagar@chromium.org">
<link rel="help" href="https://html.spec.whatwg.org/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script>
setup({explicit_done: true});

function runTest(frame) {
  let frameWindow = frame.contentWindow;

  let pageswapfired = false;
  let expectedUrl = frameWindow.location.href + '?new';
  frameWindow.onpageswap = (e) => {
      assert_equals(e.activation.entry.url, expectedUrl, 'activation url incorrect in pageswap');
      assert_equals(e.activation.navigationType, "push", 'navigation type incorrect in pageswap');
      assert_equals(e.activation.from, frameWindow.navigation.currentEntry, 'from entry incorrect in pageswap');
      assert_false(e.activation.entry.sameDocument, 'new entry must be cross-document');
      pageswapfired = true;
  }

  frameWindow.onpagehide = (e) => {
      assert_true(pageswapfired, 'pageswap not fired');
      done();
  }

  frame.src = expectedUrl;
}

promise_test(async t => {
  onload = () => {
    let frame = document.createElement('iframe');
    frame.src = "/resources/blank.html";
    frame.onload = () => {
      frame.contentWindow.requestAnimationFrame(() => {
        runTest(frame);
      });
    }
    document.body.appendChild(frame);
  };
});
</script>