summaryrefslogtreecommitdiffstats
path: root/testing/marionette/harness/marionette_harness/tests/unit/test_switch_window_chrome.py
blob: 0ad63b6ce01e425d61a238b487d869c486542325 (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
114
115
116
117
118
119
120
121
122
123
124
# 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

from marionette_driver import By

# 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 open_window_in_background(self):
        with self.marionette.using_context("chrome"):
            self.marionette.execute_script("""
              window.open("about:blank", null, "location=1,toolbar=1");
              window.focus();
            """)

    def open_window_in_foreground(self):
        with self.marionette.using_context("content"):
            self.marionette.navigate(self.test_page)
            link = self.marionette.find_element(By.ID, "new-window")
            link.click()

    @skipIf(sys.platform.startswith("linux"),
            "Bug 1335457 - Fails to open a background window on Linux")
    def test_switch_tabs_for_new_background_window_without_focus_change(self):
        # Bug 1334981 - with testmode enabled getMostRecentWindow detects the wrong window
        with self.marionette.using_prefs({"focusmanager.testmode": False}):
            # 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(trigger=self.open_tab_in_foreground)
            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 background window, but we are interested in the tab
            tab_in_new_window = self.open_tab(trigger=self.open_window_in_background)
            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)
            with self.marionette.using_context("content"):
                self.assertEqual(self.marionette.get_url(), self.empty_page)

            # 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)
            with self.marionette.using_context("content"):
                self.assertEqual(self.marionette.get_url(), "about:blank")

    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(trigger=self.open_tab_in_foreground)
        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
        tab_in_new_window = self.open_tab(trigger=self.open_window_in_foreground)
        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)
        with self.marionette.using_context("content"):
            self.assertEqual(self.marionette.get_url(), self.test_page)

        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)
        with self.marionette.using_context("content"):
            self.assertEqual(self.marionette.get_url(), self.empty_page)

        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)
        with self.marionette.using_context("content"):
            self.assertEqual(self.marionette.get_url(), self.test_page)

    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(trigger=self.open_tab_in_foreground)
        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 which automatically
        # gets the focus.
        self.open_tab(trigger=self.open_window_in_foreground)
        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)
        with self.marionette.using_context("content"):
            self.assertEqual(self.marionette.get_url(), self.test_page)

        # 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)
        with self.marionette.using_context("content"):
            self.assertEqual(self.marionette.get_url(), self.test_page)