summaryrefslogtreecommitdiffstats
path: root/toolkit/components/printing/tests/browser_preview_print_simplify_non_article.js
blob: 681e53f8b9f46b46b0cb9ed33ac2ce9342a3fb08 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
 * Verify if we recover from parsing errors of Reader Mode when
 * Simplify Page checkbox is checked.
 */

const TEST_PATH = getRootDirectory(gTestPath).replace(
  "chrome://mochitests/content",
  "http://example.com"
);

add_task(async function set_simplify_and_reader_pref() {
  // Ensure we have the simplify page preference set
  await SpecialPowers.pushPrefEnv({
    set: [
      ["print.tab_modal.enabled", false],
      ["print.use_simplify_page", true],
      ["reader.parse-on-load.enabled", true],
    ],
  });
});

add_task(async function switch_print_preview_browsers() {
  let url = TEST_PATH + "simplifyNonArticleSample.html";

  // Can only do something if we have a print preview UI:
  if (AppConstants.platform != "win" && AppConstants.platform != "linux") {
    ok(false, "Can't test if there's no print preview.");
    return;
  }

  // Ensure we get a browserStopped for this browser
  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    url,
    false,
    true
  );

  // Trick browser to think loaded tab has isArticle property set as true
  tab.linkedBrowser.isArticle = true;

  // Enter print preview
  let defaultPPBrowser = PrintPreviewListener.getPrintPreviewBrowser();
  let defaultPPEntered = PrintHelper.waitForOldPrintPreview(defaultPPBrowser);
  document.getElementById("cmd_printPreview").doCommand();
  await defaultPPEntered;

  // Assert that we are showing the initial content on default print preview browser
  await SpecialPowers.spawn(defaultPPBrowser, [], async function() {
    is(
      content.document.title,
      "Non article title",
      "Should have initial content."
    );
  });

  // Here we call simplified mode
  let simplifiedPPBrowser = PrintPreviewListener.getSimplifiedPrintPreviewBrowser();
  let simplifiedPPEntered = PrintHelper.waitForOldPrintPreview(
    simplifiedPPBrowser
  );
  let printPreviewToolbar = document.getElementById("print-preview-toolbar");

  // Wait for simplify page option enablement
  await BrowserTestUtils.waitForCondition(() => {
    return !printPreviewToolbar.mSimplifyPageCheckbox.disabled;
  });

  printPreviewToolbar.mSimplifyPageCheckbox.click();
  await simplifiedPPEntered;

  // Assert that simplify page option is checked
  is(
    printPreviewToolbar.mSimplifyPageCheckbox.checked,
    true,
    "Should have simplify page option checked"
  );

  // Assert that we are showing recovery content on simplified print preview browser
  await SpecialPowers.spawn(simplifiedPPBrowser, [], async function() {
    await ContentTaskUtils.waitForCondition(
      () => content.document.title === "Failed to load article from page",
      "Simplified document title should be updated with recovery title."
    );
  });

  // Assert that we are selecting simplified print preview browser, and not default one
  is(
    gBrowser.selectedTab.linkedBrowser,
    simplifiedPPBrowser,
    "Should have simplified print preview browser selected"
  );
  isnot(
    gBrowser.selectedTab.linkedBrowser,
    defaultPPBrowser,
    "Should not have default print preview browser selected"
  );

  PrintUtils.exitPrintPreview();

  await BrowserTestUtils.removeTab(tab);
});