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="Menu ignorekeys Test"
6 onkeydown="keyDown()"
7 onload="setTimeout(runTests, 0);"
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
10 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
11 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
13 <!--
14 This test checks that the ignorekeys attribute can be used on a menu to
15 disable key navigation. The test is performed twice by opening the menu,
16 simulating a cursor down key, and closing the popup. When keys are enabled,
17 the first item on the menu should be highlighted, otherwise the first item
18 should not be highlighted.
19 -->
21 <menupopup id="popup" onpopupshown="popupShown()" onpopuphidden="popupHidden()">
22 <menuitem id="i1" label="One" onDOMAttrModified="attrModified(event)"/>
23 <menuitem id="i2" label="Two"/>
24 <menuitem id="i3" label="Three"/>
25 <menuitem id="i4" label="Four"/>
26 </menupopup>
28 <script class="testbody" type="application/javascript">
29 <![CDATA[
31 SimpleTest.waitForExplicitFinish();
33 var gIgnoreKeys = false;
34 var gIgnoreAttrChange = false;
36 function runTests()
37 {
38 var popup = $("popup");
39 popup.enableKeyboardNavigator(false);
40 is(popup.getAttribute("ignorekeys"), "true", "keys disabled");
41 popup.enableKeyboardNavigator(true);
42 is(popup.hasAttribute("ignorekeys"), false, "keys enabled");
43 popup.openPopup(null, "after_start");
44 }
46 function popupShown()
47 {
48 synthesizeKey("VK_DOWN", { });
49 if (gIgnoreKeys) {
50 var popup = $("popup");
51 setTimeout(function() { popup.hidePopup() }, 1000);
52 }
53 }
55 function popupHidden()
56 {
57 if (gIgnoreKeys) {
58 SimpleTest.finish();
59 }
60 else {
61 // try the test again with ignorekeys set
62 gIgnoreKeys = true;
63 var popup = $("popup");
64 popup.setAttribute("ignorekeys", "true");
65 // clear this first to avoid confusion
66 gIgnoreAttrChange = true;
67 $("i1").removeAttribute("_moz-menuactive")
68 gIgnoreAttrChange = false;
69 popup.openPopup(null, "after_start");
70 }
71 }
73 function attrModified(event)
74 {
75 if (gIgnoreAttrChange || event.attrName != "_moz-menuactive")
76 return;
78 // the attribute should not be changed when ignorekeys is enabled
79 if (gIgnoreKeys) {
80 ok(false, "move key with keys disabled");
81 }
82 else {
83 is($("i1").getAttribute("_moz-menuactive"), "true", "move key with keys enabled");
84 $("popup").hidePopup();
85 }
86 }
88 function keyDown()
89 {
90 // when keys are enabled, the menu should have stopped propagation of the
91 // event, so a bubbling listener for a keydown event should only occur
92 // when keys are disabled.
93 ok(gIgnoreKeys, "key listener fired with keys " +
94 (gIgnoreKeys ? "disabled" : "enabled"));
95 }
97 ]]>
98 </script>
100 <body xmlns="http://www.w3.org/1999/xhtml">
101 <p id="display">
102 </p>
103 <div id="content" style="display: none">
104 </div>
105 <pre id="test">
106 </pre>
107 </body>
109 </window>