test_window_status.py (3887B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 import os 6 import sys 7 8 from marionette_driver import By 9 from marionette_driver.errors import NoSuchWindowException 10 11 from marionette_harness import MarionetteTestCase, WindowManagerMixin 12 13 # add this directory to the path 14 sys.path.append(os.path.dirname(__file__)) 15 16 from chrome_handler_mixin import ChromeHandlerMixin 17 18 19 class TestNoSuchWindowContent( 20 ChromeHandlerMixin, WindowManagerMixin, MarionetteTestCase 21 ): 22 def setUp(self): 23 super(TestNoSuchWindowContent, self).setUp() 24 25 def tearDown(self): 26 self.close_all_windows() 27 super(TestNoSuchWindowContent, self).tearDown() 28 29 def test_closed_chrome_window(self): 30 with self.marionette.using_context("chrome"): 31 new_window = self.open_window() 32 self.marionette.switch_to_window(new_window) 33 self.marionette.close_chrome_window() 34 35 # When closing a browser window both handles are not available 36 for context in ("chrome", "content"): 37 print("Testing handles with context {}".format(context)) 38 with self.marionette.using_context(context): 39 with self.assertRaises(NoSuchWindowException): 40 self.marionette.current_chrome_window_handle 41 with self.assertRaises(NoSuchWindowException): 42 self.marionette.current_window_handle 43 44 self.marionette.switch_to_window(self.start_window) 45 46 with self.assertRaises(NoSuchWindowException): 47 self.marionette.switch_to_window(new_window) 48 49 def test_closed_chrome_window_while_in_frame(self): 50 new_window = self.open_chrome_window(self.chrome_base_url + "test.xhtml") 51 self.marionette.switch_to_window(new_window) 52 53 with self.marionette.using_context("chrome"): 54 self.marionette.switch_to_frame(0) 55 self.marionette.close_chrome_window() 56 57 with self.assertRaises(NoSuchWindowException): 58 self.marionette.current_window_handle 59 with self.assertRaises(NoSuchWindowException): 60 self.marionette.current_chrome_window_handle 61 62 self.marionette.switch_to_window(self.start_window) 63 64 with self.assertRaises(NoSuchWindowException): 65 self.marionette.switch_to_window(new_window) 66 67 def test_closed_tab(self): 68 new_tab = self.open_tab(focus=True) 69 self.marionette.switch_to_window(new_tab) 70 self.marionette.close() 71 72 # Check that only the content window is not available in both contexts 73 for context in ("chrome", "content"): 74 with self.marionette.using_context(context): 75 with self.assertRaises(NoSuchWindowException): 76 self.marionette.current_window_handle 77 self.marionette.current_chrome_window_handle 78 79 self.marionette.switch_to_window(self.start_tab) 80 81 with self.assertRaises(NoSuchWindowException): 82 self.marionette.switch_to_window(new_tab) 83 84 def test_closed_tab_while_in_frame(self): 85 new_tab = self.open_tab() 86 self.marionette.switch_to_window(new_tab) 87 88 with self.marionette.using_context("content"): 89 self.marionette.navigate(self.marionette.absolute_url("test_iframe.html")) 90 frame = self.marionette.find_element(By.ID, "test_iframe") 91 self.marionette.switch_to_frame(frame) 92 93 self.marionette.close() 94 95 with self.assertRaises(NoSuchWindowException): 96 self.marionette.current_window_handle 97 self.marionette.current_chrome_window_handle 98 99 self.marionette.switch_to_window(self.start_tab) 100 101 with self.assertRaises(NoSuchWindowException): 102 self.marionette.switch_to_window(new_tab)