Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: LayoutTests/http/tests/serviceworker/chromium/register-error-messages.html

Issue 1058323004: Service Worker: Add a test for error messages from register() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <!-- This file tests JavaScript error messages of some of the
3 failure cases from http/tests/serviceworker/registration.html. It
4 should not be upstreamed to web platform tests since error messages
5 are not defined by the specification. -->
6 <title>Service Worker: Error messages for register()</title>
7 <script src="../../resources/testharness.js"></script>
8 <script src="../../resources/testharnessreport.js"></script>
9 <script>
10
11 function assert_register_fails(script, scope, message) {
12 return navigator.serviceWorker.getRegistration(scope)
13 .then(function(registration) {
14 if (registration)
15 return registration.unregister();
16 return Promise.resolve();
17 })
18 .then(function() {
19 return navigator.serviceWorker.register(script, { scope: scope});
20 })
21 .then(
22 function() { assert_unreached('register should fail'); },
23 function(error) { assert_equals(error.message, message); });
24 }
25
26 promise_test(function(t) {
27 var script = '../resources/registration-worker.js';
28 var scope = '../resources';
29 var message = 'Failed to register a ServiceWorker: The path of the ' +
30 'provided scope (\'/serviceworker/resources\') is not under the max ' +
31 'scope allowed (\'/serviceworker/resources/\'). Adjust the scope, ' +
32 'move the Service Worker script, or use the Service-Worker-Allowed ' +
33 'HTTP header to allow the scope.';
34 return assert_register_fails(script, scope, message);
35 }, 'Registering same scope as the script directory without the last slash');
36
37 promise_test(function(t) {
38 var script = '../resources/registration-worker.js';
39 var scope = '../different-directory/';
40 var message = 'Failed to register a ServiceWorker: The path of the ' +
41 'provided scope (\'/serviceworker/different-directory/\') is not ' +
42 'under the max scope allowed (\'/serviceworker/resources/\'). ' +
43 'Adjust the scope, move the Service Worker script, or use the ' +
44 'Service-Worker-Allowed HTTP header to allow the scope.';
45 return assert_register_fails(script, scope, message);
46 }, 'Registration scope outside the script directory');
47
48 promise_test(function(t) {
49 var script = '../resources/registration-worker.js';
50 var scope = 'http://example.com';
51 var message = 'Failed to get a ServiceWorkerRegistration: The origin of ' +
52 'the provided documentURL (\'http://example.com\') does not match ' +
53 'the current origin (\'http://127.0.0.1:8000\').';
54 return assert_register_fails(script, scope, message);
55 }, 'Registration scope outside domain');
56
57 promise_test(function(t) {
58 var script = 'http://example.com/worker.js';
59 var scope = 'http://example.com/scope/';
60 var message = 'Failed to get a ServiceWorkerRegistration: The origin of ' +
61 'the provided documentURL (\'http://example.com\') does not match ' +
62 'the current origin (\'http://127.0.0.1:8000\').';
63 return assert_register_fails(script, scope, message);
64 }, 'Registering script outside domain');
65
66 promise_test(function(t) {
67 var script = '../resources/no-such-worker.js';
68 var scope = '../resources/scope/no-such-worker';
69 var message = 'Failed to register a ServiceWorker: A bad HTTP response code ' +
70 '(404) was received when fetching the script.';
71 return assert_register_fails(script, scope, message);
72 }, 'Registering non-existent script');
73
74 promise_test(function(t) {
75 var script = '../resources/invalid-chunked-encoding.php';
76 var scope = '../resources/scope/invalid-chunked-encoding/';
77 var message = 'Failed to register a ServiceWorker: An unknown error ' +
78 'occurred when fetching the script.';
79 return assert_register_fails(script, scope, message);
80 }, 'Registering invalid chunked encoding script');
81
82 promise_test(function(t) {
83 var script = '../resources/mime-type-worker.php';
84 var scope = '../resources/scope/no-mime-type-worker/';
85 var message = 'Failed to register a ServiceWorker: The script does not ' +
86 'have a MIME type.';
87 return assert_register_fails(script, scope, message);
88 }, 'Registering script with no MIME type');
89
90 promise_test(function(t) {
91 var script = '../resources/mime-type-worker.php?mime=text/plain';
92 var scope = '../resources/scope/bad-mime-type-worker/';
93 var message = 'Failed to register a ServiceWorker: The script has an unsuppo rted MIME type (\'text/plain\').';
94 return assert_register_fails(script, scope, message);
95 }, 'Registering script with bad MIME type');
96
97 promise_test(function(t) {
98 var script = '../resources/redirect.php?Redirect=' +
99 encodeURIComponent('..//resources/registration-worker.js');
100 var scope = '../resources/scope/redirect/';
101 var message = 'Failed to register a ServiceWorker: The script resource ' +
102 'is behind a redirect, which is disallowed.';
103 return assert_register_fails(script, scope, message);
104 }, 'Registering redirected script');
105
106 promise_test(function(t) {
107 var script = '../resources/malformed-worker.php?parse-error';
108 var scope = '../resources/scope/parse-error';
109 var message = 'Failed to register a ServiceWorker: ServiceWorker script ' +
110 'evaluation failed';
111 return assert_register_fails(script, scope, message);
112 }, 'Registering script including parse error');
113
114 promise_test(function(t) {
115 var script = '../resources/malformed-worker.php?undefined-error';
116 var scope = '../resources/scope/undefined-error';
117 var message = 'Failed to register a ServiceWorker: ServiceWorker script ' +
118 'evaluation failed';
119 return assert_register_fails(script, scope, message);
120 }, 'Registering script including undefined error');
121
122 promise_test(function(t) {
123 var script = '../resources/malformed-worker.php?uncaught-exception';
124 var scope = '../resources/scope/uncaught-exception';
125 var message = 'Failed to register a ServiceWorker: ServiceWorker script ' +
126 'evaluation failed';
127 return assert_register_fails(script, scope, message);
128 }, 'Registering script including uncaught exception');
129
130 promise_test(function(t) {
131 var script = '../resources/malformed-worker.php?import-malformed-script';
132 var scope = '../resources/scope/import-malformed-script';
133 var message = 'Failed to register a ServiceWorker: ServiceWorker script ' +
134 'evaluation failed';
135 return assert_register_fails(script, scope, message);
136 }, 'Registering script importing malformed script');
137
138 promise_test(function(t) {
139 var script = '../resources/malformed-worker.php?import-no-such-script';
140 var scope = '../resources/scope/import-no-such-script';
141 var message = 'Failed to register a ServiceWorker: ServiceWorker script ' +
142 'evaluation failed';
143 return assert_register_fails(script, scope, message);
144 }, 'Registering script importing non-existent script');
145
146 promise_test(function(t) {
147 var script = '../resources%2fempty-worker.js';
148 var scope = '../resources/scope/encoded-slash-in-script-url';
149 var message = 'Failed to register a ServiceWorker: The provided scope ' +
150 '(\'http://127.0.0.1:8000/serviceworker/resources/scope/' +
151 'encoded-slash-in-script-url\') or scriptURL ' +
152 '(\'http://127.0.0.1:8000/serviceworker/' +
153 'resources%2fempty-worker.js\') ' +
154 'includes a disallowed escape character.';
155 return assert_register_fails(script, scope, message);
156 }, 'Script URL including URL-encoded slash');
157
158 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698