Bug 1850713: remove duplicated setting of early hint preloader id in `ScriptLoader...
[gecko.git] / dom / indexedDB / test / test_third_party.html
blobee90de8dac6038e4040b690faa1cc526c85e95e7
1 <!--
2 Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/
4 -->
5 <html>
6 <head>
7 <title>Indexed Database Test</title>
9 <script src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
12 <script type="text/javascript">
13 const BEHAVIOR_ACCEPT = 0;
14 const BEHAVIOR_REJECTFOREIGN = 1;
15 const BEHAVIOR_REJECT = 2;
16 const BEHAVIOR_LIMITFOREIGN = 3;
18 const testData = [
19 { host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_ACCEPT, expectedResultFrame1: true, expectedResultFrame2: true },
20 { host: "http://example.com", cookieBehavior: BEHAVIOR_ACCEPT, expectedResultFrame1: true, expectedResultFrame2: true },
21 { host: "http://sub1.test2.example.org:8000", cookieBehavior: BEHAVIOR_ACCEPT, expectedResultFrame1: true, expectedResultFrame2: true },
23 { host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_REJECT, expectedResultFrame1: false, expectedResultFrame2: false },
24 { host: "http://example.com", cookieBehavior: BEHAVIOR_REJECT, expectedResultFrame1: false, expectedResultFrame2: false },
25 { host: "http://sub1.test2.example.org:8000", cookieBehavior: BEHAVIOR_REJECT, expectedResultFrame1: false, expectedResultFrame2: false },
27 { host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_REJECTFOREIGN, expectedResultFrame1: true, expectedResultFrame2: true },
28 { host: "http://example.com", cookieBehavior: BEHAVIOR_REJECTFOREIGN, expectedResultFrame1: false, expectedResultFrame2: true },
29 { host: "http://sub1.test2.example.org:8000", cookieBehavior: BEHAVIOR_REJECTFOREIGN, expectedResultFrame1: false, expectedResultFrame2: true },
31 { host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_LIMITFOREIGN, expectedResultFrame1: true, expectedResultFrame2: true },
32 { host: "http://example.com", cookieBehavior: BEHAVIOR_LIMITFOREIGN, expectedResultFrame1: false, expectedResultFrame2: true },
33 { host: "http://sub1.test2.example.org:8000", cookieBehavior: BEHAVIOR_LIMITFOREIGN, expectedResultFrame1: false, expectedResultFrame2: true },
36 const iframe1Path =
37 window.location.pathname.replace("test_third_party.html",
38 "third_party_iframe1.html");
39 const iframe2URL =
40 "http://" + window.location.host +
41 window.location.pathname.replace("test_third_party.html",
42 "third_party_iframe2.html");
44 let testIndex = 0;
45 let openedWindow;
47 // Cookie preference changes are only applied to top-level tabs/windows
48 // when they are loaded. We need a window-proxy to continue the test.
49 function openWindow() {
50 SpecialPowers.pushPrefEnv({
51 "set": [
52 ["network.cookie.cookieBehavior", testData[testIndex].cookieBehavior],
54 }, () => {
55 openedWindow = window.open("third_party_window.html");
56 openedWindow.onload = _ => {
57 openedWindow.postMessage({
58 source: "parent",
59 href: iframe2URL,
60 iframeUrl: testData[testIndex].host + iframe1Path,
61 }, "*");
63 });
66 let testFrames = ["iframe1", "iframe2"];
67 function messageListener(event) {
68 let message = JSON.parse(event.data);
70 // TODO: This is an ad-hoc solution to get a useful assertion message.
71 // It would be desirable that the test framework provides the ability
72 // to capture context information and provide it on assertion failures,
73 // automatically stringified.
74 let testContext = `testData[${testIndex}] == ${JSON.stringify(testData[testIndex])}`;
76 let idx = testFrames.indexOf(message.source);
77 if (idx != -1) {
78 testFrames.splice(idx, 1);
79 if (message.source == "iframe1") {
80 is(message.result, testData[testIndex].expectedResultFrame1, `Good result for ${testContext} iframe1`);
81 } else if (message.source == "iframe2") {
82 is(message.result, testData[testIndex].expectedResultFrame2, `Good result for ${testContext} iframe2`);
84 } else {
85 ok(false, 'Test has already received a message from ${message.source}');
88 if (testFrames.length) {
89 return;
92 openedWindow.close();
94 if (testIndex < testData.length - 1) {
95 testFrames = ["iframe1", "iframe2"];
96 testIndex++;
97 openWindow();
98 return;
101 SimpleTest.finish();
104 function runTest() {
105 SimpleTest.waitForExplicitFinish();
107 SpecialPowers.addPermission("indexedDB", true, document);
109 window.addEventListener("message", messageListener);
110 openWindow();
112 </script>
114 </head>
116 <body onload="runTest();">
117 </body>
119 </html>