1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/tests/chrome/bug451540_window.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,267 @@ 1.4 +<?xml version="1.0"?> 1.5 + 1.6 +<!-- This Source Code Form is subject to the terms of the Mozilla Public 1.7 + - License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> 1.9 + 1.10 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.11 + 1.12 +<window id="451540test" 1.13 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.14 + width="600" 1.15 + height="600" 1.16 + title="451540 test"> 1.17 + 1.18 + <script type="application/javascript"><![CDATA[ 1.19 + const Ci = Components.interfaces; 1.20 + const Cc = Components.classes; 1.21 + const Cr = Components.results; 1.22 + const SEARCH_TEXT = "minefield"; 1.23 + 1.24 + var gFindBar = null; 1.25 + var gBrowser; 1.26 + 1.27 + var sendCtrl = true; 1.28 + var sendMeta = false; 1.29 + if (navigator.platform.indexOf("Mac") >= 0) { 1.30 + sendCtrl = false; 1.31 + sendMeta = true; 1.32 + } 1.33 + 1.34 + var imports = [ "SimpleTest", "ok"]; 1.35 + for each (var name in imports) { 1.36 + window[name] = window.opener.wrappedJSObject[name]; 1.37 + } 1.38 + 1.39 + 1.40 + function finishTest() { 1.41 + window.close(); 1.42 + SimpleTest.finish(); 1.43 + } 1.44 + 1.45 + function startTest() { 1.46 + gFindBar = document.getElementById("FindToolbar"); 1.47 + gBrowser = document.getElementById("content"); 1.48 + gBrowser.addEventListener("pageshow", onPageShow, false); 1.49 + var data = 'data:text/html,<input id="inp" type="text" />'; 1.50 + data +='<textarea id="tarea"/>' 1.51 + gBrowser.loadURI(data); 1.52 + } 1.53 + 1.54 + function goToStartOfLine(aElement) { 1.55 + if (navigator.platform.indexOf("Mac") >= 0) { 1.56 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_LEFT, 1.57 + false, false, true); 1.58 + } else { 1.59 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_HOME, 1.60 + false, false, false); 1.61 + } 1.62 + } 1.63 + 1.64 + function resetForNextTest(aElement, aText) { 1.65 + if (!aText) 1.66 + aText = SEARCH_TEXT; 1.67 + 1.68 + // Turn off highlighting 1.69 + var highlightButton = gFindBar.getElement("highlight"); 1.70 + if (highlightButton.checked) 1.71 + highlightButton.click(); 1.72 + 1.73 + // Initialise input 1.74 + aElement.value = aText; 1.75 + gFindBar._findField.value = SEARCH_TEXT; 1.76 + 1.77 + // Perform search and turn on highlighting 1.78 + gFindBar._find(); 1.79 + highlightButton.click(); 1.80 + 1.81 + // Move caret to start of element 1.82 + aElement.focus(); 1.83 + goToStartOfLine(aElement); 1.84 + } 1.85 + 1.86 + function synthesizeKey(target, isKeyCode, key, ctlKey, shiftKey, metaKey) { 1.87 + try { 1.88 + var event = document.createEvent("KeyEvents"); 1.89 + if (isKeyCode) { 1.90 + event.initKeyEvent("keypress", true, true, null, ctlKey, false, 1.91 + shiftKey, metaKey, key, 0); 1.92 + } else { 1.93 + event.initKeyEvent("keypress", true, true, null, ctlKey, false, 1.94 + shiftKey, metaKey, 0, key); 1.95 + } 1.96 + target.dispatchEvent(event); 1.97 + } catch (e) {} 1.98 + } 1.99 + 1.100 + function testInput(aElement, aTestTypeText) { 1.101 + // Initialise the findbar 1.102 + var matchCase = gFindBar.getElement("find-case-sensitive"); 1.103 + if (matchCase.checked) 1.104 + matchCase.doCommand(); 1.105 + 1.106 + // First check match has been correctly highlighted 1.107 + resetForNextTest(aElement); 1.108 + if (aElement instanceof Ci.nsIDOMNSEditableElement) { 1.109 + var controller = aElement.editor.selectionController; 1.110 + var selection = controller.getSelection(controller.SELECTION_FIND); 1.111 + ok(selection.rangeCount == 1, aTestTypeText + 1.112 + " correctly highlighted match"); 1.113 + 1.114 + // Test 2: check highlight removed when text added within the highlight 1.115 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT, 1.116 + false, false, false); 1.117 + synthesizeKey(aElement, false, KeyEvent.DOM_VK_A, 1.118 + false, false, false); 1.119 + ok(selection.rangeCount == 0, aTestTypeText + 1.120 + " correctly removed highlight on text insertion"); 1.121 + 1.122 + // Test 3: check highlighting remains when text added before highlight 1.123 + resetForNextTest(aElement); 1.124 + synthesizeKey(aElement, false, KeyEvent.DOM_VK_A, 1.125 + false, false, false); 1.126 + ok(selection.rangeCount == 1, aTestTypeText + 1.127 + " highlight correctly remained on text insertion at start"); 1.128 + 1.129 + // Test 4: check highlighting remains when text added after highlight 1.130 + resetForNextTest(aElement); 1.131 + for (var x = 0; x < SEARCH_TEXT.length; x++) 1.132 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT, 1.133 + false, false, false); 1.134 + synthesizeKey(aElement, false, KeyEvent.DOM_VK_A, 1.135 + false, false, false); 1.136 + ok(selection.rangeCount == 1, aTestTypeText + 1.137 + " highlight correctly remained on text insertion at end"); 1.138 + 1.139 + // Test 5: deleting text within the highlight 1.140 + resetForNextTest(aElement); 1.141 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT, 1.142 + false, false, false); 1.143 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_BACK_SPACE, 1.144 + false, false, false); 1.145 + ok(selection.rangeCount == 0, aTestTypeText + 1.146 + " correctly removed highlight on text deletion"); 1.147 + 1.148 + // Test 6: deleting text at end of highlight 1.149 + resetForNextTest(aElement, SEARCH_TEXT+"A"); 1.150 + for (var x = 0; x < aElement.value.length; x++) 1.151 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT, 1.152 + false, false, false); 1.153 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_BACK_SPACE, 1.154 + false, false, false); 1.155 + ok(selection.rangeCount == 1, aTestTypeText + 1.156 + " highlight correctly remained on text deletion at end"); 1.157 + 1.158 + // Test 7: deleting text at start of highlight 1.159 + resetForNextTest(aElement, "A"+SEARCH_TEXT); 1.160 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT, 1.161 + false, false, false); 1.162 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_BACK_SPACE, 1.163 + false, false, false); 1.164 + ok(selection.rangeCount == 1, aTestTypeText + 1.165 + " highlight correctly remained on text deletion at start"); 1.166 + 1.167 + // Test 8: deleting selection 1.168 + resetForNextTest(aElement); 1.169 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT, 1.170 + false, true, false); 1.171 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT, 1.172 + false, true, false); 1.173 + synthesizeKey(aElement, false, KeyEvent.DOM_VK_X, 1.174 + sendCtrl, false, sendMeta); 1.175 + ok(selection.rangeCount == 0, aTestTypeText + 1.176 + " correctly removed highlight on selection deletion"); 1.177 + 1.178 + // Test 9: Multiple matches within one editor (part 1) 1.179 + // Check second match remains highlighted after inserting text into 1.180 + // first match, and that its highlighting gets removed when the 1.181 + // second match is edited 1.182 + resetForNextTest(aElement, SEARCH_TEXT + " " + SEARCH_TEXT); 1.183 + ok(selection.rangeCount == 2, aTestTypeText + 1.184 + " correctly highlighted both matches"); 1.185 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT, 1.186 + false, false, false); 1.187 + synthesizeKey(aElement, false, KeyEvent.DOM_VK_A, 1.188 + false, false, false); 1.189 + ok(selection.rangeCount == 1, aTestTypeText + 1.190 + " correctly removed only the first highlight on text insertion"); 1.191 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT, 1.192 + sendCtrl, false, sendMeta); 1.193 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT, 1.194 + sendCtrl, false, sendMeta); 1.195 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_LEFT, 1.196 + false, false, false); 1.197 + synthesizeKey(aElement, false, KeyEvent.DOM_VK_A, 1.198 + false, false, false); 1.199 + ok(selection.rangeCount == 0, aTestTypeText + 1.200 + " correctly removed second highlight on text insertion"); 1.201 + 1.202 + // Test 10: Multiple matches within one editor (part 2) 1.203 + // Check second match remains highlighted after deleting text in 1.204 + // first match, and that its highlighting gets removed when the 1.205 + // second match is edited 1.206 + resetForNextTest(aElement, SEARCH_TEXT + " " + SEARCH_TEXT); 1.207 + ok(selection.rangeCount == 2, aTestTypeText + 1.208 + " correctly highlighted both matches"); 1.209 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT, 1.210 + false, false, false); 1.211 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_BACK_SPACE, 1.212 + false, false, false); 1.213 + ok(selection.rangeCount == 1, aTestTypeText + 1.214 + " correctly removed only the first highlight on text deletion"); 1.215 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT, 1.216 + sendCtrl, false, sendMeta); 1.217 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT, 1.218 + sendCtrl, false, sendMeta); 1.219 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_LEFT, 1.220 + false, false, false); 1.221 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_BACK_SPACE, 1.222 + false, false, false); 1.223 + ok(selection.rangeCount == 0, aTestTypeText + 1.224 + " correctly removed second highlight on text deletion"); 1.225 + 1.226 + // Test 11: Multiple matches within one editor (part 3) 1.227 + // Check second match remains highlighted after deleting selection 1.228 + // in first match, and that second match highlighting gets correctly 1.229 + // removed when it has a selection deleted from it 1.230 + resetForNextTest(aElement, SEARCH_TEXT + " " + SEARCH_TEXT); 1.231 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT, 1.232 + false, true, false); 1.233 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT, 1.234 + false, true, false); 1.235 + synthesizeKey(aElement, false, KeyEvent.DOM_VK_X, 1.236 + sendCtrl, false, sendMeta); 1.237 + ok(selection.rangeCount == 1, aTestTypeText + 1.238 + " correctly removed only first highlight on selection deletion"); 1.239 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT, 1.240 + sendCtrl, false, sendMeta); 1.241 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT, 1.242 + sendCtrl, false, sendMeta); 1.243 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_LEFT, 1.244 + false, true, false); 1.245 + synthesizeKey(aElement, true, KeyEvent.DOM_VK_LEFT, 1.246 + false, true, false); 1.247 + synthesizeKey(aElement, false, KeyEvent.DOM_VK_X, 1.248 + sendCtrl, false, sendMeta); 1.249 + ok(selection.rangeCount == 0, aTestTypeText + 1.250 + " correctly removed second highlight on selection deletion"); 1.251 + } 1.252 + } 1.253 + 1.254 + function onPageShow() { 1.255 + gBrowser.removeEventListener("load", onPageShow, true); 1.256 + gBrowser.contentWindow.focus(); 1.257 + gFindBar.open(); 1.258 + var input = gBrowser.contentDocument.getElementById("inp"); 1.259 + testInput(input, "Input:"); 1.260 + var textarea = gBrowser.contentDocument.getElementById("tarea"); 1.261 + testInput(textarea, "Textarea:"); 1.262 + finishTest(); 1.263 + } 1.264 + 1.265 + SimpleTest.waitForFocus(startTest, window); 1.266 + ]]></script> 1.267 + 1.268 + <browser type="content-primary" flex="1" id="content" src="about:blank"/> 1.269 + <findbar id="FindToolbar" browserid="content"/> 1.270 +</window>