Bug 1124604 - Add `focus` parameter to switch_to_window(). r=ato, a=test-only
authorHenrik Skupin <mail@hskupin.info>
Mon, 30 Jan 2017 15:35:16 +0100
changeset 375806 2253ac8c294734186443882d6e7139ea7926dba4
parent 375805 f7d5e5f56d5feb535ac50575d1d9366ced075b69
child 375807 ae7b6458f4de19dc45cb04ca8f665fb8f9ed43bf
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs1124604
milestone53.0a2
Bug 1124604 - Add `focus` parameter to switch_to_window(). r=ato, a=test-only To be able to run tests for backgrounds tabs, and to stay in compatibility with switch_to_frame(), switch_to_window() has to support the `focus` parameter. MozReview-Commit-ID: YGPJisiI2i
testing/marionette/browser.js
testing/marionette/client/marionette_driver/marionette.py
testing/marionette/driver.js
testing/marionette/harness/marionette_harness/tests/unit/test_switch_window_chrome.py
testing/marionette/harness/marionette_harness/tests/unit/test_switch_window_content.py
testing/marionette/harness/marionette_harness/tests/unit/test_window_handles_chrome.py
testing/marionette/harness/marionette_harness/tests/unit/test_window_handles_content.py
testing/marionette/harness/marionette_harness/tests/unit/test_window_management.py
testing/marionette/harness/marionette_harness/tests/unit/test_window_switching.py
testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini
testing/marionette/harness/marionette_harness/www/windowHandles.html
--- a/testing/marionette/browser.js
+++ b/testing/marionette/browser.js
@@ -19,58 +19,52 @@ const XUL_NS = "http://www.mozilla.org/k
 
 /**
  * Get the <xul:browser> for the specified tab.
  *
  * @param {<xul:tab>} tab
  *     The tab whose browser needs to be returned.
  *
  * @return {<xul:browser>}
- *     The linked browser for the tab.
- *
- * @throws UnsupportedOperationError
- *     If tab handling for the current application isn't supported.
+ *     The linked browser for the tab or null if no browser can be found.
  */
 browser.getBrowserForTab = function (tab) {
-  if (tab.hasOwnProperty("browser")) {
+  if ("browser" in tab) {
     // Fennec
     return tab.browser;
 
-  } else if (tab.hasOwnProperty("linkedBrowser")) {
+  } else if ("linkedBrowser" in tab) {
     // Firefox
     return tab.linkedBrowser;
 
   } else {
-      new UnsupportedOperationError("getBrowserForTab() not supported.");
+    return null;
   }
 };
 
 /**
  * Return the tab browser for the specified chrome window.
  *
  * @param {nsIDOMWindow} win
  *     The window whose tabbrowser needs to be accessed.
  *
  * @return {<xul:tabbrowser>}
  *     Tab browser or null if it's not a browser window.
- *
- * @throws UnsupportedOperationError
- *     If tab handling for the current application isn't supported.
  */
 browser.getTabBrowser = function (win) {
-  if (win.hasOwnProperty("BrowserApp")) {
+  if ("BrowserApp" in win) {
     // Fennec
     return win.BrowserApp;
 
-  } else if (win.hasOwnProperty("gBrowser")) {
+  } else if ("gBrowser" in win) {
     // Firefox
     return win.gBrowser;
 
   } else {
-      new UnsupportedOperationError("getBrowserForTab() not supported.");
+    return null;
   }
 };
 
 /**
  * Creates a browsing context wrapper.
  *
  * Browsing contexts handle interactions with the browser, according to
  * the current environment (desktop, B2G, Fennec, &c).
@@ -239,39 +233,50 @@ browser.Context = class {
   /**
    * Set the current tab and update remoteness tracking if a tabbrowser is available.
    *
    * @param {number=} index
    *     Tab index to switch to. If the parameter is undefined,
    *     the currently selected tab will be used.
    * @param {nsIDOMWindow=} win
    *     Switch to this window before selecting the tab.
+   * @param {boolean=} focus
+   *      A boolean value which determins whether to focus
+   *      the window. Defaults to true.
+   *
+   * @throws UnsupportedOperationError
+   *     If tab handling for the current application isn't supported.
    */
-  switchToTab(index, win) {
+  switchToTab(index, win, focus = true) {
     if (win) {
       this.window = win;
       this.tabBrowser = browser.getTabBrowser(win);
     }
 
     if (!this.tabBrowser) {
       return;
     }
 
     if (typeof index == "undefined") {
       this.tab = this.tabBrowser.selectedTab;
     } else {
       this.tab = this.tabBrowser.tabs[index];
 
-      if (this.tabBrowser.selectTab) {
-        // Fennec
-        this.tabBrowser.selectTab(this.tab);
+      if (focus) {
+        if (this.tabBrowser.selectTab) {
+          // Fennec
+          this.tabBrowser.selectTab(this.tab);
 
-      } else {
-        // Firefox
-        this.tabBrowser.selectedTab = this.tab;
+        } else if ("selectedTab" in this.tabBrowser) {
+          // Firefox
+          this.tabBrowser.selectedTab = this.tab;
+
+        } else {
+          throw new UnsupportedOperationError("switchToTab() not supported");
+        }
       }
     }
 
     if (this.driver.appName == "Firefox") {
       this._browserWasRemote = browser.getBrowserForTab(this.tab).isRemoteBrowser;
       this._hasRemotenessChange = false;
     }
   }
--- a/testing/marionette/client/marionette_driver/marionette.py
+++ b/testing/marionette/client/marionette_driver/marionette.py
@@ -1554,23 +1554,27 @@ class Marionette(object):
         ::
 
             alert = self.marionette.switch_to_alert()
             text = alert.text
             alert.accept()
         """
         return Alert(self)
 
-    def switch_to_window(self, window_id):
+    def switch_to_window(self, window_id, focus=True):
         """Switch to the specified window; subsequent commands will be
         directed at the new window.
 
         :param window_id: The id or name of the window to switch to.
+
+        :param focus: A boolean value which determins whether to focus
+            the window that we just switched to.
         """
-        self._send_message("switchToWindow", {"name": window_id})
+        body = {"focus": focus, "name": window_id}
+        self._send_message("switchToWindow", body)
         self.window = window_id
 
     def get_active_frame(self):
         """Returns an HTMLElement representing the frame Marionette is
         currently acting on."""
         return self._send_message("getActiveFrame", key="value")
 
     def switch_to_default_content(self):
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -510,17 +510,17 @@ GeckoDriver.prototype.registerBrowser = 
     if (this.curBrowser.isNewSession) {
       this.newSessionCommandId = null;
     }
   }
 
   return [reg, mainContent, this.capabilities.toJSON()];
 };
 
-GeckoDriver.prototype.registerPromise = function() {
+GeckoDriver.prototype.registerPromise = function () {
   const li = "Marionette:register";
 
   return new Promise(resolve => {
     let cb = msg => {
       let wid = msg.json.value;
       let be = msg.target;
       let rv = this.registerBrowser(wid, be);
 
@@ -535,29 +535,29 @@ GeckoDriver.prototype.registerPromise = 
 
       // this is a sync message and listeners expect the ID back
       return rv;
     };
     this.mm.addMessageListener(li, cb);
   });
 };
 
-GeckoDriver.prototype.listeningPromise = function() {
+GeckoDriver.prototype.listeningPromise = function () {
   const li = "Marionette:listenersAttached";
   return new Promise(resolve => {
     let cb = () => {
       this.mm.removeMessageListener(li, cb);
       resolve();
     };
     this.mm.addMessageListener(li, cb);
   });
 };
 
 /** Create a new session. */
-GeckoDriver.prototype.newSession = function*(cmd, resp) {
+GeckoDriver.prototype.newSession = function* (cmd, resp) {
   if (this.sessionId) {
     throw new SessionNotCreatedError("Maximum number of active sessions");
   }
 
   this.sessionId = cmd.parameters.sessionId ||
       cmd.parameters.session_id ||
       element.generateUUID();
   this.newSessionCommandId = cmd.id;
@@ -1186,19 +1186,23 @@ GeckoDriver.prototype.setWindowPosition 
 };
 
 /**
  * Switch current top-level browsing context by name or server-assigned ID.
  * Searches for windows by name, then ID.  Content windows take precedence.
  *
  * @param {string} name
  *     Target name or ID of the window to switch to.
+ * @param {boolean=} focus
+ *      A boolean value which determines whether to focus
+ *      the window. Defaults to true.
  */
 GeckoDriver.prototype.switchToWindow = function* (cmd, resp) {
   let switchTo = cmd.parameters.name;
+  let focus = (cmd.parameters.focus !== undefined) ? cmd.parameters.focus : true;
   let found;
 
   let byNameOrId = function (name, outerId, contentWindowId) {
     return switchTo == name ||
         switchTo == contentWindowId ||
         switchTo == outerId;
   };
 
@@ -1246,17 +1250,17 @@ GeckoDriver.prototype.switchToWindow = f
       if (registerBrowsers && browserListening) {
         yield registerBrowsers;
         yield browserListening;
       }
     } else {
       this.curBrowser = this.browsers[found.outerId];
 
       if ("tabIndex" in found) {
-        this.curBrowser.switchToTab(found.tabIndex, found.win);
+        this.curBrowser.switchToTab(found.tabIndex, found.win, focus);
       }
     }
   } else {
     throw new NoSuchWindowError(`Unable to locate window: ${switchTo}`);
   }
 };
 
 GeckoDriver.prototype.getActiveFrame = function (cmd, resp) {
new file mode 100644
--- /dev/null
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_switch_window_chrome.py
@@ -0,0 +1,124 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import sys
+from unittest import skipIf
+
+from marionette_driver import By
+
+# add this directory to the path
+sys.path.append(os.path.dirname(__file__))
+
+from test_switch_window_content import TestSwitchToWindowContent
+
+
+class TestSwitchWindowChrome(TestSwitchToWindowContent):
+
+    def setUp(self):
+        super(TestSwitchWindowChrome, self).setUp()
+
+        self.marionette.set_context("chrome")
+
+    def tearDown(self):
+        self.close_all_windows()
+
+        super(TestSwitchWindowChrome, self).tearDown()
+
+    def open_window_in_background(self):
+        with self.marionette.using_context("chrome"):
+            self.marionette.execute_script("""
+              window.open("about:blank", null, "location=1,toolbar=1");
+              window.focus();
+            """)
+
+    def open_window_in_foreground(self):
+        with self.marionette.using_context("content"):
+            self.marionette.navigate(self.test_page)
+            link = self.marionette.find_element(By.ID, "new-window")
+            link.click()
+
+    @skipIf(sys.platform.startswith("linux"),
+            "Bug 1335457 - Fails to open a background window on Linux")
+    def test_switch_tabs_for_new_background_window_without_focus_change(self):
+        # Bug 1334981 - with testmode enabled getMostRecentWindow detects the wrong window
+        with self.marionette.using_prefs({"focusmanager.testmode": False}):
+            # Open an addition tab in the original window so we can better check
+            # the selected index in thew new window to be opened.
+            second_tab = self.open_tab(trigger=self.open_tab_in_foreground)
+            self.marionette.switch_to_window(second_tab, focus=True)
+            second_tab_index = self.get_selected_tab_index()
+            self.assertNotEqual(second_tab_index, self.selected_tab_index)
+
+            # Opens a new background window, but we are interested in the tab
+            tab_in_new_window = self.open_tab(trigger=self.open_window_in_background)
+            self.assertEqual(self.marionette.current_window_handle, second_tab)
+            self.assertEqual(self.marionette.current_chrome_window_handle, self.start_window)
+            self.assertEqual(self.get_selected_tab_index(), second_tab_index)
+            with self.marionette.using_context("content"):
+                self.assertEqual(self.marionette.get_url(), self.empty_page)
+
+            # Switch to the tab in the new window but don't focus it
+            self.marionette.switch_to_window(tab_in_new_window, focus=False)
+            self.assertEqual(self.marionette.current_window_handle, tab_in_new_window)
+            self.assertNotEqual(self.marionette.current_chrome_window_handle, self.start_window)
+            self.assertEqual(self.get_selected_tab_index(), second_tab_index)
+            with self.marionette.using_context("content"):
+                self.assertEqual(self.marionette.get_url(), "about:blank")
+
+    def test_switch_tabs_for_new_foreground_window_with_focus_change(self):
+        # Open an addition tab in the original window so we can better check
+        # the selected index in thew new window to be opened.
+        second_tab = self.open_tab(trigger=self.open_tab_in_foreground)
+        self.marionette.switch_to_window(second_tab, focus=True)
+        second_tab_index = self.get_selected_tab_index()
+        self.assertNotEqual(second_tab_index, self.selected_tab_index)
+
+        # Opens a new window, but we are interested in the tab
+        tab_in_new_window = self.open_tab(trigger=self.open_window_in_foreground)
+        self.assertEqual(self.marionette.current_window_handle, second_tab)
+        self.assertEqual(self.marionette.current_chrome_window_handle, self.start_window)
+        self.assertNotEqual(self.get_selected_tab_index(), second_tab_index)
+        with self.marionette.using_context("content"):
+            self.assertEqual(self.marionette.get_url(), self.test_page)
+
+        self.marionette.switch_to_window(tab_in_new_window)
+        self.assertEqual(self.marionette.current_window_handle, tab_in_new_window)
+        self.assertNotEqual(self.marionette.current_chrome_window_handle, self.start_window)
+        self.assertNotEqual(self.get_selected_tab_index(), second_tab_index)
+        with self.marionette.using_context("content"):
+            self.assertEqual(self.marionette.get_url(), self.empty_page)
+
+        self.marionette.switch_to_window(second_tab, focus=True)
+        self.assertEqual(self.marionette.current_window_handle, second_tab)
+        self.assertEqual(self.marionette.current_chrome_window_handle, self.start_window)
+        # Bug 1335085 - The focus doesn't change even as requested so.
+        # self.assertEqual(self.get_selected_tab_index(), second_tab_index)
+        with self.marionette.using_context("content"):
+            self.assertEqual(self.marionette.get_url(), self.test_page)
+
+    def test_switch_tabs_for_new_foreground_window_without_focus_change(self):
+        # Open an addition tab in the original window so we can better check
+        # the selected index in thew new window to be opened.
+        second_tab = self.open_tab(trigger=self.open_tab_in_foreground)
+        self.marionette.switch_to_window(second_tab, focus=True)
+        second_tab_index = self.get_selected_tab_index()
+        self.assertNotEqual(second_tab_index, self.selected_tab_index)
+
+        # Opens a new window, but we are interested in the tab which automatically
+        # gets the focus.
+        self.open_tab(trigger=self.open_window_in_foreground)
+        self.assertEqual(self.marionette.current_window_handle, second_tab)
+        self.assertEqual(self.marionette.current_chrome_window_handle, self.start_window)
+        self.assertNotEqual(self.get_selected_tab_index(), second_tab_index)
+        with self.marionette.using_context("content"):
+            self.assertEqual(self.marionette.get_url(), self.test_page)
+
+        # Switch to the second tab in the first window, but don't focus it.
+        self.marionette.switch_to_window(second_tab, focus=False)
+        self.assertEqual(self.marionette.current_window_handle, second_tab)
+        self.assertEqual(self.marionette.current_chrome_window_handle, self.start_window)
+        self.assertNotEqual(self.get_selected_tab_index(), second_tab_index)
+        with self.marionette.using_context("content"):
+            self.assertEqual(self.marionette.get_url(), self.test_page)
rename from testing/marionette/harness/marionette_harness/tests/unit/test_window_switching.py
rename to testing/marionette/harness/marionette_harness/tests/unit/test_switch_window_content.py
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_window_switching.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_switch_window_content.py
@@ -1,45 +1,136 @@
-# This Source Code Form is subject to the terms of the Mozilla Public
+# This Source Code Form is subject to the terms of the Mozilla ublic
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
-from marionette_driver.by import By
-from marionette_driver.errors import NoSuchElementException
-from marionette_driver.wait import Wait
+from marionette_driver import Actions, By
+from marionette_driver.keys import Keys
 
 from marionette_harness import MarionetteTestCase, WindowManagerMixin
 
 
-class TestWindowSwitching(WindowManagerMixin, MarionetteTestCase):
+class TestSwitchToWindowContent(WindowManagerMixin, MarionetteTestCase):
+
+    def setUp(self):
+        super(TestSwitchToWindowContent, self).setUp()
+
+        if self.marionette.session_capabilities["platformName"] == "darwin":
+            self.mod_key = Keys.META
+        else:
+            self.mod_key = Keys.CONTROL
+
+        self.empty_page = self.marionette.absolute_url("empty.html")
+        self.test_page = self.marionette.absolute_url("windowHandles.html")
+
+        self.selected_tab_index = self.get_selected_tab_index()
+
+        with self.marionette.using_context("content"):
+            self.marionette.navigate(self.test_page)
+
+    def tearDown(self):
+        self.close_all_tabs()
+
+        super(TestSwitchToWindowContent, self).tearDown()
+
+    def get_selected_tab_index(self):
+        with self.marionette.using_context("chrome"):
+            return self.marionette.execute_script("""
+                Components.utils.import("resource://gre/modules/AppConstants.jsm");
+
+                let win = null;
 
-    def testJSWindowCreationAndSwitching(self):
-        test_html = self.marionette.absolute_url("test_windows.html")
-        self.marionette.navigate(test_html)
+                if (AppConstants.MOZ_APP_NAME == "fennec") {
+                  Components.utils.import("resource://gre/modules/Services.jsm");
+                  win = Services.wm.getMostRecentWindow("navigator:browser");
+                } else {
+                  Components.utils.import("resource:///modules/RecentWindow.jsm");
+                  win = RecentWindow.getMostRecentBrowserWindow();
+                }
+
+                let tabBrowser = null;
+
+                // Fennec
+                if (win.BrowserApp) {
+                  tabBrowser = win.BrowserApp;
+
+                // Firefox
+                } else if (win.gBrowser) {
+                  tabBrowser = win.gBrowser;
 
-        def open_window_with_link():
-            link = self.marionette.find_element(By.LINK_TEXT, "Open new window")
+                } else {
+                  return null;
+                }
+
+                for (let i = 0; i < tabBrowser.tabs.length; i++) {
+                  if (tabBrowser.tabs[i] == tabBrowser.selectedTab) {
+                    return i;
+                  }
+                }
+            """)
+
+    def open_tab_in_background(self):
+        with self.marionette.using_context("content"):
+            link = self.marionette.find_element(By.ID, "new-tab")
+
+            action = Actions(self.marionette)
+            action.key_down(self.mod_key).click(link).perform()
+
+    def open_tab_in_foreground(self):
+        with self.marionette.using_context("content"):
+            link = self.marionette.find_element(By.ID, "new-tab")
             link.click()
 
-        new_window = self.open_window(trigger=open_window_with_link)
-        self.marionette.switch_to_window(new_window)
+    def test_switch_tabs_with_focus_change(self):
+        new_tab = self.open_tab(self.open_tab_in_foreground)
+        self.assertEqual(self.marionette.current_window_handle, self.start_tab)
+        self.assertNotEqual(self.get_selected_tab_index(), self.selected_tab_index)
+        with self.marionette.using_context("content"):
+            self.assertEqual(self.marionette.get_url(), self.test_page)
+
+        self.marionette.switch_to_window(new_tab)
+        self.assertEqual(self.marionette.current_window_handle, new_tab)
+        self.assertNotEqual(self.get_selected_tab_index(), self.selected_tab_index)
 
-        title = self.marionette.execute_script("return document.title")
-        results_page = self.marionette.absolute_url("resultPage.html")
-        self.assertEqual(self.marionette.get_url(), results_page)
-        self.assertEqual(title, "We Arrive Here")
+        with self.marionette.using_context("content"):
+            self.assertEqual(self.marionette.get_url(), self.empty_page)
 
-        # ensure navigate works in our current window
-        other_page = self.marionette.absolute_url("test.html")
-        self.marionette.navigate(other_page)
+        self.marionette.switch_to_window(self.start_tab, focus=True)
+        self.assertEqual(self.marionette.current_window_handle, self.start_tab)
+        self.assertEqual(self.get_selected_tab_index(), self.selected_tab_index)
+        with self.marionette.using_context("content"):
+            self.assertEqual(self.marionette.get_url(), self.test_page)
+
+        self.marionette.switch_to_window(new_tab)
+        self.marionette.close()
+        self.marionette.switch_to_window(self.start_tab)
 
-        # try to access its dom
-        # since Bug 720714 stops us from checking DOMContentLoaded, we wait a bit
-        Wait(self.marionette, timeout=30, ignored_exceptions=NoSuchElementException).until(
-            lambda m: m.find_element(By.ID, 'mozLink'))
+        self.assertEqual(self.marionette.current_window_handle, self.start_tab)
+        self.assertEqual(self.get_selected_tab_index(), self.selected_tab_index)
+        with self.marionette.using_context("content"):
+            self.assertEqual(self.marionette.get_url(), self.test_page)
+
+    def test_switch_tabs_without_focus_change(self):
+        new_tab = self.open_tab(self.open_tab_in_foreground)
+        self.assertEqual(self.marionette.current_window_handle, self.start_tab)
+        self.assertNotEqual(self.get_selected_tab_index(), self.selected_tab_index)
+        with self.marionette.using_context("content"):
+            self.assertEqual(self.marionette.get_url(), self.test_page)
+
+        # Switch to new tab first because it is already selected
+        self.marionette.switch_to_window(new_tab)
+        self.assertEqual(self.marionette.current_window_handle, new_tab)
 
-        self.assertEqual(new_window, self.marionette.current_chrome_window_handle)
-        self.marionette.switch_to_window(self.start_window)
-        self.assertEqual(self.start_window, self.marionette.current_chrome_window_handle)
+        self.marionette.switch_to_window(self.start_tab, focus=False)
+        self.assertEqual(self.marionette.current_window_handle, self.start_tab)
+        self.assertNotEqual(self.get_selected_tab_index(), self.selected_tab_index)
+
+        with self.marionette.using_context("content"):
+            self.assertEqual(self.marionette.get_url(), self.test_page)
 
-    def tearDown(self):
-        self.close_all_windows()
-        super(TestWindowSwitching, self).tearDown()
+        self.marionette.switch_to_window(new_tab)
+        self.marionette.close()
+
+        self.marionette.switch_to_window(self.start_tab)
+        self.assertEqual(self.marionette.current_window_handle, self.start_tab)
+        self.assertEqual(self.get_selected_tab_index(), self.selected_tab_index)
+        with self.marionette.using_context("content"):
+            self.assertEqual(self.marionette.get_url(), self.test_page)
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_window_handles_chrome.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_window_handles_chrome.py
@@ -57,16 +57,22 @@ class TestWindowHandles(WindowManagerMix
         self.assertEqual(self.marionette.current_chrome_window_handle, self.start_window)
 
         # Check that the new tab has the correct page loaded
         self.marionette.switch_to_window(new_win)
         self.assertEqual(self.marionette.current_chrome_window_handle, new_win)
         with self.marionette.using_context("content"):
             self.assertEqual(self.marionette.get_url(), self.empty_page)
 
+        # Ensure navigate works in our current window
+        other_page = self.marionette.absolute_url("test.html")
+        with self.marionette.using_context("content"):
+            self.marionette.navigate(other_page)
+            self.assertEqual(self.marionette.get_url(), other_page)
+
         # Close the opened window and carry on in our original tab.
         self.marionette.close()
         self.assertEqual(len(self.marionette.chrome_window_handles), len(self.start_windows))
 
         self.marionette.switch_to_window(self.start_window)
         self.assertEqual(self.marionette.current_chrome_window_handle, self.start_window)
         with self.marionette.using_context("content"):
             self.assertEqual(self.marionette.get_url(), self.test_page)
@@ -81,16 +87,22 @@ class TestWindowHandles(WindowManagerMix
         self.assertEqual(len(self.marionette.window_handles), len(self.start_tabs) + 1)
         self.assertEqual(self.marionette.current_window_handle, self.start_tab)
 
         self.marionette.switch_to_window(new_tab)
         self.assertEqual(self.marionette.current_window_handle, new_tab)
         with self.marionette.using_context("content"):
             self.assertEqual(self.marionette.get_url(), self.empty_page)
 
+        # Ensure navigate works in our current tab
+        other_page = self.marionette.absolute_url("test.html")
+        with self.marionette.using_context("content"):
+            self.marionette.navigate(other_page)
+            self.assertEqual(self.marionette.get_url(), other_page)
+
         self.marionette.switch_to_window(self.start_tab)
         self.assertEqual(self.marionette.current_window_handle, self.start_tab)
         with self.marionette.using_context("content"):
             self.assertEqual(self.marionette.get_url(), self.test_page)
 
         self.marionette.switch_to_window(new_tab)
         self.marionette.close()
         self.assertEqual(len(self.marionette.window_handles), len(self.start_tabs))
@@ -110,16 +122,22 @@ class TestWindowHandles(WindowManagerMix
         self.assertEqual(self.marionette.current_window_handle, self.start_tab)
 
         # Check that the new tab has the correct page loaded
         self.marionette.switch_to_window(new_tab)
         self.assertEqual(self.marionette.current_window_handle, new_tab)
         with self.marionette.using_context("content"):
             self.assertEqual(self.marionette.get_url(), self.empty_page)
 
+        # Ensure navigate works in our current window
+        other_page = self.marionette.absolute_url("test.html")
+        with self.marionette.using_context("content"):
+            self.marionette.navigate(other_page)
+            self.assertEqual(self.marionette.get_url(), other_page)
+
         # Close the opened window and carry on in our original tab.
         self.marionette.close()
         self.assertEqual(len(self.marionette.window_handles), len(self.start_tabs))
 
         self.marionette.switch_to_window(self.start_tab)
         self.assertEqual(self.marionette.current_window_handle, self.start_tab)
         with self.marionette.using_context("content"):
             self.assertEqual(self.marionette.get_url(), self.test_page)
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_window_handles_content.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_window_handles_content.py
@@ -55,31 +55,36 @@ class TestWindowHandles(WindowManagerMix
         self.assertEqual(len(self.marionette.window_handles), len(self.start_tabs) + 1)
         self.assertEqual(self.marionette.current_window_handle, self.start_tab)
 
         # Check that the new tab has the correct page loaded
         self.marionette.switch_to_window(new_tab)
         self.assertEqual(self.marionette.current_window_handle, new_tab)
         self.assertEqual(self.marionette.get_url(), self.empty_page)
 
+        # Ensure navigate works in our current window
+        other_page = self.marionette.absolute_url("test.html")
+        self.marionette.navigate(other_page)
+        self.assertEqual(self.marionette.get_url(), other_page)
+
         # Close the opened window and carry on in our original tab.
         self.marionette.close()
         self.assertEqual(len(self.marionette.window_handles), len(self.start_tabs))
 
         self.marionette.switch_to_window(self.start_tab)
         self.assertEqual(self.marionette.current_window_handle, self.start_tab)
         self.assertEqual(self.marionette.get_url(), self.test_page)
 
     def test_window_handles_after_closing_original_tab(self):
         def open_with_link():
             link = self.marionette.find_element(By.ID, "new-tab")
             link.click()
 
         new_tab = self.open_tab(trigger=open_with_link)
         self.assertEqual(len(self.marionette.window_handles), len(self.start_tabs) + 1)
-        self.assertNotEqual(self.marionette.current_window_handle, new_tab)
+        self.assertEqual(self.marionette.current_window_handle, self.start_tab)
 
         self.marionette.close()
         self.assertEqual(len(self.marionette.window_handles), len(self.start_tabs))
 
         self.marionette.switch_to_window(new_tab)
         self.assertEqual(self.marionette.current_window_handle, new_tab)
         self.assertEqual(self.marionette.get_url(), self.empty_page)
deleted file mode 100644
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_window_management.py
+++ /dev/null
@@ -1,58 +0,0 @@
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-from marionette_driver import By
-
-from marionette_harness import MarionetteTestCase, WindowManagerMixin
-
-
-class TestSwitchWindow(WindowManagerMixin, MarionetteTestCase):
-
-    def setUp(self):
-        super(TestSwitchWindow, self).setUp()
-        self.marionette.set_context("chrome")
-
-    def tearDown(self):
-        self.close_all_windows()
-        super(TestSwitchWindow, self).tearDown()
-
-    def test_windows(self):
-        def open_browser_with_js():
-            self.marionette.execute_script(" window.open(); ")
-
-        new_window = self.open_window(trigger=open_browser_with_js)
-        self.assertEqual(self.marionette.current_chrome_window_handle, self.start_window)
-
-        # switch to the other window
-        self.marionette.switch_to_window(new_window)
-        self.assertEqual(self.marionette.current_chrome_window_handle, new_window)
-        self.assertNotEqual(self.marionette.current_chrome_window_handle, self.start_window)
-
-        # switch back and close original window
-        self.marionette.switch_to_window(self.start_window)
-        self.assertEqual(self.marionette.current_chrome_window_handle, self.start_window)
-        self.marionette.close_chrome_window()
-        self.assertNotIn(self.start_window, self.marionette.chrome_window_handles)
-        self.assertEqual(self.marionette.current_chrome_window_handle, self.start_window)
-        self.assertEqual(len(self.marionette.chrome_window_handles), len(self.start_windows))
-
-    def test_should_load_and_close_a_window(self):
-        def open_window_with_link():
-            test_html = self.marionette.absolute_url("test_windows.html")
-            with self.marionette.using_context("content"):
-                self.marionette.navigate(test_html)
-                self.marionette.find_element(By.LINK_TEXT, "Open new window").click()
-
-        new_window = self.open_window(trigger=open_window_with_link)
-        self.marionette.switch_to_window(new_window)
-        self.assertEqual(self.marionette.current_chrome_window_handle, new_window)
-        self.assertEqual(len(self.marionette.chrome_window_handles), 2)
-
-        with self.marionette.using_context('content'):
-            self.assertEqual(self.marionette.title, "We Arrive Here")
-
-        # Let's close and check
-        self.marionette.close_chrome_window()
-        self.marionette.switch_to_window(self.start_window)
-        self.assertEqual(len(self.marionette.chrome_window_handles), 1)
--- a/testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini
+++ b/testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini
@@ -55,34 +55,33 @@ skip-if = appname == 'fennec' || os == "
 [test_anonymous_content.py]
 skip-if = appname == 'fennec'
 [test_switch_frame.py]
 skip-if = os == "win" # Bug 1078237
 [test_switch_frame_chrome.py]
 skip-if = appname == 'fennec'
 [test_switch_remote_frame.py]
 skip-if = appname == 'fennec'
+[test_switch_window_chrome.py]
+skip-if = appname == 'fennec'
+[test_switch_window_content.py]
 
 [test_pagesource.py]
 [test_pagesource_chrome.py]
 skip-if = appname == 'fennec'
 
 [test_visibility.py]
-[test_window_switching.py]
+[test_window_handles_chrome.py]
 skip-if = appname == 'fennec'
-[test_window_management.py]
-skip-if = appname == 'fennec'
+[test_window_handles_content.py]
 [test_window_close_chrome.py]
 skip-if = appname == 'fennec'
 [test_window_close_content.py]
 [test_window_position.py]
 skip-if = appname == 'fennec'
-[test_window_handles_content.py]
-[test_window_handles_chrome.py]
-skip-if = appname == 'fennec'
 
 [test_screenshot.py]
 [test_cookies.py]
 [test_window_title.py]
 [test_window_title_chrome.py]
 skip-if = appname == 'fennec'
 [test_window_type.py]
 skip-if = appname == 'fennec'
--- a/testing/marionette/harness/marionette_harness/www/windowHandles.html
+++ b/testing/marionette/harness/marionette_harness/www/windowHandles.html
@@ -8,9 +8,9 @@
 <title>Marionette New Tab Link</title>
 </head>
 <body>
   <a href="empty.html" id="new-tab" target="_blank">New Tab</a>
   <a href="about:blank" id="new-blank-tab" target="_blank">New blank Tab</a>
 
   <a href="" id="new-window" onClick='javascript:window.open("empty.html", null, "location=1,toolbar=1");'>New Window</a>
 </body>
-</html>
+</html>
\ No newline at end of file