summaryrefslogtreecommitdiffstats
path: root/testing/firefox-ui/tests/functional/security/test_mixed_script_content_blocking.py
blob: 796b1dc293fb39a877a3cdbb0e5f865036ee9a7d (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
# 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 marionette_driver import By, Wait
from marionette_harness import MarionetteTestCase


class TestMixedScriptContentBlocking(PuppeteerMixin, MarionetteTestCase):

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

        self.url = 'https://mozqa.com/data/firefox/security/mixed_content_blocked/index.html'

        self.test_elements = [
            ('result1', 'Insecure script one'),
            ('result2', 'Insecure script from iFrame'),
            ('result3', 'Insecure plugin'),
            ('result4', 'Insecure stylesheet'),
        ]

        self.locationbar = self.browser.navbar.locationbar
        self.identity_popup = self.locationbar.identity_popup

    def tearDown(self):
        try:
            self.identity_popup.close(force=True)
        finally:
            super(TestMixedScriptContentBlocking, self).tearDown()

    def _expect_protection_status(self, enabled):
        if enabled:
            color, identity, state = (
                'rgb(0, 136, 0)',
                'verifiedDomain mixedActiveBlocked',
                'blocked'
            )
        else:
            color, identity, state = (
                'rgb(255, 0, 0)',
                'unknownIdentity mixedActiveContent',
                'unblocked'
            )

        # First call to Wait() needs a longer timeout due to the reload of the web page.
        Wait(self.marionette, timeout=self.marionette.timeout.page_load).until(
            lambda _: self.locationbar.identity_box.get_property('className') == identity,
            message='Expected identity "{}" not found'.format(identity)
        )

        with self.marionette.using_context('content'):
            for identifier, description in self.test_elements:
                el = self.marionette.find_element(By.ID, identifier)
                Wait(self.marionette).until(
                    lambda mn: el.value_of_css_property('color') == color,
                    message=("%s has been %s" % (description, state))
                )

    def expect_protection_enabled(self):
        self._expect_protection_status(True)

    def expect_protection_disabled(self):
        self._expect_protection_status(False)

    def test_mixed_content_page(self):
        with self.marionette.using_context('content'):
            self.marionette.navigate(self.url)

        self.expect_protection_enabled()

        # Disable mixed content blocking via identity popup
        self.locationbar.open_identity_popup()
        self.identity_popup.view.main.expander.click()
        Wait(self.marionette).until(lambda _: self.identity_popup.view.security.selected)

        disable_button = self.identity_popup.view.security.disable_mixed_content_blocking_button
        disable_button.click()

        self.expect_protection_disabled()

        # A reload keeps blocking disabled
        with self.marionette.using_context('content'):
            self.marionette.navigate(self.url)

        self.expect_protection_disabled()