Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / register-default-scope.html
blob619ce06e48ff4360a6028733cce3672f10eb1c4c
1 <!DOCTYPE html>
2 <title>register() and scope</title>
3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharness-helpers.js"></script>
5 <script src="../resources/testharnessreport.js"></script>
6 <script src="resources/test-helpers.js"></script>
7 <script>
9 promise_test(function(t) {
10 var script = 'resources/empty-worker.js';
11 var script_url = new URL(script, location.href);
12 var expected_scope = new URL('./', script_url).href;
13 return service_worker_unregister(t, expected_scope)
14 .then(function() {
15 return navigator.serviceWorker.register('resources/empty-worker.js');
16 }).then(function(registration) {
17 assert_equals(registration.scope, expected_scope,
18 'The default scope should be URL("./", script_url)');
19 return registration.unregister();
20 }).then(function() {
21 t.done();
22 });
23 }, 'default scope');
25 promise_test(function(t) {
26 // This script must be different than the 'default scope' test, or else
27 // the scopes will collide.
28 var script = 'resources/empty.js';
29 var script_url = new URL(script, location.href);
30 var expected_scope = new URL('./', script_url).href;
31 return service_worker_unregister(t, expected_scope)
32 .then(function() {
33 return navigator.serviceWorker.register('resources/empty.js',
34 { scope: undefined });
35 }).then(function(registration) {
36 assert_equals(registration.scope, expected_scope,
37 'The default scope should be URL("./", script_url)');
38 return registration.unregister();
39 }).then(function() {
40 t.done();
41 });
42 }, 'undefined scope');
44 promise_test(function(t) {
45 var script = 'resources/simple-fetch-worker.js';
46 var script_url = new URL(script, location.href);
47 var expected_scope = new URL('./', script_url).href;
48 return service_worker_unregister(t, expected_scope)
49 .then(function() {
50 return navigator.serviceWorker.register('resources/empty.js',
51 { scope: null });
53 .then(
54 function(registration) {
55 assert_unreached('register should fail');
56 service_worker_unregister_and_done(t, registration.scope);
58 function(error) {
59 assert_equals(error.name, 'SecurityError',
60 'passing a null scope should be interpreted as ' +
61 'scope="null" which violates the path restriction');
62 t.done();
63 });
64 }, 'null scope');
66 </script>