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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/fetch/api/headers/headers-record.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 <meta charset=utf-8>
3 <title></title>
4 <script src=/resources/testharness.js></script>
5 <script src=/resources/testharnessreport.js></script>
6 <script>
7 var log = [];
8 function clearLog() {
9 log = [];
10 }
11 function addLogEntry(name, args) {
12 log.push([ name, ...args ]);
13 }
14
15 var loggingHandler = {
16 };
17
18 setup(function() {
19 for (let prop of Object.getOwnPropertyNames(Reflect)) {
20 loggingHandler[prop] = function(...args) {
21 addLogEntry(prop, args);
22 return Reflect[prop](...args);
23 }
24 }
25 });
26
27 test(function() {
28 var h = new Headers();
29 assert_equals([...h].length, 0);
30 }, "Passing nothing to Headers constructor");
31
32 test(function() {
33 var h = new Headers(undefined);
34 assert_equals([...h].length, 0);
35 }, "Passing undefined to Headers constructor");
36
37 test(function() {
38 assert_throws(new TypeError, function() {
39 var h = new Headers(null);
40 });
41 }, "Passing null to Headers constructor");
42
43 test(function() {
44 this.add_cleanup(clearLog);
45 var record = { a: "b" };
46 var proxy = new Proxy(record, loggingHandler);
47 var h = new Headers(proxy);
48
49 assert_equals(log.length, 4);
50 // The first thing is the [[Get]] of Symbol.iterator to figure out whether
51 // we're a sequence, during overload resolution.
52 assert_array_equals(log[0], ["get", record, Symbol.iterator, proxy]);
53 // Then we have the [[OwnPropertyKeys]] from
54 // https://heycam.github.io/webidl/#es-to-record step 4.
55 assert_array_equals(log[1], ["ownKeys", record]);
56 // Then the [[GetOwnProperty]] from step 5.1.
57 assert_array_equals(log[2], ["getOwnPropertyDescriptor", record, "a"]);
58 // Then the [[Get]] from step 5.2.
59 assert_array_equals(log[3], ["get", record, "a", proxy]);
60
61 // Check the results.
62 assert_equals([...h].length, 1);
63 assert_array_equals([...h.keys()], ["a"]);
64 assert_true(h.has("a"));
65 assert_equals(h.get("a"), "b");
66 }, "Basic operation with one property");
67
68 test(function() {
69 this.add_cleanup(clearLog);
70 var recordProto = { c: "d" };
71 var record = Object.create(recordProto, { a: { value: "b", enumerable: true } });
72 var proxy = new Proxy(record, loggingHandler);
73 var h = new Headers(proxy);
74
75 assert_equals(log.length, 4);
76 // The first thing is the [[Get]] of Symbol.iterator to figure out whether
77 // we're a sequence, during overload resolution.
78 assert_array_equals(log[0], ["get", record, Symbol.iterator, proxy]);
79 // Then we have the [[OwnPropertyKeys]] from
80 // https://heycam.github.io/webidl/#es-to-record step 4.
81 assert_array_equals(log[1], ["ownKeys", record]);
82 // Then the [[GetOwnProperty]] from step 5.1.
83 assert_array_equals(log[2], ["getOwnPropertyDescriptor", record, "a"]);
84 // Then the [[Get]] from step 5.2.
85 assert_array_equals(log[3], ["get", record, "a", proxy]);
86
87 // Check the results.
88 assert_equals([...h].length, 1);
89 assert_array_equals([...h.keys()], ["a"]);
90 assert_true(h.has("a"));
91 assert_equals(h.get("a"), "b");
92 }, "Basic operation with one property and a proto");
93
94 test(function() {
95 this.add_cleanup(clearLog);
96 var record = { a: "b", c: "d" };
97 var proxy = new Proxy(record, loggingHandler);
98 var h = new Headers(proxy);
99
100 assert_equals(log.length, 6);
101 // The first thing is the [[Get]] of Symbol.iterator to figure out whether
102 // we're a sequence, during overload resolution.
103 assert_array_equals(log[0], ["get", record, Symbol.iterator, proxy]);
104 // Then we have the [[OwnPropertyKeys]] from
105 // https://heycam.github.io/webidl/#es-to-record step 4.
106 assert_array_equals(log[1], ["ownKeys", record]);
107 // Then the [[GetOwnProperty]] from step 5.1.
108 assert_array_equals(log[2], ["getOwnPropertyDescriptor", record, "a"]);
109 // Then the [[Get]] from step 5.2.
110 assert_array_equals(log[3], ["get", record, "a", proxy]);
111 // Then the second [[GetOwnProperty]] from step 5.1.
112 assert_array_equals(log[4], ["getOwnPropertyDescriptor", record, "c"]);
113 // Then the second [[Get]] from step 5.2.
114 assert_array_equals(log[5], ["get", record, "c", proxy]);
115
116 // Check the results.
117 assert_equals([...h].length, 2);
118 assert_array_equals([...h.keys()], ["a", "c"]);
119 assert_true(h.has("a"));
120 assert_equals(h.get("a"), "b");
121 assert_true(h.has("c"));
122 assert_equals(h.get("c"), "d");
123 }, "Correct operation ordering with two properties");
124
125 test(function() {
126 this.add_cleanup(clearLog);
127 var record = { a: "b", "\uFFFF": "d" };
128 var proxy = new Proxy(record, loggingHandler);
129 assert_throws(new TypeError, function() {
130 var h = new Headers(proxy);
131 });
132
133 assert_equals(log.length, 5);
134 // The first thing is the [[Get]] of Symbol.iterator to figure out whether
135 // we're a sequence, during overload resolution.
136 assert_array_equals(log[0], ["get", record, Symbol.iterator, proxy]);
137 // Then we have the [[OwnPropertyKeys]] from
138 // https://heycam.github.io/webidl/#es-to-record step 4.
139 assert_array_equals(log[1], ["ownKeys", record]);
140 // Then the [[GetOwnProperty]] from step 5.1.
141 assert_array_equals(log[2], ["getOwnPropertyDescriptor", record, "a"]);
142 // Then the [[Get]] from step 5.2.
143 assert_array_equals(log[3], ["get", record, "a", proxy]);
144 // Then the second [[GetOwnProperty]] from step 5.1.
145 assert_array_equals(log[4], ["getOwnPropertyDescriptor", record, "\uFFFF"]);
146 // The second [[Get]] never happens, because we convert the invalid name to a
147 // ByteString first and throw.
148 }, "Correct operation ordering with two properties one of which has an invalid n ame");
149
150 test(function() {
151 this.add_cleanup(clearLog);
152 var record = { a: "\uFFFF", c: "d" }
153 var proxy = new Proxy(record, loggingHandler);
154 assert_throws(new TypeError, function() {
155 var h = new Headers(proxy);
156 });
157
158 assert_equals(log.length, 4);
159 // The first thing is the [[Get]] of Symbol.iterator to figure out whether
160 // we're a sequence, during overload resolution.
161 assert_array_equals(log[0], ["get", record, Symbol.iterator, proxy]);
162 // Then we have the [[OwnPropertyKeys]] from
163 // https://heycam.github.io/webidl/#es-to-record step 4.
164 assert_array_equals(log[1], ["ownKeys", record]);
165 // Then the [[GetOwnProperty]] from step 5.1.
166 assert_array_equals(log[2], ["getOwnPropertyDescriptor", record, "a"]);
167 // Then the [[Get]] from step 5.2.
168 assert_array_equals(log[3], ["get", record, "a", proxy]);
169 // Nothing else after this, because converting the result of that [[Get]] to a
170 // ByteString throws.
171 }, "Correct operation ordering with two properties one of which has an invalid v alue");
172
173 test(function() {
174 this.add_cleanup(clearLog);
175 var record = {};
176 Object.defineProperty(record, "a", { value: "b", enumerable: false });
177 Object.defineProperty(record, "c", { value: "d", enumerable: true });
178 Object.defineProperty(record, "e", { value: "f", enumerable: false });
179 var proxy = new Proxy(record, loggingHandler);
180 var h = new Headers(proxy);
181
182 assert_equals(log.length, 6);
183 // The first thing is the [[Get]] of Symbol.iterator to figure out whether
184 // we're a sequence, during overload resolution.
185 assert_array_equals(log[0], ["get", record, Symbol.iterator, proxy]);
186 // Then we have the [[OwnPropertyKeys]] from
187 // https://heycam.github.io/webidl/#es-to-record step 4.
188 assert_array_equals(log[1], ["ownKeys", record]);
189 // Then the [[GetOwnProperty]] from step 5.1.
190 assert_array_equals(log[2], ["getOwnPropertyDescriptor", record, "a"]);
191 // No [[Get]] because not enumerable
192 // Then the second [[GetOwnProperty]] from step 5.1.
193 assert_array_equals(log[3], ["getOwnPropertyDescriptor", record, "c"]);
194 // Then the [[Get]] from step 5.2.
195 assert_array_equals(log[4], ["get", record, "c", proxy]);
196 // Then the third [[GetOwnProperty]] from step 5.1.
197 assert_array_equals(log[5], ["getOwnPropertyDescriptor", record, "e"]);
198 // No [[Get]] because not enumerable
199
200 // Check the results.
201 assert_equals([...h].length, 1);
202 assert_array_equals([...h.keys()], ["c"]);
203 assert_true(h.has("c"));
204 assert_equals(h.get("c"), "d");
205 }, "Correct operation ordering with non-enumerable properties");
206
207 test(function() {
208 this.add_cleanup(clearLog);
209 var record = {a: "b", c: "d", e: "f"};
210 var lyingHandler = {
211 getOwnPropertyDescriptor: function(target, name) {
212 if (name == "a" || name == "e") {
213 return undefined;
214 }
215 return Reflect.getOwnPropertyDescriptor(target, name);
216 }
217 };
218 var lyingProxy = new Proxy(record, lyingHandler);
219 var proxy = new Proxy(lyingProxy, loggingHandler);
220 var h = new Headers(proxy);
221
222 assert_equals(log.length, 6);
223 // The first thing is the [[Get]] of Symbol.iterator to figure out whether
224 // we're a sequence, during overload resolution.
225 assert_array_equals(log[0], ["get", lyingProxy, Symbol.iterator, proxy]);
226 // Then we have the [[OwnPropertyKeys]] from
227 // https://heycam.github.io/webidl/#es-to-record step 4.
228 assert_array_equals(log[1], ["ownKeys", lyingProxy]);
229 // Then the [[GetOwnProperty]] from step 5.1.
230 assert_array_equals(log[2], ["getOwnPropertyDescriptor", lyingProxy, "a"]);
231 // No [[Get]] because no descriptor
232 // Then the second [[GetOwnProperty]] from step 5.1.
233 assert_array_equals(log[3], ["getOwnPropertyDescriptor", lyingProxy, "c"]);
234 // Then the [[Get]] from step 5.2.
235 assert_array_equals(log[4], ["get", lyingProxy, "c", proxy]);
236 // Then the third [[GetOwnProperty]] from step 5.1.
237 assert_array_equals(log[5], ["getOwnPropertyDescriptor", lyingProxy, "e"]);
238 // No [[Get]] because no descriptor
239
240 // Check the results.
241 assert_equals([...h].length, 1);
242 assert_array_equals([...h.keys()], ["c"]);
243 assert_true(h.has("c"));
244 assert_equals(h.get("c"), "d");
245 }, "Correct operation ordering with undefined descriptors");
246
247 test(function() {
248 this.add_cleanup(clearLog);
249 var record = {a: "b", c: "d"};
250 var lyingHandler = {
251 ownKeys: function() {
252 return [ "a", "c", "a", "c" ];
253 },
254 getCalls: 0,
255 gotCOnce: false,
256 get: function(target, name, receiver) {
257 if (name == "c") {
258 this.gotCOnce = true;
259 }
260 if (typeof name == "string") {
261 return ++this.getCalls;
262 }
263 return Reflect.get(target, name, receiver);
264 },
265 getOwnPropertyDescriptor: function(target, name) {
266 var desc = Reflect.getOwnPropertyDescriptor(target, name);
267 if (name == "c" && this.gotCOnce) {
268 desc.enumerable = false;
269 }
270 return desc;
271 }
272 };
273 var lyingProxy = new Proxy(record, lyingHandler);
274 var proxy = new Proxy(lyingProxy, loggingHandler);
275 var h = new Headers(proxy);
276
277 assert_equals(log.length, 9);
278 // The first thing is the [[Get]] of Symbol.iterator to figure out whether
279 // we're a sequence, during overload resolution.
280 assert_array_equals(log[0], ["get", lyingProxy, Symbol.iterator, proxy]);
281 // Then we have the [[OwnPropertyKeys]] from
282 // https://heycam.github.io/webidl/#es-to-record step 4.
283 assert_array_equals(log[1], ["ownKeys", lyingProxy]);
284 // Then the [[GetOwnProperty]] from step 5.1.
285 assert_array_equals(log[2], ["getOwnPropertyDescriptor", lyingProxy, "a"]);
286 // Then the [[Get]] from step 5.2.
287 assert_array_equals(log[3], ["get", lyingProxy, "a", proxy]);
288 // Then the second [[GetOwnProperty]] from step 5.1.
289 assert_array_equals(log[4], ["getOwnPropertyDescriptor", lyingProxy, "c"]);
290 // Then the second [[Get]] from step 5.2.
291 assert_array_equals(log[5], ["get", lyingProxy, "c", proxy]);
292 // Then the third [[GetOwnProperty]] from step 5.1.
293 assert_array_equals(log[6], ["getOwnPropertyDescriptor", lyingProxy, "a"]);
294 // Then the third [[Get]] from step 5.2.
295 assert_array_equals(log[7], ["get", lyingProxy, "a", proxy]);
296 // Then the fourth [[GetOwnProperty]] from step 5.1.
297 assert_array_equals(log[8], ["getOwnPropertyDescriptor", lyingProxy, "c"]);
298 // No [[Get]] because not enumerable.
299
300 // Check the results.
301 assert_equals([...h].length, 2);
302 assert_array_equals([...h.keys()], ["a", "c"]);
303 assert_true(h.has("a"));
304 assert_equals(h.get("a"), "3");
305 assert_true(h.has("c"));
306 assert_equals(h.get("c"), "2");
307 }, "Correct operation ordering with repeated keys");
308
309 // Need to add symbol tests, but those are pending
310 // https://github.com/heycam/webidl/issues/294 being resolved.
311 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698