https://github.com/web-platform-tests/wpt
Raw File
Tip revision: 2f98030e473cd3a5411fd111d8ef9acc509ad50e authored by Joshua Bell on 06 April 2018, 17:08:18 UTC
Cookie Store: rework tests for 'expires' option
Tip revision: 2f98030
resource-timing.https.html
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script>
function resourceUrl(path) {
    return get_host_info()['HTTPS_ORIGIN'] + base_path() + path;
}

function crossOriginUrl(path) {
    return get_host_info()['HTTPS_REMOTE_ORIGIN'] + base_path() + path;
}

function verify(options) {
    var url = options.mode === 'cross-origin' ? crossOriginUrl(options.resource)
                                      : resourceUrl(options.resource);
    var entryList = options.performance.getEntriesByName(url);
    if (entryList.length === 0 && options.allow_no_performance_entry) {
        // The performance timeline may not have an entry for a resource
        // which failed to load.
        return;
    }
    var entry = entryList[0];
    assert_greater_than(entry.workerStart, 0, options.description);
    assert_greater_than_equal(entry.workerStart, entry.startTime, options.description);
    assert_less_than_equal(entry.workerStart, entry.fetchStart, options.description);
    if (options.mode === 'cross-origin') {
      assert_equals(entry.responseStart, 0, options.description);
      assert_greater_than_equal(entry.responseEnd, entry.fetchStart, options.description);
    } else {
      assert_greater_than_equal(entry.responseStart, entry.fetchStart, options.description);
      assert_greater_than_equal(entry.responseEnd, entry.responseStart, options.description);
    }
    assert_greater_than(entry.responseEnd, entry.fetchStart, options.description);
    assert_greater_than(entry.duration, 0, options.description);
    if (options.resource.indexOf('redirect.py') != -1) {
        assert_less_than_equal(entry.workerStart, entry.redirectStart,
                               options.description);
    } else {
        assert_equals(entry.redirectStart, 0, options.description);
    }
}

async_test(function(t) {
    var worker_url = 'resources/resource-timing-worker.js';
    var scope = 'resources/resource-timing-iframe.sub.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: performance,
              resource: 'resources/dummy.js',
              mode: 'same-origin',
              description: 'Generated response',
          });
          verify({
              performance: performance,
              resource: 'resources/empty.js',
              mode: 'same-origin',
              description: 'Network fallback',
          });
          verify({
              performance: performance,
              resource: 'resources/redirect.py?Redirect=empty.js',
              mode: 'same-origin',
              description: 'Redirect',
          });
          verify({
              performance: performance,
              resource: 'resources/square.png',
              mode: 'same-origin',
              description: 'Network fallback image',
          });
          // Test that worker start is available on cross-origin no-cors
          // subresources.
          verify({
              performance: performance,
              resource: 'resources/square.png',
              mode: 'cross-origin',
              description: 'Network fallback cross-origin image',
          });

          // Tests for resouces which failed to load.
          verify({
              performance: performance,
              resource: 'resources/missing.jpg',
              mode: 'same-origin',
              description: 'Network fallback load failure',
              allow_no_performance_entry: true,
          });
          verify({
              performance: performance,
              resource: 'resources/missing.jpg',
              mode: 'cross-origin',
              description: 'Network fallback cross-origin load failure',
              allow_no_performance_entry: true,
          });

          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>
back to top