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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/fetch/api/request/request-error.html

Issue 2778753002: Import //fetch from Web Platform Tests. (Closed)
Patch Set: Baselines. Created 3 years, 8 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
(Empty)
1 <!doctype html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>Request error</title>
6 <meta name="help" href="https://fetch.spec.whatwg.org/#request">
7 <meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin">
8 <meta name="author" title="Canon Research France" href="https://www.crf.cano n.fr">
9 <script src="/resources/testharness.js"></script>
10 <script src="/resources/testharnessreport.js"></script>
11 </head>
12 <body>
13 <script>
14 test(function() {
15 assert_throws(new TypeError() , function() { new Request("", {"window" : "http://test.url"}); },
16 "Expect TypeError exception");
17 },"RequestInit's window is not null");
18
19 test(function() {
20 assert_throws(new TypeError() , function() { new Request("http://:not a valid URL"); },
21 "Expect TypeError exception");
22 },"Input URL is not valid")
23
24 test(function() {
25 assert_throws(new TypeError() , function() { new Request("http://user:pa ss@test.url"); },
26 "Expect TypeError exception");
27 },"Input URL has credentials");
28
29 test(function() {
30 assert_throws(new TypeError() , function() { new Request("", {"referrer" : "http://:not a valid URL"}); },
31 "Expect TypeError exception");
32 },"RequestInit's referrer is invalid");
33
34 test(function() {
35 assert_throws(new TypeError() , function() { new Request("", {"method" : "IN VALID"}); },
36 "Expect TypeError exception");
37 }, "RequestInit's method is invalid");
38
39 test(function() {
40 assert_throws(new TypeError() , function() { new Request("", {"method" : "TRACE"}); },
41 "Expect TypeError exception");
42 }, "RequestInit's method is forbidden");
43
44 test(function() {
45 assert_throws(new TypeError() , function() { new Request("", {"mode" : " no-cors", "method" : "PUT"}); },
46 "Expect TypeError exception");
47 },"RequestInit's mode is no-cors and method is not simple");
48
49 test(function() {
50 assert_throws(new TypeError() ,
51 function() { new Request("", {"mode" : "no-cors", "integri ty" : "not an empty string"}); },
52 "Expect TypeError exception");
53 },"RequestInit's mode is no-cors and integrity is not empty");
54
55 test(function() {
56 assert_throws(new TypeError() ,
57 function() { new Request("", {"mode" : "cors", "cache" : " only-if-cached"}); },
58 "Expect TypeError exception");
59 },"RequestInit's cache mode is only-if-cached and mode is not same-origin" );
60
61 test(function() {
62 var initialHeaders = new Headers([["Content-Type", "potato"]]);
63 var initialRequest = new Request("", {"headers" : initialHeaders});
64 var request = new Request(initialRequest);
65 assert_equals(request.headers.get("Content-Type"), "potato");
66 }, "Request should get its content-type from the init request");
67
68 test(function() {
69 var initialHeaders = new Headers([["Content-Type", "potato"]]);
70 var initialRequest = new Request("", {"headers" : initialHeaders});
71 var headers = new Headers([]);
72 var request = new Request(initialRequest, {"headers" : headers});
73 assert_false(request.headers.has("Content-Type"));
74 }, "Request should not get its content-type from the init request if init headers are provided");
75
76 test(function() {
77 var initialHeaders = new Headers([["Content-Type-Extra", "potato"]]);
78 var initialRequest = new Request("", {"headers" : initialHeaders, "body" : "this is my plate", "method" : "POST"});
79 var request = new Request(initialRequest);
80 assert_equals(request.headers.get("Content-Type"), "text/plain;charset=U TF-8");
81 }, "Request should get its content-type from the body if none is provided" );
82
83 test(function() {
84 var initialHeaders = new Headers([["Content-Type", "potato"]]);
85 var initialRequest = new Request("", {"headers" : initialHeaders, "body" : "this is my plate", "method" : "POST"});
86 var request = new Request(initialRequest);
87 assert_equals(request.headers.get("Content-Type"), "potato");
88 }, "Request should get its content-type from init headers if one is provid ed");
89
90 var parameters = ["referrerPolicy", "mode", "credentials", "cache", "redir ect"];
91 parameters.forEach(function(parameter) {
92 test(function() {
93 var options = { };
94 options[parameter] = "BAD";
95 assert_throws(new TypeError(), function() { new Request("", options); });
96 },"Bad " + parameter +" init parameter value");
97 });
98
99 function testOnlyIfCachedMode(fetchMode, ok) {
100 test(function() {
101 var options = {"cache": "only-if-cached", "mode": fetchMode};
102 if (ok)
103 new Request("test", options);
104 else
105 assert_throws(new TypeError(), function() { new Request("test", opti ons); });
106 }, "Request with cache mode: only-if-cached and fetch mode: " + fetchMod e);
107 }
108 testOnlyIfCachedMode("same-origin", true);
109 testOnlyIfCachedMode("cors", false);
110 testOnlyIfCachedMode("no-cors", false);
111
112 </script>
113 </body>
114 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698