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=802557
5 -->
6 <head>
7 <meta charset="utf-8">
8 <title>Test for Bug 802557</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 802557 **/
14 SimpleTest.waitForExplicitFinish();
16 function checkThrows(fun, desc) {
17 try {
18 fun();
19 ok(false, "Didn't throw when " + desc);
20 } catch(e) {
21 ok(true, "Threw when " + desc + " " + e);
22 ok(/denied|insecure/.exec(e), "Should be security exception");
23 }
24 }
26 var loadCount = 0;
27 function go() {
28 ++loadCount;
29 window.ifr = document.getElementById('ifr');
30 window.iWin = ifr.contentWindow;
32 if (loadCount == 1) {
33 gLoc = iWin.location;
34 // Note that accessors pulled off Xrays are currently bound. This is bug 658909.
35 // [getter, description, locationObj, bound]
36 gGetters = [[ location.toString, 'toString from LW' ],
37 [ gLoc.toString, 'toString from XLW' ],
38 [ Location.prototype.toString, 'toString from Location.prototype' ],
39 [ iWin.Location.prototype.toString, 'toString from iWin.Location.prototype' ],
40 [ Object.__lookupGetter__.call(location, 'href'), 'href getter from LW' ],
41 [ Object.__lookupGetter__.call(gLoc, 'href'), 'href getter from XLW' ],
42 [ Object.getOwnPropertyDescriptor(Location.prototype, 'href').get, 'href getter from Location.prototype' ],
43 [ Object.getOwnPropertyDescriptor(iWin.Location.prototype, 'href').get, 'href getter from iWin.Location.prototype' ],
44 [ function() { return this + ''; }, 'implicit conversion via [[DefaultValue]]', /* doMessageCheck = */ true ]];
45 gGetters.forEach(function(item) {
46 try {
47 is(item[0].call(location), location.toString(), 'Same-origin LW: ' + item[1]);
48 is(item[0].call(gLoc), gLoc.toString(), 'Same-origin XLW: ' + item[1]);
49 } catch (e) {
50 ok(false, "Threw while applying " + item[1] + " to same-origin location object: " + e);
51 }
52 });
53 ifr.src = "http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html";
54 }
55 else if (loadCount == 2) {
56 gGetters.forEach(function(item) {
57 checkThrows(function() { item[0].call(gLoc); },
58 'call()ing ' + item[1] + ' after navigation cross-origin');
59 });
60 ifr.src = 'http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_bug802557.html';
61 }
62 else if (loadCount == 3) {
63 gTestFunctions = ifr.contentWindow.getAllTests();
64 var win = ifr.contentWindow;
65 for (fun in gTestFunctions)
66 is(gTestFunctions[fun](), win.location.toString(), "allowed via " + fun);
67 win.location = 'http://example.org/tests/js/xpconnect/tests/mochitest/file_bug802557.html';
68 }
69 else if (loadCount == 4) {
70 for (fun in gTestFunctions) {
71 var f = gTestFunctions[fun];
72 checkThrows(f, "calling " + fun);
73 }
74 SimpleTest.finish();
75 }
76 }
80 </script>
81 </head>
82 <body>
83 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=802557">Mozilla Bug 802557</a>
84 <p id="display"></p>
85 <div id="content" style="display: none">
87 </div>
88 <iframe id="ifr" onload="go();" src="file_empty.html"></iframe>
89 <pre id="test">
90 </pre>
91 </body>
92 </html>