Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=868996
5 -->
6 <head>
7 <meta charset="utf-8">
8 <title>Test for Bug 868996</title>
9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 <script type="application/javascript">
13 /** Test for Bug 868996 **/
14 SimpleTest.waitForExplicitFinish();
16 var sb1, sb2;
17 var Cu = SpecialPowers.Cu;
19 function testOpenerSet() {
20 // Use setTimeout to make the relevant onerror run in this window
21 var win = window.open("data:text/html,<script>opener.setTimeout(opener.basicOpenerTest, 0, this)</" + "script>");
22 // A sandbox for the window
23 sb1 = new Cu.Sandbox(win, {wantXrays: true })
24 sb1.win = win
25 // And a sandbox using the expanded principal.
26 sb2 = new Cu.Sandbox([win], {wantXrays: true })
27 sb2.win = win
28 }
30 function evalsb(str, sb) {
31 // Have to unwrap() to get objects we care about
32 return SpecialPowers.unwrap(Cu.evalInSandbox(str, sb));
33 }
35 function basicOpenerTest(win) {
36 is(win.opener, window, "Opening a window should give it the right opener");
37 is(evalsb("win.opener", sb1), window,
38 "Reading opener in sandbox 1 should work");
39 is(evalsb("win.opener", sb2), window,
40 "Reading opener in sandbox 2 should work");
42 win.opener = $("x").contentWindow;
43 evalsb("win.opener = win.opener.document.getElementById('y').contentWindow", sb1);
44 evalsb("win.opener = win.opener.document.getElementById('z').contentWindow", sb2);
46 is(win.opener, $("x").contentWindow, "Should be able to set an opener to a different window");
47 is(evalsb("win.opener", sb1), $("y").contentWindow,
48 "Should be able to set the opener to a different window in a sandbox one");
49 is(evalsb("win.opener", sb2), $("z").contentWindow,
50 "Should be able to set the opener to a different window in a sandbox two");
52 win.location = "data:text/html,<script>opener.setTimeout(opener.continueOpenerTest, 0, this);</" + "script>";
53 }
55 function continueOpenerTest(win) {
56 is(win.opener, window, "Navigating a window should have reset the opener we stashed on it temporarily");
57 is(evalsb("win.opener", sb1), window,
58 "Navigating a window should have reset the opener in sb1");
59 is(evalsb("win.opener", sb2), window,
60 "Navigating a window should have reset the opener in sb2");
62 win.opener = 5;
63 evalsb("win.opener = 5", sb1);
64 evalsb("win.opener = 5", sb2);
65 is(win.opener, 5, "Should be able to set an opener to a primitive");
66 is(evalsb("win.opener", sb1), 5,
67 "Should be able to set the opener to a primitive in a sandbox one");
68 is(evalsb("win.opener", sb2), 5,
69 "Should be able to set the opener to a primitive in a sandbox two");
70 win.location = "data:text/html,<script>opener.setTimeout(opener.continueOpenerTest2, 0, this);</" + "script>";
71 }
73 function continueOpenerTest2(win) {
74 is(win.opener, window,
75 "Navigating a window again should have reset the opener we stashed on it temporarily");
76 is(evalsb("win.opener", sb1), window,
77 "Navigating a window again should have reset the opener in sb1");
78 is(evalsb("win.opener", sb2), window,
79 "Navigating a window again should have reset the opener in sb2");
81 win.opener = null;
82 is(win.opener, null, "Should be able to set the opener to null");
83 is(evalsb("win.opener", sb1), null,
84 "Setting the opener to null should be visible in sb1");
85 is(evalsb("win.opener", sb2), null,
86 "Setting the opener to null should be visible in sb2");
88 win.location = "data:text/html,Loaded";
89 // Now poll for that load, since we have no way for the window to
90 // communicate with us now
91 setTimeout(checkForLoad, 0, win);
92 }
94 function checkForLoad(win) {
95 if (!win.document.documentElement ||
96 win.document.documentElement.textContent != "Loaded") {
97 setTimeout(checkForLoad, 0, win);
98 return;
99 }
101 is(win.opener, null, "Null opener should persist across navigations");
102 is(evalsb("win.opener", sb1), null,
103 "Null opener should persist across navigations in sb1");
104 is(evalsb("win.opener", sb2), null,
105 "Null opener should persist across navigations in sb2");
107 win.close();
108 SimpleTest.finish();
109 }
111 addLoadEvent(testOpenerSet);
112 </script>
113 </head>
114 <body>
115 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=868996">Mozilla Bug 868996</a>
116 <p id="display"></p>
117 <div id="content" style="display: none">
118 <iframe id="x"></iframe>
119 <iframe id="y"></iframe>
120 <iframe id="z"></iframe>
121 </div>
122 <pre id="test">
123 </pre>
124 </body>
125 </html>