Source code

Revision control

Other Tools

# 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
import textwrap
from telemetry_harness.testcase import TelemetryTestCase
from telemetry_harness.ping_filters import EVENT_PING
class TestEventPing(TelemetryTestCase):
"""Tests for "event" ping."""
def enable_search_events(self):
Event Telemetry categories are disabled by default.
Search events are in the "navigation" category and are not enabled by
default in builds of Firefox, so we enable them here.
script = """\
let {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
Services.telemetry.setEventRecordingEnabled("navigation", true);
with self.marionette.using_context(self.marionette.CONTEXT_CHROME):
def wait_for_search_service_init(self):
script = """\
let [resolve] = arguments;
let searchService = Components.classes[";1"]
with self.marionette.using_context(self.marionette.CONTEXT_CHROME):
def test_event_ping(self):
Barebones test for "event" ping:
Search, close Firefox, check "event" ping for search events.
self.wait_for_search_service_init()"mozilla firefox")
payload = self.wait_for_ping(self.restart_browser, EVENT_PING)["payload"]
self.assertEqual(payload["reason"], "shutdown")
self.assertEqual(payload["lostEventsCount"], 0)
self.assertIn("events", payload)
self.assertIn("parent", payload["events"])
found_it = False
for event in payload["events"]["parent"]:
# The event may optionally contain additonal fields
[timestamp, category, method, obj] = event[:4]
self.assertTrue(timestamp > 0)
if category == "navigation" and method == "search" and obj == "urlbar":
found_it = True