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
|
/**
* Verify if we correctly switch print preview browsers based on whether
* Simplify Page checkbox is checked.
*/
const TEST_PATH = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
"http://example.com"
);
add_task(async function set_simplify_and_reader_pref() {
// Ensure we have the simplify page preference set
await SpecialPowers.pushPrefEnv({
set: [
["print.tab_modal.enabled", false],
["print.use_simplify_page", true],
["reader.parse-on-load.enabled", true],
],
});
});
add_task(async function switch_print_preview_browsers() {
let url = TEST_PATH + "simplifyArticleSample.html";
// Can only do something if we have a print preview UI:
if (AppConstants.platform != "win" && AppConstants.platform != "linux") {
ok(false, "Can't test if there's no print preview.");
return;
}
// Ensure we get a browserStopped for this browser
let tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
url,
false,
true
);
// Wait for Reader Mode to parse and set property of loaded tab
await BrowserTestUtils.waitForCondition(() => {
return tab.linkedBrowser.isArticle;
});
// Enter print preview
let defaultPPBrowser = PrintPreviewListener.getPrintPreviewBrowser();
let defaultPPEntered = PrintHelper.waitForOldPrintPreview(defaultPPBrowser);
document.getElementById("cmd_printPreview").doCommand();
await defaultPPEntered;
// Assert that we are showing the initial content on default print preview browser
await SpecialPowers.spawn(defaultPPBrowser, [], async function() {
is(content.document.title, "Article title", "Should have initial content.");
});
// Here we call simplified mode
let simplifiedPPBrowser = PrintPreviewListener.getSimplifiedPrintPreviewBrowser();
let simplifiedPPEntered = PrintHelper.waitForOldPrintPreview(
simplifiedPPBrowser
);
let printPreviewToolbar = document.getElementById("print-preview-toolbar");
// Wait for simplify page option enablement
await BrowserTestUtils.waitForCondition(() => {
return !printPreviewToolbar.mSimplifyPageCheckbox.disabled;
});
printPreviewToolbar.mSimplifyPageCheckbox.click();
await simplifiedPPEntered;
// Assert that simplify page option is checked
is(
printPreviewToolbar.mSimplifyPageCheckbox.checked,
true,
"Should have simplify page option checked"
);
// Assert that we are showing custom content on simplified print preview browser
await SpecialPowers.spawn(simplifiedPPBrowser, [], async function() {
is(content.document.title, "Article title", "Should have custom content.");
});
// Assert that we are selecting simplified print preview browser, and not default one
is(
gBrowser.selectedTab.linkedBrowser,
simplifiedPPBrowser,
"Should have simplified print preview browser selected"
);
isnot(
gBrowser.selectedTab.linkedBrowser,
defaultPPBrowser,
"Should not have default print preview browser selected"
);
// Switch back to default print preview content
defaultPPEntered = PrintHelper.waitForOldPrintPreview(defaultPPBrowser);
printPreviewToolbar.mSimplifyPageCheckbox.click();
await defaultPPEntered;
// Assert that simplify page option is not checked
isnot(
printPreviewToolbar.mSimplifyPageCheckbox.checked,
true,
"Should not have simplify page option checked"
);
// Assert that we are showing the initial content on default print preview browser
await SpecialPowers.spawn(defaultPPBrowser, [], async function() {
is(content.document.title, "Article title", "Should have initial content.");
});
// Assert that we are selecting default print preview browser, and not simplified one
is(
gBrowser.selectedTab.linkedBrowser,
defaultPPBrowser,
"Should have default print preview browser selected"
);
isnot(
gBrowser.selectedTab.linkedBrowser,
simplifiedPPBrowser,
"Should not have simplified print preview browser selected"
);
PrintUtils.exitPrintPreview();
BrowserTestUtils.removeTab(tab);
});
|