summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_webconsole_non_standard_doctype_errors.js
blob: c7be1b94ca663e5a494d206c423e525fa1a90656 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Check that warning messages are displayed for documents with non-standards doctype

const QUIRKY_DOCTYPE = "<!DOCTYPE xhtml2>";
const ALMOST_STANDARD_DOCTYPE = `<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">`;
const STANDARD_DOCTYPE = "<!DOCTYPE html>";

const TEST_URI_QUIRKY_DOCTYPE = `data:text/html,${QUIRKY_DOCTYPE}<meta charset="utf8"><h1>Quirky</h1>`;
const TEST_URI_ALMOST_STANDARD_DOCTYPE = `data:text/html,${ALMOST_STANDARD_DOCTYPE}<meta charset="utf8"><h1>Almost standard</h1>`;
const TEST_URI_NO_DOCTYPE = `data:text/html,<meta charset="utf8"><h1>No DocType</h1>`;
const TEST_URI_STANDARD_DOCTYPE = `data:text/html,${STANDARD_DOCTYPE}<meta charset="utf8"><h1>Standard</h1>`;

const LEARN_MORE_URI =
  "https://developer.mozilla.org/docs/Web/HTML/Quirks_Mode_and_Standards_Mode" +
  DOCS_GA_PARAMS;

add_task(async function () {
  info("Navigate to page with quirky doctype");
  const hud = await openNewTabAndConsole(TEST_URI_QUIRKY_DOCTYPE);

  const quirkyDocTypeMessage = await waitFor(() =>
    findWarningMessage(
      hud,
      `This page is in Quirks Mode. Page layout may be impacted. For Standards Mode use “<!DOCTYPE html>”`
    )
  );
  ok(!!quirkyDocTypeMessage, "Quirky doctype warning message is visible");

  info("Clicking on the Learn More link");
  const quirkyDocTypeMessageLearnMoreLink =
    quirkyDocTypeMessage.querySelector(".learn-more-link");
  let linkSimulation = await simulateLinkClick(
    quirkyDocTypeMessageLearnMoreLink
  );

  is(
    linkSimulation.link,
    LEARN_MORE_URI,
    `Clicking the provided link opens expected URL`
  );
  is(linkSimulation.where, "tab", `Clicking the provided link opens in a tab`);

  info("Navigate to page with almost standard doctype");
  await navigateTo(TEST_URI_ALMOST_STANDARD_DOCTYPE);

  const almostStandardDocTypeMessage = await waitFor(() =>
    findWarningMessage(
      hud,
      `This page is in Almost Standards Mode. Page layout may be impacted. For Standards Mode use “<!DOCTYPE html>”`
    )
  );
  ok(
    !!almostStandardDocTypeMessage,
    "Almost standards mode doctype warning message is visible"
  );

  info("Clicking on the Learn More link");
  const almostStandardDocTypeMessageLearnMoreLink =
    almostStandardDocTypeMessage.querySelector(".learn-more-link");
  linkSimulation = await simulateLinkClick(
    almostStandardDocTypeMessageLearnMoreLink
  );

  is(
    linkSimulation.link,
    LEARN_MORE_URI,
    `Clicking the provided link opens expected URL`
  );
  is(linkSimulation.where, "tab", `Clicking the provided link opens in a tab`);

  info("Navigate to page with no doctype");
  await navigateTo(TEST_URI_NO_DOCTYPE);

  const noDocTypeMessage = await waitFor(() =>
    findWarningMessage(
      hud,
      `This page is in Quirks Mode. Page layout may be impacted. For Standards Mode use “<!DOCTYPE html>”`
    )
  );
  ok(!!noDocTypeMessage, "No doctype warning message is visible");

  info("Clicking on the Learn More link");
  const noDocTypeMessageLearnMoreLink =
    noDocTypeMessage.querySelector(".learn-more-link");
  linkSimulation = await simulateLinkClick(noDocTypeMessageLearnMoreLink);

  is(
    linkSimulation.link,
    LEARN_MORE_URI,
    `Clicking the provided link opens expected URL`
  );
  is(linkSimulation.where, "tab", `Clicking the provided link opens in a tab`);

  info("Navigate to a page with standard doctype");
  await navigateTo(TEST_URI_STANDARD_DOCTYPE);
  info("Wait for a bit to make sure there is no doctype messages");
  await wait(1000);
  ok(
    !findWarningMessage(hud, `doctype`),
    "There is no doctype warning message"
  );

  info("Navigate to a about:blank");
  await navigateTo("about:blank");
  info("Wait for a bit to make sure there is no doctype messages");
  await wait(1000);
  ok(
    !findWarningMessage(hud, `doctype`),
    "There is no doctype warning message for about:blank"
  );

  info("Navigate to a view-source uri");
  await navigateTo(`view-source:${TEST_URI_NO_DOCTYPE}`);
  info("Wait for a bit to make sure there is no doctype messages");
  await wait(1000);
  ok(
    !findWarningMessage(hud, `doctype`),
    "There is no doctype warning message for view-source"
  );

  await closeConsole();
});