summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/abort.sub.window.js
blob: b2f05cf056d54a0602a55a8dda7c67cb94883055 (plain)
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)");