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 | <?xml version="1.0"?> |
michael@0 | 2 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
michael@0 | 3 | <?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?> |
michael@0 | 4 | <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
michael@0 | 5 | |
michael@0 | 6 | <script type="application/javascript" |
michael@0 | 7 | src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 8 | <script type="application/javascript" |
michael@0 | 9 | src="/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 10 | <script type="application/javascript" |
michael@0 | 11 | src="/tests/SimpleTest/WindowSnapshot.js"></script> |
michael@0 | 12 | |
michael@0 | 13 | <html:style xmlns:html="http://www.w3.org/1999/xhtml" type="text/css"> |
michael@0 | 14 | * { outline: none; } |
michael@0 | 15 | #l1:-moz-focusring, #l3:-moz-focusring, #b1:-moz-focusring { outline: 2px solid red; } |
michael@0 | 16 | #l2:focus, #b2:focus { outline: 2px solid red; } |
michael@0 | 17 | </html:style> |
michael@0 | 18 | |
michael@0 | 19 | <script> |
michael@0 | 20 | <![CDATA[ |
michael@0 | 21 | |
michael@0 | 22 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 23 | |
michael@0 | 24 | function setOrRestoreTabFocus(newValue) { |
michael@0 | 25 | const prefSvcContractID = "@mozilla.org/preferences-service;1"; |
michael@0 | 26 | const prefSvcIID = SpecialPowers.Ci.nsIPrefService; |
michael@0 | 27 | var prefs = SpecialPowers.Cc[prefSvcContractID].getService(prefSvcIID) |
michael@0 | 28 | .getBranch("accessibility."); |
michael@0 | 29 | if (!newValue) { |
michael@0 | 30 | if (prefs.prefHasUserValue("tabfocus")) { |
michael@0 | 31 | prefs.clearUserPref("tabfocus"); |
michael@0 | 32 | } |
michael@0 | 33 | } else { |
michael@0 | 34 | prefs.setIntPref("tabfocus", newValue); |
michael@0 | 35 | } |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | function snapShot(element) { |
michael@0 | 39 | var rect = element.getBoundingClientRect(); |
michael@0 | 40 | adjustedRect = { left: rect.left - 6, top: rect.top - 6, |
michael@0 | 41 | width: rect.width + 12, height: rect.height + 12 } |
michael@0 | 42 | return SpecialPowers.snapshotRect(window, adjustedRect, "transparent"); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | function runTest() |
michael@0 | 46 | { |
michael@0 | 47 | setOrRestoreTabFocus(7); |
michael@0 | 48 | |
michael@0 | 49 | var isMac = (navigator.platform.indexOf("Mac") >= 0); |
michael@0 | 50 | var isWin = (navigator.platform.indexOf("Win") >= 0); |
michael@0 | 51 | |
michael@0 | 52 | function checkFocus(element, visible, testid) |
michael@0 | 53 | { |
michael@0 | 54 | var outline = getComputedStyle(element, "").outlineWidth; |
michael@0 | 55 | is(outline, visible ? "2px" : "0px", testid); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | // make sure that a focus ring appears on the focused button |
michael@0 | 59 | if (navigator.platform.indexOf("Mac") >= 0) { |
michael@0 | 60 | var focusedButton = $("b3"); |
michael@0 | 61 | ok(compareSnapshots(snapShot(focusedButton), snapShot($("b2")), true)[0], "unfocused shows no ring"); |
michael@0 | 62 | focusedButton.focus(); |
michael@0 | 63 | ok(compareSnapshots(snapShot(focusedButton), snapShot($("b2")), false)[0], "focus shows ring"); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | checkFocus($("l1"), false, "initial appearance"); |
michael@0 | 67 | |
michael@0 | 68 | // we can't really test the situation on Windows where a dialog doesn't show |
michael@0 | 69 | // focus rings until a key is pressed, as the default state depends on what |
michael@0 | 70 | // kind of real user input, mouse or key, was last entered. But we can handle |
michael@0 | 71 | // the test regardless of which user input last occurred. |
michael@0 | 72 | $("l1").focus(); |
michael@0 | 73 | var expectedVisible = (!isWin || getComputedStyle($("l1"), "").outlineWidth == "2px"); |
michael@0 | 74 | testHTMLElements(htmlElements, isMac, isWin && !expectedVisible); |
michael@0 | 75 | |
michael@0 | 76 | if (isMac) { |
michael@0 | 77 | var prefs = SpecialPowers.Cc["@mozilla.org/preferences-service;1"]. |
michael@0 | 78 | getService(SpecialPowers.Ci.nsIPrefBranch); |
michael@0 | 79 | prefs.setBoolPref("accessibility.mouse_focuses_formcontrol", true); |
michael@0 | 80 | |
michael@0 | 81 | testHTMLElements(htmlElementsMacPrefSet, true, false); |
michael@0 | 82 | |
michael@0 | 83 | prefs.setBoolPref("accessibility.mouse_focuses_formcontrol", false); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | $("l1").focus(); |
michael@0 | 87 | checkFocus($("l1"), expectedVisible, "appearance on list after focus() with :moz-focusring"); |
michael@0 | 88 | $("l2").focus(); |
michael@0 | 89 | |
michael@0 | 90 | checkFocus($("l2"), true, "appearance on list after focus() with :focus"); |
michael@0 | 91 | |
michael@0 | 92 | is(getComputedStyle($("l1"), "").outlineWidth, "0px", "appearance on previous list after focus() with :focus"); |
michael@0 | 93 | |
michael@0 | 94 | synthesizeMouse($("l1"), 4, 4, { }); |
michael@0 | 95 | checkFocus($("l1"), expectedVisible, "appearance on list after mouse focus with :moz-focusring"); |
michael@0 | 96 | synthesizeMouse($("l2"), 4, 4, { }); |
michael@0 | 97 | checkFocus($("l2"), true, "appearance on list after mouse focus with :focus"); |
michael@0 | 98 | |
michael@0 | 99 | synthesizeMouse($("b1"), 4, 4, { }); |
michael@0 | 100 | checkFocus($("b1"), !isMac && expectedVisible, "appearance on button after mouse focus with :moz-focusring"); |
michael@0 | 101 | if (navigator.platform.indexOf("Mac") >= 0) { |
michael@0 | 102 | ok(compareSnapshots(snapShot($("b1")), snapShot($("b2")), false)[0], "focus after mouse shows no ring"); |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | synthesizeMouse($("b2"), 4, 4, { }); |
michael@0 | 106 | checkFocus($("b2"), !isMac, "appearance on button after mouse focus with :focus"); |
michael@0 | 107 | |
michael@0 | 108 | // after a key is pressed, the focus ring will always be visible |
michael@0 | 109 | $("l2").focus(); |
michael@0 | 110 | synthesizeKey("VK_TAB", { }); |
michael@0 | 111 | checkFocus($("l3"), true, "appearance on list after tab focus"); |
michael@0 | 112 | |
michael@0 | 113 | setOrRestoreTabFocus(0); |
michael@0 | 114 | SimpleTest.finish(); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | var htmlElements = [ |
michael@0 | 118 | "<button id='elem'>Button</button>", |
michael@0 | 119 | "<input id='elem' class='canfocus'>", |
michael@0 | 120 | "<input id='elem' type='password' class='canfocus'>", |
michael@0 | 121 | "<input id='elem' type='button'>", |
michael@0 | 122 | "<input id='elem' type='checkbox'>", |
michael@0 | 123 | "<textarea id='elem' class='canfocus'></textarea>", |
michael@0 | 124 | "<select id='elem' class='canfocus'><option>One</select>", |
michael@0 | 125 | "<select id='elem' rows='5' class='canfocus'><option>One</select>", |
michael@0 | 126 | "<div id='elem' tabindex='0' class='canfocus' style='width: 10px; height: 10px;'></div>", |
michael@0 | 127 | "<a href='about:blank' class='canfocus' onclick='return false;'>about:blank</a>", |
michael@0 | 128 | ]; |
michael@0 | 129 | |
michael@0 | 130 | var htmlElementsMacPrefSet = [ |
michael@0 | 131 | "<button id='elem' class='canfocus'>Button</button>", |
michael@0 | 132 | "<input id='elem' class='canfocus'>", |
michael@0 | 133 | "<input id='elem' type='button' class='canfocus'>", |
michael@0 | 134 | "<input id='elem' type='checkbox' class='canfocus'>", |
michael@0 | 135 | ]; |
michael@0 | 136 | |
michael@0 | 137 | function testHTMLElements(list, isMac, expectedNoRingsOnWin) |
michael@0 | 138 | { |
michael@0 | 139 | var childwin = frames[0]; |
michael@0 | 140 | var childdoc = childwin.document; |
michael@0 | 141 | var container = childdoc.getElementById("container"); |
michael@0 | 142 | for (var e = 0; e < list.length; e++) { |
michael@0 | 143 | container.innerHTML = list[e]; |
michael@0 | 144 | |
michael@0 | 145 | var elem = container.firstChild; |
michael@0 | 146 | |
michael@0 | 147 | var shouldFocus = !isMac || (elem.className == "canfocus"); |
michael@0 | 148 | var ringSize = (shouldFocus ? (expectedNoRingsOnWin ? 2 : 1) : 0) + "px"; |
michael@0 | 149 | if (elem.localName == "a") |
michael@0 | 150 | ringSize = "0px"; |
michael@0 | 151 | |
michael@0 | 152 | synthesizeMouse(elem, 8, 8, { }, childwin); |
michael@0 | 153 | is(childdoc.activeElement, shouldFocus ? elem : childdoc.body, "mouse click on " + list[e]); |
michael@0 | 154 | is(childwin.getComputedStyle(elem, "").outlineWidth, ringSize, "mouse click on " + list[e] + " ring"); |
michael@0 | 155 | |
michael@0 | 156 | if (childdoc.activeElement) |
michael@0 | 157 | childdoc.activeElement.blur(); |
michael@0 | 158 | |
michael@0 | 159 | ringSize = (elem.localName == "a" ? "0" : (expectedNoRingsOnWin ? 2 : 1)) + "px"; |
michael@0 | 160 | |
michael@0 | 161 | elem.focus(); |
michael@0 | 162 | is(childdoc.activeElement, elem, "focus() on " + list[e]); |
michael@0 | 163 | is(childwin.getComputedStyle(elem, "").outlineWidth, ringSize, |
michael@0 | 164 | "focus() on " + list[e] + " ring"); |
michael@0 | 165 | |
michael@0 | 166 | childdoc.activeElement.blur(); |
michael@0 | 167 | } |
michael@0 | 168 | } |
michael@0 | 169 | |
michael@0 | 170 | SimpleTest.waitForFocus(runTest); |
michael@0 | 171 | |
michael@0 | 172 | ]]> |
michael@0 | 173 | </script> |
michael@0 | 174 | |
michael@0 | 175 | <listbox id="l1" class="plain" height="20"/> |
michael@0 | 176 | <listbox id="l2" class="plain" height="20"/> |
michael@0 | 177 | <listbox id="l3" class="plain" height="20"/> |
michael@0 | 178 | <button id="b1" label="Button"/> |
michael@0 | 179 | <button id="b2" label="Button"/> |
michael@0 | 180 | <button id="b3" label="Button"/> |
michael@0 | 181 | |
michael@0 | 182 | <iframe id="child" src="data:text/html,<html><style>* { outline: none; -moz-appearance: none; } %23elem:focus { outline: 2px solid red; } %23elem:-moz-focusring { outline: 1px solid blue; }</style><div id='container'></html>"/> |
michael@0 | 183 | |
michael@0 | 184 | <body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/> |
michael@0 | 185 | |
michael@0 | 186 | </window> |