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

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: line wrap 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
« no previous file with comments | « no previous file | LayoutTests/http/tests/serviceworker/registration.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ' +
70 'code (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 ' +
94 'unsupported MIME type (\'text/plain\').';
95 return assert_register_fails(script, scope, message);
96 }, 'Registering script with bad MIME type');
97
98 promise_test(function(t) {
99 var script = '../resources/redirect.php?Redirect=' +
100 encodeURIComponent('..//resources/registration-worker.js');
101 var scope = '../resources/scope/redirect/';
102 var message = 'Failed to register a ServiceWorker: The script resource ' +
103 'is behind a redirect, which is disallowed.';
104 return assert_register_fails(script, scope, message);
105 }, 'Registering redirected script');
106
107 promise_test(function(t) {
108 var script = '../resources/malformed-worker.php?parse-error';
109 var scope = '../resources/scope/parse-error';
110 var message = 'Failed to register a ServiceWorker: ServiceWorker script ' +
111 'evaluation failed';
112 return assert_register_fails(script, scope, message);
113 }, 'Registering script including parse error');
114
115 promise_test(function(t) {
116 var script = '../resources/malformed-worker.php?undefined-error';
117 var scope = '../resources/scope/undefined-error';
118 var message = 'Failed to register a ServiceWorker: ServiceWorker script ' +
119 'evaluation failed';
120 return assert_register_fails(script, scope, message);
121 }, 'Registering script including undefined error');
122
123 promise_test(function(t) {
124 var script = '../resources/malformed-worker.php?uncaught-exception';
125 var scope = '../resources/scope/uncaught-exception';
126 var message = 'Failed to register a ServiceWorker: ServiceWorker script ' +
127 'evaluation failed';
128 return assert_register_fails(script, scope, message);
129 }, 'Registering script including uncaught exception');
130
131 promise_test(function(t) {
132 var script = '../resources/malformed-worker.php?import-malformed-script';
133 var scope = '../resources/scope/import-malformed-script';
134 var message = 'Failed to register a ServiceWorker: ServiceWorker script ' +
135 'evaluation failed';
136 return assert_register_fails(script, scope, message);
137 }, 'Registering script importing malformed script');
138
139 promise_test(function(t) {
140 var script = '../resources/malformed-worker.php?import-no-such-script';
141 var scope = '../resources/scope/import-no-such-script';
142 var message = 'Failed to register a ServiceWorker: ServiceWorker script ' +
143 'evaluation failed';
144 return assert_register_fails(script, scope, message);
145 }, 'Registering script importing non-existent script');
146
147 promise_test(function(t) {
148 var script = '../resources%2fempty-worker.js';
149 var scope = '../resources/scope/encoded-slash-in-script-url';
150 var message = 'Failed to register a ServiceWorker: The provided scope ' +
151 '(\'http://127.0.0.1:8000/serviceworker/resources/scope/' +
152 'encoded-slash-in-script-url\') or scriptURL ' +
153 '(\'http://127.0.0.1:8000/serviceworker/' +
154 'resources%2fempty-worker.js\') ' +
155 'includes a disallowed escape character.';
156 return assert_register_fails(script, scope, message);
157 }, 'Script URL including URL-encoded slash');
158
159 </script>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/http/tests/serviceworker/registration.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698