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
|
/* 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/. */
"use strict";
/**
* Snippets endpoint has two snippets that share the same campaign id.
* We want to make sure that dismissing the snippet on the first about:newtab
* will clear the snippet on the next (preloaded) about:newtab.
*/
const { ASRouter } = ChromeUtils.import(
"resource://activity-stream/lib/ASRouter.jsm"
);
async function setup() {
await SpecialPowers.pushPrefEnv({
set: [
[
"browser.newtabpage.activity-stream.asrouter.providers.snippets",
'{"id":"snippets","enabled":true,"type":"remote","url":"https://example.com/browser/browser/components/newtab/test/browser/snippet.json","updateCycleInMs":14400000}',
],
["browser.newtabpage.activity-stream.feeds.snippets", true],
// Disable onboarding, this would prevent snippets from showing up
[
"browser.newtabpage.activity-stream.asrouter.providers.onboarding",
'{"id":"onboarding","type":"local","localProvider":"OnboardingMessageProvider","enabled":false,"exclude":[]}',
],
// Ensure this is true, this is the main behavior we want to test for
["browser.newtab.preload", true],
],
});
}
add_task(async function test_campaign_dismiss() {
await setup();
let tab1 = await BrowserTestUtils.openNewForegroundTab({
gBrowser,
opening: "about:home",
});
await ContentTask.spawn(gBrowser.selectedBrowser, {}, async () => {
await ContentTaskUtils.waitForCondition(
() => content.document.querySelector(".activity-stream"),
`Should render Activity Stream`
);
await ContentTaskUtils.waitForCondition(
() =>
content.document.querySelector(
"#footer-asrouter-container .SimpleSnippet"
),
"Should find the snippet inside the footer container"
);
content.document
.querySelector("#footer-asrouter-container .blockButton")
.click();
await ContentTaskUtils.waitForCondition(
() =>
!content.document.querySelector(
"#footer-asrouter-container .SimpleSnippet"
),
"Should wait for the snippet to block"
);
});
ok(
ASRouter.state.messageBlockList.length,
"Should have the campaign blocked"
);
let tab2 = await BrowserTestUtils.openNewForegroundTab({
gBrowser,
opening: "about:newtab",
// This is important because the newtab is preloaded and doesn't behave
// like a regular page load
waitForLoad: false,
});
await ContentTask.spawn(gBrowser.selectedBrowser, {}, async () => {
await ContentTaskUtils.waitForCondition(
() => content.document.querySelector(".activity-stream"),
`Should render Activity Stream`
);
let snippet = content.document.querySelector(
"#footer-asrouter-container .SimpleSnippet"
);
Assert.equal(
snippet,
null,
"No snippets shown because campaign is blocked"
);
});
BrowserTestUtils.removeTab(tab1);
BrowserTestUtils.removeTab(tab2);
await ASRouter.unblockMessageById(["10533", "10534"]);
await SpecialPowers.popPrefEnv();
});
|