2 Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/
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;
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 },
37 window
.location
.pathname
.replace("test_third_party.html",
38 "third_party_iframe1.html");
40 "http://" + window
.location
.host
+
41 window
.location
.pathname
.replace("test_third_party.html",
42 "third_party_iframe2.html");
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({
52 ["network.cookie.cookieBehavior", testData
[testIndex
].cookieBehavior
],
55 openedWindow
= window
.open("third_party_window.html");
56 openedWindow
.onload
= _
=> {
57 openedWindow
.postMessage({
60 iframeUrl
: testData
[testIndex
].host
+ iframe1Path
,
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
);
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`);
85 ok(false, 'Test has already received a message from ${message.source}');
88 if (testFrames
.length
) {
94 if (testIndex
< testData
.length
- 1) {
95 testFrames
= ["iframe1", "iframe2"];
105 SimpleTest
.waitForExplicitFinish();
107 SpecialPowers
.addPermission("indexedDB", true, document
);
109 window
.addEventListener("message", messageListener
);
116 <body onload=
"runTest();">