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"?>
4 <!--
5 XUL Widget Test for search textbox
6 -->
7 <window title="Search textbox test" width="500" height="600"
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
10 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
12 <hbox>
13 <textbox id="searchbox"
14 type="search"
15 oncommand="doSearch(this.value);"
16 placeholder="random placeholder"
17 timeout="1"/>
18 </hbox>
20 <!-- test results are displayed in the html:body -->
21 <body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/>
23 <!-- test code goes here -->
24 <script type="application/javascript"><![CDATA[
26 SimpleTest.waitForExplicitFinish();
28 var gExpectedValue;
29 var gLastTest;
31 function doTests() {
32 var textbox = $("searchbox");
33 var icons = document.getAnonymousElementByAttribute(textbox, "anonid", "search-icons");
34 var searchIcon = document.getAnonymousElementByAttribute(textbox, "class", "textbox-search-icon");
35 var clearIcon = document.getAnonymousElementByAttribute(textbox, "class", "textbox-search-clear");
37 ok(icons, "icon deck found");
38 ok(searchIcon, "search icon found");
39 ok(clearIcon, "clear icon found");
40 is(icons.selectedPanel, searchIcon, "search icon is displayed");
42 is(textbox.placeholder, "random placeholder", "search textbox supports placeholder");
43 is(textbox.value, "", "placeholder doesn't interfere with the real value");
45 function iconClick(aIcon) {
46 is(icons.selectedPanel, aIcon, aIcon.className + " icon must be displayed in order to be clickable");
48 //XXX synthesizeMouse worked on Linux but failed on Windows an Mac
49 // for unknown reasons. Manually dispatch the event for now.
50 //synthesizeMouse(aIcon, 0, 0, {});
52 var event = document.createEvent("MouseEvent");
53 event.initMouseEvent("click", true, true, window, 1,
54 0, 0, 0, 0,
55 false, false, false, false,
56 0, null);
57 aIcon.dispatchEvent(event);
58 }
60 iconClick(searchIcon);
61 is(textbox.getAttribute("focused"), "true", "clicking the search icon focuses the textbox");
63 textbox.value = "foo";
64 is(icons.selectedPanel, clearIcon, "clear icon is displayed when setting a value");
66 textbox.reset();
67 is(textbox.defaultValue, "", "defaultValue is empty");
68 is(textbox.value, "", "reset method clears the textbox");
69 is(icons.selectedPanel, searchIcon, "search icon is displayed after textbox.reset()");
71 textbox.value = "foo";
72 gExpectedValue = "";
73 iconClick(clearIcon);
74 is(textbox.value, "", "clicking the clear icon clears the textbox");
75 ok(gExpectedValue == null, "search triggered when clearing the textbox with the clear icon");
77 textbox.value = "foo";
78 gExpectedValue = "";
79 synthesizeKey("VK_ESCAPE", {});
80 is(textbox.value, "", "escape key clears the textbox");
81 ok(gExpectedValue == null, "search triggered when clearing the textbox with the escape key");
83 textbox.value = "bar";
84 gExpectedValue = "bar";
85 textbox.doCommand();
86 ok(gExpectedValue == null, "search triggered with doCommand");
88 gExpectedValue = "bar";
89 synthesizeKey("VK_RETURN", {});
90 ok(gExpectedValue == null, "search triggered with enter key");
92 textbox.value = "";
93 textbox.searchButton = true;
94 is(textbox.getAttribute("searchbutton"), "true", "searchbutton attribute set on the textbox");
95 is(searchIcon.getAttribute("searchbutton"), "true", "searchbutton attribute inherited to the search icon");
97 textbox.value = "foo";
98 is(icons.selectedPanel, searchIcon, "search icon displayed in search button mode if there's a value");
100 gExpectedValue = "foo";
101 iconClick(searchIcon);
102 ok(gExpectedValue == null, "search triggered when clicking the search icon in search button mode");
103 is(icons.selectedPanel, clearIcon, "clear icon displayed in search button mode after submitting");
105 synthesizeKey("o", {});
106 is(icons.selectedPanel, searchIcon, "search icon displayed in search button mode when typing a key");
108 gExpectedValue = "fooo";
109 iconClick(searchIcon); // display the clear icon (tested above)
111 textbox.value = "foo";
112 is(icons.selectedPanel, searchIcon, "search icon displayed in search button mode when the value is changed");
114 gExpectedValue = "foo";
115 synthesizeKey("VK_RETURN", {});
116 ok(gExpectedValue == null, "search triggered with enter key in search button mode");
117 is(icons.selectedPanel, clearIcon, "clear icon displayed in search button mode after submitting with enter key");
119 textbox.value = "x";
120 synthesizeKey("VK_BACK_SPACE", {});
121 is(icons.selectedPanel, searchIcon, "search icon displayed in search button mode when deleting the value with the backspace key");
123 gExpectedValue = "";
124 synthesizeKey("VK_RETURN", {});
125 ok(gExpectedValue == null, "search triggered with enter key in search button mode");
126 is(icons.selectedPanel, searchIcon, "search icon displayed in search button mode after submitting an empty string");
128 textbox.readOnly = true;
129 gExpectedValue = "foo";
130 textbox.value = "foo";
131 iconClick(searchIcon);
132 ok(gExpectedValue == null, "search triggered when clicking the search icon in search button mode while the textbox is read-only");
133 is(icons.selectedPanel, searchIcon, "search icon persists in search button mode after submitting while the textbox is read-only");
134 textbox.readOnly = false;
136 textbox.disabled = true;
137 is(searchIcon.getAttribute("disabled"), "true", "disabled attribute inherited to the search icon");
138 is(clearIcon.getAttribute("disabled"), "true", "disabled attribute inherited to the clear icon");
139 gExpectedValue = false;
140 textbox.value = "foo";
141 iconClick(searchIcon);
142 ok(gExpectedValue == false, "search *not* triggered when clicking the search icon in search button mode while the textbox is disabled");
143 is(icons.selectedPanel, searchIcon, "search icon persists in search button mode when trying to submit while the textbox is disabled");
144 textbox.disabled = false;
145 ok(!searchIcon.hasAttribute("disabled"), "disabled attribute removed from the search icon");
146 ok(!clearIcon.hasAttribute("disabled"), "disabled attribute removed from the clear icon");
148 textbox.searchButton = false;
149 ok(!textbox.hasAttribute("searchbutton"), "searchbutton attribute removed from the textbox");
150 ok(!searchIcon.hasAttribute("searchbutton"), "searchbutton attribute removed from the search icon");
152 gLastTest = true;
153 gExpectedValue = "123";
154 textbox.value = "1";
155 synthesizeKey("2", {});
156 synthesizeKey("3", {});
157 }
159 function doSearch(aValue) {
160 is(aValue, gExpectedValue, "search triggered with expected value");
161 gExpectedValue = null;
162 if (gLastTest)
163 SimpleTest.finish();
164 }
166 SimpleTest.waitForFocus(doTests);
168 ]]></script>
170 </window>