Bug 1550718 - Test Telemetry opt out across sessions r=raphael
authorChris H-C <chutten@mozilla.com>
Mon, 27 May 2019 18:00:36 +0000
changeset 475759 fb0a19250082610e0f59eb0921fd7ff58640fce3
parent 475758 f1f333d752907c5c3e0c96846f0e669daa178233
child 475760 34cc442a91cb99a9ef2f3090db57c9825ae5d4b5
push id86464
push userchutten@mozilla.com
push dateMon, 27 May 2019 18:29:11 +0000
treeherderautoland@fb0a19250082 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersraphael
bugs1550718
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1550718 - Test Telemetry opt out across sessions r=raphael This supercedes the previous test and ensures the optout persists across sessions. It would also ideally ensure there's no Pending Pings present, but the tests appear to be currently using any available app data dir instead of a test-specific one so we should implement that part later. Differential Revision: https://phabricator.services.mozilla.com/D31270
toolkit/components/telemetry/tests/marionette/tests/client/test_optout_ping.py
--- a/toolkit/components/telemetry/tests/marionette/tests/client/test_optout_ping.py
+++ b/toolkit/components/telemetry/tests/marionette/tests/client/test_optout_ping.py
@@ -1,55 +1,70 @@
 # 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 telemetry_harness.testcase import TelemetryTestCase
-from telemetry_harness.ping_filters import ANY_PING, OPTOUT_PING, FIRST_SHUTDOWN_PING
+from telemetry_harness.ping_filters import ANY_PING, OPTOUT_PING, MAIN_SHUTDOWN_PING
 
 
 class TestOptoutPing(TelemetryTestCase):
     """Tests for "optout" ping."""
 
     def disable_telemetry(self):
+        self.marionette.instance.profile.set_persistent_preferences(
+            {"datareporting.healthreport.uploadEnabled": False})
         self.marionette.set_pref("datareporting.healthreport.uploadEnabled", False)
 
     def enable_telemetry(self):
+        self.marionette.instance.profile.set_persistent_preferences(
+            {"datareporting.healthreport.uploadEnabled": True})
         self.marionette.set_pref("datareporting.healthreport.uploadEnabled", True)
 
-    def test_optout_ping(self):
-        """Test for "optout" ping."""
+    def test_optout_ping_across_sessions(self):
+        """Test the "optout" ping behaviour across sessions."""
 
         # Get the client_id.
         client_id = self.wait_for_ping(self.install_addon, ANY_PING)["clientId"]
         self.assertIsValidUUID(client_id)
 
-        # Trigger an "optout" ping and check its contents.
+        # Trigger an "optout" ping.
         optout_ping = self.wait_for_ping(self.disable_telemetry, OPTOUT_PING)
 
-        self.assertIsNotNone(optout_ping)
         self.assertNotIn("clientId", optout_ping)
         self.assertIn("payload", optout_ping)
         self.assertNotIn("environment", optout_ping["payload"])
 
-        # Ensure the "optout" ping was the last ping sent
+        # Close Firefox cleanly.
+        self.marionette.quit(in_app=True)
+
+        # TODO: Check pending pings aren't persisted
+
+        # Start Firefox.
+        self.marionette.start_session()
+
+        # Trigger an environment change, which isn't allowed to send a ping.
+        self.install_addon()
+
+        # Ensure we've sent no pings since "optout".
         self.assertEqual(self.ping_server.pings[-1], optout_ping)
 
-        """ Test what happens when the user opts back in """
-
+        # Turn Telemetry back on.
         self.enable_telemetry()
 
-        # Restart Firefox so we can capture a "first-shutdown" ping.
-        # We want to check that the client id changed and telemetry.data_upload_optin is set.
-        shutdown_ping = self.wait_for_ping(self.restart_browser, FIRST_SHUTDOWN_PING)
+        # Close Firefox cleanly, collecting its "main"/"shutdown" ping.
+        main_ping = self.wait_for_ping(self.restart_browser, MAIN_SHUTDOWN_PING)
 
-        self.assertIn("clientId", shutdown_ping)
-        self.assertIsValidUUID(shutdown_ping["clientId"])
-        self.assertNotEqual(shutdown_ping["clientId"], client_id)
+        # Ensure the "main" ping has changed its client id.
+        self.assertIn("clientId", main_ping)
+        self.assertIsValidUUID(main_ping["clientId"])
+        self.assertNotEqual(main_ping["clientId"], client_id)
 
-        self.assertIn("payload", shutdown_ping)
-        self.assertIn("processes", shutdown_ping["payload"])
-        self.assertIn("parent", shutdown_ping["payload"]["processes"])
-        self.assertIn("scalars", shutdown_ping["payload"]["processes"]["parent"])
-        scalars = shutdown_ping["payload"]["processes"]["parent"]["scalars"]
+        # Ensure we note in the ping that the user opted in.
+        parent_scalars = main_ping["payload"]["processes"]["parent"]["scalars"]
 
-        self.assertIn("telemetry.data_upload_optin", scalars)
-        self.assertTrue(scalars["telemetry.data_upload_optin"])
+        self.assertIn("telemetry.data_upload_optin", parent_scalars)
+        self.assertIs(parent_scalars["telemetry.data_upload_optin"], True)
+
+        # Ensure all pings sent during this test don't have the c0ffee client id.
+        for ping in self.ping_server.pings:
+            if "clientId" in ping:
+                self.assertIsValidUUID(ping["clientId"])