Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=369306
5 -->
6 <head>
7 <title>Test for Bug 369306</title>
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=369306">Mozilla Bug 369306</a>
14 <p id="display"></p>
15 <div id='content'>
16 </div>
17 <pre id="test">
18 <script type="application/javascript">
20 /** Test for Bug 369306 **/
22 var originatingWindow = self;
24 function focusShouldNotChange(aAction, nextTest)
25 {
26 var w = window.open('about:blank', '', 'foo');
27 var fail = false;
29 SimpleTest.waitForFocus(function () {
30 function failHandler() { fail = true; }
32 originatingWindow.addEventListener("focus", failHandler, false);
33 w.addEventListener("blur", failHandler, false);
35 aAction(w);
37 SimpleTest.executeSoon(function () {
38 originatingWindow.removeEventListener("focus", failHandler, false);
39 w.removeEventListener("blur", failHandler, false);
41 ok(!fail, "The focus should not have been changed!");
43 // Cleaning and running next test.
44 w.close();
45 SimpleTest.waitForFocus(nextTest, originatingWindow);
46 });
47 }, w, true);
48 }
50 function focusShouldNotChange2(aURL, nextTest)
51 {
52 var w = window.open(aURL, '', 'foo');
53 var fail = false;
55 SimpleTest.waitForFocus(function () {
56 function failHandler() { fail = true; }
58 originatingWindow.addEventListener("focus", failHandler, false);
59 w.addEventListener("blur", failHandler, false);
61 /**
62 * NOTE: This setTimeout can cause a random green.
63 * onload handler + executeSoon doesn't work too so we have to use setTimeout.
64 * The check may be call before w script being executed but that would make
65 * this check green even if it should be orange.
66 */
67 setTimeout(function () {
68 originatingWindow.removeEventListener("focus", failHandler, false);
69 w.removeEventListener("blur", failHandler, false);
71 ok(!fail, "The focus should not have been changed with URL=" + aURL);
73 // Cleaning and running next test.
74 w.close();
75 SimpleTest.waitForFocus(nextTest, originatingWindow);
76 }, 1000);
77 }, w);
78 }
80 function test1()
81 {
82 focusShouldNotChange(function (aW) { aW.blur(); }, test2);
83 }
85 function test2()
86 {
87 focusShouldNotChange(function () { originatingWindow.focus(); }, test3);
88 }
90 function test3()
91 {
92 focusShouldNotChange2("data:text/html,\<script>opener.focus();\<\/script>", test4);
93 }
95 function test4()
96 {
97 focusShouldNotChange2("data:text/html,\<script>blur();\<\/script>", test5);
98 }
100 function test5()
101 {
102 var w = window.open('about:blank', '', 'foo');
104 SimpleTest.waitForFocus(function () {
105 SimpleTest.waitForFocus(function () {
106 SimpleTest.waitForFocus(function () {
107 ok(true, "The last opened window should be able to get focus");
108 w.close();
109 SimpleTest.executeSoon(SimpleTest.finish);
110 }, w, true);
112 w.focus();
113 }, originatingWindow);
115 SimpleTest.executeSoon(function() {
116 // We have to focus back the originating window but we can't do that with
117 // .focus() or .blur() anymore.
118 SpecialPowers.focus(window);
119 });
120 }, w, true);
121 }
123 SimpleTest.waitForExplicitFinish();
126 function startTest() {
127 // dom.disable_window_flip has to be set to true for this test.
128 SpecialPowers.pushPrefEnv({"set": [["dom.disable_window_flip", true]]}, test1);
129 }
131 // startTest is going to call the next tests.
132 SimpleTest.waitForFocus(startTest);
134 </script>
135 </pre>
136 </body>
137 </html>