File: executor.sub.html

package info (click to toggle)
firefox 143.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,617,328 kB
  • sloc: cpp: 7,478,492; javascript: 6,417,157; ansic: 3,720,058; python: 1,396,372; xml: 627,523; asm: 438,677; java: 186,156; sh: 63,477; makefile: 19,171; objc: 13,059; perl: 12,983; yacc: 4,583; cs: 3,846; pascal: 3,405; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (99 lines) | stat: -rw-r--r-- 3,998 bytes parent folder | download | duplicates (4)
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
<!DOCTYPE html>
<script src="/common/dispatcher/dispatcher.js" nonce="abc"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="utils.sub.js" nonce="abc"></script>
<script nonce="abc">
// For a given string `str` that is escaped by WPT's `.sub.html` or
// `pipe=sub(html)` functionality, return the original unescaped string.
//
// Concretely, for `str` as the result of `html.escape(x, quote=True)`,
// return the original unescaped string `x`.
// See `/tools/wptserve/wptserve/pipes.py` and
// https://docs.python.org/3/library/html.html#html.escape.
//
// See https://crbug.com/404573971 for fixing the escaping issue.
function reverse_html_escape(str) {
  str = str.replaceAll('&lt;', '<');
  str = str.replaceAll('&gt;', '>');
  str = str.replaceAll('&quot;', '"');
  str = str.replaceAll('&#x27;', "'");
  str = str.replaceAll('&amp;', '&');
  return str;
}

// To be consistent with https://fetch.spec.whatwg.org/#headers-class
// (accessed via iterable),
// - The keys are lower-cased header names, and
// - The entries are removed when the corresponding headers are non-existent.
window.requestHeaders = {
  "purpose": "{{header_or_default(Purpose, NONEXISTENT)}}",
  "sec-purpose": "{{header_or_default(Sec-Purpose, NONEXISTENT)}}",
  "referer": "{{header_or_default(Referer, NONEXISTENT)}}",
  "sec-fetch-dest": "{{header_or_default(Sec-Fetch-Dest, NONEXISTENT)}}",
  "sec-fetch-mode": "{{header_or_default(Sec-Fetch-Mode, NONEXISTENT)}}",
  "service-worker-navigation-preload":
      "{{header_or_default(Service-Worker-Navigation-Preload, NONEXISTENT)}}",
  // Convert to the raw string to avoid backslashes from being processed as
  // escape sequences.
  // TODO(crbug.com/404573971): Remove `header_or_default` to reflect
  // `__no_tags__` properly.
  sec_speculation_tags:
      String.raw`{{header_or_default(Sec-Speculation-Tags, __no_tags__)}}`,
};
Object.keys(requestHeaders).forEach(key => {
  if (requestHeaders[key] === "NONEXISTENT") {
    delete requestHeaders[key];
  } else {
    requestHeaders[key] = reverse_html_escape(requestHeaders[key]);
  }
});

// Add a link to the page in order to use during the test
function add_link(id, url) {
  const link_element = document.createElement("a");
  const link_text = document.createTextNode(url);
  link_element.setAttribute("href", url);
  link_element.setAttribute("id", id);
  link_element.appendChild(link_text);
  document.body.appendChild(link_element);
}

// "id" is the id of the link that we need to hover on in order
// to start the prefetch
async function start_non_immediate_prefetch_on_hover(id) {
  let target = document.getElementById(id);

  test_driver.set_test_context(window.opener);
  // Inject the inputs to run this test.
  await new test_driver.Actions().addPointer("mouse").pointerMove(0, 0, {origin: target}).send();
}

// "id" is the id of the link that we need to press on in order
// to start the prefetch
async function start_non_immediate_prefetch_on_pointerdown(id) {
  let target = document.getElementById(id);

  test_driver.set_test_context(window.opener);
  // Inject the inputs to run this test.
  // Move mouse pointer outside of the anchor so that we don't start the
  // navigation before making sure the prefetch request started server-side.
  await new test_driver.Actions().addPointer("mouse").pointerMove(0, 0, {origin: target}).pointerDown().pointerMove(0, 0).pointerUp().send();
}

async function navigate_by_form_generated_post(url) {
  let form = document.createElement('form');
  form.method = 'POST';
  form.action = url;
  document.body.appendChild(form);
  form.submit();
}

// The fetch request's URL sent to the server.
window.requestUrl = reverse_html_escape(
    "{{location[server]}}{{location[path]}}{{location[query]}}");

const uuid = new URLSearchParams(location.search).get('uuid');
window.executor = new Executor(uuid);
</script>