diff --git a/toolkit/components/reader/test/browser.ini b/toolkit/components/reader/test/browser.ini index 9dede3eab239..59d57e150287 100644 --- a/toolkit/components/reader/test/browser.ini +++ b/toolkit/components/reader/test/browser.ini @@ -41,3 +41,6 @@ support-files = readerModeArticle.html readerModeArticleShort.html readerModeArticleMedium.html +[browser_readerMode_remoteType.js] +support-files = + readerModeArticleShort.html diff --git a/toolkit/components/reader/test/browser_readerMode_remoteType.js b/toolkit/components/reader/test/browser_readerMode_remoteType.js new file mode 100644 index 000000000000..6fe7ae7988f8 --- /dev/null +++ b/toolkit/components/reader/test/browser_readerMode_remoteType.js @@ -0,0 +1,87 @@ +/* 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" +); + +const CROSS_SITE_TEST_PATH = getRootDirectory(gTestPath).replace( + "chrome://mochitests/content", + "http://example.org" +); + +/** + * Test that switching an article into readermode doesn't change its' remoteType. + * Test that the reader mode correctly calculates and displays the + * estimated reading time for a short article + */ +add_task(async function() { + info("opening readermode normally to ensure process doesn't change"); + let articleRemoteType; + let aboutReaderURL; + await BrowserTestUtils.withNewTab( + TEST_PATH + "readerModeArticleShort.html", + async function(browser) { + articleRemoteType = browser.remoteType; + + // Click on the readermode button to switch into reader mode, and get the + // URL for that reader mode. + let pageShownPromise = BrowserTestUtils.waitForContentEvent( + browser, + "AboutReaderContentReady" + ); + let readerButton = document.getElementById("reader-mode-button"); + readerButton.click(); + await pageShownPromise; + + aboutReaderURL = browser.documentURI.spec; + ok( + aboutReaderURL.startsWith("about:reader"), + "about:reader should have been opened" + ); + is( + browser.remoteType, + articleRemoteType, + "remote type should not have changed" + ); + } + ); + + info( + "opening new tab directly with about reader URL into correct remote type" + ); + await BrowserTestUtils.withNewTab(aboutReaderURL, async function(browser) { + is( + browser.remoteType, + articleRemoteType, + "Should have performed about:reader load in the correct remote type" + ); + }); + + info("navigating process into correct remote type"); + await BrowserTestUtils.withNewTab( + CROSS_SITE_TEST_PATH + "readerModeArticleShort.html", + async function(browser) { + if (SpecialPowers.useRemoteSubframes) { + isnot( + browser.remoteType, + articleRemoteType, + "Cross-site article should have different remote type with fission" + ); + } + + BrowserTestUtils.loadURI(browser, aboutReaderURL); + await BrowserTestUtils.browserLoaded(browser); + + is( + browser.remoteType, + articleRemoteType, + "Should have switched into the correct remote type" + ); + } + ); +}); diff --git a/toolkit/modules/E10SUtils.jsm b/toolkit/modules/E10SUtils.jsm index a9a48ad38882..4cc6f76ac4af 100644 --- a/toolkit/modules/E10SUtils.jsm +++ b/toolkit/modules/E10SUtils.jsm @@ -82,6 +82,16 @@ function getAboutModule(aURL) { } } +function getOriginalReaderModeURI(aURI) { + try { + let searchParams = new URLSearchParams(aURI.query); + if (searchParams.has("url")) { + return Services.io.newURI(searchParams.get("url")); + } + } catch (e) {} + return null; +} + const NOT_REMOTE = null; // These must match any similar ones in ContentParent.h and ProcInfo.h @@ -474,6 +484,32 @@ var E10SUtils = { ) { return PRIVILEGEDABOUT_REMOTE_TYPE; } + + // When loading about:reader, try to display the document in the same + // web remote type as the document it's loading. + if (aURI.filePath == "reader") { + let readerModeURI = getOriginalReaderModeURI(aURI); + if (readerModeURI) { + let innerRemoteType = this.getRemoteTypeForURIObject( + readerModeURI, + aMultiProcess, + aRemoteSubframes, + aPreferredRemoteType, + aCurrentUri, + null, // aResultPrincipal + aIsSubframe, + aIsWorker, + aOriginAttributes + ); + if ( + innerRemoteType && + innerRemoteType.startsWith(WEB_REMOTE_TYPE) + ) { + return innerRemoteType; + } + } + } + return DEFAULT_REMOTE_TYPE; }