summaryrefslogtreecommitdiffstats
path: root/testing/firefox-ui/tests/functional/private_browsing/test_about_private_browsing.py
blob: 4b22d03ea988261e88384f8c4f2800c7bdf6ea21 (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
# 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/.

from firefox_puppeteer import PuppeteerMixin
from firefox_puppeteer.ui.browser.window import BrowserWindow
from marionette_driver import By, Wait
from marionette_harness import MarionetteTestCase


class TestAboutPrivateBrowsing(PuppeteerMixin, MarionetteTestCase):

    def setUp(self):
        super(TestAboutPrivateBrowsing, self).setUp()

        # Use a fake local support URL
        support_url = 'about:blank?'
        self.marionette.set_pref('app.support.baseURL', support_url)

        self.pb_url = support_url + 'private-browsing'

    def tearDown(self):
        try:
            self.marionette.clear_pref('app.support.baseURL')
        finally:
            super(TestAboutPrivateBrowsing, self).tearDown()

    def testCheckAboutPrivateBrowsing(self):
        self.assertFalse(self.browser.is_private)

        with self.marionette.using_context('content'):
            self.marionette.navigate('about:privatebrowsing')

            status_node = self.marionette.find_element(By.CSS_SELECTOR, 'p.showNormal')
            self.assertEqual(status_node.text,
                             self.browser.localize_entity('aboutPrivateBrowsing.notPrivate'),
                             'Status text indicates we are not in private browsing mode')

        def window_opener(win):
            with win.marionette.using_context('content'):
                button = self.marionette.find_element(By.ID, 'startPrivateBrowsing')
                button.click()

        pb_window = self.browser.open_window(callback=window_opener,
                                             expected_window_class=BrowserWindow)

        try:
            self.assertTrue(pb_window.is_private)

            def tab_opener(tab):
                with tab.marionette.using_context('content'):
                    link = tab.marionette.find_element(By.ID, 'learnMore')
                    link.click()

            tab = pb_window.tabbar.open_tab(trigger=tab_opener)
            Wait(self.marionette, timeout=self.marionette.timeout.page_load).until(
                lambda _: tab.location == self.pb_url)

        finally:
            pb_window.close()