Bug 1052992: Add quick-search event listeners to system event group, so stopPropagation on keyboard events does not affect the findbar. r=MattN

This commit is contained in:
Iaroslav Sheptykin 2014-10-16 00:38:58 -07:00
parent cd6ea41067
commit ba19dca4a9
4 changed files with 88 additions and 5 deletions

View File

@ -1,5 +1,5 @@
[DEFAULT]
support-files = head.js
[browser_autoscroll_disabled.js]
skip-if = e10s # Bug ?????? - test touches content (getElementById on the content document)
[browser_browserDrop.js]

View File

@ -2,6 +2,52 @@ XPCOMUtils.defineLazyModuleGetter(this, "Promise",
"resource://gre/modules/Promise.jsm");
Components.utils.import("resource://gre/modules/Timer.jsm", this);
/**
* Makes sure that the findbar hotkeys (' and /) event listeners
* are added to the system event group and do not get blocked
* by calling stopPropagation on a keypress event on a page.
*/
add_task(function* test_hotkey_event_propagation() {
info("Ensure hotkeys are not affected by stopPropagation.");
// Opening new tab
let tab = yield promiseTestPageLoad();
let browser = gBrowser.getBrowserForTab(tab);
let findbar = gBrowser.getFindBar();
// Pressing these keys open the findbar.
const HOTKEYS = ["/", "'"];
// Checking if findbar appears when any hotkey is pressed.
for (let key of HOTKEYS) {
is(findbar.hidden, true, "Findbar is hidden now.");
gBrowser.selectedTab = tab;
yield promiseFocus();
EventUtils.sendChar(key, browser.contentWindow);
is(findbar.hidden, false, "Findbar should not be hidden.");
yield closeFindbarAndWait(findbar);
}
// Stop propagation for all keyboard events.
let window = browser.contentWindow;
let stopPropagation = function(e) { e.stopImmediatePropagation(); };
window.addEventListener("keydown", stopPropagation, true);
window.addEventListener("keypress", stopPropagation, true);
window.addEventListener("keyup", stopPropagation, true);
// Checking if findbar still appears when any hotkey is pressed.
for (let key of HOTKEYS) {
is(findbar.hidden, true, "Findbar is hidden now.");
gBrowser.selectedTab = tab;
yield promiseFocus();
EventUtils.sendChar(key, browser.contentWindow);
is(findbar.hidden, false, "Findbar should not be hidden.");
yield closeFindbarAndWait(findbar);
}
gBrowser.removeTab(tab);
});
add_task(function* test_not_found() {
info("Check correct 'Phrase not found' on new tab");
@ -103,3 +149,14 @@ function promiseFindFinished(searchText, highlightOn) {
return deferred.promise;
}
/**
* A promise-like wrapper for the waitForFocus helper.
*/
function promiseFocus() {
return new Promise((resolve) => {
waitForFocus(function(){
resolve();
}, content);
});
}

View File

@ -0,0 +1,20 @@
"use strict";
/**
* A wrapper for the findbar's method "close", which is not synchronous
* because of animation.
*/
function closeFindbarAndWait(findbar) {
return new Promise((resolve) => {
if (findbar.hidden)
return resolve();
findbar.addEventListener("transitionend", function cont(aEvent) {
if (aEvent.propertyName != "visibility") {
return;
}
findbar.removeEventListener("transitionend", cont);
resolve();
});
findbar.close();
});
}

View File

@ -257,9 +257,15 @@
return this._browser;
]]></getter>
<setter><![CDATA[
// A shortcut for the service.
let els = Components.classes["@mozilla.org/eventlistenerservice;1"].
getService(Components.interfaces.nsIEventListenerService);
if (this._browser) {
this._browser.removeEventListener("keypress", this, false);
this._browser.removeEventListener("mouseup", this, false);
els.removeSystemEventListener(this._browser, "keypress", this,
false);
els.removeSystemEventListener(this._browser, "mouseup", this,
false);
let finder = this._browser.finder;
if (finder)
finder.removeResultListener(this);
@ -267,8 +273,8 @@
this._browser = val;
if (this._browser) {
this._browser.addEventListener("keypress", this, false);
this._browser.addEventListener("mouseup", this, false);
els.addSystemEventListener(this._browser, "keypress", this, false);
els.addSystemEventListener(this._browser, "mouseup", this, false);
this._browser.finder.addResultListener(this);
this._findField.value = this._browser._lastSearchString;