summaryrefslogtreecommitdiffstats
path: root/testing/marionette/harness/marionette_harness/tests/unit/test_switch_window_chrome.py
blob: 0b02e453517a6ea55d0f000a2e1b81d5c1af34e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# 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

# 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 test_switch_to_unloaded_tab(self):
        # Can only run in content context
        pass

    @skipIf(
        sys.platform.startswith("linux"),
        "Bug 1511970 - New window isn't moved to the background on Linux",
    )
    def test_switch_tabs_for_new_background_window_without_focus_change(self):
        # Open an additional 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(focus=True)
        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)

        # Open a new background window, but we are interested in the tab
        with self.marionette.using_context("content"):
            tab_in_new_window = self.open_window()
        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)

        # 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)

    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()
        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
        with self.marionette.using_context("content"):
            tab_in_new_window = self.open_window(focus=True)
        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)

        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)

        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)

    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()
        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)

        self.open_window(focus=True)
        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)

        # 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)