fune/toolkit/components/reader/test/browser_readerMode_readingTime.js
Kris Maglione 94e3b0bd8d Bug 1596918: Part 3a - Scripted rewrite of most ContentTask.spawn calls to SpecialPowers.spawn calls. r=mccr8,remote-protocol-reviewers,ato
This is generally pretty straightforward, and rewrites nearly all calls. It
skips the ones that it can detect using frame script globals like
`sendAsyncMessage`, though.

Differential Revision: https://phabricator.services.mozilla.com/D53740

--HG--
extra : moz-landing-system : lando
2019-12-13 20:36:16 +00:00

104 lines
3.4 KiB
JavaScript

/* 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");
is(
readingTimeElement.textContent,
"9-12 minutes",
"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");
is(
readingTimeElement.textContent,
"1 minute",
"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");
is(
readingTimeElement.textContent,
"3 minutes",
"Reading time should be '3 minutes'"
);
});
}
);
});