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 <?xml version="1.0"?>
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
5 <window title="Key Tests"
6 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
8 <script type="application/javascript"
9 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
10 <script type="application/javascript"
11 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
13 <script>
14 <![CDATA[
16 SimpleTest.waitForExplicitFinish();
18 var gExpected = null;
20 var keysToTest = [
21 ["k-v", "V", { } ],
22 ["", "V", { shiftKey: true } ],
23 ["k-v-scy", "V", { ctrlKey: true } ],
24 ["", "V", { altKey: true } ],
25 ["", "V", { metaKey: true } ],
26 ["", "V", { osKey: true } ],
27 ["k-v-scy", "V", { shiftKey: true, ctrlKey: true } ],
28 ["", "V", { shiftKey: true, ctrlKey: true, altKey: true } ],
29 ["k-e-y", "E", { } ],
30 ["", "E", { shiftKey: true } ],
31 ["", "E", { ctrlKey: true } ],
32 ["", "E", { altKey: true } ],
33 ["", "E", { metaKey: true } ],
34 ["", "E", { osKey: true } ],
35 ["k-d-a", "D", { altKey: true } ],
36 ["k-8-m", "8", { metaKey: true } ],
37 ["", "8", { metaKey: true, osKey: true } ],
38 ["k-a-o", "A", { osKey: true } ],
39 ["", "A", { osKey: true, metaKey: true } ],
40 ["k-b-myo", "B", { osKey: true } ],
41 ["k-b-myo", "B", { osKey: true, metaKey: true } ],
42 ["k-f-oym", "F", { metaKey: true } ],
43 ["k-f-oym", "F", { metaKey: true, osKey: true } ],
44 ["k-c-scaym", "C", { metaKey: true } ],
45 ["k-c-scaym", "C", { shiftKey: true, ctrlKey: true, altKey: true, metaKey: true } ],
46 ["", "V", { shiftKey: true, ctrlKey: true, altKey: true } ],
47 ["k-h-l", "H", { accelKey: true } ],
48 // ["k-j-s", "J", { accessKey: true } ],
49 ["", "T", { } ],
50 ["scommand", "Y", { } ],
51 ["", "U", { } ],
52 ];
54 function runTest()
55 {
56 iterateKeys(true, "normal");
58 var keyset = document.getElementById("keyset");
59 keyset.setAttribute("disabled", "true");
60 iterateKeys(false, "disabled");
62 var keyset = document.getElementById("keyset");
63 keyset.removeAttribute("disabled");
64 iterateKeys(true, "reenabled");
66 keyset.parentNode.removeChild(keyset);
67 iterateKeys(false, "removed");
69 document.documentElement.appendChild(keyset);
70 iterateKeys(true, "appended");
72 var accelText = function(menuitem) menuitem.getAttribute("acceltext").toLowerCase();
74 $("menubutton").open = true;
76 // now check if a menu updates its accelerator text when a key attribute is changed
77 var menuitem1 = $("menuitem1");
78 ok(accelText(menuitem1).indexOf("d") >= 0, "menuitem1 accelText before");
79 if (navigator.platform.indexOf("Win") != -1) {
80 ok(accelText(menuitem1).indexOf("alt") >= 0, "menuitem1 accelText modifier before");
81 }
83 menuitem1.setAttribute("key", "k-s-c");
84 ok(accelText(menuitem1).indexOf("s") >= 0, "menuitem1 accelText after");
85 if (navigator.platform.indexOf("Win") != -1) {
86 ok(accelText(menuitem1).indexOf("ctrl") >= 0, "menuitem1 accelText modifier after");
87 }
89 menuitem1.setAttribute("acceltext", "custom");
90 is(accelText(menuitem1), "custom", "menuitem1 accelText set custom");
91 menuitem1.removeAttribute("acceltext");
92 ok(accelText(menuitem1).indexOf("s") >= 0, "menuitem1 accelText remove");
93 if (navigator.platform.indexOf("Win") != -1) {
94 ok(accelText(menuitem1).indexOf("ctrl") >= 0, "menuitem1 accelText modifier remove");
95 }
97 var menuitem2 = $("menuitem2");
98 is(accelText(menuitem2), "", "menuitem2 accelText before");
99 menuitem2.setAttribute("key", "k-s-c");
100 ok(accelText(menuitem2).indexOf("s") >= 0, "menuitem2 accelText before");
101 if (navigator.platform.indexOf("Win") != -1) {
102 ok(accelText(menuitem2).indexOf("ctrl") >= 0, "menuitem2 accelText modifier before");
103 }
105 menuitem2.setAttribute("key", "k-h-l");
106 ok(accelText(menuitem2).indexOf("h") >= 0, "menuitem2 accelText after");
107 if (navigator.platform.indexOf("Win") != -1) {
108 ok(accelText(menuitem2).indexOf("ctrl") >= 0, "menuitem2 accelText modifier after");
109 }
111 menuitem2.removeAttribute("key");
112 is(accelText(menuitem2), "", "menuitem2 accelText after remove");
114 $("menubutton").open = false;
116 window.close();
117 window.opener.wrappedJSObject.SimpleTest.finish();
118 }
120 function iterateKeys(enabled, testid)
121 {
122 for (var k = 0; k < keysToTest.length; k++) {
123 gExpected = keysToTest[k];
124 var expectedKey = gExpected[0];
125 if (!gExpected[2].accessKey || navigator.platform.indexOf("Mac") == -1) {
126 synthesizeKey(gExpected[1], gExpected[2]);
127 ok((enabled && expectedKey) || expectedKey == "k-d-a" ?
128 !gExpected : gExpected, testid + " key step " + (k + 1));
129 }
130 }
131 }
133 function checkKey(event)
134 {
135 // the first element of the gExpected array holds the id of the <key> element
136 // that was expected. If this is empty, a handler wasn't expected to be called
137 if (gExpected[0])
138 is(event.originalTarget.id, gExpected[0], "key " + gExpected[1]);
139 else
140 is("key " + event.originalTarget.id + " was activated", "", "key " + gExpected[1]);
141 gExpected = null;
142 }
144 function is(l, r, n) { window.opener.wrappedJSObject.SimpleTest.is(l,r,n); }
145 function ok(v, n) { window.opener.wrappedJSObject.SimpleTest.ok(v,n); }
147 SimpleTest.waitForFocus(runTest);
149 ]]>
150 </script>
152 <command id="scommand" oncommand="checkKey(event)"/>
153 <command id="scommand-disabled" disabled="true"/>
155 <keyset id="keyset">
156 <key id="k-v" key="v" oncommand="checkKey(event)"/>
157 <key id="k-v-scy" key="v" modifiers="shift any control" oncommand="checkKey(event)"/>
158 <key id="k-e-y" key="e" modifiers="any" oncommand="checkKey(event)"/>
159 <key id="k-8-m" key="8" modifiers="meta" oncommand="checkKey(event)"/>
160 <key id="k-a-o" key="a" modifiers="os" oncommand="checkKey(event)"/>
161 <key id="k-b-myo" key="b" modifiers="meta any os" oncommand="checkKey(event)"/>
162 <key id="k-f-oym" key="f" modifiers="os any meta" oncommand="checkKey(event)"/>
163 <key id="k-c-scaym" key="c" modifiers="shift control alt any meta" oncommand="checkKey(event)"/>
164 <key id="k-h-l" key="h" modifiers="accel" oncommand="checkKey(event)"/>
165 <key id="k-j-s" key="j" modifiers="access" oncommand="checkKey(event)"/>
166 <key id="k-t-y" disabled="true" key="t" oncommand="checkKey(event)"/>
167 <key id="k-y" key="y" command="scommand"/>
168 <key id="k-u" key="u" command="scommand-disabled"/>
169 </keyset>
171 <keyset id="keyset2">
172 <key id="k-d-a" key="d" modifiers="alt" oncommand="checkKey(event)"/>
173 <key id="k-s-c" key="s" modifiers="control" oncommand="checkKey(event)"/>
174 </keyset>
176 <button id="menubutton" label="Menu" type="menu">
177 <menupopup>
178 <menuitem id="menuitem1" label="Item 1" key="k-d-a"/>
179 <menuitem id="menuitem2" label="Item 2"/>
180 </menupopup>
181 </button>
183 <body xmlns="http://www.w3.org/1999/xhtml">
184 <p id="display">
185 </p>
186 <div id="content" style="display: none">
187 </div>
188 <pre id="test">
189 </pre>
190 </body>
192 </window>