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=260264
5 -->
6 <head>
7 <title>Test for Bug 260264</title>
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
10 <script type="application/javascript" src="utils_bug260264.js"></script>
11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
12 </head>
13 <body>
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=260264">Mozilla Bug 260264</a>
15 <p id="display">
16 <a id="link" href="javascript:(function(){})()">link</a>
17 </p>
18 <div id="content" style="display: none">
20 </div>
21 <pre id="test">
22 <script type="application/javascript">
24 /** Test for Bug 260264 **/
26 SimpleTest.waitForExplicitFinish();
28 /**
29 * These functions can be called without arguments to retrieve the current
30 * value of the preference/privilege, or called with a single argument to set
31 * the preference/privilege to a new value.
32 *
33 * In other words, they obey the interface that |hold| expects its |accessor|
34 * parameter to obey.
35 */
36 var popupMax = makePrefAccessor("dom.popup_maximum"),
37 popupEvents = makePrefAccessor("dom.popup_allowed_events"),
38 blockPopups = makePrefAccessor("dom.disable_open_during_load"),
39 ownPopupPriv = makePopupPrivAccessor(location.href);
41 var a = $("link"),
42 checkOpened = function() { ok(window.open("http://example.com"), "not properly opened") },
43 checkBlocked = function() { ok(!window.open("http://example.com"), "not properly blocked") };
45 /**
46 * Intentional popups are not limited by dom.popup_maximum.
47 */
48 function testIntentional(event) {
49 hold(popupMax, 3, function() {
50 send(a, event, checkOpened);
51 send(a, event, checkOpened);
52 send(a, event, checkOpened);
53 send(a, event, checkOpened);
54 });
55 window.open.close();
56 }
58 /**
59 * Probably-intentional popups are limited only by dom.popup_maximum, and
60 * closing the popup window immediately allows another to open.
61 */
62 function testProbablyIntentional(event) {
63 var max = 3;
64 hold(popupMax, max, function() {
65 for (var count = 0, n = 0; n < max; n++)
66 send(a, event, function() { if (window.open("http://example.com")) count++ });
67 send(a, event, checkBlocked);
68 window.open.close(1);
69 send(a, event, checkOpened);
70 send(a, event, checkBlocked);
71 send(a, event, checkBlocked);
72 window.open.close();
73 ok(count > 0, "Windows left open by previous tests?");
74 while (count --> 0)
75 send(a, event, checkOpened);
76 send(a, event, checkBlocked);
77 });
78 window.open.close();
79 }
81 /**
82 * Probably-unintentional popups are forbidden entirely.
83 */
84 function testProbablyUnintentional(event) {
85 hold(popupMax, 2, function() {
86 send(a, event, checkBlocked);
87 });
88 window.open.close();
89 }
91 /**
92 * Please be patient; run_tests opens/closes a LOT of windows.
93 */
94 function run_tests() {
95 hold(popupEvents, "click mouseup", function() {
96 // Note: UNKNOWN_ACTION is the same as DENY_ACTION.
97 hold(ownPopupPriv, DENY_ACTION, function() {
98 testIntentional("click");
99 testProbablyIntentional("mouseup");
100 testProbablyUnintentional("mouseover");
101 });
102 hold(ownPopupPriv, ALLOW_ACTION, function() {
103 testIntentional("click");
104 testIntentional("mouseup");
105 testProbablyIntentional("mouseover");
106 });
107 });
109 hold(popupEvents, "click", function() {
110 // Note: UNKNOWN_ACTION is the same as DENY_ACTION.
111 hold(ownPopupPriv, DENY_ACTION, function() {
112 testIntentional("click");
113 testProbablyUnintentional("mouseup");
114 testProbablyUnintentional("mouseover");
115 });
116 hold(ownPopupPriv, ALLOW_ACTION, function() {
117 testIntentional("click");
118 testProbablyIntentional("mouseup");
119 testProbablyIntentional("mouseover");
120 });
121 });
123 window.open.close(); // just in case
124 }
126 function check_sanity() {
127 hold(ownPopupPriv, UNKNOWN_ACTION, function(unknown) {
128 hold(ownPopupPriv, ALLOW_ACTION, function(allow) {
129 is(ownPopupPriv(), allow, "properly set to allow");
130 });
131 is(ownPopupPriv(), unknown, "properly reset to unknown");
132 });
133 }
135 setTimeout(function() {
136 check_sanity();
137 hold(blockPopups, true, run_tests);
138 SimpleTest.finish();
139 }, 200);
141 </script>
142 </pre>
143 </body>
144 </html>