test_windowless.py (2303B)
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 from marionette_driver import errors, Wait 6 from marionette_harness import MarionetteTestCase 7 8 9 class TestWindowless(MarionetteTestCase): 10 def setUp(self): 11 super(TestWindowless, self).setUp() 12 13 self.marionette.delete_session() 14 self.marionette.start_session({"moz:windowless": True}) 15 16 def tearDown(self): 17 # Reset the browser and active WebDriver session 18 self.marionette.restart(in_app=True) 19 self.marionette.delete_session() 20 21 super(TestWindowless, self).tearDown() 22 23 def wait_for_first_window(self): 24 wait = Wait( 25 self.marionette, 26 ignored_exceptions=errors.NoSuchWindowException, 27 timeout=5, 28 ) 29 return wait.until(lambda _: self.marionette.window_handles) 30 31 def test_last_chrome_window_can_be_closed(self): 32 with self.marionette.using_context("chrome"): 33 handles = self.marionette.chrome_window_handles 34 self.assertGreater(len(handles), 0) 35 self.marionette.switch_to_window(handles[0]) 36 self.marionette.close_chrome_window() 37 self.assertEqual(len(self.marionette.chrome_window_handles), 0) 38 39 def test_last_content_window_can_be_closed(self): 40 handles = self.marionette.window_handles 41 self.assertGreater(len(handles), 0) 42 self.marionette.switch_to_window(handles[0]) 43 self.marionette.close() 44 self.assertEqual(len(self.marionette.window_handles), 0) 45 46 def test_no_window_handles_after_silent_restart(self): 47 # Check that windows are present, but not after a silent restart 48 handles = self.marionette.window_handles 49 self.assertGreater(len(handles), 0) 50 51 self.marionette.restart(silent=True) 52 with self.assertRaises(errors.TimeoutException): 53 self.wait_for_first_window() 54 55 # After a normal restart a browser window will be opened again 56 self.marionette.restart(in_app=True) 57 handles = self.wait_for_first_window() 58 59 self.assertGreater(len(handles), 0) 60 self.marionette.switch_to_window(handles[0])