test_chrome_switch_window.py (4850B)
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 file, 3 # You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 import os 6 import sys 7 8 # add this directory to the path 9 sys.path.append(os.path.dirname(__file__)) 10 11 from test_switch_window import TestSwitchToWindowContent 12 13 14 class TestSwitchWindowChrome(TestSwitchToWindowContent): 15 def setUp(self): 16 super(TestSwitchWindowChrome, self).setUp() 17 18 self.marionette.set_context("chrome") 19 20 def tearDown(self): 21 self.close_all_windows() 22 23 super(TestSwitchWindowChrome, self).tearDown() 24 25 def test_switch_to_unloaded_tab(self): 26 # Can only run in content context 27 pass 28 29 def test_switch_tabs_for_new_background_window_without_focus_change(self): 30 # Open an additional tab in the original window so we can better check 31 # the selected index in thew new window to be opened. 32 second_tab = self.open_tab(focus=True) 33 self.marionette.switch_to_window(second_tab, focus=True) 34 second_tab_index = self.get_selected_tab_index() 35 self.assertNotEqual(second_tab_index, self.selected_tab_index) 36 37 # Open a new background window, but we are interested in the tab 38 with self.marionette.using_context("content"): 39 tab_in_new_window = self.open_window() 40 self.assertEqual(self.marionette.current_window_handle, second_tab) 41 self.assertEqual( 42 self.marionette.current_chrome_window_handle, self.start_window 43 ) 44 self.assertEqual(self.get_selected_tab_index(), second_tab_index) 45 46 # Switch to the tab in the new window but don't focus it 47 self.marionette.switch_to_window(tab_in_new_window, focus=False) 48 self.assertEqual(self.marionette.current_window_handle, tab_in_new_window) 49 self.assertNotEqual( 50 self.marionette.current_chrome_window_handle, self.start_window 51 ) 52 self.assertEqual(self.get_selected_tab_index(), second_tab_index) 53 54 def test_switch_tabs_for_new_foreground_window_with_focus_change(self): 55 # Open an addition tab in the original window so we can better check 56 # the selected index in thew new window to be opened. 57 second_tab = self.open_tab() 58 self.marionette.switch_to_window(second_tab, focus=True) 59 second_tab_index = self.get_selected_tab_index() 60 self.assertNotEqual(second_tab_index, self.selected_tab_index) 61 62 # Opens a new window, but we are interested in the tab 63 with self.marionette.using_context("content"): 64 tab_in_new_window = self.open_window(focus=True) 65 self.assertEqual(self.marionette.current_window_handle, second_tab) 66 self.assertEqual( 67 self.marionette.current_chrome_window_handle, self.start_window 68 ) 69 self.assertNotEqual(self.get_selected_tab_index(), second_tab_index) 70 71 self.marionette.switch_to_window(tab_in_new_window) 72 self.assertEqual(self.marionette.current_window_handle, tab_in_new_window) 73 self.assertNotEqual( 74 self.marionette.current_chrome_window_handle, self.start_window 75 ) 76 self.assertNotEqual(self.get_selected_tab_index(), second_tab_index) 77 78 self.marionette.switch_to_window(second_tab, focus=True) 79 self.assertEqual(self.marionette.current_window_handle, second_tab) 80 self.assertEqual( 81 self.marionette.current_chrome_window_handle, self.start_window 82 ) 83 # Bug 1335085 - The focus doesn't change even as requested so. 84 # self.assertEqual(self.get_selected_tab_index(), second_tab_index) 85 86 def test_switch_tabs_for_new_foreground_window_without_focus_change(self): 87 # Open an addition tab in the original window so we can better check 88 # the selected index in thew new window to be opened. 89 second_tab = self.open_tab() 90 self.marionette.switch_to_window(second_tab, focus=True) 91 second_tab_index = self.get_selected_tab_index() 92 self.assertNotEqual(second_tab_index, self.selected_tab_index) 93 94 self.open_window(focus=True) 95 self.assertEqual(self.marionette.current_window_handle, second_tab) 96 self.assertEqual( 97 self.marionette.current_chrome_window_handle, self.start_window 98 ) 99 self.assertNotEqual(self.get_selected_tab_index(), second_tab_index) 100 101 # Switch to the second tab in the first window, but don't focus it. 102 self.marionette.switch_to_window(second_tab, focus=False) 103 self.assertEqual(self.marionette.current_window_handle, second_tab) 104 self.assertEqual( 105 self.marionette.current_chrome_window_handle, self.start_window 106 ) 107 self.assertNotEqual(self.get_selected_tab_index(), second_tab_index)