mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
261 lines
11 KiB
XML
261 lines
11 KiB
XML
<?xml version="1.0"?>
|
|
|
|
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
|
|
|
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
|
|
|
<window id="451540test"
|
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
|
width="600"
|
|
height="600"
|
|
title="451540 test">
|
|
|
|
<script type="application/javascript"><![CDATA[
|
|
const Ci = Components.interfaces;
|
|
const Cc = Components.classes;
|
|
const Cr = Components.results;
|
|
const SEARCH_TEXT = "minefield";
|
|
|
|
var gFindBar = null;
|
|
var gBrowser;
|
|
|
|
var sendCtrl = true;
|
|
var sendMeta = false;
|
|
if (navigator.platform.indexOf("Mac") >= 0) {
|
|
sendCtrl = false;
|
|
sendMeta = true;
|
|
}
|
|
|
|
var imports = [ "SimpleTest", "ok"];
|
|
for each (var name in imports) {
|
|
window[name] = window.opener.wrappedJSObject[name];
|
|
}
|
|
|
|
|
|
function finishTest() {
|
|
window.close();
|
|
SimpleTest.finish();
|
|
}
|
|
|
|
function startTest() {
|
|
gFindBar = document.getElementById("FindToolbar");
|
|
gBrowser = document.getElementById("content");
|
|
gBrowser.addEventListener("pageshow", onPageShow, false);
|
|
var data = 'data:text/html,<input id="inp" type="text" />';
|
|
data +='<textarea id="tarea"/>'
|
|
gBrowser.loadURI(data);
|
|
}
|
|
|
|
function resetForNextTest(aElement, aText) {
|
|
if (!aText)
|
|
aText = SEARCH_TEXT;
|
|
|
|
// Turn off highlighting
|
|
var highlightButton = gFindBar.getElement("highlight");
|
|
if (highlightButton.checked)
|
|
highlightButton.click();
|
|
|
|
// Initialise input
|
|
aElement.value = aText;
|
|
gFindBar._findField.value = SEARCH_TEXT;
|
|
|
|
// Perform search and turn on highlighting
|
|
gFindBar._find();
|
|
highlightButton.click();
|
|
|
|
// Move caret to start of element
|
|
aElement.focus();
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_UP,
|
|
sendCtrl, false, sendMeta);
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_LEFT,
|
|
sendCtrl, false, sendMeta);
|
|
}
|
|
|
|
function synthesizeKey(target, isKeyCode, key, ctlKey, shiftKey, metaKey) {
|
|
try {
|
|
var event = document.createEvent("KeyEvents");
|
|
if (isKeyCode) {
|
|
event.initKeyEvent("keypress", true, true, null, ctlKey, false,
|
|
shiftKey, metaKey, key, 0);
|
|
} else {
|
|
event.initKeyEvent("keypress", true, true, null, ctlKey, false,
|
|
shiftKey, metaKey, 0, key);
|
|
}
|
|
target.dispatchEvent(event);
|
|
} catch (e) {}
|
|
}
|
|
|
|
function testInput(aElement, aTestTypeText) {
|
|
// Initialise the findbar
|
|
var matchCase = gFindBar.getElement("find-case-sensitive");
|
|
if (matchCase.checked)
|
|
matchCase.doCommand();
|
|
|
|
// First check match has been correctly highlighted
|
|
resetForNextTest(aElement);
|
|
if (aElement instanceof Ci.nsIDOMNSEditableElement) {
|
|
var controller = aElement.editor.selectionController;
|
|
var selection = controller.getSelection(controller.SELECTION_FIND);
|
|
ok(selection.rangeCount == 1, aTestTypeText +
|
|
" correctly highlighted match");
|
|
|
|
// Test 2: check highlight removed when text added within the highlight
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
|
|
false, false, false);
|
|
synthesizeKey(aElement, false, KeyEvent.DOM_VK_A,
|
|
false, false, false);
|
|
ok(selection.rangeCount == 0, aTestTypeText +
|
|
" correctly removed highlight on text insertion");
|
|
|
|
// Test 3: check highlighting remains when text added before highlight
|
|
resetForNextTest(aElement);
|
|
synthesizeKey(aElement, false, KeyEvent.DOM_VK_A,
|
|
false, false, false);
|
|
ok(selection.rangeCount == 1, aTestTypeText +
|
|
" highlight correctly remained on text insertion at start");
|
|
|
|
// Test 4: check highlighting remains when text added after highlight
|
|
resetForNextTest(aElement);
|
|
for (var x = 0; x < SEARCH_TEXT.length; x++)
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
|
|
false, false, false);
|
|
synthesizeKey(aElement, false, KeyEvent.DOM_VK_A,
|
|
false, false, false);
|
|
ok(selection.rangeCount == 1, aTestTypeText +
|
|
" highlight correctly remained on text insertion at end");
|
|
|
|
// Test 5: deleting text within the highlight
|
|
resetForNextTest(aElement);
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
|
|
false, false, false);
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_BACK_SPACE,
|
|
false, false, false);
|
|
ok(selection.rangeCount == 0, aTestTypeText +
|
|
" correctly removed highlight on text deletion");
|
|
|
|
// Test 6: deleting text at end of highlight
|
|
resetForNextTest(aElement, SEARCH_TEXT+"A");
|
|
for (var x = 0; x < aElement.value.length; x++)
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
|
|
false, false, false);
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_BACK_SPACE,
|
|
false, false, false);
|
|
ok(selection.rangeCount == 1, aTestTypeText +
|
|
" highlight correctly remained on text deletion at end");
|
|
|
|
// Test 7: deleting text at start of highlight
|
|
resetForNextTest(aElement, "A"+SEARCH_TEXT);
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
|
|
false, false, false);
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_BACK_SPACE,
|
|
false, false, false);
|
|
ok(selection.rangeCount == 1, aTestTypeText +
|
|
" highlight correctly remained on text deletion at start");
|
|
|
|
// Test 8: deleting selection
|
|
resetForNextTest(aElement);
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
|
|
false, true, false);
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
|
|
false, true, false);
|
|
synthesizeKey(aElement, false, KeyEvent.DOM_VK_X,
|
|
sendCtrl, false, sendMeta);
|
|
ok(selection.rangeCount == 0, aTestTypeText +
|
|
" correctly removed highlight on selection deletion");
|
|
|
|
// Test 9: Multiple matches within one editor (part 1)
|
|
// Check second match remains highlighted after inserting text into
|
|
// first match, and that its highlighting gets removed when the
|
|
// second match is edited
|
|
resetForNextTest(aElement, SEARCH_TEXT + " " + SEARCH_TEXT);
|
|
ok(selection.rangeCount == 2, aTestTypeText +
|
|
" correctly highlighted both matches");
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
|
|
false, false, false);
|
|
synthesizeKey(aElement, false, KeyEvent.DOM_VK_A,
|
|
false, false, false);
|
|
ok(selection.rangeCount == 1, aTestTypeText +
|
|
" correctly removed only the first highlight on text insertion");
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
|
|
sendCtrl, false, sendMeta);
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
|
|
sendCtrl, false, sendMeta);
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_LEFT,
|
|
false, false, false);
|
|
synthesizeKey(aElement, false, KeyEvent.DOM_VK_A,
|
|
false, false, false);
|
|
ok(selection.rangeCount == 0, aTestTypeText +
|
|
" correctly removed second highlight on text insertion");
|
|
|
|
// Test 10: Multiple matches within one editor (part 2)
|
|
// Check second match remains highlighted after deleting text in
|
|
// first match, and that its highlighting gets removed when the
|
|
// second match is edited
|
|
resetForNextTest(aElement, SEARCH_TEXT + " " + SEARCH_TEXT);
|
|
ok(selection.rangeCount == 2, aTestTypeText +
|
|
" correctly highlighted both matches");
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
|
|
false, false, false);
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_BACK_SPACE,
|
|
false, false, false);
|
|
ok(selection.rangeCount == 1, aTestTypeText +
|
|
" correctly removed only the first highlight on text deletion");
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
|
|
sendCtrl, false, sendMeta);
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
|
|
sendCtrl, false, sendMeta);
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_LEFT,
|
|
false, false, false);
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_BACK_SPACE,
|
|
false, false, false);
|
|
ok(selection.rangeCount == 0, aTestTypeText +
|
|
" correctly removed second highlight on text deletion");
|
|
|
|
// Test 11: Multiple matches within one editor (part 3)
|
|
// Check second match remains highlighted after deleting selection
|
|
// in first match, and that second match highlighting gets correctly
|
|
// removed when it has a selection deleted from it
|
|
resetForNextTest(aElement, SEARCH_TEXT + " " + SEARCH_TEXT);
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
|
|
false, true, false);
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
|
|
false, true, false);
|
|
synthesizeKey(aElement, false, KeyEvent.DOM_VK_X,
|
|
sendCtrl, false, sendMeta);
|
|
ok(selection.rangeCount == 1, aTestTypeText +
|
|
" correctly removed only first highlight on selection deletion");
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
|
|
sendCtrl, false, sendMeta);
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_RIGHT,
|
|
sendCtrl, false, sendMeta);
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_LEFT,
|
|
false, true, false);
|
|
synthesizeKey(aElement, true, KeyEvent.DOM_VK_LEFT,
|
|
false, true, false);
|
|
synthesizeKey(aElement, false, KeyEvent.DOM_VK_X,
|
|
sendCtrl, false, sendMeta);
|
|
ok(selection.rangeCount == 0, aTestTypeText +
|
|
" correctly removed second highlight on selection deletion");
|
|
}
|
|
}
|
|
|
|
function onPageShow() {
|
|
gBrowser.removeEventListener("load", onPageShow, true);
|
|
gBrowser.contentWindow.focus();
|
|
gFindBar.open();
|
|
var input = gBrowser.contentDocument.getElementById("inp");
|
|
testInput(input, "Input:");
|
|
var textarea = gBrowser.contentDocument.getElementById("tarea");
|
|
testInput(textarea, "Textarea:");
|
|
finishTest();
|
|
}
|
|
|
|
SimpleTest.waitForFocus(startTest, window);
|
|
]]></script>
|
|
|
|
<browser type="content-primary" flex="1" id="content" src="about:blank"/>
|
|
<findbar id="FindToolbar" browserid="content"/>
|
|
</window>
|