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

Side by Side Diff: LayoutTests/http/tests/serviceworker/resources/fetch-worker.js

Issue 333423004: moved to https://codereview.chromium.org/399543002/ (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 6 years, 5 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
OLDNEW
1 self.onmessage = function(e) { 1 self.onmessage = function(e) {
2 var message = e.data; 2 var message = e.data;
3 if ('port' in message) { 3 if ('port' in message) {
4 port = message.port; 4 port = message.port;
5 doNextFetchTest(port); 5 doNextFetchTest(port);
6 } 6 }
7 }; 7 };
8 8
9 var shouldBeResolved = function (status, statusText, type, url, target, resolved , data) {
10 if (!resolved) {
11 port.postMessage('FAILED: \'' + JSON.stringify(target) + '\' should be resol ved, but rejected with an error \'' + data.name + '\'');
12 }
13 if (data.status != status) {
14 port.postMessage('FAILED: Responce.status should be ' + status + ' but was ' + data.status);
15 }
16 if (data.statusText != statusText) {
17 port.postMessage('FAILED: Responce.statusText should be \'' + statusText + ' \' but was \'' + data.statusText + '\'');
18 }
19 if (data.type != type) {
20 port.postMessage('FAILED: Responce.type should be \'' + type + '\' but was \ '' + data.type + '\'');
21 }
22 if (data.url != url) {
23 port.postMessage('FAILED: Responce.url should be \'' + url + '\' but was \'' + data.url + '\'');
24 }
25 };
26
27 var shouldBeRejected = function (target, resolved, data) {
28 if (resolved) {
29 port.postMessage('FAILED: request \'' + JSON.stringify(target) + '\' should be rejected, but resolved with the response \'' + JSON.stringify(data) + '\'');
30 }
31 };
32
33
34 var baseUrl = 'http://127.0.0.1:8000/serviceworker/resources/';
35 var corsBaseUrl = 'http://localhost:8000/xmlhttprequest/resources/';
9 var testTargets = [ 36 var testTargets = [
10 'other.html', 37 [['other.html'],
11 'http://', 38 [shouldBeResolved.bind(this, 200, 'OK', 'cors', baseUrl + 'other.html')]],
12 'http://www.example.com/foo', 39 [['other.html', {mode: 'same-origin'}],
13 'fetch-status.php?status=200', 40 [shouldBeResolved.bind(this, 200, 'OK', 'basic', baseUrl + 'other.html')]],
14 'fetch-status.php?status=404' 41 [['other.html', {mode: 'no-cors'}],
42 [shouldBeResolved.bind(this, 200, 'OK', 'basic', baseUrl + 'other.html')]],
43 [['other.html', {mode: 'cors'}],
44 [shouldBeResolved.bind(this, 200, 'OK', 'cors', baseUrl + 'other.html')]],
45 [['http://'], [shouldBeRejected]],
46 [['http://www.example.com/foo'], [shouldBeRejected]],
47 [['fetch-status.php?status=200'],
48 [shouldBeResolved.bind(this, 200, 'OK', 'cors', baseUrl + 'fetch-status.php?s tatus=200')]],
49 [['fetch-status.php?status=404'],
50 [shouldBeResolved.bind(this, 404, 'Not Found', 'cors', baseUrl + 'fetch-statu s.php?status=404')]],
51 [[corsBaseUrl + 'access-control-basic-allow.cgi'],
52 [shouldBeResolved.bind(this, 200, 'OK', 'cors', corsBaseUrl + 'access-control -basic-allow.cgi')]],
53 [[new Request(corsBaseUrl + 'access-control-basic-allow.cgi')],
54 [shouldBeResolved.bind(this, 200, 'OK', 'cors', corsBaseUrl + 'access-control -basic-allow.cgi')]],
55 [[corsBaseUrl + 'access-control-basic-denied.cgi'], [shouldBeRejected]]
15 ]; 56 ];
16 57
17 function doNextFetchTest(port) { 58 function doNextFetchTest(port) {
18 if (testTargets.length == 0) { 59 if (testTargets.length == 0) {
19 port.postMessage('quit'); 60 port.postMessage('quit');
20 // Destroying the execution context while fetch is happening should not cause a crash. 61 // Destroying the execution context while fetch is happening should not caus e a crash.
21 fetch('dummy.html').then(function() {}).catch(function() {}); 62 fetch('dummy.html').then(function() {}).catch(function() {});
22 self.close(); 63 self.close();
23 return; 64 return;
24 } 65 }
25 var target = testTargets.shift(); 66 var target = testTargets.shift();
26 fetch(target) 67 fetch.apply(this, target[0])
27 .then(function(response) { 68 .then(function(response) {
28 port.postMessage('Resolved: ' + target + ' [' + response.status + ']' + response.statusText); 69 target[1].forEach(function(checkFunc) {
29 doNextFetchTest(port); 70 checkFunc.call(this, target[0], true, response);
30 }).catch(function(e) {
31 port.postMessage('Rejected: ' + target + ' : '+ e.message);
32 doNextFetchTest(port);
33 }); 71 });
72 doNextFetchTest(port);
73 }).catch(function(e) {
74 target[1].forEach(function(checkFunc) {
75 checkFunc.call(this, target[0], false, e);
76 });
77 doNextFetchTest(port);
78 });
34 }; 79 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698