File: session-storage.tentative.https.window.js

package info (click to toggle)
thunderbird 1%3A115.16.0esr-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,476,252 kB
  • sloc: cpp: 6,972,150; javascript: 5,209,211; ansic: 3,507,222; python: 1,137,609; asm: 432,531; xml: 205,149; java: 175,761; sh: 116,485; makefile: 22,152; perl: 13,971; objc: 12,561; yacc: 4,583; pascal: 2,840; lex: 1,720; ruby: 1,075; exp: 762; sql: 666; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (57 lines) | stat: -rw-r--r-- 2,128 bytes parent folder | download | duplicates (18)
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
// META: script=/common/get-host-info.sub.js
// META: script=/common/utils.js
// META: script=/common/dispatcher/dispatcher.js
// META: script=/html/cross-origin-embedder-policy/credentialless/resources/common.js
// META: script=./resources/common.js

// Make |iframe| to store |key|=|value| into sessionStorage.
const store = async (iframe, key, value) => {
  const response_queue = token();
  send(iframe, `
    sessionStorage.setItem("${key}", "${value}");
    send("${response_queue}", "stored");
  `);
  assert_equals(await receive(response_queue), "stored");
};

// Make |iframe| to load |key| in sessionStorage. Check it matches the
// |expected_value|.
const load = async (iframe, key, expected_value) => {
  const response_queue = token();
  send(iframe, `
    const value = sessionStorage.getItem("${key}");
    send("${response_queue}", value || "not found");
  `);
  assert_equals(await receive(response_queue), expected_value);
};

promise_test(async test => {
  const origin = get_host_info().HTTPS_REMOTE_ORIGIN;
  const key_1 = token();
  const key_2 = token();

  // 4 actors: 2 credentialless iframe and 2 normal iframe.
  const iframe_credentialless_1 = newIframeCredentialless(origin);
  const iframe_credentialless_2 = newIframeCredentialless(origin);
  const iframe_normal_1 = newIframe(origin);
  const iframe_normal_2 = newIframe(origin);

  // 1. Store a value in one credentialless iframe and one normal iframe.
  await Promise.all([
    store(iframe_credentialless_1, key_1, "value_1"),
    store(iframe_normal_1, key_2, "value_2"),
  ]);

  // 2. Check what each of them can retrieve.
  await Promise.all([
    load(iframe_credentialless_1, key_1, "value_1"),
    load(iframe_credentialless_2, key_1, "value_1"),
    load(iframe_credentialless_1, key_2, "not found"),
    load(iframe_credentialless_2, key_2, "not found"),

    load(iframe_normal_1, key_1, "not found"),
    load(iframe_normal_2, key_1, "not found"),
    load(iframe_normal_1, key_2, "value_2"),
    load(iframe_normal_2, key_2, "value_2"),
  ]);
}, "Session storage is correctly partitioned with regards to credentialless iframe");