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
124
125
126
127
128
129
130
131
132
133
134
135
136
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// This test verifies that the Save To Pocket button appears in reader mode,
// and is toggled hidden and visible when pocket is disabled and enabled.
const TEST_PATH = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
"http://example.com"
);
async function getPocketButtonsCount(browser) {
return SpecialPowers.spawn(browser, [], () => {
return content.document.getElementsByClassName("pocket-button").length;
});
}
add_task(async function () {
// set the pocket preference before beginning.
await SpecialPowers.pushPrefEnv({
set: [["extensions.pocket.enabled", true]],
});
var readerButton = document.getElementById("reader-mode-button");
let tab1 = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
TEST_PATH + "readerModeArticleShort.html"
);
let promiseTabLoad = promiseTabLoadEvent(tab1);
readerButton.click();
await promiseTabLoad;
let tab2 = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
TEST_PATH + "readerModeArticleMedium.html"
);
promiseTabLoad = promiseTabLoadEvent(tab2);
readerButton.click();
await promiseTabLoad;
is(
await getPocketButtonsCount(tab1.linkedBrowser),
1,
"tab 1 has a pocket button"
);
is(
await getPocketButtonsCount(tab1.linkedBrowser),
1,
"tab 2 has a pocket button"
);
// Turn off the pocket preference. The Save To Pocket buttons should disappear.
await SpecialPowers.pushPrefEnv({
set: [["extensions.pocket.enabled", false]],
});
is(
await getPocketButtonsCount(tab1.linkedBrowser),
0,
"tab 1 has no pocket button"
);
is(
await getPocketButtonsCount(tab1.linkedBrowser),
0,
"tab 2 has no pocket button"
);
// Turn on the pocket preference. The Save To Pocket buttons should reappear again.
await SpecialPowers.pushPrefEnv({
set: [["extensions.pocket.enabled", true]],
});
is(
await getPocketButtonsCount(tab1.linkedBrowser),
1,
"tab 1 has a pocket button again"
);
is(
await getPocketButtonsCount(tab1.linkedBrowser),
1,
"tab 2 has a pocket button again"
);
BrowserTestUtils.removeTab(tab1);
BrowserTestUtils.removeTab(tab2);
});
/**
* Test that the pocket button toggles the pocket popup successfully
*/
add_task(async function () {
await BrowserTestUtils.withNewTab(
TEST_PATH + "readerModeArticleShort.html",
async function (browser) {
let pageShownPromise = BrowserTestUtils.waitForContentEvent(
browser,
"AboutReaderContentReady"
);
let readerButton = document.getElementById("reader-mode-button");
readerButton.click();
await pageShownPromise;
await SpecialPowers.spawn(browser, [], async function () {
content.document.querySelector(".pocket-button").click();
});
let panel = gBrowser.selectedBrowser.ownerDocument.querySelector(
"#customizationui-widget-panel"
);
await BrowserTestUtils.waitForMutationCondition(
panel,
{ attributes: true },
() => {
return BrowserTestUtils.isVisible(panel);
}
);
ok(BrowserTestUtils.isVisible(panel), "Panel buttons are visible");
await SpecialPowers.spawn(browser, [], async function () {
content.document.querySelector(".pocket-button").click();
});
await BrowserTestUtils.waitForMutationCondition(
panel,
{ attributes: true },
() => {
return BrowserTestUtils.isHidden(panel);
}
);
ok(BrowserTestUtils.isHidden(panel), "Panel buttons are hidden");
}
);
});
|