summaryrefslogtreecommitdiffstats
path: root/toolkit/components/telemetry/tests/marionette/harness/telemetry_harness/fog_testcase.py
blob: 9bcf29d2f4772477793bef249200dbb38bf6c751 (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
# 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 mozlog

from telemetry_harness.fog_ping_server import FOGPingServer
from telemetry_harness.testcase import TelemetryTestCase


class FOGTestCase(TelemetryTestCase):
    """Base testcase class for project FOG."""

    def __init__(self, *args, **kwargs):
        """Initialize the test case and create a ping server."""
        super(FOGTestCase, self).__init__(*args, **kwargs)
        self._logger = mozlog.get_default_logger(component="FOGTestCase")

    def setUp(self, *args, **kwargs):
        """Set up the test case and create a FOG ping server.

        This test is skipped if the build doesn't support FOG.
        """
        super(FOGTestCase, self).setUp(*args, **kwargs)

        with self.marionette.using_context(self.marionette.CONTEXT_CHROME):
            fog_android = self.marionette.execute_script(
                "return AppConstants.MOZ_GLEAN_ANDROID;"
            )

        if fog_android:
            # Before we skip this test, we need to quit marionette and the ping
            # server created in TelemetryTestCase by running tearDown
            super(FOGTestCase, self).tearDown(*args, **kwargs)
            self.skipTest("FOG is only initialized when not in an Android build.")

        self.fog_ping_server = FOGPingServer(
            self.testvars["server_root"], "http://localhost:0"
        )
        self.fog_ping_server.start()

        self._logger.info(
            "Submitting to FOG ping server at {}".format(self.fog_ping_server.url)
        )

        self.marionette.enforce_gecko_prefs(
            {
                "telemetry.fog.test.localhost_port": self.fog_ping_server.port,
                # Enable FOG logging. 5 means "Verbose". See
                # https://firefox-source-docs.mozilla.org/xpcom/logging.html
                # for details.
                "logging.config.clear_on_startup": False,
                "logging.config.sync": True,
                "logging.fog::*": 5,
                "logging.fog_control::*": 5,
                "logging.glean::*": 5,
                "logging.glean_core::*": 5,
                # Slow down the user inactivity timeout (bug 1690728)
                "dom.events.user_interaction_interval": 60000,
            }
        )

    def tearDown(self, *args, **kwargs):
        super(FOGTestCase, self).tearDown(*args, **kwargs)
        self.fog_ping_server.stop()