Bug 1189491 - Take anchors into account in the reader view, r=gijs

MozReview-Commit-ID: 1udixhxnVao

--HG--
rename : browser/base/content/test/general/browser_bug1124271_readerModePinnedTab.js => toolkit/components/reader/test/browser_bug1124271_readerModePinnedTab.js
rename : browser/base/content/test/general/browser_readerMode.js => toolkit/components/reader/test/browser_readerMode.js
rename : browser/base/content/test/general/browser_readerMode_hidden_nodes.js => toolkit/components/reader/test/browser_readerMode_hidden_nodes.js
rename : browser/base/content/test/general/readerModeArticle.html => toolkit/components/reader/test/readerModeArticle.html
rename : browser/base/content/test/general/readerModeArticleHiddenNodes.html => toolkit/components/reader/test/readerModeArticleHiddenNodes.html
extra : rebase_source : fe5a56da7c51be03b3f6e4fca298f15fe1cc3552
extra : intermediate-source : 1cb8dac3eb40e519ee45a3fc5a9490b889ee5fc7
extra : source : 4da7d22ebcd2fdd3047487d7c2e483093324263c
This commit is contained in:
Sébastien Blin 2016-11-03 05:50:00 +00:00
Родитель 1492b47732
Коммит 26b39d5a68
12 изменённых файлов: 207 добавлений и 21 удалений

Просмотреть файл

@ -481,16 +481,6 @@ tags = mcb
[browser_windowactivation.js]
[browser_contextmenu_childprocess.js]
[browser_bug963945.js]
[browser_readerMode.js]
support-files =
readerModeArticle.html
readerModeArticleHiddenNodes.html
[browser_readerMode_hidden_nodes.js]
support-files =
readerModeArticleHiddenNodes.html
[browser_bug1124271_readerModePinnedTab.js]
support-files =
readerModeArticle.html
[browser_domFullscreen_fullscreenMode.js]
tags = fullscreen
[browser_menuButtonBadgeManager.js]

Просмотреть файл

@ -796,6 +796,8 @@ AboutReader.prototype = {
this._requestFavicon();
this._doc.body.classList.add("loaded");
this._goToReference(articleUri.ref);
Services.obs.notifyObservers(this._win, "AboutReader:Ready", "");
this._doc.dispatchEvent(
@ -982,5 +984,14 @@ AboutReader.prototype = {
if (openDropdowns.length) {
this._mm.sendAsyncMessage("Reader:DropdownClosed", this.viewId);
}
},
/*
* Scroll reader view to a reference
*/
_goToReference(ref) {
if (ref) {
this._win.location.hash = ref;
}
}
};

Просмотреть файл

@ -141,17 +141,26 @@ this.ReaderMode = {
return null;
}
let outerHash = "";
try {
let uriObj = Services.io.newURI(url, null, null);
url = uriObj.specIgnoringRef;
outerHash = uriObj.ref;
} catch (ex) { /* ignore, use the raw string */ }
let searchParams = new URLSearchParams(url.substring("about:reader?".length));
if (!searchParams.has("url")) {
return null;
}
let encodedURL = searchParams.get("url");
try {
return decodeURIComponent(encodedURL);
} catch (e) {
Cu.reportError("Error decoding original URL: " + e);
return encodedURL;
let originalUrl = searchParams.get("url");
if (outerHash) {
try {
let uriObj = Services.io.newURI(originalUrl, null, null);
uriObj = Services.io.newURI('#' + outerHash, null, uriObj);
originalUrl = uriObj.spec;
} catch (ex) {}
}
return originalUrl;
},
/**

Просмотреть файл

@ -18,5 +18,9 @@ EXTRA_JS_MODULES.reader = [
'ReaderWorker.jsm'
]
BROWSER_CHROME_MANIFESTS += [
'test/browser.ini'
]
with Files('**'):
BUG_COMPONENT = ('Toolkit', 'Reader Mode')

Просмотреть файл

@ -0,0 +1,15 @@
[DEFAULT]
support-files = head.js
[browser_readerMode.js]
support-files =
readerModeArticle.html
readerModeArticleHiddenNodes.html
[browser_readerMode_hidden_nodes.js]
support-files =
readerModeArticleHiddenNodes.html
[browser_readerMode_with_anchor.js]
support-files =
readerModeArticle.html
[browser_bug1124271_readerModePinnedTab.js]
support-files =
readerModeArticle.html

Просмотреть файл

@ -6,7 +6,7 @@
const PREF = "reader.parse-on-load.enabled";
const TEST_PATH = "http://example.com/browser/browser/base/content/test/general/";
const TEST_PATH = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "http://example.com");
var readerButton = document.getElementById("reader-mode-button");
@ -37,9 +37,9 @@ add_task(function* () {
// Ensure no new tabs are opened when exiting reader mode in a pinned tab
is(gBrowser.tabs.length, initialTabsCount, "No additional tabs were opened.");
let pageShownPromise = BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, "pageshow");
readerButton.click();
yield BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, "pageshow");
yield pageShownPromise;
// Ensure no new tabs are opened when exiting reader mode in a pinned tab
is(gBrowser.tabs.length, initialTabsCount, "No additional tabs were opened.");

Просмотреть файл

@ -10,7 +10,7 @@ const TEST_PREFS = [
["reader.parse-on-load.enabled", true],
];
const TEST_PATH = "http://example.com/browser/browser/base/content/test/general/";
const TEST_PATH = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "http://example.com");
var readerButton = document.getElementById("reader-mode-button");
@ -38,10 +38,14 @@ add_task(function* test_reader_button() {
ok(!Services.prefs.getBoolPref("browser.reader.detectedFirstArticle"),
"Shouldn't have detected the first article");
// We're going to show the reader mode intro popup, make sure we wait for it:
let tourPopupShownPromise =
BrowserTestUtils.waitForEvent(document.getElementById("UITourTooltip"), "popupshown");
// Point tab to a test page that is reader-able.
let url = TEST_PATH + "readerModeArticle.html";
yield promiseTabLoadEvent(tab, url);
yield promiseWaitForCondition(() => !readerButton.hidden);
yield tourPopupShownPromise;
is_element_visible(readerButton, "Reader mode button is present on a reader-able page");
ok(UITour.isInfoOnTarget(window, "readerMode-urlBar"),
"Info panel should be anchored at the reader mode button");

Просмотреть файл

@ -11,7 +11,7 @@ const TEST_PREFS = [
["browser.reader.detectedFirstArticle", false],
];
const TEST_PATH = "http://example.com/browser/browser/base/content/test/general/";
const TEST_PATH = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "http://example.com");
var readerButton = document.getElementById("reader-mode-button");

Просмотреть файл

@ -0,0 +1,21 @@
/* 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");
add_task(function* () {
yield BrowserTestUtils.withNewTab(TEST_PATH + "readerModeArticle.html#foo", function* (browser) {
let pageShownPromise = BrowserTestUtils.waitForContentEvent(browser, "AboutReaderContentReady");
let readerButton = document.getElementById("reader-mode-button");
readerButton.click();
yield pageShownPromise;
yield ContentTask.spawn(browser, null, function* () {
// Check if offset != 0
ok(content.document.getElementById("foo") !== null, "foo element should be in document");
ok(content.pageYOffset != 0, "pageYOffset should be > 0");
});
});
});

Просмотреть файл

@ -0,0 +1,126 @@
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
"resource://gre/modules/Promise.jsm");
/* exported promiseTabLoadEvent, promiseWaitForCondition, is_element_visible, is_element_hidden */
/**
* Waits for a load (or custom) event to finish in a given tab. If provided
* load an uri into the tab.
*
* @param tab
* The tab to load into.
* @param [optional] url
* The url to load, or the current url.
* @return {Promise} resolved when the event is handled.
* @resolves to the received event
* @rejects if a valid load event is not received within a meaningful interval
*/
function promiseTabLoadEvent(tab, url) {
let deferred = Promise.defer();
info("Wait tab event: load");
function handle(loadedUrl) {
if (loadedUrl === "about:blank" || (url && loadedUrl !== url)) {
info(`Skipping spurious load event for ${loadedUrl}`);
return false;
}
info("Tab event received: load");
return true;
}
// Create two promises: one resolved from the content process when the page
// loads and one that is rejected if we take too long to load the url.
let loaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, handle);
let timeout = setTimeout(() => {
deferred.reject(new Error("Timed out while waiting for a 'load' event"));
}, 30000);
loaded.then(() => {
clearTimeout(timeout);
deferred.resolve();
});
if (url)
BrowserTestUtils.loadURI(tab.linkedBrowser, url);
// Promise.all rejects if either promise rejects (i.e. if we time out) and
// if our loaded promise resolves before the timeout, then we resolve the
// timeout promise as well, causing the all promise to resolve.
return Promise.all([deferred.promise, loaded]);
}
function waitForCondition(condition, nextTest, errorMsg, retryTimes) {
retryTimes = typeof retryTimes !== 'undefined' ? retryTimes : 30;
var tries = 0;
var interval = setInterval(function() {
if (tries >= retryTimes) {
ok(false, errorMsg);
moveOn();
}
var conditionPassed;
try {
conditionPassed = condition();
} catch (e) {
ok(false, e + "\n" + e.stack);
conditionPassed = false;
}
if (conditionPassed) {
moveOn();
}
tries++;
}, 100);
var moveOn = function() {
clearInterval(interval);
nextTest();
};
}
function promiseWaitForCondition(aConditionFn) {
let deferred = Promise.defer();
waitForCondition(aConditionFn, deferred.resolve, "Condition didn't pass.");
return deferred.promise;
}
function is_element_visible(element, msg) {
isnot(element, null, "Element should not be null, when checking visibility");
ok(is_visible(element), msg || "Element should be visible");
}
function is_element_hidden(element, msg) {
isnot(element, null, "Element should not be null, when checking visibility");
ok(is_hidden(element), msg || "Element should be hidden");
}
function is_visible(element) {
var style = element.ownerGlobal.getComputedStyle(element);
if (style.display == "none")
return false;
if (style.visibility != "visible")
return false;
if (style.display == "-moz-popup" && element.state != "open")
return false;
// Hiding a parent element will hide all its children
if (element.parentNode != element.ownerDocument)
return is_visible(element.parentNode);
return true;
}
function is_hidden(element) {
var style = element.ownerGlobal.getComputedStyle(element);
if (style.display == "none")
return true;
if (style.visibility != "visible")
return true;
if (style.display == "-moz-popup")
return ["hiding", "closed"].indexOf(element.state) != -1;
// Hiding a parent element will hide all its children
if (element.parentNode != element.ownerDocument)
return is_hidden(element.parentNode);
return false;
}

Просмотреть файл

@ -14,6 +14,12 @@
<p>Vivamus fermentum semper porta. Nunc diam velit, adipiscing ut tristique vitae, sagittis vel odio. Maecenas convallis ullamcorper ultricies. Curabitur ornare, ligula semper consectetur sagittis, nisi diam iaculis velit, id fringilla sem nunc vel mi. Nam dictum, odio nec pretium volutpat, arcu ante placerat erat, non tristique elit urna et turpis. Quisque mi metus, ornare sit amet fermentum et, tincidunt et orci. Fusce eget orci a orci congue vestibulum. Ut dolor diam, elementum et vestibulum eu, porttitor vel elit. Curabitur venenatis pulvinar tellus gravida ornare. Sed et erat faucibus nunc euismod ultricies ut id justo. Nullam cursus suscipit nisi, et ultrices justo sodales nec. Fusce venenatis facilisis lectus ac semper. Aliquam at massa ipsum. Quisque bibendum purus convallis nulla ultrices ultricies. Nullam aliquam, mi eu aliquam tincidunt, purus velit laoreet tortor, viverra pretium nisi quam vitae mi. Fusce vel volutpat elit. Nam sagittis nisi dui.</p>
<p>Vivamus fermentum semper porta. Nunc diam velit, adipiscing ut tristique vitae, sagittis vel odio. Maecenas convallis ullamcorper ultricies. Curabitur ornare, ligula semper consectetur sagittis, nisi diam iaculis velit, id fringilla sem nunc vel mi. Nam dictum, odio nec pretium volutpat, arcu ante placerat erat, non tristique elit urna et turpis. Quisque mi metus, ornare sit amet fermentum et, tincidunt et orci. Fusce eget orci a orci congue vestibulum. Ut dolor diam, elementum et vestibulum eu, porttitor vel elit. Curabitur venenatis pulvinar tellus gravida ornare. Sed et erat faucibus nunc euismod ultricies ut id justo. Nullam cursus suscipit nisi, et ultrices justo sodales nec. Fusce venenatis facilisis lectus ac semper. Aliquam at massa ipsum. Quisque bibendum purus convallis nulla ultrices ultricies. Nullam aliquam, mi eu aliquam tincidunt, purus velit laoreet tortor, viverra pretium nisi quam vitae mi. Fusce vel volutpat elit. Nam sagittis nisi dui.</p>
<p>Vivamus fermentum semper porta. Nunc diam velit, adipiscing ut tristique vitae, sagittis vel odio. Maecenas convallis ullamcorper ultricies. Curabitur ornare, ligula semper consectetur sagittis, nisi diam iaculis velit, id fringilla sem nunc vel mi. Nam dictum, odio nec pretium volutpat, arcu ante placerat erat, non tristique elit urna et turpis. Quisque mi metus, ornare sit amet fermentum et, tincidunt et orci. Fusce eget orci a orci congue vestibulum. Ut dolor diam, elementum et vestibulum eu, porttitor vel elit. Curabitur venenatis pulvinar tellus gravida ornare. Sed et erat faucibus nunc euismod ultricies ut id justo. Nullam cursus suscipit nisi, et ultrices justo sodales nec. Fusce venenatis facilisis lectus ac semper. Aliquam at massa ipsum. Quisque bibendum purus convallis nulla ultrices ultricies. Nullam aliquam, mi eu aliquam tincidunt, purus velit laoreet tortor, viverra pretium nisi quam vitae mi. Fusce vel volutpat elit. Nam sagittis nisi dui.</p>
<div id="foo">by John Doe</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est.</p>
<p>Vivamus fermentum semper porta. Nunc diam velit, adipiscing ut tristique vitae, sagittis vel odio. Maecenas convallis ullamcorper ultricies. Curabitur ornare, ligula semper consectetur sagittis, nisi diam iaculis velit, id fringilla sem nunc vel mi. Nam dictum, odio nec pretium volutpat, arcu ante placerat erat, non tristique elit urna et turpis. Quisque mi metus, ornare sit amet fermentum et, tincidunt et orci. Fusce eget orci a orci congue vestibulum. Ut dolor diam, elementum et vestibulum eu, porttitor vel elit. Curabitur venenatis pulvinar tellus gravida ornare. Sed et erat faucibus nunc euismod ultricies ut id justo. Nullam cursus suscipit nisi, et ultrices justo sodales nec. Fusce venenatis facilisis lectus ac semper. Aliquam at massa ipsum. Quisque bibendum purus convallis nulla ultrices ultricies. Nullam aliquam, mi eu aliquam tincidunt, purus velit laoreet tortor, viverra pretium nisi quam vitae mi. Fusce vel volutpat elit. Nam sagittis nisi dui.</p>
<p>Vivamus fermentum semper porta. Nunc diam velit, adipiscing ut tristique vitae, sagittis vel odio. Maecenas convallis ullamcorper ultricies. Curabitur ornare, ligula semper consectetur sagittis, nisi diam iaculis velit, id fringilla sem nunc vel mi. Nam dictum, odio nec pretium volutpat, arcu ante placerat erat, non tristique elit urna et turpis. Quisque mi metus, ornare sit amet fermentum et, tincidunt et orci. Fusce eget orci a orci congue vestibulum. Ut dolor diam, elementum et vestibulum eu, porttitor vel elit. Curabitur venenatis pulvinar tellus gravida ornare. Sed et erat faucibus nunc euismod ultricies ut id justo. Nullam cursus suscipit nisi, et ultrices justo sodales nec. Fusce venenatis facilisis lectus ac semper. Aliquam at massa ipsum. Quisque bibendum purus convallis nulla ultrices ultricies. Nullam aliquam, mi eu aliquam tincidunt, purus velit laoreet tortor, viverra pretium nisi quam vitae mi. Fusce vel volutpat elit. Nam sagittis nisi dui.</p>
<p>Vivamus fermentum semper porta. Nunc diam velit, adipiscing ut tristique vitae, sagittis vel odio. Maecenas convallis ullamcorper ultricies. Curabitur ornare, ligula semper consectetur sagittis, nisi diam iaculis velit, id fringilla sem nunc vel mi. Nam dictum, odio nec pretium volutpat, arcu ante placerat erat, non tristique elit urna et turpis. Quisque mi metus, ornare sit amet fermentum et, tincidunt et orci. Fusce eget orci a orci congue vestibulum. Ut dolor diam, elementum et vestibulum eu, porttitor vel elit. Curabitur venenatis pulvinar tellus gravida ornare. Sed et erat faucibus nunc euismod ultricies ut id justo. Nullam cursus suscipit nisi, et ultrices justo sodales nec. Fusce venenatis facilisis lectus ac semper. Aliquam at massa ipsum. Quisque bibendum purus convallis nulla ultrices ultricies. Nullam aliquam, mi eu aliquam tincidunt, purus velit laoreet tortor, viverra pretium nisi quam vitae mi. Fusce vel volutpat elit. Nam sagittis nisi dui.</p>
<p>Vivamus fermentum semper porta. Nunc diam velit, adipiscing ut tristique vitae, sagittis vel odio. Maecenas convallis ullamcorper ultricies. Curabitur ornare, ligula semper consectetur sagittis, nisi diam iaculis velit, id fringilla sem nunc vel mi. Nam dictum, odio nec pretium volutpat, arcu ante placerat erat, non tristique elit urna et turpis. Quisque mi metus, ornare sit amet fermentum et, tincidunt et orci. Fusce eget orci a orci congue vestibulum. Ut dolor diam, elementum et vestibulum eu, porttitor vel elit. Curabitur venenatis pulvinar tellus gravida ornare. Sed et erat faucibus nunc euismod ultricies ut id justo. Nullam cursus suscipit nisi, et ultrices justo sodales nec. Fusce venenatis facilisis lectus ac semper. Aliquam at massa ipsum. Quisque bibendum purus convallis nulla ultrices ultricies. Nullam aliquam, mi eu aliquam tincidunt, purus velit laoreet tortor, viverra pretium nisi quam vitae mi. Fusce vel volutpat elit. Nam sagittis nisi dui.</p>
</div>
</body>
</html>