1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/* 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/. */
/**
* Tests page view time recording for interactions after DOM history API usage.
*/
const TEST_URL = "https://example.com/";
const TEST_URL2 = "https://example.com/browser";
add_task(async function test_interactions_pushState() {
await Interactions.reset();
await BrowserTestUtils.withNewTab(TEST_URL, async browser => {
Interactions._pageViewStartTime = Cu.now() - 10000;
await ContentTask.spawn(browser, TEST_URL2, url => {
content.history.pushState(null, "", url);
});
Interactions._pageViewStartTime = Cu.now() - 20000;
});
await assertDatabaseValues([
{
url: TEST_URL,
totalViewTime: 10000,
},
{
url: TEST_URL2,
totalViewTime: 20000,
},
]);
});
add_task(async function test_interactions_pushState_sameUrl() {
await Interactions.reset();
await BrowserTestUtils.withNewTab(TEST_URL, async browser => {
Interactions._pageViewStartTime = Cu.now() - 10000;
await ContentTask.spawn(browser, TEST_URL, url => {
content.history.pushState(null, "", url);
});
Interactions._pageViewStartTime = Cu.now() - 20000;
});
await assertDatabaseValues([
{
url: TEST_URL,
totalViewTime: 20000,
},
]);
});
add_task(async function test_interactions_replaceState() {
await Interactions.reset();
await BrowserTestUtils.withNewTab(TEST_URL, async browser => {
Interactions._pageViewStartTime = Cu.now() - 10000;
await ContentTask.spawn(browser, TEST_URL2, url => {
content.history.replaceState(null, "", url);
});
Interactions._pageViewStartTime = Cu.now() - 20000;
});
await assertDatabaseValues([
{
url: TEST_URL,
totalViewTime: 10000,
},
{
url: TEST_URL2,
totalViewTime: 20000,
},
]);
});
add_task(async function test_interactions_replaceState_sameUrl() {
await Interactions.reset();
await BrowserTestUtils.withNewTab(TEST_URL, async browser => {
Interactions._pageViewStartTime = Cu.now() - 10000;
await ContentTask.spawn(browser, TEST_URL, url => {
content.history.replaceState(null, "", url);
});
Interactions._pageViewStartTime = Cu.now() - 20000;
});
await assertDatabaseValues([
{
url: TEST_URL,
totalViewTime: 20000,
},
]);
});
add_task(async function test_interactions_hashchange() {
await Interactions.reset();
await BrowserTestUtils.withNewTab(TEST_URL, async browser => {
Interactions._pageViewStartTime = Cu.now() - 10000;
await ContentTask.spawn(browser, TEST_URL + "#foo", url => {
content.location = url;
});
Interactions._pageViewStartTime = Cu.now() - 20000;
});
await assertDatabaseValues([
{
url: TEST_URL,
totalViewTime: 20000,
},
]);
});
|