From 8fd6fc6676339f229bf5480b2a235c8b667204f5 Mon Sep 17 00:00:00 2001 From: "Luis Miguel [:quicksaver]" Date: Wed, 4 Nov 2015 15:26:40 +0000 Subject: [PATCH] Bug 1218351 - (e10s) Don't lose initial typed characters when opening the findbar; r=mikedeboer Moved some of the routine from content to chrome process. The drawback is that now the content process must wait for a response on every keypress. --HG-- extra : transplant_source : f%99%83H%91%C6B%3FJ%DC%29s%AF%E1%BA%E6GO%0B%17 --- .../BrowserTestUtils/BrowserTestUtils.jsm | 13 ++++++- .../tests/SimpleTest/AsyncUtilsContent.js | 5 ++- toolkit/content/browser-content.js | 20 +++------- .../content/tests/browser/browser_findbar.js | 39 +++++++++++++++++++ toolkit/content/widgets/findbar.xml | 23 ++++++++--- 5 files changed, 78 insertions(+), 22 deletions(-) diff --git a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm index 871224c42a06..2b8a1ee0eace 100644 --- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm +++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm @@ -32,6 +32,8 @@ Cc["@mozilla.org/globalmessagemanager;1"] XPCOMUtils.defineLazyModuleGetter(this, "E10SUtils", "resource:///modules/E10SUtils.jsm"); +var gSendCharCount = 0; + this.BrowserTestUtils = { /** * Loads a page in a new tab, executes a Task and closes the tab. @@ -663,12 +665,21 @@ this.BrowserTestUtils = { */ sendChar(char, browser) { return new Promise(resolve => { + let seq = ++gSendCharCount; let mm = browser.messageManager; + mm.addMessageListener("Test:SendCharDone", function charMsg(message) { + if (message.data.seq != seq) + return; + mm.removeMessageListener("Test:SendCharDone", charMsg); resolve(message.data.sendCharResult); }); - mm.sendAsyncMessage("Test:SendChar", { char: char }); + + mm.sendAsyncMessage("Test:SendChar", { + char: char, + seq: seq + }); }); } }; diff --git a/testing/mochitest/tests/SimpleTest/AsyncUtilsContent.js b/testing/mochitest/tests/SimpleTest/AsyncUtilsContent.js index 92af2d77418d..793e23858083 100644 --- a/testing/mochitest/tests/SimpleTest/AsyncUtilsContent.js +++ b/testing/mochitest/tests/SimpleTest/AsyncUtilsContent.js @@ -53,5 +53,8 @@ addMessageListener("Test:SynthesizeMouse", (message) => { addMessageListener("Test:SendChar", message => { let result = EventUtils.sendChar(message.data.char, content); - sendAsyncMessage("Test:SendCharDone", { sendCharResult: result }); + sendAsyncMessage("Test:SendCharDone", { + sendCharResult: result, + seq: message.data.seq + }); }); diff --git a/toolkit/content/browser-content.js b/toolkit/content/browser-content.js index 3f48d060c29b..071159fb9c1f 100644 --- a/toolkit/content/browser-content.js +++ b/toolkit/content/browser-content.js @@ -580,15 +580,10 @@ var FindBar = { FIND_NORMAL: 0, FIND_TYPEAHEAD: 1, FIND_LINKS: 2, - FAYT_LINKS_KEY: "'".charCodeAt(0), - FAYT_TEXT_KEY: "/".charCodeAt(0), _findMode: 0, - _findAsYouType: false, init() { - this._findAsYouType = - Services.prefs.getBoolPref("accessibility.typeaheadfind"); addMessageListener("Findbar:UpdateState", this); Services.els.addSystemEventListener(global, "keypress", this, false); Services.els.addSystemEventListener(global, "mouseup", this, false); @@ -598,7 +593,6 @@ var FindBar = { switch (msg.name) { case "Findbar:UpdateState": this._findMode = msg.data.findMode; - this._findAsYouType = msg.data.findAsYouType; break; } }, @@ -632,16 +626,9 @@ var FindBar = { if (event.ctrlKey || event.altKey || event.metaKey || event.defaultPrevented) { return; } - // Not interested in random keypresses most of the time: - if (this._findMode == this.FIND_NORMAL && !this._findAsYouType && - event.charCode != this.FAYT_LINKS_KEY && event.charCode != this.FAYT_TEXT_KEY) { - return; - } // Check the focused element etc. - if (!this._shouldFastFind()) { - return; - } + let shouldFastFind = this._shouldFastFind(); let fakeEvent = {}; for (let k in event) { @@ -650,7 +637,10 @@ var FindBar = { } } // sendSyncMessage returns an array of the responses from all listeners - let rv = sendSyncMessage("Findbar:Keypress", fakeEvent); + let rv = sendSyncMessage("Findbar:Keypress", { + fakeEvent: fakeEvent, + shouldFastFind: shouldFastFind + }); if (rv.indexOf(false) !== -1) { event.preventDefault(); return false; diff --git a/toolkit/content/tests/browser/browser_findbar.js b/toolkit/content/tests/browser/browser_findbar.js index 0d08e4b41398..e438eb55b6de 100644 --- a/toolkit/content/tests/browser/browser_findbar.js +++ b/toolkit/content/tests/browser/browser_findbar.js @@ -158,6 +158,45 @@ add_task(function * test_reinitialization_at_remoteness_change() { yield BrowserTestUtils.removeTab(tab); }); +/** + * Ensure that the initial typed characters aren't lost immediately after + * opening the find bar. + */ +add_task(function* () { + // This test only makes sence in e10s evironment. + if (!gMultiProcessBrowser) { + info("Skipping this test because of non-e10s environment."); + return true; + } + + let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PAGE_URI); + let browser = tab.linkedBrowser; + + ok(!gFindBarInitialized, "findbar isn't initialized yet"); + + let findBar = gFindBar; + let initialValue = findBar._findField.value; + + EventUtils.synthesizeKey("f", { accelKey: true }, window); + + let promises = [ + BrowserTestUtils.sendChar("a", browser), + BrowserTestUtils.sendChar("b", browser), + BrowserTestUtils.sendChar("c", browser) + ]; + + isnot(document.activeElement, findBar._findField.inputField, + "findbar is not yet focused"); + is(findBar._findField.value, initialValue, "still has initial find query"); + + yield Promise.all(promises); + is(document.activeElement, findBar._findField.inputField, + "findbar is now focused"); + is(findBar._findField.value, "abc", "abc fully entered as find query"); + + yield BrowserTestUtils.removeTab(tab); +}); + function promiseFindFinished(searchText, highlightOn) { let deferred = Promise.defer(); diff --git a/toolkit/content/widgets/findbar.xml b/toolkit/content/widgets/findbar.xml index ebe76190d4eb..b55d87a55276 100644 --- a/toolkit/content/widgets/findbar.xml +++ b/toolkit/content/widgets/findbar.xml @@ -285,7 +285,7 @@ this._browser = val; if (this._browser) { - // Need to do this in case FAYT + // Need to do this to ensure the correct initial state. this._updateBrowserWithState(); this._browser.messageManager.addMessageListener("Findbar:Keypress", this); this._browser.messageManager.addMessageListener("Findbar:Mouseup", this); @@ -320,7 +320,6 @@ switch (aPrefName) { case "accessibility.typeaheadfind": this._self._findAsYouType = prefsvc.getBoolPref(aPrefName); - this._self._updateBrowserWithState(); break; case "accessibility.typeaheadfind.linksonly": this._self._typeAheadLinksOnly = prefsvc.getBoolPref(aPrefName); @@ -741,10 +740,21 @@ on the real event. --> + @@ -806,8 +820,7 @@