summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_webconsole_warning_group_cookies.js
blob: 55a2e0945c1d10f567418113620a9b9a92a47da5 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// Load a page that generates cookie warning/info messages. See bug 1622306.

"use strict";
requestLongerTimeout(2);

const TEST_FILE =
  "browser/devtools/client/webconsole/test/browser/test-warning-groups.html";

pushPref("devtools.webconsole.groupWarningMessages", true);

async function cleanUp() {
  await new Promise(resolve => {
    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, () =>
      resolve()
    );
  });
}

add_task(cleanUp);

add_task(async function testSameSiteCookieMessage() {
  const tests = [
    {
      pref: true,
      message1:
        "Cookie “a” has “SameSite” policy set to “Lax” because it is missing a “SameSite” attribute, and “SameSite=Lax” is the default value for this attribute.",
      typeMessage1: ".info",
      groupLabel:
        "Some cookies are misusing the “SameSite“ attribute, so it won’t work as expected",
      message2:
        "Cookie “b” has “SameSite” policy set to “Lax” because it is missing a “SameSite” attribute, and “SameSite=Lax” is the default value for this attribute.",
    },
    {
      pref: false,
      groupLabel:
        "Some cookies are misusing the recommended “SameSite“ attribute",
      message1:
        "Cookie “a” does not have a proper “SameSite” attribute value. Soon, cookies without the “SameSite” attribute or with an invalid value will be treated as “Lax”. This means that the cookie will no longer be sent in third-party contexts. If your application depends on this cookie being available in such contexts, please add the “SameSite=None“ attribute to it. To know more about the “SameSite“ attribute, read https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie/SameSite",
      typeMessage1: ".warn",
      message2:
        "Cookie “b” does not have a proper “SameSite” attribute value. Soon, cookies without the “SameSite” attribute or with an invalid value will be treated as “Lax”. This means that the cookie will no longer be sent in third-party contexts. If your application depends on this cookie being available in such contexts, please add the “SameSite=None“ attribute to it. To know more about the “SameSite“ attribute, read https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie/SameSite",
    },
  ];

  for (const test of tests) {
    info("LaxByDefault: " + test.pref);
    await pushPref("network.cookie.sameSite.laxByDefault", test.pref);

    const { hud, tab, win } = await openNewWindowAndConsole(
      "http://example.org/" + TEST_FILE
    );

    info("Test cookie messages");
    const onLaxMissingWarningMessage = waitForMessageByType(
      hud,
      test.message1,
      test.typeMessage1
    );

    SpecialPowers.spawn(tab.linkedBrowser, [], () => {
      content.wrappedJSObject.createCookie("a=1");
    });

    await onLaxMissingWarningMessage;

    ok(true, "The first message was displayed");

    info("Emit a new cookie message to check that it causes a grouping");

    const onCookieSameSiteWarningGroupMessage = waitForMessageByType(
      hud,
      test.groupLabel,
      ".warn"
    );

    SpecialPowers.spawn(tab.linkedBrowser, [], () => {
      content.wrappedJSObject.createCookie("b=1");
    });

    const { node } = await onCookieSameSiteWarningGroupMessage;
    is(
      node.querySelector(".warning-group-badge").textContent,
      "2",
      "The badge has the expected text"
    );

    await checkConsoleOutputForWarningGroup(hud, [`▶︎⚠ ${test.groupLabel} 2`]);

    info("Open the group");
    node.querySelector(".arrow").click();
    await waitFor(() => findWarningMessage(hud, "SameSite"));

    await checkConsoleOutputForWarningGroup(hud, [
      `▼︎⚠ ${test.groupLabel} 2`,
      `| ${test.message1}`,
      `| ${test.message2}`,
    ]);

    await win.close();
  }
});

add_task(cleanUp);

add_task(async function testInvalidSameSiteMessage() {
  await pushPref("network.cookie.sameSite.laxByDefault", true);

  const groupLabel =
    "Some cookies are misusing the “SameSite“ attribute, so it won’t work as expected";
  const message1 =
    "Invalid “SameSite“ value for cookie “a”. The supported values are: “Lax“, “Strict“, “None“.";
  const message2 =
    "Cookie “a” has “SameSite” policy set to “Lax” because it is missing a “SameSite” attribute, and “SameSite=Lax” is the default value for this attribute.";

  const { hud, tab, win } = await openNewWindowAndConsole(
    "http://example.org/" + TEST_FILE
  );

  info("Test cookie messages");

  SpecialPowers.spawn(tab.linkedBrowser, [], () => {
    content.wrappedJSObject.createCookie("a=1; sameSite=batman");
  });

  const { node } = await waitForMessageByType(hud, groupLabel, ".warn");
  is(
    node.querySelector(".warning-group-badge").textContent,
    "2",
    "The badge has the expected text"
  );

  await checkConsoleOutputForWarningGroup(hud, [`▶︎⚠ ${groupLabel} 2`]);

  info("Open the group");
  node.querySelector(".arrow").click();
  await waitFor(() => findWarningMessage(hud, "SameSite"));

  await checkConsoleOutputForWarningGroup(hud, [
    `▼︎⚠ ${groupLabel} 2`,
    `| ${message1}`,
    `| ${message2}`,
  ]);

  // Source map are being resolved in background and we might have
  // pending request related to this service if we close the window
  // immeditely. So just wait for these request to finish before proceeding.
  await hud.toolbox.sourceMapURLService.waitForSourcesLoading();

  await win.close();
});

add_task(cleanUp);