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
from telemetry_harness.testcase import TelemetryTestCase
6
from telemetry_harness.ping_filters import (
7
MAIN_ENVIRONMENT_CHANGE_PING,
8
MAIN_SHUTDOWN_PING,
9
)
10
11
12
class TestSubsessionManagement(TelemetryTestCase):
13
"""Tests for Firefox Telemetry subsession management."""
14
15
def test_subsession_management(self):
16
"""Test for Firefox Telemetry subsession management."""
17
18
# Session S1, subsession 1
19
# Actions:
20
# 1. Open browser
21
# 2. Open a new tab
22
# 3. Restart browser in new session
23
24
with self.new_tab():
25
# If Firefox Telemetry is working correctly, this will
26
# be sufficient to record a tab open event.
27
pass
28
29
ping1 = self.wait_for_ping(self.restart_browser, MAIN_SHUTDOWN_PING)
30
31
# Session S2, subsession 1
32
# Outcome 1:
33
# Received a main ping P1 for previous session
34
# - Ping base contents:
35
# - clientId should be a valid UUID
36
# - reason should be "shutdown"
37
# - sessionId should be set
38
# - subsessionId should be set
39
# - previousSessionId should not be set
40
# - previousSubsessionId should not be set
41
# - subSessionCounter should be 1
42
# - profileSubSessionCounter should be 1
43
# - Other ping contents:
44
# - tab_open_event_count in scalars
45
46
client_id = ping1["clientId"]
47
self.assertIsValidUUID(client_id)
48
49
ping1_info = ping1["payload"]["info"]
50
self.assertEqual(ping1_info["reason"], "shutdown")
51
52
s1_session_id = ping1_info["sessionId"]
53
self.assertNotEqual(s1_session_id, "")
54
55
s1_s1_subsession_id = ping1_info["subsessionId"]
56
self.assertNotEqual(s1_s1_subsession_id, "")
57
self.assertIsNone(ping1_info["previousSessionId"])
58
self.assertIsNone(ping1_info["previousSubsessionId"])
59
self.assertEqual(ping1_info["subsessionCounter"], 1)
60
self.assertEqual(ping1_info["profileSubsessionCounter"], 1)
61
62
scalars1 = ping1["payload"]["processes"]["parent"]["scalars"]
63
self.assertNotIn("browser.engagement.window_open_event_count", scalars1)
64
self.assertEqual(scalars1["browser.engagement.tab_open_event_count"], 1)
65
66
# Actions:
67
# 1. Install addon
68
69
ping2 = self.wait_for_ping(self.install_addon, MAIN_ENVIRONMENT_CHANGE_PING)
70
71
[addon_id] = self.addon_ids # Store the addon ID for verifying ping3 later
72
73
# Session S2, subsession 2
74
# Outcome 2:
75
# Received a main ping P2 for previous subsession
76
# - Ping base contents:
77
# - clientId should be set to the same value
78
# - sessionId should be set to a new value
79
# - subsessionId should be set to a new value
80
# - previousSessionId should be set to P1s sessionId value
81
# - previousSubsessionId should be set to P1s subsessionId value
82
# - subSessionCounter should be 1
83
# - profileSubSessionCounter should be 2
84
# - reason should be "environment-change"
85
# - Other ping contents:
86
# - tab_open_event_count not in scalars
87
88
self.assertEqual(ping2["clientId"], client_id)
89
90
ping2_info = ping2["payload"]["info"]
91
self.assertEqual(ping2_info["reason"], "environment-change")
92
93
s2_session_id = ping2_info["sessionId"]
94
self.assertNotEqual(s2_session_id, s1_session_id)
95
96
s2_s1_subsession_id = ping2_info["subsessionId"]
97
self.assertNotEqual(s2_s1_subsession_id, s1_s1_subsession_id)
98
self.assertEqual(ping2_info["previousSessionId"], s1_session_id)
99
self.assertEqual(ping2_info["previousSubsessionId"], s1_s1_subsession_id)
100
self.assertEqual(ping2_info["subsessionCounter"], 1)
101
self.assertEqual(ping2_info["profileSubsessionCounter"], 2)
102
103
scalars2 = ping2["payload"]["processes"]["parent"]["scalars"]
104
self.assertNotIn("browser.engagement.window_open_event_count", scalars2)
105
self.assertNotIn("browser.engagement.tab_open_event_count", scalars2)
106
107
# Actions
108
# 1. Restart browser in new session
109
110
ping3 = self.wait_for_ping(self.restart_browser, MAIN_SHUTDOWN_PING)
111
112
# Session S3, subsession 1
113
# Outcome 3:
114
# Received a main ping P3 for session 2, subsession 2
115
# - Ping base contents:
116
# - clientId should be set to the same value
117
# - sessionId should be set to P2s sessionId value
118
# - subsessionId should be set to a new value
119
# - previousSessionId should be set to P1s sessionId value
120
# - previousSubsessionId should be set to P2s subsessionId value
121
# - subSessionCounter should be 2
122
# - profileSubSessionCounter should be 3
123
# - reason should be "shutdown"
124
# - Other ping contents:
125
# - addon ID in activeAddons in environment
126
127
self.assertEqual(ping3["clientId"], client_id)
128
129
ping3_info = ping3["payload"]["info"]
130
self.assertEqual(ping3_info["reason"], "shutdown")
131
132
self.assertEqual(ping3_info["sessionId"], s2_session_id)
133
134
s2_s2_subsession_id = ping3_info["subsessionId"]
135
self.assertNotEqual(s2_s2_subsession_id, s1_s1_subsession_id)
136
self.assertNotEqual(s2_s2_subsession_id, s2_s1_subsession_id)
137
self.assertEqual(ping3_info["previousSessionId"], s1_session_id)
138
self.assertEqual(ping3_info["previousSubsessionId"], s2_s1_subsession_id)
139
self.assertEqual(ping3_info["subsessionCounter"], 2)
140
self.assertEqual(ping3_info["profileSubsessionCounter"], 3)
141
142
scalars3 = ping3["payload"]["processes"]["parent"]["scalars"]
143
self.assertNotIn("browser.engagement.window_open_event_count", scalars3)
144
self.assertNotIn("browser.engagement.tab_open_event_count", scalars3)
145
146
active_addons = ping3["environment"]["addons"]["activeAddons"]
147
self.assertIn(addon_id, active_addons)