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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/register-foreign-fetch-errors-worker.js

Issue 2892473003: Upstream service worker "register" tests to WPT (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/serviceworker/register-wait-forever-in-install-worker.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 self.addEventListener('install', function(event) {
2 var scope = registration.scope;
3 var scope_url = new URL(scope);
4
5 test(function() {
6 assert_throws(new TypeError(), function() {
7 event.registerForeignFetch({});
8 });
9 }, 'Invalid options');
10
11 test(function() {
12 assert_throws(new TypeError(), function() {
13 event.registerForeignFetch({scopes: scope, origins: ['*']});
14 });
15 }, 'Scopes not an array');
16
17 test(function() {
18 assert_throws(new TypeError(), function() {
19 event.registerForeignFetch({scopes: [{}], origins: ['*']});
20 });
21 }, 'Scopes not a string in array');
22
23 test(function() {
24 assert_throws(new TypeError(), function() {
25 event.registerForeignFetch({scopes: ['/foo'], origins: ['*']});
26 });
27 }, 'Relative url not under scope');
28
29 test(function() {
30 var url = new URL(scope_url);
31 url.host = 'example.com';
32 assert_throws(new TypeError(), function() {
33 event.registerForeignFetch({scopes: [url.href], origins: ['*']});
34 });
35 }, 'Absolute url not under scope');
36
37 test(function() {
38 assert_throws(new TypeError(), function() {
39 event.registerForeignFetch({scopes: [], origins: ['*']});
40 });
41 }, 'Empty scope array');
42
43 async_test(function(t) {
44 self.setTimeout(t.step_func(function() {
45 assert_throws('InvalidStateError', function() {
46 event.registerForeignFetch({scopes: [scope], origins: ['*']});
47 });
48 t.done();
49 }), 1);
50 }, 'Call after event returned');
51
52 test(function() {
53 event.registerForeignFetch({scopes: [scope], origins: ['*']});
54 }, 'Valid scopes with wildcard origin string');
55
56 test(function() {
57 event.registerForeignFetch({scopes: [scope, scope + '/foo'], origins: [' *']});
58 }, 'Absolute urls');
59
60 test(function() {
61 // Figure out scope relative to location of this script:
62 var local_dir = location.pathname;
63 local_dir = local_dir.substr(0, local_dir.lastIndexOf('/'));
64 assert_true(scope_url.pathname.startsWith(local_dir));
65 var relative_scope = scope_url.pathname.substr(local_dir.length + 1);
66
67 event.registerForeignFetch({scopes: [
68 scope_url.pathname,
69 relative_scope,
70 './' + relative_scope,
71 relative_scope + '/foo'], origins: ['*']});
72 }, 'Relative urls');
73
74 test(function() {
75 assert_throws(new TypeError(), function() {
76 event.registerForeignFetch({scopes: [scope]});
77 });
78 }, 'No origins specified');
79
80 test(function() {
81 assert_throws(new TypeError(), function() {
82 event.registerForeignFetch({scopes: [scope], origins: {}});
83 });
84 }, 'Origins not a string or array');
85
86 test(function() {
87 assert_throws(new TypeError(), function() {
88 event.registerForeignFetch({scopes: [scope], origins: [{}]});
89 });
90 }, 'Origins contains something not a string');
91
92 test(function() {
93 assert_throws(new TypeError(), function() {
94 event.registerForeignFetch({scopes: [scope], origins: ['/foo']});
95 });
96 }, 'Origin not an absolute URL');
97
98 test(function() {
99 event.registerForeignFetch({scopes: [scope], origins: ['*']});
100 }, 'Wildcard origin string in array');
101
102 test(function() {
103 assert_throws(new TypeError(), function() {
104 event.registerForeignFetch({scopes: [scope], origins: 'https://examp le.com/'});
105 });
106 }, 'Origin string');
107
108 test(function() {
109 event.registerForeignFetch({scopes: [scope], origins: ['https://example. com/']});
110 }, 'Origin string in array');
111
112 test(function() {
113 event.registerForeignFetch({
114 scopes: [scope], origins: ['https://example.com/', 'https://chromium .org']});
115 }, 'Array with multiple origins');
116
117 test(function() {
118 assert_throws(new TypeError(), function() {
119 event.registerForeignFetch({scopes: [scope],
120 origins: ['*', 'https://example.com/']}) ;
121 });
122 }, 'Origins includes wildcard and other strings');
123
124 test(function() {
125 assert_throws(new TypeError(), function() {
126 event.registerForeignFetch({scopes: [scope],
127 origins: ['https://example.com/', '*']}) ;
128 });
129 }, 'Origins includes other strings and wildcard');
130 });
131
132 // Import testharness after install handler to make sure our install handler
133 // runs first. Otherwise only one test will run.
134 importScripts('../../resources/testharness.js');
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/serviceworker/register-wait-forever-in-install-worker.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698