summaryrefslogtreecommitdiffstats
path: root/toolkit/components/reader/test/browser_readerMode_remoteType.js
blob: 690cb743382e44168917eafaa4fb2d5d3c6d3f35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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.loadURIString(browser, aboutReaderURL);
      await BrowserTestUtils.browserLoaded(browser);

      is(
        browser.remoteType,
        articleRemoteType,
        "Should have switched into the correct remote type"
      );
    }
  );
});