Skip to content

Commit

Permalink
Upstream service worker fetch test to WPT
Browse files Browse the repository at this point in the history
**fetch-request-css-cross-origin-mime-check**

Update resource file paths as appropriate and use HTTPS version of
absolute URLs.

**fetch-request-fallback**

Both the Chromium version and upstream version of this test cover the
following conditions:

- same origin XHR should succeed
- CORS-unsupported other origin XHR should fail
- CORS-supported other origin XHR should succeed
- redirected XHR should succeed
- XHR which is redirected to CORS-unsupported other origin should fail
- XHR which is redirected to CORS-supported other origin should succeed

However, the Chromium version includes additional tests for image
requests:

- image request should succeed
- other origin image request should succeed
- CORS-unsupported other origin image request should fail
- CORS-supported other origin image request should succeed
- redirected image request should succeed
- image request which is redirected to other origin should succeed
- image request which is redirected to CORS-unsupported other origin should fail
- image request which is redirected to CORS-supported other origin should succeed

The two versions differ significantly in test structure, as well. Adopt
the Chromium version's structure because that implements more granular
assertion messages.

BUG=688116
R=mek@chromium.org

Review-Url: https://codereview.chromium.org/2858933003
Cr-Commit-Position: refs/heads/master@{#470248}
  • Loading branch information
jugglinmike authored and chromium-wpt-export-bot committed May 9, 2017
1 parent f9d7e40 commit 37e1c37
Show file tree
Hide file tree
Showing 9 changed files with 369 additions and 92 deletions.
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<title>Service Worker: Mime type checking of CSS files fetched via SW.</title>
<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 getElementColorInFrame(frame, id) {
var element = frame.contentDocument.getElementById(id);
var style = frame.contentWindow.getComputedStyle(element, '');
return style['color'];
}

promise_test(function(t) {
var SCOPE =
'resources/fetch-request-css-cross-origin-mime-check-iframe.html';
var SCRIPT =
'resources/fetch-request-css-cross-origin-mime-check-worker.js';
var EXPECTED_COLOR = 'rgb(0, 0, 255)';

return service_worker_unregister_and_register(t, SCRIPT, SCOPE)
.then(r => wait_for_state(t, r.installing, 'activated'))
.then(_ => with_iframe(SCOPE) )
.then(f => {
assert_equals(
getElementColorInFrame(f, 'crossOriginCss'),
EXPECTED_COLOR,
'The color must be overridden by cross origin CSS.');
assert_equals(
getElementColorInFrame(f, 'crossOriginHtml'),
EXPECTED_COLOR,
'The color must not be overridden by cross origin non CSS file.');
assert_equals(
getElementColorInFrame(f, 'sameOriginCss'),
EXPECTED_COLOR,
'The color must be overridden by same origin CSS.');
assert_equals(
getElementColorInFrame(f, 'sameOriginHtml'),
EXPECTED_COLOR,
'The color must be overridden by same origin non CSS file.');
assert_equals(
getElementColorInFrame(f, 'synthetic'),
EXPECTED_COLOR,
'The color must be overridden by synthetic CSS.');
f.remove();
return service_worker_unregister_and_done(t, SCOPE);
});
}, 'Mime type checking of CSS files fetched via SW.');
</script>

0 comments on commit 37e1c37

Please sign in to comment.