From d50cd925d5109007d565b0614aeff4e4aeb2f34f Mon Sep 17 00:00:00 2001 From: Felipe Gomes Date: Fri, 17 Jun 2011 17:09:05 -0700 Subject: [PATCH] Bug 583976. Part 2 - Remove manual focus activation in mobile and add a test. r=stechz --- mobile/chrome/content/browser.js | 12 +----- mobile/chrome/tests/Makefile.in | 3 ++ mobile/chrome/tests/browser_focus.html | 7 ++++ mobile/chrome/tests/browser_focus.js | 52 ++++++++++++++++++++++++++ mobile/chrome/tests/remote_focus.js | 16 ++++++++ 5 files changed, 79 insertions(+), 11 deletions(-) create mode 100644 mobile/chrome/tests/browser_focus.html create mode 100644 mobile/chrome/tests/browser_focus.js create mode 100644 mobile/chrome/tests/remote_focus.js diff --git a/mobile/chrome/content/browser.js b/mobile/chrome/content/browser.js index 26bd765d4ed8..edc128050980 100644 --- a/mobile/chrome/content/browser.js +++ b/mobile/chrome/content/browser.js @@ -1836,13 +1836,8 @@ const ContentTouchHandler = { }, tapDown: function tapDown(aX, aY) { - // Ensure that the content process has gets an activate event let browser = getBrowser(); - let fl = browser.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader; browser.focus(); - try { - fl.activateRemoteFrame(); - } catch (e) {} // if the page might capture touch events, we give it the option this.updateCanCancel(aX, aY); @@ -2964,12 +2959,7 @@ Tab.prototype = { Elements.browsers.selectedPanel = notification; browser.active = true; document.getElementById("tabs").selectedTab = this._chromeTab; - - // Ensure that the content process has gets an activate event - try { - let fl = browser.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader; - fl.activateRemoteFrame(); - } catch (e) {} + browser.focus(); } else { browser.messageManager.sendAsyncMessage("Browser:Blur", { }); browser.setAttribute("type", "content"); diff --git a/mobile/chrome/tests/Makefile.in b/mobile/chrome/tests/Makefile.in index 9525a7cf01d1..8a43668358a8 100644 --- a/mobile/chrome/tests/Makefile.in +++ b/mobile/chrome/tests/Makefile.in @@ -51,6 +51,7 @@ _BROWSER_FILES = \ remote_autocomplete.js \ remote_contentpopup.js \ remote_head.js \ + remote_focus.js \ remote_forms.js \ remote_formsZoom.js \ remote_vkb.js \ @@ -64,6 +65,8 @@ _BROWSER_FILES = \ browser_contacts.js \ browser_dragger.js \ browser_find.js \ + browser_focus.html \ + browser_focus.js \ browser_forms.html \ $(warning browser_forms.js disabled due to failures) \ browser_formsZoom.html \ diff --git a/mobile/chrome/tests/browser_focus.html b/mobile/chrome/tests/browser_focus.html new file mode 100644 index 000000000000..95550379da60 --- /dev/null +++ b/mobile/chrome/tests/browser_focus.html @@ -0,0 +1,7 @@ + + + Focus/Activate test + + + + diff --git a/mobile/chrome/tests/browser_focus.js b/mobile/chrome/tests/browser_focus.js new file mode 100644 index 000000000000..5b53f4339c48 --- /dev/null +++ b/mobile/chrome/tests/browser_focus.js @@ -0,0 +1,52 @@ +"use strict"; +let testURL = chromeRoot + "browser_focus.html"; +let newTab = null; + +function test() { + waitForExplicitFinish(); + + registerCleanupFunction(function() { + try { + messageManager.sendAsyncMessage("Test:E10SFocusTestFinished", {}); + Browser.closeTab(newTab); + } finally { + newTab = null; + } + }); + + messageManager.addMessageListener("pageshow", function listener(aMessage) { + if (newTab && newTab.browser.currentURI.spec != "about:blank") { + messageManager.removeMessageListener("pageshow", listener); + setTimeout(onTabLoaded, 0); + } + }); + + newTab = Browser.addTab(testURL, true); +} + +function onTabLoaded() { + // ensure that the is not already focused + newTab.browser.blur(); + messageManager.loadFrameScript(chromeRoot + "remote_focus.js", false); + testFocus(); +} + +function testFocus() { + onMessageOnce(messageManager, "Test:E10SFocusReceived", function() { + ok("Focus in triggered activateRemoteFrame as expected"); + testBlur(); + }); + newTab.browser.focus(); +} + +function testBlur() { + onMessageOnce(messageManager, "Test:E10SBlurReceived", function() { + ok("Blur in triggerered deactivateRemoteFrame as expected"); + endTest(); + }); + newTab.browser.blur(); +} + +function endTest() { + finish(); +} diff --git a/mobile/chrome/tests/remote_focus.js b/mobile/chrome/tests/remote_focus.js new file mode 100644 index 000000000000..d3c4544c2715 --- /dev/null +++ b/mobile/chrome/tests/remote_focus.js @@ -0,0 +1,16 @@ +function focusReceived() { + sendAsyncMessage("Test:E10SFocusReceived"); +} + +function blurReceived() { + sendAsyncMessage("Test:E10SBlurReceived"); +} + +addEventListener("focus", focusReceived, true); +addEventListener("blur", blurReceived, true); + +addMessageListener("Test:E10SFocusTestFinished", function testFinished() { + removeEventListener("focus", focusReceived, true); + removeEventListener("blur", blurReceived, true); + removeMessageListener("Test:E10SFocusTestFinished", testFinished); +});