summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/service-workers/service-worker/uncontrolled-page.https.html
blob: a9523a54cdce27ccddb5860121101cdd1bdb50cc (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
<!DOCTYPE html>
<title>Service Worker: Registration</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script>
function fetch_url(url) {
  return new Promise(function(resolve, reject) {
      var request = new XMLHttpRequest();
      request.addEventListener('load', function(event) {
          if (request.status == 200)
            resolve(request.response);
          else
            reject(Error(request.statusText));
        });
      request.open('GET', url);
      request.send();
    });
}
var worker = 'resources/fail-on-fetch-worker.js';

async_test(function(t) {
    var scope = 'resources/scope/uncontrolled-page/';
    service_worker_unregister_and_register(t, worker, scope)
      .then(function(reg) {
          return wait_for_state(t, reg.installing, 'activated');
        })
      .then(function() {
          return fetch_url('resources/simple.txt');
        })
      .then(function(text) {
          assert_equals(text, 'a simple text file\n');
          service_worker_unregister_and_done(t, scope);
        })
      .catch(t.step_func(function(reason) {
          assert_unreached(reason.message);
        }));
  }, 'Fetch events should not go through uncontrolled page.');
</script>