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