Bug 1311350 - Add unit tests for close window commands. r=ato a=test-only
authorHenrik Skupin <mail@hskupin.info>
Mon, 09 Jan 2017 23:06:00 +0100
changeset 353545 81a582e0ca627c4faa88e2b354428ec373910176
parent 353544 7691c31a7067cad93013eb8d36d4c067f6cf2247
child 353546 b451be5d9f7b076877b402b08285c2f466cc1026
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs1311350
milestone52.0a2
Bug 1311350 - Add unit tests for close window commands. r=ato a=test-only MozReview-Commit-ID: Ldsx5M1vxCe
testing/marionette/harness/marionette_harness/__init__.py
testing/marionette/harness/marionette_harness/runner/mixins/window_manager.py
testing/marionette/harness/marionette_harness/tests/unit/test_window_close_chrome.py
testing/marionette/harness/marionette_harness/tests/unit/test_window_close_content.py
testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini
--- a/testing/marionette/harness/marionette_harness/__init__.py
+++ b/testing/marionette/harness/marionette_harness/__init__.py
@@ -3,16 +3,17 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 __version__ = '4.0.0'
 
 from .marionette_test import (
     CommonTestCase,
     expectedFailure,
     MarionetteTestCase,
+    parameterized,
     run_if_e10s,
     run_if_manage_instance,
     skip,
     skip_if_chrome,
     skip_if_desktop,
     skip_if_e10s,
     skip_if_mobile,
     SkipTest,
--- a/testing/marionette/harness/marionette_harness/runner/mixins/window_manager.py
+++ b/testing/marionette/harness/marionette_harness/runner/mixins/window_manager.py
@@ -91,17 +91,17 @@ class WindowManagerMixin(object):
             [new_tab] = list(set(self.marionette.window_handles) - set(current_tabs))
 
             return new_tab
 
     def open_window(self, trigger=None):
         current_windows = self.marionette.chrome_window_handles
 
         def loaded(handle):
-            with self.marionette.using_context('chrome'):
+            with self.marionette.using_context("chrome"):
                 return self.marionette.execute_script("""
                   Components.utils.import("resource://gre/modules/Services.jsm");
 
                   let win = Services.wm.getOuterWindowWithId(Number(arguments[0]));
                   return win.document.readyState == "complete";
                 """, script_args=[handle])
 
         try:
new file mode 100644
--- /dev/null
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_window_close_chrome.py
@@ -0,0 +1,80 @@
+# 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_harness import MarionetteTestCase, WindowManagerMixin
+
+
+class TestCloseWindow(WindowManagerMixin, MarionetteTestCase):
+
+    def setUp(self):
+        super(TestCloseWindow, self).setUp()
+
+        self.marionette.set_context("chrome")
+
+    def tearDown(self):
+        self.close_all_windows()
+        self.close_all_tabs()
+
+        super(TestCloseWindow, self).tearDown()
+
+    def test_close_chrome_window_for_browser_window(self):
+        win = self.open_window()
+        self.marionette.switch_to_window(win)
+
+        self.assertNotIn(win, self.marionette.window_handles)
+        chrome_window_handles = self.marionette.close_chrome_window()
+        self.assertNotIn(win, chrome_window_handles)
+        self.assertListEqual(self.start_windows, chrome_window_handles)
+        self.assertNotIn(win, self.marionette.window_handles)
+
+    def test_close_chrome_window_for_non_browser_window(self):
+
+        def open_window_with_js():
+            self.marionette.execute_script("""
+              window.open('chrome://marionette/content/test.xul',
+                          'foo', 'chrome,centerscreen');
+            """)
+
+        win = self.open_window(trigger=open_window_with_js)
+        self.marionette.switch_to_window(win)
+
+        self.assertIn(win, self.marionette.window_handles)
+        chrome_window_handles = self.marionette.close_chrome_window()
+        self.assertNotIn(win, chrome_window_handles)
+        self.assertListEqual(self.start_windows, chrome_window_handles)
+        self.assertNotIn(win, self.marionette.window_handles)
+
+    def test_close_chrome_window_for_last_open_window(self):
+        self.close_all_windows()
+
+        self.assertListEqual([], self.marionette.close_chrome_window())
+        self.assertListEqual([self.start_tab], self.marionette.window_handles)
+        self.assertListEqual([self.start_window], self.marionette.chrome_window_handles)
+        self.assertIsNotNone(self.marionette.session)
+
+    def test_close_window_for_browser_tab(self):
+        tab = self.open_tab()
+        self.marionette.switch_to_window(tab)
+
+        window_handles = self.marionette.close()
+        self.assertNotIn(tab, window_handles)
+        self.assertListEqual(self.start_tabs, window_handles)
+
+    def test_close_window_for_browser_window_with_single_tab(self):
+        win = self.open_window()
+        self.marionette.switch_to_window(win)
+
+        self.assertEqual(len(self.start_tabs) + 1, len(self.marionette.window_handles))
+        window_handles = self.marionette.close()
+        self.assertNotIn(win, window_handles)
+        self.assertListEqual(self.start_tabs, window_handles)
+        self.assertListEqual(self.start_windows, self.marionette.chrome_window_handles)
+
+    def test_close_window_for_last_open_tab(self):
+        self.close_all_tabs()
+
+        self.assertListEqual([], self.marionette.close())
+        self.assertListEqual([self.start_tab], self.marionette.window_handles)
+        self.assertListEqual([self.start_window], self.marionette.chrome_window_handles)
+        self.assertIsNotNone(self.marionette.session)
new file mode 100644
--- /dev/null
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_window_close_content.py
@@ -0,0 +1,80 @@
+# 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_harness import MarionetteTestCase, skip_if_mobile, WindowManagerMixin
+
+
+class TestCloseWindow(WindowManagerMixin, MarionetteTestCase):
+
+    def tearDown(self):
+        self.close_all_windows()
+        self.close_all_tabs()
+
+        super(TestCloseWindow, self).tearDown()
+
+    @skip_if_mobile("Interacting with chrome windows not available for Fennec")
+    def test_close_chrome_window_for_browser_window(self):
+        win = self.open_window()
+        self.marionette.switch_to_window(win)
+
+        self.assertNotIn(win, self.marionette.window_handles)
+        chrome_window_handles = self.marionette.close_chrome_window()
+        self.assertNotIn(win, chrome_window_handles)
+        self.assertListEqual(self.start_windows, chrome_window_handles)
+        self.assertNotIn(win, self.marionette.window_handles)
+
+    @skip_if_mobile("Interacting with chrome windows not available for Fennec")
+    def test_close_chrome_window_for_non_browser_window(self):
+
+        def open_window_with_js():
+            with self.marionette.using_context("chrome"):
+                self.marionette.execute_script("""
+                  window.open('chrome://marionette/content/test.xul',
+                              'foo', 'chrome,centerscreen');
+                """)
+
+        win = self.open_window(trigger=open_window_with_js)
+        self.marionette.switch_to_window(win)
+
+        self.assertIn(win, self.marionette.window_handles)
+        chrome_window_handles = self.marionette.close_chrome_window()
+        self.assertNotIn(win, chrome_window_handles)
+        self.assertListEqual(self.start_windows, chrome_window_handles)
+        self.assertNotIn(win, self.marionette.window_handles)
+
+    @skip_if_mobile("Interacting with chrome windows not available for Fennec")
+    def test_close_chrome_window_for_last_open_window(self):
+        self.close_all_windows()
+
+        self.assertListEqual([], self.marionette.close_chrome_window())
+        self.assertListEqual([self.start_tab], self.marionette.window_handles)
+        self.assertListEqual([self.start_window], self.marionette.chrome_window_handles)
+        self.assertIsNotNone(self.marionette.session)
+
+    @skip_if_mobile("Needs application independent method to open a new tab")
+    def test_close_window_for_browser_tab(self):
+        tab = self.open_tab()
+        self.marionette.switch_to_window(tab)
+
+        window_handles = self.marionette.close()
+        self.assertNotIn(tab, window_handles)
+        self.assertListEqual(self.start_tabs, window_handles)
+
+    def test_close_window_for_browser_window_with_single_tab(self):
+        win = self.open_window()
+        self.marionette.switch_to_window(win)
+
+        self.assertEqual(len(self.start_tabs) + 1, len(self.marionette.window_handles))
+        window_handles = self.marionette.close()
+        self.assertNotIn(win, window_handles)
+        self.assertListEqual(self.start_tabs, window_handles)
+        self.assertListEqual(self.start_windows, self.marionette.chrome_window_handles)
+
+    def test_close_window_for_last_open_tab(self):
+        self.close_all_tabs()
+
+        self.assertListEqual([], self.marionette.close())
+        self.assertListEqual([self.start_tab], self.marionette.window_handles)
+        self.assertListEqual([self.start_window], self.marionette.chrome_window_handles)
+        self.assertIsNotNone(self.marionette.session)
--- a/testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini
+++ b/testing/marionette/harness/marionette_harness/tests/unit/unit-tests.ini
@@ -65,16 +65,19 @@ skip-if = appname == 'fennec'
 [test_pagesource_chrome.py]
 skip-if = appname == 'fennec'
 
 [test_visibility.py]
 [test_window_switching.py]
 skip-if = appname == 'fennec'
 [test_window_management.py]
 skip-if = appname == 'fennec'
+[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.py]
 skip-if = appname == 'fennec'
 
 [test_screenshot.py]
 [test_cookies.py]
 [test_window_title.py]