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
5from marionette_driver import By, Wait
6from marionette_driver.keys import Keys
7
8from marionette_harness import MarionetteTestCase, skip, skip_if_mobile, WindowManagerMixin
9
10
11class TestAboutPages(WindowManagerMixin, MarionetteTestCase):
12
13    def setUp(self):
14        super(TestAboutPages, self).setUp()
15
16        if self.marionette.session_capabilities['platformName'] == 'darwin':
17            self.mod_key = Keys.META
18        else:
19            self.mod_key = Keys.CONTROL
20
21        self.remote_uri = self.marionette.absolute_url("windowHandles.html")
22
23    def tearDown(self):
24        self.close_all_tabs()
25
26        super(TestAboutPages, self).tearDown()
27
28    def open_tab_with_link(self):
29        with self.marionette.using_context("content"):
30            self.marionette.navigate(self.remote_uri)
31
32            link = self.marionette.find_element(By.ID, "new-tab")
33            link.click()
34
35    @skip_if_mobile("Bug 1333209 - Process killed because of connection loss")
36    def test_back_forward(self):
37        # Bug 1311041 - Prevent changing of window handle by forcing the test
38        # to be run in a new tab.
39        new_tab = self.open_tab(trigger=self.open_tab_with_link)
40        self.marionette.switch_to_window(new_tab)
41
42        self.marionette.navigate("about:blank")
43        self.marionette.navigate(self.remote_uri)
44        self.marionette.navigate("about:support")
45
46        self.marionette.go_back()
47        self.assertEqual(self.marionette.get_url(), self.remote_uri)
48
49        self.marionette.go_forward()
50        self.assertEqual(self.marionette.get_url(), "about:support")
51
52        self.marionette.close()
53        self.marionette.switch_to_window(self.start_tab)
54
55    @skip_if_mobile("Bug 1333209 - Process killed because of connection loss")
56    def test_navigate_non_remote_about_pages(self):
57        # Bug 1311041 - Prevent changing of window handle by forcing the test
58        # to be run in a new tab.
59        new_tab = self.open_tab(trigger=self.open_tab_with_link)
60        self.marionette.switch_to_window(new_tab)
61
62        self.marionette.navigate("about:blank")
63        self.assertEqual(self.marionette.get_url(), "about:blank")
64        self.marionette.navigate("about:support")
65        self.assertEqual(self.marionette.get_url(), "about:support")
66
67        self.marionette.close()
68        self.marionette.switch_to_window(self.start_tab)
69
70    @skip_if_mobile("On Android no shortcuts are available")
71    def test_navigate_shortcut_key(self):
72        def open_with_shortcut():
73            self.marionette.navigate(self.remote_uri)
74            with self.marionette.using_context("chrome"):
75                main_win = self.marionette.find_element(By.ID, "main-window")
76                main_win.send_keys(self.mod_key, Keys.SHIFT, 'a')
77
78        new_tab = self.open_tab(trigger=open_with_shortcut)
79        self.marionette.switch_to_window(new_tab)
80
81        Wait(self.marionette).until(lambda mn: mn.get_url() == "about:addons",
82                                    message="'about:addons' hasn't been loaded")
83
84        self.marionette.close()
85        self.marionette.switch_to_window(self.start_tab)
86
87    @skip("Bug 1334137 - Intermittent: Process killed because of hang in getCurrentUrl()")
88    @skip_if_mobile("Interacting with chrome elements not available for Fennec")
89    def test_type_to_non_remote_tab(self):
90        # Bug 1311041 - Prevent changing of window handle by forcing the test
91        # to be run in a new tab.
92        new_tab = self.open_tab(trigger=self.open_tab_with_link)
93        self.marionette.switch_to_window(new_tab)
94
95        with self.marionette.using_context("chrome"):
96            urlbar = self.marionette.find_element(By.ID, 'urlbar')
97            urlbar.send_keys(self.mod_key + 'a')
98            urlbar.send_keys(self.mod_key + 'x')
99            urlbar.send_keys('about:support' + Keys.ENTER)
100        Wait(self.marionette).until(lambda mn: mn.get_url() == "about:support",
101                                    message="'about:support' hasn't been loaded")
102
103        self.marionette.close()
104        self.marionette.switch_to_window(self.start_tab)
105
106    @skip_if_mobile("Interacting with chrome elements not available for Fennec")
107    def test_type_to_remote_tab(self):
108        # Bug 1311041 - Prevent changing of window handle by forcing the test
109        # to be run in a new tab.
110        new_tab = self.open_tab(trigger=self.open_tab_with_link)
111        self.marionette.switch_to_window(new_tab)
112
113        # about:blank keeps remoteness from remote_uri
114        self.marionette.navigate("about:blank")
115        with self.marionette.using_context("chrome"):
116            urlbar = self.marionette.find_element(By.ID, 'urlbar')
117            urlbar.send_keys(self.mod_key + 'a')
118            urlbar.send_keys(self.mod_key + 'x')
119            urlbar.send_keys(self.remote_uri + Keys.ENTER)
120
121        Wait(self.marionette).until(lambda mn: mn.get_url() == self.remote_uri,
122                                    message="'{}' hasn't been loaded".format(self.remote_uri))
123
124    @skip_if_mobile("Needs application independent method to open a new tab")
125    def test_hang(self):
126        # Bug 1311041 - Prevent changing of window handle by forcing the test
127        # to be run in a new tab.
128        new_tab = self.open_tab(trigger=self.open_tab_with_link)
129
130        # Close the start tab
131        self.marionette.close()
132        self.marionette.switch_to_window(new_tab)
133
134        self.marionette.navigate(self.remote_uri)
135