toolkit/content/tests/chrome/test_textbox_search.xul

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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.

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

mercurial