Source code

Revision control

Other Tools

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
5
from telemetry_harness.testcase import TelemetryTestCase
6
from telemetry_harness.ping_filters import ANY_PING, OPTOUT_PING, MAIN_SHUTDOWN_PING
7
8
9
class TestOptoutPing(TelemetryTestCase):
10
"""Tests for "optout" ping."""
11
12
def disable_telemetry(self):
13
self.marionette.instance.profile.set_persistent_preferences(
14
{"datareporting.healthreport.uploadEnabled": False})
15
self.marionette.set_pref("datareporting.healthreport.uploadEnabled", False)
16
17
def enable_telemetry(self):
18
self.marionette.instance.profile.set_persistent_preferences(
19
{"datareporting.healthreport.uploadEnabled": True})
20
self.marionette.set_pref("datareporting.healthreport.uploadEnabled", True)
21
22
def test_optout_ping_across_sessions(self):
23
"""Test the "optout" ping behaviour across sessions."""
24
25
# Get the client_id.
26
client_id = self.wait_for_ping(self.install_addon, ANY_PING)["clientId"]
27
self.assertIsValidUUID(client_id)
28
29
# Trigger an "optout" ping.
30
optout_ping = self.wait_for_ping(self.disable_telemetry, OPTOUT_PING)
31
32
self.assertNotIn("clientId", optout_ping)
33
self.assertIn("payload", optout_ping)
34
self.assertNotIn("environment", optout_ping["payload"])
35
36
# Close Firefox cleanly.
37
self.marionette.quit(in_app=True)
38
39
# TODO: Check pending pings aren't persisted
40
41
# Start Firefox.
42
self.marionette.start_session()
43
44
# Trigger an environment change, which isn't allowed to send a ping.
45
self.install_addon()
46
47
# Ensure we've sent no pings since "optout".
48
self.assertEqual(self.ping_server.pings[-1], optout_ping)
49
50
# Turn Telemetry back on.
51
self.enable_telemetry()
52
53
# Close Firefox cleanly, collecting its "main"/"shutdown" ping.
54
main_ping = self.wait_for_ping(self.restart_browser, MAIN_SHUTDOWN_PING)
55
56
# Ensure the "main" ping has changed its client id.
57
self.assertIn("clientId", main_ping)
58
self.assertIsValidUUID(main_ping["clientId"])
59
self.assertNotEqual(main_ping["clientId"], client_id)
60
61
# Ensure we note in the ping that the user opted in.
62
parent_scalars = main_ping["payload"]["processes"]["parent"]["scalars"]
63
64
self.assertIn("telemetry.data_upload_optin", parent_scalars)
65
self.assertIs(parent_scalars["telemetry.data_upload_optin"], True)
66
67
# Ensure all pings sent during this test don't have the c0ffee client id.
68
for ping in self.ping_server.pings:
69
if "clientId" in ping:
70
self.assertIsValidUUID(ping["clientId"])