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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/payment-request/payment-request-constructor.https.html

Issue 2851383002: Verify behavior of PaymentRequest constructor. (Closed)
Patch Set: Comments Created 3 years, 7 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 <!-- Copyright © 2017 Chromium authors and World Wide Web Consortium, (Massachus etts Institute of Technology, ERCIM, Keio University, Beihang). -->
3 <meta charset="utf-8">
4 <title>Test for PaymentRequest Constructor</title>
5 <link rel="help" href="https://w3c.github.io/browser-payment-api/#constructor">
6 <script src="/resources/testharness.js"></script>
7 <script src="/resources/testharnessreport.js"></script>
8 <script>
9 'use strict';
10
11 test(() => {
12 assert_equals((new PaymentRequest([{
13 supportedMethods: ['basic-card'],
14 }], {
15 id: 'foo',
16 total: {
17 label: '',
18 amount: {
19 currency: 'USD',
20 value: '1.00',
21 },
22 },
23 })).id, 'foo');
24 }, 'Use provided request ID');
25
26 test(() => {
27 assert_throws({
28 name: 'TypeError',
29 },
30 () => {
31 new PaymentRequest([], {
32 total: {
33 label: '',
34 amount: {
35 currency: 'USD',
36 value: '1.00',
37 },
38 },
39 });
40 });
41 }, 'If the length of the methodData sequence is zero, then throw a TypeError');
42
43 test(() => {
44 assert_throws({
45 name: 'TypeError',
46 },
47 () => {
48 new PaymentRequest([{
49 supportedMethods: [],
50 }], {
51 total: {
52 label: '',
53 amount: {
54 currency: 'USD',
55 value: '1.00',
56 },
57 },
58 });
59 });
60 }, 'If the length of the paymentMethod.supportedMethods sequence is zero, ' +
61 'then throw a TypeError');
62
63 test(() => {
64 new PaymentRequest([{
65 supportedMethods: ['basic-card'],
66 data: ['some-data'],
67 }], {
68 total: {
69 label: '',
70 amount: {
71 currency: 'USD',
72 value: '1.00',
73 },
74 },
75 });
76 }, 'Method data must be JSON-serializable object (a list in this case)');
77
78 test(() => {
79 new PaymentRequest([{
80 supportedMethods: ['basic-card'],
81 data: {
82 some: 'data',
83 },
84 }], {
85 total: {
86 label: '',
87 amount: {
88 currency: 'USD',
89 value: '1.00',
90 },
91 },
92 });
93 }, 'Method data must be JSON-serializable object (a dictionary in this case)');
94
95 test(() => {
96 const recursiveDictionary = {};
97 recursiveDictionary.foo = recursiveDictionary;
98 assert_throws({
99 name: 'TypeError',
100 },
101 () => {
102 new PaymentRequest([{
103 supportedMethods: ['basic-card'],
104 data: recursiveDictionary,
105 }], {
106 total: {
107 label: '',
108 amount: {
109 currency: 'USD',
110 value: '1.00',
111 },
112 },
113 });
114 });
115 assert_throws({
116 name: 'TypeError',
117 },
118 () => {
119 new PaymentRequest([{
120 supportedMethods: ['basic-card'],
121 data: 'a string',
122 }], {
123 total: {
124 label: '',
125 amount: {
126 currency: 'USD',
127 value: '1.00',
128 },
129 },
130 });
131 });
132 }, 'Rethrow any exceptions of JSON-serializing paymentMethod.data into ' +
133 'a string');
134
135 const invalidMonetaryAmounts = ['-', 'notdigits', 'ALSONOTDIGITS', '10.', '.99',
136 '-10.', '-.99', '10-', '1-0', '1.0.0', '1/3', '', null,
137 ];
138 for (const amount of invalidMonetaryAmounts) {
139 test(() => {
140 assert_throws({
141 name: 'TypeError',
142 },
143 () => {
144 new PaymentRequest([{
145 supportedMethods: ['basic-card'],
146 }], {
147 total: {
148 label: '',
149 amount: {
150 currency: 'USD',
151 value: amount,
152 },
153 },
154 });
155 });
156 }, 'If details.total.amount.value is not a valid decimal monetary value ' +
157 '(in this case "' + amount + '"), then throw a TypeError');
158 }
159
160 test(() => {
161 assert_throws({
162 name: 'TypeError',
163 },
164 () => {
165 new PaymentRequest([{
166 supportedMethods: ['basic-card'],
167 }], {
168 total: {
169 label: '',
170 amount: {
171 currency: 'USD',
172 value: '-1.00',
173 },
174 },
175 });
176 });
177 }, 'If the first character of details.total.amount.value is ' +
178 'U+002D HYPHEN-MINUS, then throw a TypeError');
179
180 for (const amount of invalidMonetaryAmounts) {
181 test(() => {
182 assert_throws({
183 name: 'TypeError',
184 },
185 () => {
186 new PaymentRequest([{
187 supportedMethods: ['basic-card'],
188 }], {
189 total: {
190 label: '',
191 amount: {
192 currency: 'USD',
193 value: '1.00',
194 },
195 },
196 displayItems: [{
197 label: '',
198 amount: {
199 currency: 'USD',
200 value: amount,
201 },
202 }],
203 });
204 });
205 }, 'For each item in details.displayItems: if item.amount.value is not ' +
206 'a valid decimal monetary value (in this case "' + amount +
207 '"), then throw a TypeError');
208 }
209
210 test(() => {
211 new PaymentRequest([{
212 supportedMethods: ['basic-card'],
213 }], {
214 total: {
215 label: '',
216 amount: {
217 currency: 'USD',
218 value: '1.00',
219 },
220 },
221 modifiers: [{
222 supportedMethods: ['basic-card'],
223 data: ['some-data'],
224 }],
225 });
226 }, 'Modifier data must be JSON-serializable object (a list in this case)');
227
228 test(() => {
229 new PaymentRequest([{
230 supportedMethods: ['basic-card'],
231 }], {
232 total: {
233 label: '',
234 amount: {
235 currency: 'USD',
236 value: '1.00',
237 },
238 },
239 modifiers: [{
240 supportedMethods: ['basic-card'],
241 data: {
242 some: 'data',
243 },
244 }],
245 });
246 }, 'Modifier data must be JSON-serializable object (a dictionary in this ' +
247 'case)');
248
249 test(() => {
250 const recursiveDictionary = {};
251 recursiveDictionary.foo = recursiveDictionary;
252 assert_throws({
253 name: 'TypeError',
254 },
255 () => {
256 new PaymentRequest([{
257 supportedMethods: ['basic-card'],
258 }], {
259 total: {
260 label: '',
261 amount: {
262 currency: 'USD',
263 value: '1.00',
264 },
265 },
266 modifiers: [{
267 supportedMethods: ['basic-card'],
268 data: recursiveDictionary,
269 }],
270 });
271 });
272 assert_throws({
273 name: 'TypeError',
274 },
275 () => {
276 new PaymentRequest([{
277 supportedMethods: ['basic-card'],
278 }], {
279 total: {
280 label: '',
281 amount: {
282 currency: 'USD',
283 value: '1.00',
284 },
285 },
286 modifiers: [{
287 supportedMethods: ['basic-card'],
288 data: 'a string',
289 }],
290 });
291 });
292 }, 'Rethrow any exceptions of JSON-serializing modifier.data into a string');
293
294 test(() => {
295 assert_throws({
296 name: 'TypeError',
297 },
298 () => {
299 new PaymentRequest([{
300 supportedMethods: ['basic-card'],
301 }], {});
302 });
303 }, 'Total is required');
304
305 test(() => {
306 assert_throws({
307 name: 'TypeError',
308 },
309 () => {
310 new PaymentRequest([{
311 supportedMethods: ['basic-card'],
312 }], {
313 total: {
314 amount: {
315 currency: 'USD',
316 value: '1.00',
317 },
318 },
319 });
320 });
321 }, 'Label is required');
322
323 test(() => {
324 assert_throws({
325 name: 'TypeError',
326 },
327 () => {
328 new PaymentRequest([{
329 supportedMethods: ['basic-card'],
330 }], {
331 total: {
332 label: '',
333 },
334 });
335 });
336 }, 'Amount is required');
337
338 test(() => {
339 assert_throws({
340 name: 'TypeError',
341 },
342 () => {
343 new PaymentRequest([{
344 supportedMethods: ['basic-card'],
345 }], {
346 total: {
347 label: '',
348 amount: {
349 currency: 'USD',
350 },
351 },
352 });
353 });
354 }, 'Amount value is required');
355
356 test(() => {
357 assert_throws({
358 name: 'TypeError',
359 },
360 () => {
361 new PaymentRequest([{
362 supportedMethods: ['basic-card'],
363 }], {
364 total: {
365 label: '',
366 amount: {
367 value: '1.00',
368 },
369 },
370 });
371 });
372 }, 'Amount currency is required');
373
374 test(() => {
375 assert_throws({
376 name: 'TypeError',
377 },
378 () => {
379 new PaymentRequest([{
380 supportedMethods: ['basic-card'],
381 }], {
382 total: {
383 label: '',
384 amount: {
385 currency: 'USD',
386 value: '1.00',
387 },
388 },
389 }, {
390 shippingType: 'invalid',
391 });
392 });
393 }, 'Shipping type should be valid');
394 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698