Bug 1539830 - Test "optout" ping. r=raphael

This doesn't exactly match the test plan due to issues I experienced trying to
set preferences or manually control when the Firefox under test closes and
opens.

Differential Revision: https://phabricator.services.mozilla.com/D29695

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Chris H-C 2019-05-13 11:02:45 +00:00
Родитель 8e3d08807a
Коммит ef06d67971
3 изменённых файлов: 79 добавлений и 1 удалений

Просмотреть файл

@ -10,6 +10,16 @@ class PingFilter(object):
return True
class FirstShutdownPingFilter(PingFilter):
"""Ping filter that accepts first-shutdown pings."""
def __call__(self, ping):
if not super(FirstShutdownPingFilter, self).__call__(ping):
return False
return ping["type"] == "first-shutdown"
class MainPingFilter(PingFilter):
"""Ping filter that accepts main pings."""
@ -36,7 +46,19 @@ class MainPingReasonFilter(MainPingFilter):
return ping["payload"]["info"]["reason"] == self.reason
class OptoutPingFilter(PingFilter):
"""Ping filter that accepts optout pings."""
def __call__(self, ping):
if not super(OptoutPingFilter, self).__call__(ping):
return False
return ping["type"] == "optout"
ANY_PING = PingFilter()
FIRST_SHUTDOWN_PING = FirstShutdownPingFilter()
MAIN_PING = MainPingFilter()
MAIN_SHUTDOWN_PING = MainPingReasonFilter("shutdown")
MAIN_ENVIRONMENT_CHANGE_PING = MainPingReasonFilter("environment-change")
OPTOUT_PING = OptoutPingFilter()

Просмотреть файл

@ -2,5 +2,6 @@
tags = client
[test_main_tab_scalars.py]
[test_optout_ping.py]
[test_search_counts_across_sessions.py]
[test_subsession_management.py]
[test_subsession_management.py]

Просмотреть файл

@ -0,0 +1,55 @@
# 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
class TestOptoutPing(TelemetryTestCase):
"""Tests for "optout" ping."""
def disable_telemetry(self):
self.marionette.set_pref("datareporting.healthreport.uploadEnabled", False)
def enable_telemetry(self):
self.marionette.set_pref("datareporting.healthreport.uploadEnabled", True)
def test_optout_ping(self):
"""Test for "optout" ping."""
# 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.
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
self.assertEqual(self.ping_server.pings[-1], optout_ping)
""" Test what happens when the user opts back in """
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)
self.assertIn("clientId", shutdown_ping)
self.assertIsValidUUID(shutdown_ping["clientId"])
self.assertNotEqual(shutdown_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"]
self.assertIn("telemetry.data_upload_optin", scalars)
self.assertTrue(scalars["telemetry.data_upload_optin"])