summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/service-workers/service-worker/resource-timing.https.html
blob: 3a1adfa486ed991fc8021cdc2e0ec78970d54ee0 (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
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/get-host-info.sub.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script>
function resourceUrl(path) {
    return get_host_info()['HTTP_ORIGIN'] + base_path() + path;
}

function verify(performance, resource, description) {
    var entry = performance.getEntriesByName(resourceUrl(resource))[0];
    assert_greater_than(entry.workerStart, 0, description);
    assert_greater_than_equal(entry.workerStart, entry.startTime, description);
    assert_less_than_equal(entry.workerStart, entry.fetchStart, description);
    assert_greater_than_equal(entry.responseStart, entry.fetchStart, description);
    assert_greater_than_equal(entry.responseEnd, entry.responseStart, description);
    assert_greater_than(entry.responseEnd, entry.fetchStart, description);
    assert_greater_than(entry.duration, 0, description);
    if (resource.indexOf('redirect.py') != -1) {
        assert_less_than_equal(entry.workerStart, entry.redirectStart,
                               description);
    } else {
        assert_equals(entry.redirectStart, 0, description);
    }
}

async_test(function(t) {
    var worker_url = 'resources/resource-timing-worker.js';
    var scope = 'resources/resource-timing-iframe.html';
    var registration;

    service_worker_unregister_and_register(t, worker_url, scope)
      .then(function(r) {
          registration = r;
          return wait_for_state(t, r.installing, 'activated');
        })
      .then(function() {
          return with_iframe(scope);
        })
      .then(function(frame) {
          var performance = frame.contentWindow.performance;
          verify(performance, 'resources/dummy.js', 'Generated response');
          verify(performance, 'resources/empty.js', 'Network fallback');
          verify(performance, 'resources/redirect.py?Redirect=empty.js',
                 'Redirect');
          frame.remove();
          return registration.unregister();
        })
      .then(function() {
          t.done();
        })
      .catch(unreached_rejection(t));
}, 'Controlled resource loads');

test(function() {
    var url = resourceUrl('resources/test-helpers.sub.js');
    var entry = window.performance.getEntriesByName(url)[0];
    assert_equals(entry.workerStart, 0, 'Non-controlled');
}, 'Non-controlled resource loads');

</script>