gecko-dev/toolkit/components/reader/test/browser_readerMode_readingTime.js
Cameron McCormack 544acb33d3 Bug 1417837 - Part 3: Replace all IDs in about:reader documents with class names. r=Gijs
Since the readerized article content will have its class names stripped
but will retain its original IDs, and we don't want our aboutReader.css
rules targetting UI elements to match anything in the article.

MozReview-Commit-ID: JuXTo8Nth5Q

--HG--
extra : rebase_source : dde58f56e55f82ddda364ec5978e43fe71be875c
2017-11-30 11:55:32 +08:00

65 lines
3.1 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 ContentTask.spawn(browser, null, 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 ContentTask.spawn(browser, null, 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 ContentTask.spawn(browser, null, 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'");
});
});
});