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

Side by Side Diff: third_party/WebKit/LayoutTests/payments/payment-request-interface.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
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <meta charset="utf-8"> 2 <meta charset="utf-8">
3 <title>Tests for PaymentRequest interface</title> 3 <title>Tests for PaymentRequest interface</title>
4 <script src="../resources/testharness.js"></script> 4 <script src="../resources/testharness.js"></script>
5 <script src="../resources/testharnessreport.js"></script> 5 <script src="../resources/testharnessreport.js"></script>
6 <script> 6 <script>
7 function substitute(originalObject, substituteKeyValuePairs) { 7 function substitute(originalObject, substituteKeyValuePairs) {
8 for (var key in originalObject) { 8 for (var key in originalObject) {
9 if (originalObject.hasOwnProperty(key) && substituteKeyValuePairs.hasOwn Property(key)) { 9 if (originalObject.hasOwnProperty(key) && substituteKeyValuePairs.hasOwn Property(key)) {
10 originalObject[key] = substituteKeyValuePairs[key]; 10 originalObject[key] = substituteKeyValuePairs[key];
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 }, 'Android Pay parameters for network token without environment key should not throw.'); 265 }, 'Android Pay parameters for network token without environment key should not throw.');
266 266
267 test(function() { 267 test(function() {
268 new PaymentRequest([{'supportedMethods': ['https://bobpay.com'], 'data': {'a llowedCardNetworks': 0}}], buildDetails()); 268 new PaymentRequest([{'supportedMethods': ['https://bobpay.com'], 'data': {'a llowedCardNetworks': 0}}], buildDetails());
269 }, 'Invalid Android Pay parameters should not throw when method name is not "htt ps://android.com/pay".'); 269 }, 'Invalid Android Pay parameters should not throw when method name is not "htt ps://android.com/pay".');
270 270
271 test(function() { 271 test(function() {
272 new PaymentRequest([{'supportedMethods': ['https://android.com/pay'], 'data' : {'allowedCardNetworks': 0}}], buildDetails()); 272 new PaymentRequest([{'supportedMethods': ['https://android.com/pay'], 'data' : {'allowedCardNetworks': 0}}], buildDetails());
273 }, 'Invalid Android Pay parameters should not throw even when method name is "ht tps://android.com/pay".'); 273 }, 'Invalid Android Pay parameters should not throw even when method name is "ht tps://android.com/pay".');
274 274
275 test(function() {
276 new PaymentRequest([{'supportedMethods': ['foo'], 'data': []}], buildDetails ());
277 }, 'Array value for payment method specific data parameter should not throw');
278
275 promise_test(function(t) { 279 promise_test(function(t) {
276 return promise_rejects(t, null, new PaymentRequest([{'supportedMethods': ['f oo']}], buildDetails()).abort()); 280 return promise_rejects(t, null, new PaymentRequest([{'supportedMethods': ['f oo']}], buildDetails()).abort());
277 }, 'abort() without show() should reject with error'); 281 }, 'abort() without show() should reject with error');
278 282
279 generate_tests(assert_throws, [ 283 generate_tests(assert_throws, [
280 ['PaymentRequest constructor should throw for incorrect parameter types.', n ull, function() { 284 ['PaymentRequest constructor should throw for incorrect parameter types.', n ull, function() {
281 new PaymentRequest('', '', '') 285 new PaymentRequest('', '', '')
282 }], 286 }],
283 ['PaymentRequest constructor should throw for undefined required parameters. ', null, function() { 287 ['PaymentRequest constructor should throw for undefined required parameters. ', null, function() {
284 new PaymentRequest(undefined, undefined) 288 new PaymentRequest(undefined, undefined)
(...skipping 21 matching lines...) Expand all
306 }], 310 }],
307 ['Undefined supportedMethods in modifiers should throw TypeError.', null, fu nction() { 311 ['Undefined supportedMethods in modifiers should throw TypeError.', null, fu nction() {
308 new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem( ), 'modifiers': [{'supportedMethods': undefined}]}) 312 new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem( ), 'modifiers': [{'supportedMethods': undefined}]})
309 }], 313 }],
310 ['Empty supportedMethods in modifiers should throw TypeError.', null, functi on() { 314 ['Empty supportedMethods in modifiers should throw TypeError.', null, functi on() {
311 new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem( ), 'modifiers': [{'supportedMethods': []}]}) 315 new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem( ), 'modifiers': [{'supportedMethods': []}]})
312 }], 316 }],
313 ['Absence of supportedMethods in modifiers should throw TypeError.', null, f unction() { 317 ['Absence of supportedMethods in modifiers should throw TypeError.', null, f unction() {
314 new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem( ), 'modifiers': [{'total': buildItem()}]}) 318 new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem( ), 'modifiers': [{'total': buildItem()}]})
315 }], 319 }],
316 ['Empty modifiers should throw TypeError.', null, function() {
317 new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem( ), 'modifiers': []})
318 }],
319 ['Empty details should throw', null, function() { 320 ['Empty details should throw', null, function() {
320 new PaymentRequest([{'supportedMethods': ['foo']}], {}) 321 new PaymentRequest([{'supportedMethods': ['foo']}], {})
321 }], 322 }],
322 ['Null items should throw', new TypeError(), function() { 323 ['Null items should throw', new TypeError(), function() {
323 new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem( ), 'displayItems': null}); 324 new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem( ), 'displayItems': null});
324 }], 325 }],
325 ['Null shipping options should throw', new TypeError(), function() { 326 ['Null shipping options should throw', new TypeError(), function() {
326 new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem( ), 'displayItems': [buildItem()], 'shippingOptions': null}); 327 new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem( ), 'displayItems': [buildItem()], 'shippingOptions': null});
327 }], 328 }],
328 ['Undefined PaymentShippingType value for shppingType should throw a TypeErr or', new TypeError(), function() { 329 ['Undefined PaymentShippingType value for shppingType should throw a TypeErr or', new TypeError(), function() {
329 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildD etails(), {'requestShipping': true, 'shippingType': 'invalid'}); 330 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildD etails(), {'requestShipping': true, 'shippingType': 'invalid'});
330 }], 331 }],
331 ['Null for shppingType should throw a TypeError', new TypeError(), function( ) { 332 ['Null for shppingType should throw a TypeError', new TypeError(), function( ) {
332 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildD etails(), {'requestShipping': true, 'shippingType': null}); 333 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildD etails(), {'requestShipping': true, 'shippingType': null});
333 }], 334 }],
334 ['Array value for shppingType should throw a TypeError', new TypeError(), fu nction() { 335 ['Array value for shppingType should throw a TypeError', new TypeError(), fu nction() {
335 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildD etails(), {'requestShipping': true, 'shippingType': []}); 336 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildD etails(), {'requestShipping': true, 'shippingType': []});
336 }], 337 }],
337 ['Object value for shppingType should throw a TypeError', new TypeError(), f unction() { 338 ['Object value for shppingType should throw a TypeError', new TypeError(), f unction() {
338 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildD etails(), {'requestShipping': true, 'shippingType': {}}); 339 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildD etails(), {'requestShipping': true, 'shippingType': {}});
339 }], 340 }],
340 ['Numeric value for shppingType should throw a TypeError', new TypeError(), function() { 341 ['Numeric value for shppingType should throw a TypeError', new TypeError(), function() {
341 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildD etails(), {'requestShipping': true, 'shippingType': 0}); 342 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildD etails(), {'requestShipping': true, 'shippingType': 0});
342 }], 343 }],
343 344
344 // Payment method specific data should be a JSON-serializable object. 345 // Payment method specific data should be a JSON-serializable object.
345 ['Array value for payment method specific data parameter should throw', null , function() {
346 new PaymentRequest([{'supportedMethods': ['foo'], 'data': []}], buildDet ails(), {})
347 }],
348 ['String value for payment method specific data parameter should throw', nul l, function() { 346 ['String value for payment method specific data parameter should throw', nul l, function() {
349 new PaymentRequest([{'supportedMethods': ['foo'], 'data': 'foo'}], build Details(), {}) 347 new PaymentRequest([{'supportedMethods': ['foo'], 'data': 'foo'}], build Details(), {})
350 }], 348 }],
351 ['Numeric value for payment method specific data parameter should throw', nu ll, function() { 349 ['Numeric value for payment method specific data parameter should throw', nu ll, function() {
352 new PaymentRequest([{'supportedMethods': ['foo'], 'data': 42}], buildDet ails(), {}) 350 new PaymentRequest([{'supportedMethods': ['foo'], 'data': 42}], buildDet ails(), {})
353 }], 351 }],
354 ['Infinite JSON value for one of the payment method specific data pieces sho uld throw', null, function() { 352 ['Infinite JSON value for one of the payment method specific data pieces sho uld throw', null, function() {
355 var infiniteData = {'foo': {}}; 353 var infiniteData = {'foo': {}};
356 infiniteData.foo = infiniteData; 354 infiniteData.foo = infiniteData;
357 new PaymentRequest([{'supportedMethods': ['foo'], 'data': infiniteData}] , buildDetails()) 355 new PaymentRequest([{'supportedMethods': ['foo'], 'data': infiniteData}] , buildDetails())
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 }], 409 }],
412 ['Null amount in ' + detailNames[i] + ' should throw', null, function() { 410 ['Null amount in ' + detailNames[i] + ' should throw', null, function() {
413 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': null}), {requestShipping: true}) 411 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': null}), {requestShipping: true})
414 }], 412 }],
415 ['Undefined amount in ' + detailNames[i] + ' should throw', null, functi on() { 413 ['Undefined amount in ' + detailNames[i] + ' should throw', null, functi on() {
416 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': undefined}), {requestShipping: true}) 414 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': undefined}), {requestShipping: true})
417 }], 415 }],
418 ]); 416 ]);
419 } 417 }
420 </script> 418 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698