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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/http/tests/serviceworker/resources/fetch-worker.js
diff --git a/LayoutTests/http/tests/serviceworker/resources/fetch-worker.js b/LayoutTests/http/tests/serviceworker/resources/fetch-worker.js
index 7f5d401c3f0a3e618eefac237f462b0fb9ee5b2c..ac6bae7f0a49ee6024a5487447eb9934d57157b0 100644
--- a/LayoutTests/http/tests/serviceworker/resources/fetch-worker.js
+++ b/LayoutTests/http/tests/serviceworker/resources/fetch-worker.js
@@ -1,34 +1,79 @@
self.onmessage = function(e) {
- var message = e.data;
- if ('port' in message) {
- port = message.port;
- doNextFetchTest(port);
- }
+ var message = e.data;
+ if ('port' in message) {
+ port = message.port;
+ doNextFetchTest(port);
+ }
};
+var shouldBeResolved = function (status, statusText, type, url, target, resolved, data) {
+ if (!resolved) {
+ port.postMessage('FAILED: \'' + JSON.stringify(target) + '\' should be resolved, but rejected with an error \'' + data.name + '\'');
+ }
+ if (data.status != status) {
+ port.postMessage('FAILED: Responce.status should be ' + status + ' but was ' + data.status);
+ }
+ if (data.statusText != statusText) {
+ port.postMessage('FAILED: Responce.statusText should be \'' + statusText + '\' but was \'' + data.statusText + '\'');
+ }
+ if (data.type != type) {
+ port.postMessage('FAILED: Responce.type should be \'' + type + '\' but was \'' + data.type + '\'');
+ }
+ if (data.url != url) {
+ port.postMessage('FAILED: Responce.url should be \'' + url + '\' but was \'' + data.url + '\'');
+ }
+};
+
+var shouldBeRejected = function (target, resolved, data) {
+ if (resolved) {
+ port.postMessage('FAILED: request \'' + JSON.stringify(target) + '\' should be rejected, but resolved with the response \'' + JSON.stringify(data) + '\'');
+ }
+};
+
+
+var baseUrl = 'http://127.0.0.1:8000/serviceworker/resources/';
+var corsBaseUrl = 'http://localhost:8000/xmlhttprequest/resources/';
var testTargets = [
- 'other.html',
- 'http://',
- 'http://www.example.com/foo',
- 'fetch-status.php?status=200',
- 'fetch-status.php?status=404'
+ [['other.html'],
+ [shouldBeResolved.bind(this, 200, 'OK', 'cors', baseUrl + 'other.html')]],
+ [['other.html', {mode: 'same-origin'}],
+ [shouldBeResolved.bind(this, 200, 'OK', 'basic', baseUrl + 'other.html')]],
+ [['other.html', {mode: 'no-cors'}],
+ [shouldBeResolved.bind(this, 200, 'OK', 'basic', baseUrl + 'other.html')]],
+ [['other.html', {mode: 'cors'}],
+ [shouldBeResolved.bind(this, 200, 'OK', 'cors', baseUrl + 'other.html')]],
+ [['http://'], [shouldBeRejected]],
+ [['http://www.example.com/foo'], [shouldBeRejected]],
+ [['fetch-status.php?status=200'],
+ [shouldBeResolved.bind(this, 200, 'OK', 'cors', baseUrl + 'fetch-status.php?status=200')]],
+ [['fetch-status.php?status=404'],
+ [shouldBeResolved.bind(this, 404, 'Not Found', 'cors', baseUrl + 'fetch-status.php?status=404')]],
+ [[corsBaseUrl + 'access-control-basic-allow.cgi'],
+ [shouldBeResolved.bind(this, 200, 'OK', 'cors', corsBaseUrl + 'access-control-basic-allow.cgi')]],
+ [[new Request(corsBaseUrl + 'access-control-basic-allow.cgi')],
+ [shouldBeResolved.bind(this, 200, 'OK', 'cors', corsBaseUrl + 'access-control-basic-allow.cgi')]],
+ [[corsBaseUrl + 'access-control-basic-denied.cgi'], [shouldBeRejected]]
];
function doNextFetchTest(port) {
- if (testTargets.length == 0) {
- port.postMessage('quit');
- // Destroying the execution context while fetch is happening should not cause a crash.
- fetch('dummy.html').then(function() {}).catch(function() {});
- self.close();
- return;
- }
- var target = testTargets.shift();
- fetch(target)
- .then(function(response) {
- port.postMessage('Resolved: ' + target + ' [' + response.status + ']' + response.statusText);
- doNextFetchTest(port);
- }).catch(function(e) {
- port.postMessage('Rejected: ' + target + ' : '+ e.message);
- doNextFetchTest(port);
+ if (testTargets.length == 0) {
+ port.postMessage('quit');
+ // Destroying the execution context while fetch is happening should not cause a crash.
+ fetch('dummy.html').then(function() {}).catch(function() {});
+ self.close();
+ return;
+ }
+ var target = testTargets.shift();
+ fetch.apply(this, target[0])
+ .then(function(response) {
+ target[1].forEach(function(checkFunc) {
+ checkFunc.call(this, target[0], true, response);
+ });
+ doNextFetchTest(port);
+ }).catch(function(e) {
+ target[1].forEach(function(checkFunc) {
+ checkFunc.call(this, target[0], false, e);
});
+ doNextFetchTest(port);
+ });
};

Powered by Google App Engine
This is Rietveld 408576698