File: javascript-urls.window.js

package info (click to toggle)
firefox-esr 140.4.0esr-1~deb13u1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 4,539,284 kB
  • sloc: cpp: 7,381,286; javascript: 6,388,710; ansic: 3,710,139; python: 1,393,780; xml: 628,165; asm: 426,916; java: 184,004; sh: 65,742; makefile: 19,302; objc: 13,059; perl: 12,912; yacc: 4,583; cs: 3,846; pascal: 3,352; lex: 1,720; ruby: 1,226; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (63 lines) | stat: -rw-r--r-- 2,909 bytes parent folder | download | duplicates (22)
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
// The results of this test are all over the map due to browsers behaving very differently for
// javascript: URLs.
//
// Chromium is pretty close execution-wise, but it parses javascript: URLs incorrectly.
// Gecko navigates to non-string return values of the result of executing a javascript: URL.
// WebKit executes javascript: URLs too early and has a harness error due to URL parsing.
//
// The expectations below should match the HTML and URL standards.
[
  {
    "description": "javascript: URL that fails to parse due to invalid host",
    "input": "javascript://test:test/%0aglobalThis.shouldNotExistA=1",
    "property": "shouldNotExistA",
    "expected": undefined
  },
  {
    "description": "javascript: URL that fails to parse due to invalid host and has a U+0009 in scheme",
    "input": "java\x09script://test:test/%0aglobalThis.shouldNotExistB=1",
    "property": "shouldNotExistB",
    "expected": undefined
  },
  {
    "description": "javascript: URL without an opaque path",
    "input": "javascript://host/1%0a//../0/;globalThis.shouldBeOne=1;/%0aglobalThis.shouldBeOne=2;/..///",
    "property": "shouldBeOne",
    "expected": 1
  },
  {
    "description": "javascript: URL containing a JavaScript string split over path and query",
    // Use ";undefined" to avoid returning a string.
    "input": "javascript:globalThis.shouldBeAStringA = \"https://whatsoever.com/?a=b&c=5&x=y\";undefined",
    "property": "shouldBeAStringA",
    "expected": "https://whatsoever.com/?a=b&c=5&x=y"
  },
  {
    "description": "javascript: URL containing a JavaScript string split over path and query and has a U+000A in scheme",
    // Use ";undefined" to avoid returning a string.
    "input": "java\x0Ascript:globalThis.shouldBeAStringB = \"https://whatsoever.com/?a=b&c=5&x=y\";undefined",
    "property": "shouldBeAStringB",
    "expected": "https://whatsoever.com/?a=b&c=5&x=y"
  }
].forEach(({ description, input, property, expected }) => {
  // Use promise_test so the tests run in sequence. Needed for globalThis.verify below.
  promise_test(t => {
    const anchor = document.body.appendChild(document.createElement("a"));
    t.add_cleanup(() => anchor.remove());
    anchor.href = input;
    assert_equals(globalThis[property], undefined, "Property is undefined before the click");
    anchor.click();
    assert_equals(globalThis[property], undefined, "Property is undefined immediately after the click");

    // Since we cannot reliably queue a task to run after the task queued as a result of the click()
    // above, we do another click() with a new URL.
    return new Promise(resolve => {
      globalThis.verify = t.step_func(() => {
        assert_equals(globalThis[property], expected, `Property is ${expected} once the navigation happened`);
        resolve();
      });
      anchor.href = "javascript:globalThis.verify()";
      anchor.click();
    });
  }, description);
});