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

Side by Side Diff: LayoutTests/http/tests/serviceworker/chromium/resources/fetch-error-messages-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: use t.unreached_func instead of unreached_rejection 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 unified diff | Download patch
OLDNEW
(Empty)
1 importScripts('../../resources/worker-testharness.js');
2 importScripts('../../resources/test-helpers.js');
3
4 async_test(function(t) {
5 var url = get_host_info()['HTTP_REMOTE_ORIGIN'] + '/dummy.html';
6 fetch(new Request(url, {mode: 'same-origin'}))
7 .then(
8 t.unreached_func('Fetching must fail.'),
9 function(e) {
10 assert_equals(
11 e.message,
12 'Fetch API cannot load ' + url + '. ' +
13 'Request mode is "same-origin" but the URL\'s origin is not same ' +
14 'as the request origin ' + get_host_info()['HTTP_ORIGIN'] + '.');
15 t.done();
16 })
17 .catch(unreached_rejection(t));
18 }, 'Fetch API error message - not same origin request');
19
20 async_test(function(t) {
21 var url = 'ftp://example.com/dummy.html';
22 fetch(new Request(url, {mode: 'cors'}))
23 .then(
24 t.unreached_func('Fetching must fail.'),
25 function(e) {
26 assert_equals(
27 e.message,
28 'Fetch API cannot load ' + url + '. ' +
29 'URL scheme must be "http" or "https" for CORS request.');
30 t.done();
31 })
32 .catch(unreached_rejection(t));
33 }, 'Fetch API error message - non http cors request');
34
35 async_test(function(t) {
36 var url = 'about://blank';
37 fetch(new Request(url))
38 .then(
39 t.unreached_func('Fetching must fail.'),
40 function(e) {
41 assert_equals(
42 e.message,
43 'Fetch API cannot load ' + url + '. ' +
44 'URL scheme "about" is not supported.');
45 t.done();
46 })
47 .catch(unreached_rejection(t));
48 }, 'Fetch API error message - unsupported scheme.');
49
50 async_test(function(t) {
51 var url =
52 new URL(get_host_info()['HTTP_ORIGIN'] + base_path() +
53 '../../resources/invalid-chunked-encoding.php').toString();
54 fetch(new Request(url))
55 .then(
56 t.unreached_func('Fetching must fail.'),
57 function(e) {
58 assert_equals(
59 e.message,
60 'Fetch API cannot load ' + url + '. ' +
61 'net::ERR_INVALID_CHUNKED_ENCODING');
62 t.done();
63 })
64 .catch(unreached_rejection(t));
65 }, 'Fetch API error message - invalid chunked encoding.');
66
67 async_test(function(t) {
68 var url =
69 new URL(get_host_info()['HTTP_REMOTE_ORIGIN'] + base_path() +
70 '../../resources/fetch-access-control.php').toString();
71 fetch(new Request(url))
72 .then(
73 t.unreached_func('Fetching must fail.'),
74 function(e) {
75 assert_equals(
76 e.message,
77 'Fetch API cannot load ' + url + '. ' +
78 'No \'Access-Control-Allow-Origin\' header is present on the ' +
79 'requested resource. Origin \'' + get_host_info()['HTTP_ORIGIN'] +
80 '\' is therefore not allowed access.');
81 t.done();
82 })
83 .catch(unreached_rejection(t));
84 }, 'Fetch API error message - cors error.');
85
86 async_test(function(t) {
87 // FIXME: When we support the redirection in Fech API, we have to change
88 // this test case.
89 var redirect = 'http://www.example.com';
90 var url =
91 new URL(get_host_info()['HTTP_REMOTE_ORIGIN'] + base_path() +
92 '../../resources/redirect.php?Redirect=' + redirect).toString();
93 fetch(new Request(url))
94 .then(
95 t.unreached_func('Fetching must fail.'),
96 function(e) {
97 assert_equals(
98 e.message,
99 'Fetch API cannot load ' + url + '. ' +
100 'Redirects are not yet supported.');
101 t.done();
102 })
103 .catch(unreached_rejection(t));
104 }, 'Fetch API error message - redirect error.');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698