summaryrefslogtreecommitdiffstats
path: root/toolkit/components/reader/test/browser_readerMode_readingTime.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /toolkit/components/reader/test/browser_readerMode_readingTime.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/reader/test/browser_readerMode_readingTime.js')
-rw-r--r--toolkit/components/reader/test/browser_readerMode_readingTime.js101
1 files changed, 101 insertions, 0 deletions
diff --git a/toolkit/components/reader/test/browser_readerMode_readingTime.js b/toolkit/components/reader/test/browser_readerMode_readingTime.js
new file mode 100644
index 0000000000..91631b6234
--- /dev/null
+++ b/toolkit/components/reader/test/browser_readerMode_readingTime.js
@@ -0,0 +1,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'");
+ });
+ }
+ );
+});