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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/fetch/api/headers/headers-errors.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>Headers errors</title>
6 <meta name="help" href="https://fetch.spec.whatwg.org/#headers">
7 <meta name="author" title="Canon Research France" href="https://www.crf.cano n.fr">
8 <script src="/resources/testharness.js"></script>
9 <script src="/resources/testharnessreport.js"></script>
10 </head>
11 <body>
12 <script>
13
14 test(function() {
15 assert_throws(new TypeError() , function() { new Headers([["name"]]); }) ;
16 }, "Create headers giving an array having one string as init argument");
17
18 test(function() {
19 assert_throws(new TypeError() , function() { new Headers([["invalid", "i nvalidValue1", "invalidValue2"]]); });
20 }, "Create headers giving an array having three strings as init argument") ;
21
22 test(function() {
23 assert_throws(new TypeError() , function() { new Headers([["invalidĀ", " Value1"]]); });
24 }, "Create headers giving bad header name as init argument");
25
26 test(function() {
27 assert_throws(new TypeError() , function() { new Headers([["name", "inva lidValueĀ"]]); });
28 }, "Create headers giving bad header value as init argument");
29
30 var badNames = ["invalidĀ", {}];
31 var badValues = ["invalidĀ"];
32
33 badNames.forEach(function(name) {
34 test(function() {
35 var headers = new Headers();
36 assert_throws(new TypeError() , function() { headers.get(name); });
37 }, "Check headers get with an invalid name " + name);
38 });
39
40 badNames.forEach(function(name) {
41 test(function() {
42 var headers = new Headers();
43 assert_throws(new TypeError() , function() { headers.delete(name); });
44 }, "Check headers delete with an invalid name " + name);
45 });
46
47 badNames.forEach(function(name) {
48 test(function() {
49 var headers = new Headers();
50 assert_throws(new TypeError() , function() { headers.has(name); });
51 }, "Check headers has with an invalid name " + name);
52 });
53
54 badNames.forEach(function(name) {
55 test(function() {
56 var headers = new Headers();
57 assert_throws(new TypeError() , function() { headers.set(name, "Value1 "); });
58 }, "Check headers set with an invalid name " + name);
59 });
60
61 badValues.forEach(function(value) {
62 test(function() {
63 var headers = new Headers();
64 assert_throws(new TypeError() , function() { headers.set("name", value ); });
65 }, "Check headers set with an invalid value " + value);
66 });
67
68 badNames.forEach(function(name) {
69 test(function() {
70 var headers = new Headers();
71 assert_throws(new TypeError() , function() { headers.append("invalidĀ" , "Value1"); });
72 }, "Check headers append with an invalid name " + name);
73 });
74
75 badValues.forEach(function(value) {
76 test(function() {
77 var headers = new Headers();
78 assert_throws(new TypeError() , function() { headers.append("name", va lue); });
79 }, "Check headers append with an invalid value " + value);
80 });
81
82 test(function() {
83 var headers = new Headers([["name", "value"]]);
84 assert_throws(new TypeError() , function() { headers.forEach(); });
85 assert_throws(new TypeError() , function() { headers.forEach(undefined); });
86 assert_throws(new TypeError() , function() { headers.forEach(1); });
87 }, "Headers forEach throws if argument is not callable");
88
89 test(function() {
90 var headers = new Headers([["name1", "value1"], ["name2", "value2"], ["n ame3", "value3"]]);
91 var counter = 0;
92 try {
93 headers.forEach(function(value, name) {
94 counter++;
95 if (name == "name2")
96 throw "error";
97 });
98 } catch (e) {
99 assert_equals(counter, 2);
100 assert_equals(e, "error");
101 return;
102 }
103 assert_unreached();
104 }, "Headers forEach loop should stop if callback is throwing exception");
105 </script>
106 </body>
107 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698