summaryrefslogtreecommitdiffstats
path: root/testing/marionette/harness/marionette_harness/tests/unit/test_reftest.py
blob: e173e5a96324e69b635f507295eb5256198dd2b1 (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
# 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 marionette_driver.errors import UnsupportedOperationException
from marionette_harness import MarionetteTestCase, skip


class TestReftest(MarionetteTestCase):
    def setUp(self):
        super(TestReftest, self).setUp()

        self.original_window = self.marionette.current_window_handle

        self.marionette.set_pref("marionette.log.truncate", False)
        self.marionette.set_pref("dom.send_after_paint_to_content", True)
        self.marionette.set_pref("widget.gtk.overlay-scrollbars.enabled", False)

    def tearDown(self):
        try:
            # make sure we've teared down any reftest context
            self.marionette._send_message("reftest:teardown", {})
        except UnsupportedOperationException:
            # this will throw if we aren't currently in a reftest context
            pass

        self.marionette.switch_to_window(self.original_window)

        self.marionette.clear_pref("dom.send_after_paint_to_content")
        self.marionette.clear_pref("marionette.log.truncate")
        self.marionette.clear_pref("widget.gtk.overlay-scrollbars.enabled")

        super(TestReftest, self).tearDown()

    @skip("Bug 1648444 - Unexpected page unload when refreshing about:blank")
    def test_basic(self):
        self.marionette._send_message("reftest:setup", {"screenshot": "unexpected"})
        rv = self.marionette._send_message(
            "reftest:run",
            {
                "test": "about:blank",
                "references": [["about:blank", [], "=="]],
                "expected": "PASS",
                "timeout": 10 * 1000,
            },
        )
        self.marionette._send_message("reftest:teardown", {})
        expected = {
            "value": {
                "extra": {},
                "message": "Testing about:blank == about:blank\n",
                "stack": None,
                "status": "PASS",
            }
        }
        self.assertEqual(expected, rv)

    def test_url_comparison(self):
        test_page = self.fixtures.where_is("test.html")
        test_page_2 = self.fixtures.where_is("foo/../test.html")

        self.marionette._send_message("reftest:setup", {"screenshot": "unexpected"})
        rv = self.marionette._send_message(
            "reftest:run",
            {
                "test": test_page,
                "references": [[test_page_2, [], "=="]],
                "expected": "PASS",
                "timeout": 10 * 1000,
            },
        )
        self.marionette._send_message("reftest:teardown", {})
        self.assertEqual("PASS", rv["value"]["status"])

    def test_cache_multiple_sizes(self):
        teal = self.fixtures.where_is("reftest/teal-700x700.html")
        mostly_teal = self.fixtures.where_is("reftest/mostly-teal-700x700.html")

        self.marionette._send_message("reftest:setup", {"screenshot": "unexpected"})
        rv = self.marionette._send_message(
            "reftest:run",
            {
                "test": teal,
                "references": [[mostly_teal, [], "=="]],
                "expected": "PASS",
                "timeout": 10 * 1000,
                "width": 600,
                "height": 600,
            },
        )
        self.assertEqual("PASS", rv["value"]["status"])

        rv = self.marionette._send_message(
            "reftest:run",
            {
                "test": teal,
                "references": [[mostly_teal, [], "=="]],
                "expected": "PASS",
                "timeout": 10 * 1000,
                "width": 700,
                "height": 700,
            },
        )
        self.assertEqual("FAIL", rv["value"]["status"])
        self.marionette._send_message("reftest:teardown", {})