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

Side by Side Diff: third_party/WebKit/LayoutTests/payments/payment-request-interface.html

Issue 2045833002: Add 'selected' boolean to 'ShippingOption' (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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, substituteKeyValuePair) { 7 function substitute(originalObject, substituteKeyValuePairs) {
8 for (var key in originalObject) { 8 for (var key in originalObject) {
9 if (originalObject.hasOwnProperty(key) && substituteKeyValuePair.hasOwnP roperty(key)) { 9 if (originalObject.hasOwnProperty(key) && substituteKeyValuePairs.hasOwn Property(key)) {
10 originalObject[key] = substituteKeyValuePair[key]; 10 originalObject[key] = substituteKeyValuePairs[key];
11 } 11 }
12 } 12 }
13 } 13 }
14 14
15 function buildItem(optionalSubstituteKeyValuePair) { 15 function buildItem(optionalSubstituteKeyValuePairs) {
16 var item = {'id': 'item_id', 'label': 'Item Description', 'amount': {'curren cy': 'USD', 'value': '10.00'}}; 16 var item = {
17 'id': 'item_id',
18 'label': 'Item Description',
19 'amount': {
20 'currency': 'USD',
21 'value': '10.00'
22 },
23 'selected': false
24 };
17 25
18 if (optionalSubstituteKeyValuePair) { 26 if (optionalSubstituteKeyValuePairs) {
19 substitute(item, optionalSubstituteKeyValuePair); 27 for (var key in optionalSubstituteKeyValuePairs) {
20 substitute(item['amount'], optionalSubstituteKeyValuePair); 28 assert_true(item.hasOwnProperty(key) || item['amount'].hasOwnPropert y(key), 'Unrecognized substitution key "' + key + '"');
29 }
30
31 substitute(item, optionalSubstituteKeyValuePairs);
32 substitute(item['amount'], optionalSubstituteKeyValuePairs);
21 } 33 }
22 34
23 return item; 35 return item;
24 } 36 }
25 37
26 function buildDetails(optionalDetailName, optionalSubstituteKeyValuePair) { 38 function buildDetails(optionalDetailName, optionalSubstituteKeyValuePairs) {
27 var details = {}; 39 var details = {};
28 var detailNames = ['total', 'displayItems', 'shippingOptions']; 40 var detailNames = ['total', 'displayItems', 'shippingOptions'];
29 41
30 assert_true(!optionalDetailName || detailNames.indexOf(optionalDetailName) > = 0, 'Detail name "' + optionalDetailName + '" should be either "total", "displa yItems", or "shippingOptions".'); 42 assert_true(!optionalDetailName || detailNames.indexOf(optionalDetailName) > = 0, 'Detail name "' + optionalDetailName + '" should be either "total", "displa yItems", or "shippingOptions".');
31 43
32 for (var i in detailNames) { 44 for (var i in detailNames) {
33 if (optionalDetailName == detailNames[i]) { 45 if (optionalDetailName == detailNames[i]) {
34 if (detailNames[i] == 'total') { 46 if (detailNames[i] == 'total') {
35 details[detailNames[i]] = buildItem(optionalSubstituteKeyValuePa ir); 47 details[detailNames[i]] = buildItem(optionalSubstituteKeyValuePa irs);
36 } else { 48 } else {
37 details[detailNames[i]] = [buildItem(optionalSubstituteKeyValueP air)]; 49 details[detailNames[i]] = [buildItem(optionalSubstituteKeyValueP airs)];
38 } 50 }
39 } else { 51 } else {
40 if (detailNames[i] == 'total') { 52 if (detailNames[i] == 'total') {
41 details[detailNames[i]] = buildItem(); 53 details[detailNames[i]] = buildItem();
42 } else { 54 } else {
43 details[detailNames[i]] = [buildItem()]; 55 details[detailNames[i]] = [buildItem()];
44 } 56 }
45 } 57 }
46 } 58 }
47 59
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 var request = new PaymentRequest(['foo'], buildDetails('shippingOptions', {' id': 'standard'})); 114 var request = new PaymentRequest(['foo'], buildDetails('shippingOptions', {' id': 'standard'}));
103 assert_equals(null, request.shippingOption); 115 assert_equals(null, request.shippingOption);
104 }, 'Shipping option identifier should be null if shipping request is omitted.'); 116 }, 'Shipping option identifier should be null if shipping request is omitted.');
105 117
106 test(function() { 118 test(function() {
107 var request = new PaymentRequest(['foo'], buildDetails('shippingOptions', {' id': 'standard'}), {'requestShipping': false}); 119 var request = new PaymentRequest(['foo'], buildDetails('shippingOptions', {' id': 'standard'}), {'requestShipping': false});
108 assert_equals(null, request.shippingOption); 120 assert_equals(null, request.shippingOption);
109 }, 'Shipping option identifier should be null if shipping is explicitly not requ ested.'); 121 }, 'Shipping option identifier should be null if shipping is explicitly not requ ested.');
110 122
111 test(function() { 123 test(function() {
112 var request = new PaymentRequest(['foo'], buildDetails('shippingOptions', {' id': 'standard'}), {'requestShipping': true});
113 assert_equals('standard', request.shippingOption);
114 }, 'Shipping option identifier should default to the single provided option.');
115
116 test(function() {
117 var request = new PaymentRequest(['foo'], {'total': buildItem(), 'displayIte ms': [buildItem()]}, {'requestShipping': true}); 124 var request = new PaymentRequest(['foo'], {'total': buildItem(), 'displayIte ms': [buildItem()]}, {'requestShipping': true});
118 assert_equals(null, request.shippingOption); 125 assert_equals(null, request.shippingOption);
119 }, 'Shipping option identifier should be null when no shipping options are provi ded.'); 126 }, 'Shipping option identifier should be null if no shipping options are provide d.');
120 127
121 test(function() { 128 test(function() {
122 var request = new PaymentRequest(['foo'], {'total': buildItem(), 'displayIte ms': [buildItem()], 'shippingOptions': [buildItem({'id': 'standard'}), buildItem ({'id': 'express'})]}, {'requestShipping': true}); 129 var request = new PaymentRequest(['foo'], buildDetails('shippingOptions', {' selected': false}), {'requestShipping': true});
123 assert_equals(null, request.shippingOption); 130 assert_equals(null, request.shippingOption);
124 }, 'Shipping option identifier should be null at first when multiple shipping op tions are provided.'); 131 }, 'Shipping option identifier should be null if the single provided option is n ot selected.');
132
133 test(function() {
134 var request = new PaymentRequest(['foo'], buildDetails('shippingOptions', {' id': 'standard', 'selected': true}), {'requestShipping': true});
135 assert_equals('standard', request.shippingOption);
136 }, 'Shipping option identifier should default to the single provided option if i t is selected.');
137
138 test(function() {
139 var shippingOptions = [buildItem({'id': 'standard'}), buildItem({'id': 'expr ess'})];
140 var request = new PaymentRequest(['foo'], {'total': buildItem(), 'displayIte ms': [buildItem()], 'shippingOptions': shippingOptions}, {'requestShipping': tru e});
141 assert_equals(null, request.shippingOption);
142 }, 'Shipping option identifier should be null if multiple unselected shipping op tions are provided.');
143
144 test(function() {
145 var shippingOptions = [buildItem({'id': 'standard', 'selected': true}), buil dItem({'id': 'express'})];
146 var request = new PaymentRequest(['foo'], {'total': buildItem(), 'displayIte ms': [buildItem()], 'shippingOptions': shippingOptions}, {'requestShipping': tru e});
147 assert_equals('standard', request.shippingOption);
148 }, 'Shipping option identifier should default to the selected shipping option.') ;
149
150 test(function() {
151 var shippingOptions = [buildItem({'id': 'standard', 'selected': true}), buil dItem({'id': 'express', 'selected': true})];
152 var request = new PaymentRequest(['foo'], {'total': buildItem(), 'displayIte ms': [buildItem()], 'shippingOptions': shippingOptions}, {'requestShipping': tru e});
153 assert_equals('express', request.shippingOption);
154 }, 'Shipping option identifier should default to the last selected shipping opti on, if multiple are selected.');
125 155
126 test(function() { 156 test(function() {
127 new PaymentRequest(['foo'], {'total': buildItem(), 'displayItems': undefined }); 157 new PaymentRequest(['foo'], {'total': buildItem(), 'displayItems': undefined });
128 }, 'Undefined display items should not throw.'); 158 }, 'Undefined display items should not throw.');
129 159
130 test(function() { 160 test(function() {
131 new PaymentRequest(['foo'], {'total': buildItem(), 'displayItems': []}); 161 new PaymentRequest(['foo'], {'total': buildItem(), 'displayItems': []});
132 }, 'Empty display items should not throw.'); 162 }, 'Empty display items should not throw.');
133 163
134 test(function() { 164 test(function() {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 }], 303 }],
274 ['Null amount should throw', null, function() { 304 ['Null amount should throw', null, function() {
275 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': n ull})) 305 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': n ull}))
276 }], 306 }],
277 ['Undefined amount should throw', null, function() { 307 ['Undefined amount should throw', null, function() {
278 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': u ndefined})) 308 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': u ndefined}))
279 }], 309 }],
280 ]); 310 ]);
281 } 311 }
282 </script> 312 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698