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

package info (click to toggle)
firefox 145.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,653,344 kB
  • sloc: cpp: 7,594,932; javascript: 6,459,612; ansic: 3,752,905; python: 1,403,433; xml: 629,811; asm: 438,677; java: 186,421; sh: 67,287; makefile: 19,169; objc: 13,086; perl: 12,982; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (57 lines) | stat: -rw-r--r-- 2,118 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 LocalStorage.
const store = async (iframe, key, value) => {
  const response_queue = token();
  send(iframe, `
    localStorage.setItem("${key}", "${value}");
    send("${response_queue}", "stored");
  `);
  assert_equals(await receive(response_queue), "stored");
};

// Make |iframe| to load |key| in LocalStorage. Check it matches the
// |expected_value|.
const load = async (iframe, key, expected_value) => {
  const response_queue = token();
  send(iframe, `
    const value = localStorage.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"),
  ]);
}, "Local storage is correctly partitioned with regards to credentialless iframe");