Auto merge of #11114 - creativcoder:nav-sw, r=jdm

implement related service worker interface and register method

Fixes  #11091

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11114)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-06-02 06:18:59 -05:00
commit cc017fc0b8
33 changed files with 1285 additions and 217 deletions

View file

@ -6898,6 +6898,12 @@
"url": "/_mozilla/mozilla/sequence-hole.html"
}
],
"mozilla/service-workers/service-worker-registration.html": [
{
"path": "mozilla/service-workers/service-worker-registration.html",
"url": "/_mozilla/mozilla/service-workers/service-worker-registration.html"
}
],
"mozilla/storage.html": [
{
"path": "mozilla/storage.html",

View file

@ -0,0 +1 @@
prefs: ["dom.serviceworker.enabled:true"]

View file

@ -0,0 +1 @@
console.log("Hey Servo; lets cache something! :)");

View file

@ -0,0 +1,52 @@
<!doctype html>
<meta charset="utf-8">
<title></title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
function register_sw(script_url, scope_str='') {
var registration = navigator.serviceWorker.register(script_url, {'scope': scope_str });
return registration;
}
test(function (){
assert_true('serviceWorker' in navigator);
}, "Test: Asserts ServiceWorkerContainer in Navigator");
test(function() {
var sw_reg = register_sw('sw.js');
assert_class_string(sw_reg, "ServiceWorkerRegistration");
assert_class_string(sw_reg.active, "ServiceWorker");
assert_class_string(navigator.serviceWorker.controller, "ServiceWorker");
}, "Test: Asserts Active Service Worker and its Registration");
test(function() {
var sw_reg = register_sw('resources/sw.js', './');
assert_equals(sw_reg.scope, location.href.replace("service-worker-registration.html", ""));
}, "Test: Service Worker Registration property scope Url when no scope");
test(function() {
var sw_reg = register_sw('resources/sw.js', '/some/nested/cache/directory');
var expected_scope_url = location.protocol + '//' + location.host + '/some/nested/cache/directory';
assert_equals(sw_reg.scope, expected_scope_url);
}, "Test: Service Worker Registration property scope when provided a scope");
test(function () {
assert_throws(new TypeError(),
function() { var sw_reg = register_sw('./in%5Csome%5fdir/sw.js'); },
"Invalid URL Path");
}, "Test: Throws Error when Invalid Url Path");
test(function () {
assert_throws(new TypeError(),
function() { var sw_reg = register_sw('sw.js', './mal%5fformed/sco%5Cpe/'); },
"Invalid URL Path");
}, "Test: Throws Error when Invalid Scope");
test(function() {
var sw_reg = register_sw('resources/sw.js');
assert_equals(sw_reg.active.scriptURL, location.href.replace("service-worker-registration.html", "resources/sw.js"));
}, "Test: Active Service Worker ScriptURL property");
</script>

View file

@ -0,0 +1 @@
console.log("Hey Servo; lets cache something! :)");