toolkit/content/tests/chrome/bug451540_window.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <?xml version="1.0"?>
michael@0 2
michael@0 3 <!-- This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 - License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
michael@0 6
michael@0 7 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
michael@0 8
michael@0 9 <window id="451540test"
michael@0 10 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
michael@0 11 width="600"
michael@0 12 height="600"
michael@0 13 title="451540 test">
michael@0 14
michael@0 15 <script type="application/javascript"><![CDATA[
michael@0 16 const Ci = Components.interfaces;
michael@0 17 const Cc = Components.classes;
michael@0 18 const Cr = Components.results;
michael@0 19 const SEARCH_TEXT = "minefield";
michael@0 20
michael@0 21 var gFindBar = null;
michael@0 22 var gBrowser;
michael@0 23
michael@0 24 var sendCtrl = true;
michael@0 25 var sendMeta = false;
michael@0 26 if (navigator.platform.indexOf("Mac") >= 0) {
michael@0 27 sendCtrl = false;
michael@0 28 sendMeta = true;
michael@0 29 }
michael@0 30
michael@0 31 var imports = [ "SimpleTest", "ok"];
michael@0 32 for each (var name in imports) {
michael@0 33 window[name] = window.opener.wrappedJSObject[name];
michael@0 34 }
michael@0 35
michael@0 36
michael@0 37 function finishTest() {
michael@0 38 window.close();
michael@0 39 SimpleTest.finish();
michael@0 40 }
michael@0 41
michael@0 42 function startTest() {
michael@0 43 gFindBar = document.getElementById("FindToolbar");
michael@0 44 gBrowser = document.getElementById("content");
michael@0 45 gBrowser.addEventListener("pageshow", onPageShow, false);
michael@0 46 var data = 'data:text/html,<input id="inp" type="text" />';
michael@0 47 data +='<textarea id="tarea"/>'
michael@0 48 gBrowser.loadURI(data);
michael@0 49 }
michael@0 50
michael@0 51 function goToStartOfLine(aElement) {
michael@0 52 if (navigator.platform.indexOf("Mac") >= 0) {
michael@0 53 synthesizeKey(aElement, true, KeyEvent.DOM_VK_LEFT,
michael@0 54 false, false, true);
michael@0 55 } else {
michael@0 56 synthesizeKey(aElement, true, KeyEvent.DOM_VK_HOME,
michael@0 57 false, false, false);
michael@0 58 }
michael@0 59 }
michael@0 60
michael@0 61 function resetForNextTest(aElement, aText) {
michael@0 62 if (!aText)
michael@0 63 aText = SEARCH_TEXT;
michael@0 64
michael@0 65 // Turn off highlighting
michael@0 66 var highlightButton = gFindBar.getElement("highlight");
michael@0 67 if (highlightButton.checked)
michael@0 68 highlightButton.click();
michael@0 69
michael@0 70 // Initialise input
michael@0 71 aElement.value = aText;
michael@0 72 gFindBar._findField.value = SEARCH_TEXT;
michael@0 73
michael@0 74 // Perform search and turn on highlighting
michael@0 75 gFindBar._find();
michael@0 76 highlightButton.click();
michael@0 77
michael@0 78 // Move caret to start of element
michael@0 79 aElement.focus();
michael@0 80 goToStartOfLine(aElement);
michael@0 81 }
michael@0 82
michael@0 83 function synthesizeKey(target, isKeyCode, key, ctlKey, shiftKey, metaKey) {
michael@0 84 try {
michael@0 85 var event = document.createEvent("KeyEvents");
michael@0 86 if (isKeyCode) {
michael@0 87 event.initKeyEvent("keypress", true, true, null, ctlKey, false,
michael@0 88 shiftKey, metaKey, key, 0);
michael@0 89 } else {
michael@0 90 event.initKeyEvent("keypress", true, true, null, ctlKey, false,
michael@0 91 shiftKey, metaKey, 0, key);
michael@0 92 }
michael@0 93 target.dispatchEvent(event);
michael@0 94 } catch (e) {}
michael@0 95 }
michael@0 96
michael@0 97 function testInput(aElement, aTestTypeText) {
michael@0 98 // Initialise the findbar
michael@0 99 var matchCase = gFindBar.getElement("find-case-sensitive");
michael@0 100 if (matchCase.checked)
michael@0 101 matchCase.doCommand();
michael@0 102
michael@0 103 // First check match has been correctly highlighted
michael@0 104 resetForNextTest(aElement);
michael@0 105 if (aElement instanceof Ci.nsIDOMNSEditableElement) {
michael@0 106 var controller = aElement.editor.selectionController;
michael@0 107 var selection = controller.getSelection(controller.SELECTION_FIND);
michael@0 108 ok(selection.rangeCount == 1, aTestTypeText +
michael@0 109 " correctly highlighted match");
michael@0 110
michael@0 111 // Test 2: check highlight removed when text added within the highlight
michael@0 112 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
michael@0 113 false, false, false);
michael@0 114 synthesizeKey(aElement, false, KeyEvent.DOM_VK_A,
michael@0 115 false, false, false);
michael@0 116 ok(selection.rangeCount == 0, aTestTypeText +
michael@0 117 " correctly removed highlight on text insertion");
michael@0 118
michael@0 119 // Test 3: check highlighting remains when text added before highlight
michael@0 120 resetForNextTest(aElement);
michael@0 121 synthesizeKey(aElement, false, KeyEvent.DOM_VK_A,
michael@0 122 false, false, false);
michael@0 123 ok(selection.rangeCount == 1, aTestTypeText +
michael@0 124 " highlight correctly remained on text insertion at start");
michael@0 125
michael@0 126 // Test 4: check highlighting remains when text added after highlight
michael@0 127 resetForNextTest(aElement);
michael@0 128 for (var x = 0; x < SEARCH_TEXT.length; x++)
michael@0 129 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
michael@0 130 false, false, false);
michael@0 131 synthesizeKey(aElement, false, KeyEvent.DOM_VK_A,
michael@0 132 false, false, false);
michael@0 133 ok(selection.rangeCount == 1, aTestTypeText +
michael@0 134 " highlight correctly remained on text insertion at end");
michael@0 135
michael@0 136 // Test 5: deleting text within the highlight
michael@0 137 resetForNextTest(aElement);
michael@0 138 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
michael@0 139 false, false, false);
michael@0 140 synthesizeKey(aElement, true, KeyEvent.DOM_VK_BACK_SPACE,
michael@0 141 false, false, false);
michael@0 142 ok(selection.rangeCount == 0, aTestTypeText +
michael@0 143 " correctly removed highlight on text deletion");
michael@0 144
michael@0 145 // Test 6: deleting text at end of highlight
michael@0 146 resetForNextTest(aElement, SEARCH_TEXT+"A");
michael@0 147 for (var x = 0; x < aElement.value.length; x++)
michael@0 148 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
michael@0 149 false, false, false);
michael@0 150 synthesizeKey(aElement, true, KeyEvent.DOM_VK_BACK_SPACE,
michael@0 151 false, false, false);
michael@0 152 ok(selection.rangeCount == 1, aTestTypeText +
michael@0 153 " highlight correctly remained on text deletion at end");
michael@0 154
michael@0 155 // Test 7: deleting text at start of highlight
michael@0 156 resetForNextTest(aElement, "A"+SEARCH_TEXT);
michael@0 157 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
michael@0 158 false, false, false);
michael@0 159 synthesizeKey(aElement, true, KeyEvent.DOM_VK_BACK_SPACE,
michael@0 160 false, false, false);
michael@0 161 ok(selection.rangeCount == 1, aTestTypeText +
michael@0 162 " highlight correctly remained on text deletion at start");
michael@0 163
michael@0 164 // Test 8: deleting selection
michael@0 165 resetForNextTest(aElement);
michael@0 166 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
michael@0 167 false, true, false);
michael@0 168 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
michael@0 169 false, true, false);
michael@0 170 synthesizeKey(aElement, false, KeyEvent.DOM_VK_X,
michael@0 171 sendCtrl, false, sendMeta);
michael@0 172 ok(selection.rangeCount == 0, aTestTypeText +
michael@0 173 " correctly removed highlight on selection deletion");
michael@0 174
michael@0 175 // Test 9: Multiple matches within one editor (part 1)
michael@0 176 // Check second match remains highlighted after inserting text into
michael@0 177 // first match, and that its highlighting gets removed when the
michael@0 178 // second match is edited
michael@0 179 resetForNextTest(aElement, SEARCH_TEXT + " " + SEARCH_TEXT);
michael@0 180 ok(selection.rangeCount == 2, aTestTypeText +
michael@0 181 " correctly highlighted both matches");
michael@0 182 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
michael@0 183 false, false, false);
michael@0 184 synthesizeKey(aElement, false, KeyEvent.DOM_VK_A,
michael@0 185 false, false, false);
michael@0 186 ok(selection.rangeCount == 1, aTestTypeText +
michael@0 187 " correctly removed only the first highlight on text insertion");
michael@0 188 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
michael@0 189 sendCtrl, false, sendMeta);
michael@0 190 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
michael@0 191 sendCtrl, false, sendMeta);
michael@0 192 synthesizeKey(aElement, true, KeyEvent.DOM_VK_LEFT,
michael@0 193 false, false, false);
michael@0 194 synthesizeKey(aElement, false, KeyEvent.DOM_VK_A,
michael@0 195 false, false, false);
michael@0 196 ok(selection.rangeCount == 0, aTestTypeText +
michael@0 197 " correctly removed second highlight on text insertion");
michael@0 198
michael@0 199 // Test 10: Multiple matches within one editor (part 2)
michael@0 200 // Check second match remains highlighted after deleting text in
michael@0 201 // first match, and that its highlighting gets removed when the
michael@0 202 // second match is edited
michael@0 203 resetForNextTest(aElement, SEARCH_TEXT + " " + SEARCH_TEXT);
michael@0 204 ok(selection.rangeCount == 2, aTestTypeText +
michael@0 205 " correctly highlighted both matches");
michael@0 206 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
michael@0 207 false, false, false);
michael@0 208 synthesizeKey(aElement, true, KeyEvent.DOM_VK_BACK_SPACE,
michael@0 209 false, false, false);
michael@0 210 ok(selection.rangeCount == 1, aTestTypeText +
michael@0 211 " correctly removed only the first highlight on text deletion");
michael@0 212 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
michael@0 213 sendCtrl, false, sendMeta);
michael@0 214 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
michael@0 215 sendCtrl, false, sendMeta);
michael@0 216 synthesizeKey(aElement, true, KeyEvent.DOM_VK_LEFT,
michael@0 217 false, false, false);
michael@0 218 synthesizeKey(aElement, true, KeyEvent.DOM_VK_BACK_SPACE,
michael@0 219 false, false, false);
michael@0 220 ok(selection.rangeCount == 0, aTestTypeText +
michael@0 221 " correctly removed second highlight on text deletion");
michael@0 222
michael@0 223 // Test 11: Multiple matches within one editor (part 3)
michael@0 224 // Check second match remains highlighted after deleting selection
michael@0 225 // in first match, and that second match highlighting gets correctly
michael@0 226 // removed when it has a selection deleted from it
michael@0 227 resetForNextTest(aElement, SEARCH_TEXT + " " + SEARCH_TEXT);
michael@0 228 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
michael@0 229 false, true, false);
michael@0 230 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
michael@0 231 false, true, false);
michael@0 232 synthesizeKey(aElement, false, KeyEvent.DOM_VK_X,
michael@0 233 sendCtrl, false, sendMeta);
michael@0 234 ok(selection.rangeCount == 1, aTestTypeText +
michael@0 235 " correctly removed only first highlight on selection deletion");
michael@0 236 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
michael@0 237 sendCtrl, false, sendMeta);
michael@0 238 synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
michael@0 239 sendCtrl, false, sendMeta);
michael@0 240 synthesizeKey(aElement, true, KeyEvent.DOM_VK_LEFT,
michael@0 241 false, true, false);
michael@0 242 synthesizeKey(aElement, true, KeyEvent.DOM_VK_LEFT,
michael@0 243 false, true, false);
michael@0 244 synthesizeKey(aElement, false, KeyEvent.DOM_VK_X,
michael@0 245 sendCtrl, false, sendMeta);
michael@0 246 ok(selection.rangeCount == 0, aTestTypeText +
michael@0 247 " correctly removed second highlight on selection deletion");
michael@0 248 }
michael@0 249 }
michael@0 250
michael@0 251 function onPageShow() {
michael@0 252 gBrowser.removeEventListener("load", onPageShow, true);
michael@0 253 gBrowser.contentWindow.focus();
michael@0 254 gFindBar.open();
michael@0 255 var input = gBrowser.contentDocument.getElementById("inp");
michael@0 256 testInput(input, "Input:");
michael@0 257 var textarea = gBrowser.contentDocument.getElementById("tarea");
michael@0 258 testInput(textarea, "Textarea:");
michael@0 259 finishTest();
michael@0 260 }
michael@0 261
michael@0 262 SimpleTest.waitForFocus(startTest, window);
michael@0 263 ]]></script>
michael@0 264
michael@0 265 <browser type="content-primary" flex="1" id="content" src="about:blank"/>
michael@0 266 <findbar id="FindToolbar" browserid="content"/>
michael@0 267 </window>

mercurial