summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/cross-origin-opener-policy/reporting/access-reporting/property-indexed-getter.https.html
blob: b6c5f5acb1f1a57205cec425e1feba35674d3c7d (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
<title> Check reports are sent for the indexed getter</title>
<meta name=timeout content=long>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/common/get-host-info.sub.js></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script>

const directory = "/html/cross-origin-opener-policy";
const executor_path = "/common/dispatcher/executor.html?pipe=";
const coep_header = '|header(Cross-Origin-Embedder-Policy,require-corp)';

let origin = [
  ["cross-origin" , get_host_info().HTTPS_REMOTE_ORIGIN ] ,
  ["same-site"    , get_host_info().HTTPS_ORIGIN        ] ,
];

let testCase = [
//[operation  , expectReport ] ,
  [w => w[0]  , true         ], // Existing iframe.
  [w => w[1]  , false        ], // Out of bounds (positive).
  [w => w[-1] , false        ], // Out of bounds (negative).
];

origin.forEach(([origin_name, origin]) => {
  testCase.forEach(([op, expectReport]) =>  {
    promise_test(async t => {
      const opener_token = token();
      const openee_token = token();

      const openee_url = origin+ executor_path + `&uuid=${openee_token}`;
      const openee = window.open(openee_url);
      t.add_cleanup(() => send(openee_token, "window.close()"))

      // 1. Create an iframe in the openee.
      send(openee_token, `
        let iframe = document.createElement("iframe");
        document.body.appendChild(iframe);

        send("${opener_token}", "openee loaded");
      `);
      let reply = await receive(opener_token);
      assert_equals(reply, "openee loaded");

      // 2. Try to access the openee.
      let observer = new ReportingObserver(()=>{});
      observer.observe();
      try {op(openee)} catch(e) {}
      let reports = observer.takeRecords();
      observer.disconnect();

      // 3. Check the received reports.
      if (expectReport) {
        assert_equals(reports.length, 1);
        assert_equals(reports[0].type, "coop-access-violation");
        assert_equals(reports[0].body.property, "indexed");
      } else {
        assert_equals(reports.length, 0);
      }

    }, `${origin_name} > ${op}`);
});
});

</script>