summaryrefslogtreecommitdiffstats
path: root/dom/security/test/general/browser_same_site_cookies_bug1748693.js
blob: da3c3d77623fb677dc7c7240d577c0a8fd317376 (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
"use strict";

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

function checkCookies(expectedCookies = {}) {
  info(JSON.stringify(expectedCookies));
  return SpecialPowers.spawn(
    gBrowser.selectedBrowser,
    [expectedCookies],
    async function (expectedCookies) {
      let cookies = content.document.getElementById("msg").innerHTML;
      info(cookies);
      for (const [cookie, expected] of Object.entries(expectedCookies)) {
        if (expected) {
          ok(cookies.includes(cookie), `${cookie} should be sent`);
        } else {
          ok(!cookies.includes(cookie), `${cookie} should not be sent`);
        }
      }
    }
  );
}

add_task(async function bug1748693() {
  waitForExplicitFinish();

  let loaded = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
  BrowserTestUtils.loadURIString(
    gBrowser,
    `${HTTPS_PATH}file_same_site_cookies_bug1748693.sjs?setcookies`
  );
  await loaded;

  loaded = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
  BrowserTestUtils.loadURIString(
    gBrowser,
    `${HTTP_PATH}file_same_site_cookies_bug1748693.sjs`
  );
  await loaded;

  await checkCookies({ auth: true, auth_secure: false });

  finish();
});