Skip to content

Commit

Permalink
Bug 1328676 - Focus web content on starting new session and navigatin…
Browse files Browse the repository at this point in the history
…g. r=automatedtester, a=test-only

When a new Marionette session is started, the web content frame (currently
selected <xul:browser> element) is not in focus, causing issues such
as mozilla/geckodriver#394.

This changes the current web content to be selected upon top-level
browsing context navigation and the creation of new sessions.

MozReview-Commit-ID: EgG9gRHtwOA

--HG--
extra : source : 8c25f4454f5bf48257416a1443cd715d44bdd492
  • Loading branch information
andreastt committed Jan 4, 2017
1 parent f3348c4 commit 6800df5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions testing/marionette/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@ GeckoDriver.prototype.newSession = function*(cmd, resp) {
yield registerBrowsers;
yield browserListening;

this.curBrowser.browserForTab.focus();

return {
sessionId: this.sessionId,
capabilities: this.sessionCapabilities,
Expand Down Expand Up @@ -1027,6 +1029,7 @@ GeckoDriver.prototype.get = function*(cmd, resp) {
});

yield get;
this.curBrowser.browserForTab.focus();
};

/**
Expand Down Expand Up @@ -2336,8 +2339,7 @@ GeckoDriver.prototype.sessionTearDown = function (cmd, resp) {
if (this.mainFrame) {
try {
this.mainFrame.focus();
}
catch (e) {
} catch (e) {
this.mainFrame = null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ def test_image_document_to_image_document(self):
self.marionette.navigate(self.fixtures.where_is("black.png"))
self.assertIn("black.png", self.marionette.title)

def test_focus_after_navigation(self):
self.marionette.quit()
self.marionette.start_session()

self.marionette.navigate(inline("<input autofocus>"))
active_el = self.marionette.execute_script("return document.activeElement")
focus_el = self.marionette.find_element(By.CSS_SELECTOR, ":focus")
self.assertEqual(active_el, focus_el)


class TestTLSNavigation(MarionetteTestCase):
insecure_tls = {"acceptInsecureCerts": True}
Expand Down

0 comments on commit 6800df5

Please sign in to comment.