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

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

Issue 728713003: [ServiceWorker] Provide more descriptive error messages when fetch API fails. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month 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 5b99dd86b494f9022d7e7ac0dfef225f536ca76d..7198c7fafac44a024b65eeefd819c6d48528a01d 100644
--- a/LayoutTests/http/tests/serviceworker/resources/fetch-worker.js
+++ b/LayoutTests/http/tests/serviceworker/resources/fetch-worker.js
@@ -139,6 +139,103 @@ async_test(function(t) {
.catch(unreached_rejection(t));
}, 'Fetch with FormData body test in ServiceWorkerGlobalScope');
+async_test(function(t) {
+ var url = get_host_info()['HTTP_REMOTE_ORIGIN'] + '/dymmy.html';
falken 2014/11/17 02:14:46 nit: dummy
horo 2014/11/17 03:25:35 Done.
+ fetch(new Request(url, {mode: 'same-origin'}))
+ .then(
+ unreached_rejection(t, 'Fetching must fail.'),
+ function(e) {
+ assert_equals(
+ e.message,
+ 'Fetch API cannot load ' + url + '. ' +
+ 'Request mode is "same-origin" but the URL is not same origin.');
+ t.done();
+ })
+ .catch(unreached_rejection(t));
+ }, 'Fetch API error message - not same origin request');
+
+async_test(function(t) {
+ var url = 'ftp://example.com/dummy.html';
+ fetch(new Request(url, {mode: 'cors'}))
+ .then(
+ unreached_rejection(t, 'Fetching must fail.'),
+ function(e) {
+ assert_equals(
+ e.message,
+ 'Fetch API cannot load ' + url + '. ' +
+ 'URL scheme must be "http" or "https" for CORS request.');
+ t.done();
+ })
+ .catch(unreached_rejection(t));
+ }, 'Fetch API error message - non http cors request');
+
+async_test(function(t) {
+ var url = 'about://blank';
+ fetch(new Request(url))
+ .then(
+ unreached_rejection(t, 'Fetching must fail.'),
+ function(e) {
+ assert_equals(
+ e.message,
+ 'Fetch API cannot load ' + url + '. ' +
+ 'URL scheme "about" is not supported.');
+ t.done();
+ })
+ .catch(unreached_rejection(t));
+ }, 'Fetch API error message - unsupported scheme.');
+
+async_test(function(t) {
+ var url = get_host_info()['HTTP_ORIGIN'] + base_path() +
+ 'invalid-chunked-encoding.php';
+ fetch(new Request(url))
+ .then(
+ unreached_rejection(t, 'Fetching must fail.'),
+ function(e) {
+ assert_equals(
+ e.message,
+ 'Fetch API cannot load ' + url + '. ' +
+ 'net::ERR_INVALID_CHUNKED_ENCODING');
+ t.done();
+ })
+ .catch(unreached_rejection(t));
+ }, 'Fetch API error message - invalid chunled encoding.');
falken 2014/11/17 02:14:46 nit: chunked
horo 2014/11/17 03:25:35 Done.
+
+async_test(function(t) {
+ var url = get_host_info()['HTTP_REMOTE_ORIGIN'] + base_path() +
+ 'fetch-access-control.php';
+ fetch(new Request(url))
+ .then(
+ unreached_rejection(t, 'Fetching must fail.'),
+ function(e) {
+ assert_equals(
+ e.message,
+ 'Fetch API cannot load ' + url + '. ' +
+ 'No \'Access-Control-Allow-Origin\' header is present on the ' +
+ 'requested resource. Origin \'' + get_host_info()['HTTP_ORIGIN'] +
+ '\' is therefore not allowed access.');
+ t.done();
+ })
+ .catch(unreached_rejection(t));
+ }, 'Fetch API error message - cors error.');
+
+async_test(function(t) {
+ // FIXME: When we support the redirection in Fech API, we have to change
+ // this test case.
+ var url = get_host_info()['HTTP_ORIGIN'] + base_path() +
+ 'redirect.php?Redirect=http://www.example.com';
+ fetch(new Request(url))
+ .then(
+ unreached_rejection(t, 'Fetching must fail.'),
+ function(e) {
+ assert_equals(
+ e.message,
+ 'Fetch API cannot load ' + url + '. ' +
+ 'Unsupported redirection.');
+ t.done();
+ })
+ .catch(unreached_rejection(t));
+ }, 'Fetch API error message - redirect error.');
+
test(function(t) {
function runInfiniteFetchLoop() {
fetch('dummy.html')
« no previous file with comments | « no previous file | Source/modules/serviceworkers/FetchManager.cpp » ('j') | Source/modules/serviceworkers/FetchManager.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698