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
import textwrap
6
7
from telemetry_harness.testcase import TelemetryTestCase
8
from telemetry_harness.ping_filters import EVENT_PING
9
10
11
class TestEventPing(TelemetryTestCase):
12
"""Tests for "event" ping."""
13
14
def enable_search_events(self):
15
"""
16
Event Telemetry categories are disabled by default.
17
Search events are in the "navigation" category and are not enabled by
18
default in builds of Firefox, so we enable them here.
19
"""
20
21
script = """\
22
let {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
23
Services.telemetry.setEventRecordingEnabled("navigation", true);
24
"""
25
26
with self.marionette.using_context(self.marionette.CONTEXT_CHROME):
27
self.marionette.execute_script(textwrap.dedent(script))
28
29
def wait_for_search_service_init(self):
30
script = """\
31
let [resolve] = arguments;
32
let searchService = Components.classes["@mozilla.org/browser/search-service;1"]
33
.getService(Components.interfaces.nsISearchService);
34
searchService.init().then(resolve);
35
"""
36
37
with self.marionette.using_context(self.marionette.CONTEXT_CHROME):
38
self.marionette.execute_async_script(textwrap.dedent(script))
39
40
def test_event_ping(self):
41
"""
42
Barebones test for "event" ping:
43
Search, close Firefox, check "event" ping for search events.
44
"""
45
46
self.enable_search_events()
47
self.wait_for_search_service_init()
48
49
self.search("mozilla firefox")
50
51
payload = self.wait_for_ping(self.restart_browser, EVENT_PING)["payload"]
52
53
self.assertEqual(payload["reason"], "shutdown")
54
self.assertEqual(payload["lostEventsCount"], 0)
55
56
self.assertIn("events", payload)
57
self.assertIn("parent", payload["events"])
58
found_it = False
59
for [timestamp, category, method, object, value, extra] in payload["events"]["parent"]:
60
self.assertTrue(timestamp > 0)
61
if category == "navigation" and method == "search" and object == "urlbar":
62
found_it = True
63
64
self.assertTrue(found_it)