Bug 1382821 - Deletion Ping Received Test draft
authorJohn Dorlus <jsdorlus@gmail.com>
Tue, 25 Jul 2017 22:47:31 -0400
changeset 618765 6c91e2b53048700b0eb035337a0cff2ba38b438a
parent 617496 16ffc1d05422a81099ce8b9b59de66dde4c8b2f0
child 640173 a24d770d4368cecbd10e085129fc10c211ec4151
push id71445
push userbmo:jdorlus@mozilla.com
push dateTue, 01 Aug 2017 02:35:38 +0000
bugs1382821
milestone56.0a1
Bug 1382821 - Deletion Ping Received Test Added test_deletion_ping_received Added manifest file entry Made change to testcase.py to allow any pref to be toggled. MozReview-Commit-ID: 3eE7Wk16UR
toolkit/components/telemetry/tests/marionette/harness/telemetry_harness/testcase.py
toolkit/components/telemetry/tests/marionette/tests/client/manifest.ini
toolkit/components/telemetry/tests/marionette/tests/client/test_deletion_ping_received.py
--- a/toolkit/components/telemetry/tests/marionette/harness/telemetry_harness/testcase.py
+++ b/toolkit/components/telemetry/tests/marionette/harness/telemetry_harness/testcase.py
@@ -46,36 +46,36 @@ class TelemetryTestCase(PuppeteerMixin, 
         }
 
         # Firefox will be forced to restart with the prefs enforced.
         self.marionette.enforce_gecko_prefs(telemetry_prefs)
 
         # Wait 5 seconds to ensure that telemetry has reinitialized
         time.sleep(5)
 
-    def wait_for_ping(self, action_func, ping_filter_func):
+    def wait_for_ping(self, ping_filter_func, action_func=None):
         current_num_pings = len(self.ping_list)
         if callable(action_func):
             action_func()
         try:
             Wait(self.marionette, 60).until(lambda _: len(self.ping_list) > current_num_pings)
         except Exception as e:
             self.fail('Error generating ping: {}'.format(e.message))
         # Filter pings based on type and reason to make sure right ping is captured.
         self.ping_list = [p for p in self.ping_list if ping_filter_func(p)]
 
         # TODO: Bug 1380748 - Pings are being cached between test
         # runs when using --repeat flag in marionette harness
         # Causes the assert to fail.
         # assert len(self.ping_list) == 1
         return self.ping_list.pop()
 
-    def toggle_update_pref(self):
-        value = self.marionette.get_pref('app.update.enabled')
-        self.marionette.enforce_gecko_prefs({'app.update.enabled': not value})
+    def toggle_pref(self, pref):
+        value = self.marionette.get_pref(pref)
+        self.marionette.set_pref(pref, not value)
 
     def restart_browser(self):
         """Restarts browser while maintaining the same profile and session."""
         self.restart(clean=False, in_app=True)
 
     def install_addon(self):
         trigger = Process(target=self._install_addon)
         trigger.start()
--- a/toolkit/components/telemetry/tests/marionette/tests/client/manifest.ini
+++ b/toolkit/components/telemetry/tests/marionette/tests/client/manifest.ini
@@ -1,4 +1,5 @@
 [DEFAULT]
 tags = client
 
-[test_main_tab_scalars.py]
\ No newline at end of file
+[test_main_tab_scalars.py]
+[test_deletion_ping_received.py]
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/toolkit/components/telemetry/tests/marionette/tests/client/test_deletion_ping_received.py
@@ -0,0 +1,19 @@
+# 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
+
+
+class TestDeletionPingReceived(TelemetryTestCase):
+
+    def test_deletion_ping_received(self):
+
+        ping = self.wait_for_ping(
+            lambda p: p['type'] == 'deletion',
+            lambda: self.toggle_pref('datareporting.healthreport.uploadEnabled')
+        )
+
+        assert self.client_id == ping['clientId']
+        assert ping['type'] == 'deletion'
+        assert ping['payload'] == {}