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
|
/* 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";
const TEST_PATH = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
"http://example.com"
);
/**
* Test that the reader mode correctly calculates and displays the
* estimated reading time for a normal length article
*/
add_task(async function () {
await BrowserTestUtils.withNewTab(
TEST_PATH + "readerModeArticle.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 () {
// make sure there is a reading time on the page and that it displays the correct information
let readingTimeElement = content.document.querySelector(
".reader-estimated-time"
);
ok(readingTimeElement, "Reading time element should be in document");
const args = JSON.parse(readingTimeElement.dataset.l10nArgs);
is(args.rangePlural, "other", "Reading time should be '9-12 minutes'");
ok(
/\b9\b.*\b12\b/.test(args.range),
"Reading time should be '9-12 minutes'"
);
});
}
);
});
/**
* Test that the reader mode correctly calculates and displays the
* estimated reading time for a short article
*/
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 () {
// make sure there is a reading time on the page and that it displays the correct information
let readingTimeElement = content.document.querySelector(
".reader-estimated-time"
);
ok(readingTimeElement, "Reading time element should be in document");
const args = JSON.parse(readingTimeElement.dataset.l10nArgs);
is(args.rangePlural, "one", "Reading time should be '~1 minute'");
ok(/\b1\b/.test(args.range), "Reading time should be '~1 minute'");
});
}
);
});
/**
* Test that the reader mode correctly calculates and displays the
* estimated reading time for a medium article where a single number
* is displayed.
*/
add_task(async function () {
await BrowserTestUtils.withNewTab(
TEST_PATH + "readerModeArticleMedium.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 () {
// make sure there is a reading time on the page and that it displays the correct information
let readingTimeElement = content.document.querySelector(
".reader-estimated-time"
);
ok(readingTimeElement, "Reading time element should be in document");
const args = JSON.parse(readingTimeElement.dataset.l10nArgs);
is(args.rangePlural, "other", "Reading time should be '~3 minutes'");
ok(/\b3\b/.test(args.range), "Reading time should be '~3 minutes'");
});
}
);
});
|