File: abort.sub.window.js

package info (click to toggle)
thunderbird 1%3A115.12.0-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,463,904 kB
  • sloc: cpp: 6,971,272; javascript: 5,208,988; ansic: 3,507,245; python: 1,137,377; asm: 432,531; xml: 205,149; java: 175,761; sh: 116,483; makefile: 22,157; 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 (104 lines) | stat: -rw-r--r-- 4,108 bytes parent folder | download | duplicates (28)
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
100
101
102
103
104
async_test(t => {
  const frame = document.body.appendChild(document.createElement("iframe"));
  t.add_cleanup(() => frame.remove());
  frame.onload = t.step_func(() => {
    frame.onload = null;
    let happened = false;
    const client = new frame.contentWindow.XMLHttpRequest();
    client.open("GET", "/common/blank.html");
    client.onload = t.step_func_done(e => {
      assert_true(happened);
    });
    client.onerror = t.unreached_func("XMLHttpRequest should have succeeded");
    client.onabort = t.unreached_func("XMLHttpRequest should have succeeded");
    client.ontimeout = t.unreached_func("XMLHttpRequest should have succeeded");
    client.send();
    frame.contentDocument.open();
    happened = true;
  });
  frame.src = "/common/blank.html";
}, "document.open() does not abort documents that are not navigating (XMLHttpRequest)");

async_test(t => {
  const frame = document.body.appendChild(document.createElement("iframe"));
  t.add_cleanup(() => frame.remove());
  frame.onload = t.step_func(() => {
    frame.onload = null;
    let happened = false;
    frame.contentWindow.fetch("/common/blank.html").then(
      t.step_func_done(() => {
        assert_true(happened);
      }),
      t.unreached_func("Fetch should have succeeded")
    );
    frame.contentDocument.open();
    happened = true;
  });
  frame.src = "/common/blank.html";
}, "document.open() does not abort documents that are not navigating (fetch())");

async_test(t => {
  const frame = document.body.appendChild(document.createElement("iframe"));
  t.add_cleanup(() => frame.remove());
  frame.onload = t.step_func(() => {
    frame.onload = null;
    let happened = false;
    const img = frame.contentDocument.createElement("img");
    img.src = new URL("resources/slow-png.py", document.URL);
    img.onload = t.step_func_done(() => {
      assert_true(happened);
    });
    img.onerror = t.unreached_func("Image loading should not have errored");
    // The image fetch starts in a microtask, so let's be sure to test after
    // the fetch has started.
    t.step_timeout(() => {
      frame.contentDocument.open();
      happened = true;
    });
  });
  frame.src = "/common/blank.html";
}, "document.open() does not abort documents that are not navigating (image loading)");

async_test(t => {
  const __SERVER__NAME = "{{host}}";
  const __PORT = {{ports[ws][0]}};
  const frame = document.body.appendChild(document.createElement("iframe"));
  t.add_cleanup(() => frame.remove());
  frame.onload = t.step_func(() => {
    frame.onload = null;
    let happened = false;
    const ws = new frame.contentWindow.WebSocket(`ws://${__SERVER__NAME}:${__PORT}/echo`);
    ws.onopen = t.step_func_done(() => {
      assert_true(happened);
    });
    ws.onclose = t.unreached_func("WebSocket fetch should have succeeded");
    ws.onerror = t.unreached_func("WebSocket should have no error");
    frame.contentDocument.open();
    happened = true;
  });
  frame.src = "/common/blank.html";
}, "document.open() does not abort documents that are not navigating (establish a WebSocket connection)");

// An already established WebSocket connection shouldn't be terminated during
// an "abort a document" anyway. Test just for completeness.
async_test(t => {
  const __SERVER__NAME = "{{host}}";
  const __PORT = {{ports[ws][0]}};
  const frame = document.body.appendChild(document.createElement("iframe"));
  t.add_cleanup(() => frame.remove());
  frame.onload = t.step_func(() => {
    frame.onload = null;
    let happened = false;
    const ws = new frame.contentWindow.WebSocket(`ws://${__SERVER__NAME}:${__PORT}/echo`);
    ws.onopen = t.step_func(() => {
      t.step_timeout(t.step_func_done(() => {
        assert_true(happened);
      }), 100);
      frame.contentDocument.open();
      happened = true;
    });
    ws.onclose = t.unreached_func("WebSocket should not be closed");
    ws.onerror = t.unreached_func("WebSocket should have no error");
  });
  frame.src = "/common/blank.html";
}, "document.open() does not abort documents that are not navigating (already established WebSocket connection)");