summaryrefslogtreecommitdiffstats
path: root/netwerk/test/mochitests/test_1396395.html
blob: dcfb952b3afa62e2bdb92b74ebf0e2f08f7724b0 (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
<!DOCTYPE HTML>
<!-- vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: -->
<html>
  <!-- Any copyright is dedicated to the Public Domain.
    - http://creativecommons.org/publicdomain/zero/1.0/ -->
<head>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>
  <iframe id="f" src="about:blank"></iframe>
  <script type="text/javascript">
SimpleTest.waitForExplicitFinish();

var script = SpecialPowers.loadChromeScript(() => {
  /* eslint-env mozilla/chrome-script */
  Services.obs.addObserver(function onExamResp(subject, topic, data) {
    let channel = subject.QueryInterface(Ci.nsIHttpChannel);
    if (!channel.URI.spec.startsWith("http://example.org")) {
      return;
    }
    Services.obs.removeObserver(onExamResp, 'http-on-examine-response');
    channel.suspend();
    Promise.resolve().then(() => {
      channel.resume();
    });
  }, 'http-on-examine-response');

  sendAsyncMessage('start-test');
});

script.addMessageListener('start-test', () => {
  const iframe = document.getElementById('f');

  iframe.contentWindow.onunload = function () {
    info('initiate sync XHR during the page loading');
    let xhr = new XMLHttpRequest();
    xhr.open('GET', window.location, false);
    xhr.send(null);
    ok(true, 'complete without crash');
    script.destroy();
    SimpleTest.finish();
  }

  iframe.src = 'http://example.org';
});
  </script>
</body>
</html>