npm-polymer-elements
Version:
Polymer Elements package for npm
63 lines (56 loc) • 2.82 kB
HTML
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../../web-component-tester/browser.js"></script>
<link rel="import" href="../../platinum-sw-register.html">
<link rel="import" href="../../platinum-sw-import-script.html">
<link rel="import" href="../../platinum-sw-fetch.html">
</head>
<body>
<platinum-sw-register skip-waiting clients-claim auto-register>
<platinum-sw-fetch handler="custom203FetchHandler"
path="/(.*)customFetch"></platinum-sw-fetch>
<platinum-sw-fetch handler="custom410FetchHandler"
path="/(.*)customFetch"
origin="https://matching\.domain"></platinum-sw-fetch>
<platinum-sw-import-script href="custom-fetch-handler.js"></platinum-sw-import-script>
</platinum-sw-register>
<script>
suite('Service Worker Fetch Handlers', function() {
test('the same-origin custom fetch handler is used when the path matches', function() {
return navigator.serviceWorker.ready.then(function() {
return window.fetch('customFetch').then(function(response) {
assert.equal(response.status, 203, 'Custom response status doesn\'t match');
});
});
});
test('the same-origin custom fetch handler isn\'t used when the path doesn\t match', function() {
return navigator.serviceWorker.ready.then(function() {
return window.fetch('dummyUrlThatShould404').then(function(response) {
assert.equal(response.status, 404, 'Expected response status doesn\'t match');
});
});
});
test('the cross-origin fetch handler is used when the path and origin matches', function() {
return navigator.serviceWorker.ready.then(function() {
return window.fetch('https://matching.domain/path/to/customFetch').then(function(response) {
assert.equal(response.status, 410, 'Custom response status doesn\'t match');
});
});
});
});
</script>
</body>
</html>