зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1261584: refactor bug360437_window.xul and findbar_events_window.xul to run the test on remote browsers as well. r=felipe
This commit is contained in:
Родитель
eeab7ef352
Коммит
a0e3842c41
|
@ -5,69 +5,83 @@
|
|||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
|
||||
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
||||
<?xml-stylesheet
|
||||
href="chrome://mochikit/content/tests/SimpleTest/test.css"
|
||||
type="text/css"?>
|
||||
|
||||
<window id="360437Test"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
width="600"
|
||||
height="600"
|
||||
onload="onLoad();"
|
||||
onload="startTest();"
|
||||
title="360437 test">
|
||||
|
||||
<script type="application/javascript"><![CDATA[
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
const Cr = Components.results;
|
||||
const {interfaces: Ci, classes: Cc, results: Cr, utils: Cu} = Components;
|
||||
Cu.import("resource://gre/modules/Task.jsm");
|
||||
Cu.import("resource://testing-common/ContentTask.jsm");
|
||||
ContentTask.setTestScope(window.opener.wrappedJSObject);
|
||||
|
||||
var gFindBar = null;
|
||||
var gBrowser;
|
||||
|
||||
function ok(condition, message) {
|
||||
window.opener.wrappedJSObject.SimpleTest.ok(condition, message);
|
||||
}
|
||||
function finish() {
|
||||
window.close();
|
||||
window.opener.wrappedJSObject.SimpleTest.finish();
|
||||
var imports = ["SimpleTest", "ok", "is", "info"];
|
||||
for (var name of imports) {
|
||||
window[name] = window.opener.wrappedJSObject[name];
|
||||
}
|
||||
|
||||
function onLoad() {
|
||||
var _delayedOnLoad = function() {
|
||||
function startTest() {
|
||||
Task.spawn(function* () {
|
||||
gFindBar = document.getElementById("FindToolbar");
|
||||
gBrowser = document.getElementById("content");
|
||||
gBrowser.addEventListener("pageshow", onPageShow, false);
|
||||
gBrowser.loadURI("data:text/html,<form><input id='input' type='text' value='text inside an input element'></form>");
|
||||
}
|
||||
setTimeout(_delayedOnLoad, 1000);
|
||||
for (let browserId of ["content", "content-remote"]) {
|
||||
yield startTestWithBrowser(browserId);
|
||||
}
|
||||
}).then(() => {
|
||||
window.close();
|
||||
SimpleTest.finish();
|
||||
});
|
||||
}
|
||||
|
||||
function onPageShow() {
|
||||
testNormalFind();
|
||||
function* startTestWithBrowser(browserId) {
|
||||
info("Starting test with browser '" + browserId + "'");
|
||||
gBrowser = document.getElementById(browserId);
|
||||
gFindBar.browser = gBrowser;
|
||||
let promise = ContentTask.spawn(gBrowser, null, function* () {
|
||||
return new Promise(resolve => {
|
||||
addEventListener("DOMContentLoaded", function listener() {
|
||||
removeEventListener("DOMContentLoaded", listener);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
gBrowser.loadURI("data:text/html,<form><input id='input' type='text' value='text inside an input element'></form>");
|
||||
yield promise;
|
||||
yield onDocumentLoaded();
|
||||
}
|
||||
|
||||
function enterStringIntoFindField(aString) {
|
||||
for (var i=0; i < aString.length; i++) {
|
||||
var event = document.createEvent("KeyEvents");
|
||||
event.initKeyEvent("keypress", true, true, null, false, false,
|
||||
false, false, 0, aString.charCodeAt(i));
|
||||
gFindBar._findField.inputField.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
function testNormalFind() {
|
||||
function* onDocumentLoaded() {
|
||||
gFindBar.onFindCommand();
|
||||
|
||||
// Make sure the findfield is correctly focused on open
|
||||
var searchStr = "text inside an input element";
|
||||
enterStringIntoFindField(searchStr);
|
||||
ok(document.commandDispatcher.focusedElement ==
|
||||
yield* enterStringIntoFindField(searchStr);
|
||||
is(document.commandDispatcher.focusedElement,
|
||||
gFindBar._findField.inputField, "Find field isn't focused");
|
||||
|
||||
// Make sure "find again" correctly transfers focus to the content element
|
||||
// when the find bar is closed.
|
||||
gFindBar.close();
|
||||
gFindBar.onFindAgainCommand(false);
|
||||
ok(document.commandDispatcher.focusedElement ==
|
||||
gBrowser.contentDocument.getElementById("input"),
|
||||
"Input Element isn't focused");
|
||||
// For remote browsers, the content document DOM tree is not accessible, thus
|
||||
// the focused element should fall back to the browser element.
|
||||
if (gBrowser.hasAttribute("remote")) {
|
||||
is(document.commandDispatcher.focusedElement, gBrowser,
|
||||
"Browser element isn't focused");
|
||||
}
|
||||
yield ContentTask.spawn(gBrowser, null, function* () {
|
||||
Assert.equal(content.document.activeElement,
|
||||
content.document.getElementById("input"), "Input Element isn't focused");
|
||||
});
|
||||
|
||||
// Make sure "find again" doesn't focus the content element if focus
|
||||
// isn't in the content document.
|
||||
|
@ -77,10 +91,29 @@
|
|||
gFindBar.onFindAgainCommand(false);
|
||||
ok(textbox.hasAttribute("focused"),
|
||||
"Focus was stolen from a chrome element");
|
||||
finish();
|
||||
}
|
||||
|
||||
function* enterStringIntoFindField(aString) {
|
||||
for (let i = 0; i < aString.length; i++) {
|
||||
let event = document.createEvent("KeyEvents");
|
||||
let promise = new Promise(resolve => {
|
||||
let listener = {
|
||||
onFindResult: function() {
|
||||
gFindBar.browser.finder.removeResultListener(listener);
|
||||
resolve();
|
||||
}
|
||||
};
|
||||
gFindBar.browser.finder.addResultListener(listener);
|
||||
});
|
||||
event.initKeyEvent("keypress", true, true, null, false, false,
|
||||
false, false, 0, aString.charCodeAt(i));
|
||||
gFindBar._findField.inputField.dispatchEvent(event);
|
||||
yield promise;
|
||||
}
|
||||
}
|
||||
]]></script>
|
||||
<textbox id="textbox"/>
|
||||
<browser type="content-primary" flex="1" id="content" src="about:blank"/>
|
||||
<browser type="content-primary" flex="1" id="content-remote" remote="true" src="about:blank"/>
|
||||
<findbar id="FindToolbar" browserid="content"/>
|
||||
</window>
|
||||
|
|
|
@ -68,6 +68,7 @@ skip-if = buildapp == 'mulet'
|
|||
[test_bug331215.xul]
|
||||
[test_bug360220.xul]
|
||||
[test_bug360437.xul]
|
||||
skip-if = os == 'linux'
|
||||
[test_bug365773.xul]
|
||||
[test_bug366992.xul]
|
||||
[test_bug382990.xul]
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
|
||||
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
||||
<?xml-stylesheet
|
||||
href="chrome://mochikit/content/tests/SimpleTest/test.css"
|
||||
type="text/css"?>
|
||||
|
||||
<window id="FindbarTest"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
|
@ -14,151 +17,163 @@
|
|||
title="findbar events test">
|
||||
|
||||
<script type="application/javascript"><![CDATA[
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
const Cr = Components.results;
|
||||
const {interfaces: Ci, classes: Cc, results: Cr, utils: Cu} = Components;
|
||||
Cu.import("resource://gre/modules/Task.jsm");
|
||||
Cu.import("resource://testing-common/ContentTask.jsm");
|
||||
ContentTask.setTestScope(window.opener.wrappedJSObject);
|
||||
|
||||
var gFindBar = null;
|
||||
var gBrowser;
|
||||
const kTimeout = 5000; // 5 seconds.
|
||||
|
||||
var imports = ["SimpleTest", "ok", "is"];
|
||||
var imports = ["SimpleTest", "ok", "is", "info"];
|
||||
for (var name of imports) {
|
||||
window[name] = window.opener.wrappedJSObject[name];
|
||||
}
|
||||
|
||||
function finish() {
|
||||
window.close();
|
||||
SimpleTest.finish();
|
||||
}
|
||||
SimpleTest.requestLongerTimeout(2);
|
||||
|
||||
function startTest() {
|
||||
gFindBar = document.getElementById("FindToolbar");
|
||||
gBrowser = document.getElementById("content");
|
||||
gBrowser.addEventListener("pageshow", onPageShow, false);
|
||||
gBrowser.loadURI('data:text/html,hello there');
|
||||
Task.spawn(function* () {
|
||||
gFindBar = document.getElementById("FindToolbar");
|
||||
for (let browserId of ["content", "content-remote"]) {
|
||||
yield startTestWithBrowser(browserId);
|
||||
}
|
||||
}).then(() => {
|
||||
window.close();
|
||||
SimpleTest.finish();
|
||||
});
|
||||
}
|
||||
|
||||
var tests = [
|
||||
testFind,
|
||||
testFindAgain,
|
||||
testCaseSensitivity,
|
||||
testHighlight,
|
||||
finish
|
||||
];
|
||||
|
||||
// Iterates through the above tests and takes care of passing the done
|
||||
// callback for any async tests.
|
||||
function nextTest() {
|
||||
if (!tests.length) {
|
||||
return;
|
||||
}
|
||||
var func = tests.shift();
|
||||
if (!func.length) {
|
||||
// Test isn't async advance to the next test here.
|
||||
func();
|
||||
SimpleTest.executeSoon(nextTest);
|
||||
} else {
|
||||
func(nextTest);
|
||||
}
|
||||
function* startTestWithBrowser(browserId) {
|
||||
info("Starting test with browser '" + browserId + "'");
|
||||
gBrowser = document.getElementById(browserId);
|
||||
gFindBar.browser = gBrowser;
|
||||
let promise = ContentTask.spawn(gBrowser, null, function* () {
|
||||
return new Promise(resolve => {
|
||||
addEventListener("DOMContentLoaded", function listener() {
|
||||
removeEventListener("DOMContentLoaded", listener);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
gBrowser.loadURI("data:text/html,hello there");
|
||||
yield promise;
|
||||
yield onDocumentLoaded();
|
||||
}
|
||||
|
||||
function onPageShow() {
|
||||
function* onDocumentLoaded() {
|
||||
gFindBar.open();
|
||||
gFindBar.onFindCommand();
|
||||
nextTest();
|
||||
|
||||
yield testFind();
|
||||
yield testFindAgain();
|
||||
yield testCaseSensitivity();
|
||||
yield testHighlight();
|
||||
}
|
||||
|
||||
function checkSelection(done) {
|
||||
SimpleTest.executeSoon(function() {
|
||||
var selected = gBrowser.contentWindow.getSelection();
|
||||
is(String(selected), "", "No text is selected");
|
||||
function checkSelection() {
|
||||
return new Promise(resolve => {
|
||||
SimpleTest.executeSoon(() => {
|
||||
ContentTask.spawn(gBrowser, null, function* () {
|
||||
let selected = content.getSelection();
|
||||
Assert.equal(String(selected), "", "No text is selected");
|
||||
|
||||
var controller = gFindBar.browser.docShell.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsISelectionDisplay)
|
||||
.QueryInterface(Ci.nsISelectionController);
|
||||
var selection = controller.getSelection(controller.SELECTION_FIND);
|
||||
is(selection.rangeCount, 0, "No text is highlighted");
|
||||
done();
|
||||
let controller = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsISelectionDisplay)
|
||||
.QueryInterface(Ci.nsISelectionController);
|
||||
let selection = controller.getSelection(controller.SELECTION_FIND);
|
||||
Assert.equal(selection.rangeCount, 0, "No text is highlighted");
|
||||
}).then(resolve);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function once(node, eventName, callback) {
|
||||
node.addEventListener(eventName, function clb(e) {
|
||||
node.removeEventListener(eventName, clb);
|
||||
callback(e);
|
||||
})
|
||||
function once(node, eventName, preventDefault = true) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let timeout = window.setTimeout(() => {
|
||||
reject("Event wasn't fired within " + kTimeout + "ms for event '" +
|
||||
eventName + "'.");
|
||||
}, kTimeout);
|
||||
|
||||
node.addEventListener(eventName, function clb(e) {
|
||||
window.clearTimeout(timeout);
|
||||
node.removeEventListener(eventName, clb);
|
||||
if (preventDefault)
|
||||
e.preventDefault();
|
||||
resolve(e);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function testFind(done) {
|
||||
var eventTriggered = false;
|
||||
var query = "t";
|
||||
once(gFindBar, "find", function(e) {
|
||||
eventTriggered = true;
|
||||
ok(e.detail.query === query, "find event query should match '" + query + "'");
|
||||
e.preventDefault();
|
||||
// Since we're preventing the default make sure nothing was selected.
|
||||
checkSelection(done);
|
||||
});
|
||||
function* testFind() {
|
||||
info("Testing normal find.");
|
||||
let query = "t";
|
||||
let promise = once(gFindBar, "find");
|
||||
|
||||
// Put some text in the find box.
|
||||
var event = document.createEvent("KeyEvents");
|
||||
let event = document.createEvent("KeyEvents");
|
||||
event.initKeyEvent("keypress", true, true, null, false, false,
|
||||
false, false, 0, query.charCodeAt(0));
|
||||
gFindBar._findField.inputField.dispatchEvent(event);
|
||||
ok(eventTriggered, "find event should be triggered");
|
||||
|
||||
let e = yield promise;
|
||||
ok(e.detail.query === query, "find event query should match '" + query + "'");
|
||||
// Since we're preventing the default make sure nothing was selected.
|
||||
yield checkSelection();
|
||||
}
|
||||
|
||||
function testFindAgain(done) {
|
||||
var eventTriggered = false;
|
||||
once(gFindBar, "findagain", function(e) {
|
||||
eventTriggered = true;
|
||||
e.preventDefault();
|
||||
// Since we're preventing the default make sure nothing was selected.
|
||||
checkSelection(done);
|
||||
});
|
||||
function testFindAgain() {
|
||||
info("Testing repeating normal find.");
|
||||
let promise = once(gFindBar, "findagain");
|
||||
|
||||
gFindBar.onFindAgainCommand();
|
||||
ok(eventTriggered, "findagain event should be triggered");
|
||||
|
||||
yield promise;
|
||||
// Since we're preventing the default make sure nothing was selected.
|
||||
yield checkSelection();
|
||||
}
|
||||
|
||||
function testCaseSensitivity() {
|
||||
var eventTriggered = false;
|
||||
once(gFindBar, "findcasesensitivitychange", function(e) {
|
||||
eventTriggered = true;
|
||||
ok(e.detail.caseSensitive, "find should be case sensitive");
|
||||
});
|
||||
function* testCaseSensitivity() {
|
||||
info("Testing normal case sensitivity.");
|
||||
let promise = once(gFindBar, "findcasesensitivitychange", false);
|
||||
|
||||
var matchCaseCheckbox = gFindBar.getElement("find-case-sensitive");
|
||||
let matchCaseCheckbox = gFindBar.getElement("find-case-sensitive");
|
||||
matchCaseCheckbox.click();
|
||||
|
||||
let e = yield promise;
|
||||
ok(e.detail.caseSensitive, "find should be case sensitive");
|
||||
|
||||
// Toggle it back to the original setting.
|
||||
matchCaseCheckbox.click();
|
||||
ok(eventTriggered, "findcasesensitivitychange should be triggered");
|
||||
|
||||
// Changing case sensitivity does the search so clear the selected text
|
||||
// before the next test.
|
||||
gBrowser.contentWindow.getSelection().removeAllRanges();
|
||||
yield ContentTask.spawn(gBrowser, null, () => content.getSelection().removeAllRanges());
|
||||
}
|
||||
|
||||
function testHighlight(done) {
|
||||
function* testHighlight() {
|
||||
info("Testing find with highlight all.");
|
||||
// Update the find state so the highlight button is clickable.
|
||||
gFindBar.updateControlState(Ci.nsITypeAheadFind.FIND_FOUND, false);
|
||||
var eventTriggered = false;
|
||||
once(gFindBar, "findhighlightallchange", function(e) {
|
||||
eventTriggered = true;
|
||||
ok(e.detail.highlightAll, "find event should have highlight all set");
|
||||
e.preventDefault();
|
||||
// Since we're preventing the default make sure nothing was highlighted.
|
||||
SimpleTest.executeSoon(function() {
|
||||
checkSelection(done);
|
||||
});
|
||||
});
|
||||
|
||||
var highlightButton = gFindBar.getElement("highlight");
|
||||
if (!highlightButton.checked) {
|
||||
let promise = once(gFindBar, "findhighlightallchange");
|
||||
|
||||
let highlightButton = gFindBar.getElement("highlight");
|
||||
if (!highlightButton.checked)
|
||||
highlightButton.click();
|
||||
|
||||
let e = yield promise;
|
||||
ok(e.detail.highlightAll, "find event should have highlight all set");
|
||||
// Since we're preventing the default make sure nothing was highlighted.
|
||||
yield checkSelection();
|
||||
|
||||
// Toggle it back to the original setting.
|
||||
if (highlightButton.checked)
|
||||
highlightButton.click();
|
||||
}
|
||||
ok(eventTriggered, "findhighlightallchange should be triggered");
|
||||
}
|
||||
]]></script>
|
||||
|
||||
<browser type="content-primary" flex="1" id="content" src="about:blank"/>
|
||||
<browser type="content-primary" flex="1" id="content-remote" remote="true" src="about:blank"/>
|
||||
<findbar id="FindToolbar" browserid="content"/>
|
||||
</window>
|
||||
|
|
Загрузка…
Ссылка в новой задаче