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

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

Issue 2020883002: PaymentRequest: Introduce PaymentMethodData. (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, substituteKeyValuePair) {
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) && substituteKeyValuePair.hasOwnP roperty(key)) {
10 originalObject[key] = substituteKeyValuePair[key]; 10 originalObject[key] = substituteKeyValuePair[key];
(...skipping 21 matching lines...) Expand all
32 details[detailNames[i]] = [buildItem(optionalSubstituteKeyValuePair) ]; 32 details[detailNames[i]] = [buildItem(optionalSubstituteKeyValuePair) ];
33 } else { 33 } else {
34 details[detailNames[i]] = [buildItem()]; 34 details[detailNames[i]] = [buildItem()];
35 } 35 }
36 } 36 }
37 37
38 return details; 38 return details;
39 } 39 }
40 40
41 test(function() { 41 test(function() {
42 new PaymentRequest(['foo'], buildDetails(), {}, {}); 42 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(), {});
43 }, 'Creating a PaymentRequest with empty parameters should not throw or crash.') ; 43 }, 'Creating a PaymentRequest with empty parameters should not throw or crash.') ;
44 44
45 test(function() { 45 test(function() {
46 new PaymentRequest(['foo'], buildDetails(), {}, {}, ''); 46 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(), {}, '');
47 }, 'Creating a PaymentRequest with extra parameters should not throw or crash.') ; 47 }, 'Creating a PaymentRequest with extra parameters should not throw or crash.') ;
48 48
49 test(function() { 49 test(function() {
50 new PaymentRequest(['foo'], buildDetails()); 50 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails());
51 }, 'Creating a PaymentRequest with omitted optional parameters should not throw or crash.'); 51 }, 'Creating a PaymentRequest with omitted optional parameters should not throw or crash.');
52 52
53 test(function() { 53 test(function() {
54 new PaymentRequest(['foo'], buildDetails(), undefined, undefined); 54 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(), undefine d);
55 }, 'Creating a PaymentRequest with undefined optional parameters should not thro w or crash.'); 55 }, 'Creating a PaymentRequest with undefined optional parameters should not thro w or crash.');
56 56
57 test(function() { 57 test(function() {
58 new PaymentRequest(['foo'], buildDetails(), null, null); 58 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(), null);
59 }, 'Creating a PaymentRequest with null optional parameters should not throw or crash.'); 59 }, 'Creating a PaymentRequest with null optional parameters should not throw or crash.');
60 60
61 test(function() { 61 test(function() {
62 var request = new PaymentRequest(['foo'], buildDetails()); 62 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai ls());
63 assert_readonly(request, 'shippingAddress', 'PaymentRequest should have a re adonly shippingAddress property.'); 63 assert_readonly(request, 'shippingAddress', 'PaymentRequest should have a re adonly shippingAddress property.');
64 assert_readonly(request, 'shippingOption', 'PaymentRequest should have a rea donly shippingOption property.'); 64 assert_readonly(request, 'shippingOption', 'PaymentRequest should have a rea donly shippingOption property.');
65 }, 'PaymentRequest should have readonly shippingAddress and shippingOption prope rties.'); 65 }, 'PaymentRequest should have readonly shippingAddress and shippingOption prope rties.');
66 66
67 test(function() { 67 test(function() {
68 var request = new PaymentRequest(['foo'], buildDetails()); 68 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai ls());
69 assert_not_equals(request.onshippingaddresschange, undefined, 'PaymentReques t should have onShippingAddressChange event.'); 69 assert_not_equals(request.onshippingaddresschange, undefined, 'PaymentReques t should have onShippingAddressChange event.');
70 assert_not_equals(request.onshippingoptionchange, undefined, 'PaymentRequest should have onShippingOptionChange event.'); 70 assert_not_equals(request.onshippingoptionchange, undefined, 'PaymentRequest should have onShippingOptionChange event.');
71 }, 'PaymentRequest should have onShippingAddressChange and onShippingOptionChang e events.'); 71 }, 'PaymentRequest should have onShippingAddressChange and onShippingOptionChang e events.');
72 72
73 test(function() { 73 test(function() {
74 var request = new PaymentRequest(['foo'], buildDetails()); 74 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai ls());
75 assert_not_equals(request.abort, undefined, 'PaymentRequest should have abor t() method.'); 75 assert_not_equals(request.abort, undefined, 'PaymentRequest should have abor t() method.');
76 assert_not_equals(request.show, undefined, 'PaymentRequest should have show( ) method.'); 76 assert_not_equals(request.show, undefined, 'PaymentRequest should have show( ) method.');
77 }, 'PaymentRequest should have methods abort() and show().'); 77 }, 'PaymentRequest should have methods abort() and show().');
78 78
79 test(function() { 79 test(function() {
80 var request = new PaymentRequest(['foo'], buildDetails()); 80 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai ls());
81 request.show(); 81 request.show();
82 request.abort(); 82 request.abort();
83 }, 'PaymentRequest.abort() and PaymentRequest.show() should take no parameters.' ); 83 }, 'PaymentRequest.abort() and PaymentRequest.show() should take no parameters.' );
84 84
85 test(function() { 85 test(function() {
86 var request = new PaymentRequest(['foo'], buildDetails(), {'requestShipping' : true}, {'foo': {'gateway': 'bar'}}); 86 var request = new PaymentRequest([{'supportedMethods': ['foo'], 'data': {'fo o': {'gateway': 'bar'}}}], buildDetails(), {'requestShipping': true});
87 request.show(); 87 request.show();
88 request.abort(); 88 request.abort();
89 }, 'Valid data causes no errors.'); 89 }, 'Valid data causes no errors.');
90 90
91 test(function() { 91 test(function() {
92 var request = new PaymentRequest(['foo'], buildDetails('shippingOptions', {' id': 'standard'})); 92 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai ls('shippingOptions', {'id': 'standard'}));
93 assert_equals(null, request.shippingOption); 93 assert_equals(null, request.shippingOption);
94 }, 'Shipping option identifier should be null if shipping request is omitted.'); 94 }, 'Shipping option identifier should be null if shipping request is omitted.');
95 95
96 test(function() { 96 test(function() {
97 var request = new PaymentRequest(['foo'], buildDetails('shippingOptions', {' id': 'standard'}), {'requestShipping': false}); 97 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai ls('shippingOptions', {'id': 'standard'}), {'requestShipping': false});
98 assert_equals(null, request.shippingOption); 98 assert_equals(null, request.shippingOption);
99 }, 'Shipping option identifier should be null if shipping is explicitly not requ ested.'); 99 }, 'Shipping option identifier should be null if shipping is explicitly not requ ested.');
100 100
101 test(function() { 101 test(function() {
102 var request = new PaymentRequest(['foo'], buildDetails('shippingOptions', {' id': 'standard'}), {'requestShipping': true}); 102 var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetai ls('shippingOptions', {'id': 'standard'}), {'requestShipping': true});
103 assert_equals('standard', request.shippingOption); 103 assert_equals('standard', request.shippingOption);
104 }, 'Shipping option identifier should default to the single provided option.'); 104 }, 'Shipping option identifier should default to the single provided option.');
105 105
106 test(function() { 106 test(function() {
107 var request = new PaymentRequest(['foo'], {"items": [buildItem()]}, {'reques tShipping': true}); 107 var request = new PaymentRequest([{'supportedMethods': ['foo']}], {"items": [buildItem()]}, {'requestShipping': true});
108 assert_equals(null, request.shippingOption); 108 assert_equals(null, request.shippingOption);
109 }, 'Shipping option identifier should be null when no shipping options are provi ded.'); 109 }, 'Shipping option identifier should be null when no shipping options are provi ded.');
110 110
111 test(function() { 111 test(function() {
112 var request = new PaymentRequest(['foo'], {'items': [buildItem()], 'shipping Options': [buildItem({'id': 'standard'}), buildItem({'id': 'express'})]}, {'requ estShipping': true}); 112 var request = new PaymentRequest([{'supportedMethods': ['foo']}], {'items': [buildItem()], 'shippingOptions': [buildItem({'id': 'standard'}), buildItem({'id ': 'express'})]}, {'requestShipping': true});
113 assert_equals(null, request.shippingOption); 113 assert_equals(null, request.shippingOption);
114 }, 'Shipping option identifier should be null at first when multiple shipping op tions are provided.'); 114 }, 'Shipping option identifier should be null at first when multiple shipping op tions are provided.');
115 115
116 116
117 generate_tests(assert_throws, [ 117 generate_tests(assert_throws, [
118 ['PaymentRequest constructor should throw for incorrect parameter types.', n ull, function() { 118 ['PaymentRequest constructor should throw for incorrect parameter types.', n ull, function() {
119 new PaymentRequest('', '', '', '') 119 new PaymentRequest('', '', '')
120 }], 120 }],
121 ['PaymentRequest constructor should throw for undefined required parameters. ', null, function() { 121 ['PaymentRequest constructor should throw for undefined required parameters. ', null, function() {
122 new PaymentRequest(undefined, undefined) 122 new PaymentRequest(undefined, undefined)
123 }], 123 }],
124 ['PaymentRequest constructor should throw for null required parameter.', nul l, function() { 124 ['PaymentRequest constructor should throw for null required parameter.', nul l, function() {
125 new PaymentRequest(null, null) 125 new PaymentRequest(null, null)
126 }], 126 }],
127 ['Empty list of supported payment method identifiers should throw TypeError. ', new TypeError(), function() { 127 ['Empty list of supported payment method identifiers should throw TypeError. ', new TypeError(), function() {
128 new PaymentRequest([], buildDetails()) 128 new PaymentRequest([], buildDetails())
129 }], 129 }],
130 ['Keys in payment method specific data object should match accepted method i dentifiers.', null, function() {
131 new PaymentRequest(['foo'], buildDetails(), {}, {'bar': {'gateway': 'baz '}})
132 }],
133 ['Empty details should throw', null, function() { 130 ['Empty details should throw', null, function() {
134 new PaymentRequest(['foo'], {}) 131 new PaymentRequest([{'supportedMethods': ['foo']}], {})
135 }], 132 }],
136 ['Empty items should throw', null, function() { 133 ['Empty items should throw', null, function() {
137 new PaymentRequest(['foo'], {'items': []}) 134 new PaymentRequest([{'supportedMethods': ['foo']}], {'items': []})
138 }], 135 }],
139 ['Aborting before showing should throw.', null, function() { 136 ['Aborting before showing should throw.', null, function() {
140 new PaymentRequest(['foo'], buildDetails()).abort() 137 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails()).abor t()
141 }], 138 }],
142 139
143 // Payment method specific data should be a JSON-serializable object. 140 // Payment method specific data should be a JSON-serializable object.
144 ['Array value for payment method specific data parameter should throw', null , function() { 141 ['Array value for payment method specific data parameter should throw', null , function() {
145 new PaymentRequest(['foo'], buildDetails(), {}, []) 142 new PaymentRequest([{'supportedMethods': ['foo'], 'data': []}], buildDet ails())
146 }], 143 }],
147 ['String value for payment method specific data parameter should throw', nul l, function() { 144 ['String value for payment method specific data parameter should throw', nul l, function() {
148 new PaymentRequest(['foo'], buildDetails(), {}, 'foo') 145 new PaymentRequest([{'supportedMethods': ['foo'], 'data': 'foo'}], build Details())
149 }], 146 }],
150 ['Numeric value for payment method specific data parameter should throw', nu ll, function() { 147 ['Numeric value for payment method specific data parameter should throw', nu ll, function() {
151 new PaymentRequest(['foo'], buildDetails(), {}, 42) 148 new PaymentRequest([{'supportedMethods': ['foo'], 'data': 42}], buildDet ails())
152 }], 149 }],
153 ['Infinite JSON value for one of the payment method specific data pieces sho uld throw', null, function() { 150 ['Infinite JSON value for one of the payment method specific data pieces sho uld throw', null, function() {
154 var infiniteData = {'foo': {}}; 151 var infiniteData = {'foo': {}};
155 infiniteData.foo = infiniteData; 152 infiniteData.foo = infiniteData;
156 new PaymentRequest(['foo'], buildDetails(), {}, infiniteData) 153 new PaymentRequest([{'supportedMethods': ['foo'], 'data': infiniteData}] , buildDetails())
157 }], 154 }],
158 155 ['undefined for payment method specific data parameter should throw', null, function() {
please use gerrit instead 2016/06/01 19:20:21 s/undefined/Undefined
159 // Values in payment method specific data object should be JSON-serializable objects. 156 new PaymentRequest([{'supportedMethods': ['foo'], 'data': undefined}], b uildDetails())
160 ['Array value for one of the payment method specific data pieces should thro w', null, function() {
161 new PaymentRequest(['foo'], buildDetails(), {}, {'foo': []})
162 }], 157 }],
163 ['String value for one of the payment method specific data pieces should thr ow', null, function() { 158 ['null for payment method specific data parameter should throw', null, funct ion() {
please use gerrit instead 2016/06/01 19:20:21 s/null/Null
164 new PaymentRequest(['foo'], buildDetails(), {}, {'foo': 'bar'}) 159 new PaymentRequest([{'supportedMethods': ['foo'], 'data': null}], buildD etails())
165 }], 160 }],
166 ['Numeric value for one of the payment method specific data pieces should th row', null, function() { 161 ['empty string for payment method specific data parameter should throw', nul l, function() {
please use gerrit instead 2016/06/01 19:20:21 s/empty/Empty
167 new PaymentRequest(['foo'], buildDetails(), {}, {'foo': 42}) 162 new PaymentRequest([{'supportedMethods': ['foo'], 'data': null}], buildD etails())
please use gerrit instead 2016/06/01 19:20:21 s/null/''
168 }], 163 }],
169 ]); 164 ]);
170 165
171 var detailNames = ['items', 'shippingOptions']; 166 var detailNames = ['items', 'shippingOptions'];
172 for (var i in detailNames) { 167 for (var i in detailNames) {
173 generate_tests(assert_throws, [ 168 generate_tests(assert_throws, [
174 // Invalid currency code formats. 169 // Invalid currency code formats.
175 ['Invalid currency code US1 should throw', null, function() { 170 ['Invalid currency code US1 should throw', null, function() {
176 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currency' : 'US1'})) 171 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'currency': 'US1'}))
177 }], 172 }],
178 ['Invalid currency code US should throw', null, function() { 173 ['Invalid currency code US should throw', null, function() {
179 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currency' : 'US'})) 174 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'currency': 'US'}))
180 }], 175 }],
181 ['Invalid currency code USDO should throw', null, function() { 176 ['Invalid currency code USDO should throw', null, function() {
182 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currency' : 'USDO'})) 177 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'currency': 'USDO'}))
183 }], 178 }],
184 ['Invalid currency code usd should throw', null, function() { 179 ['Invalid currency code usd should throw', null, function() {
185 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currency' : 'usd'})) 180 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'currency': 'usd'}))
186 }], 181 }],
187 ['Empty currency code should throw', null, function() { 182 ['Empty currency code should throw', null, function() {
188 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currency' : ''})) 183 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'currency': ''}))
189 }], 184 }],
190 ['Null currency code should throw', null, function() { 185 ['Null currency code should throw', null, function() {
191 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currency' : null})) 186 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'currency': null}))
192 }], 187 }],
193 ['Undefined currency code should throw', null, function() { 188 ['Undefined currency code should throw', null, function() {
194 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currency' : undefined})) 189 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'currency': undefined}))
195 }], 190 }],
196 191
197 // Invalid amount formats. 192 // Invalid amount formats.
198 ['Invalid amount "-" should throw', null, function() { 193 ['Invalid amount "-" should throw', null, function() {
199 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' -'})) 194 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': '-'}))
200 }], 195 }],
201 ['Invalid amount "notdigits" should throw', null, function() { 196 ['Invalid amount "notdigits" should throw', null, function() {
202 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' notdigits'})) 197 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': 'notdigits'}))
203 }], 198 }],
204 ['Invalid amount "ALSONOTDIGITS" should throw', null, function() { 199 ['Invalid amount "ALSONOTDIGITS" should throw', null, function() {
205 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' ALSONOTDIGITS'})) 200 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': 'ALSONOTDIGITS'}))
206 }], 201 }],
207 ['Invalid amount "10." should throw', null, function() { 202 ['Invalid amount "10." should throw', null, function() {
208 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' 10.'})) 203 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': '10.'}))
209 }], 204 }],
210 ['Invalid amount ".99" should throw', null, function() { 205 ['Invalid amount ".99" should throw', null, function() {
211 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' .99'})) 206 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': '.99'}))
212 }], 207 }],
213 ['Invalid amount "-10." should throw', null, function() { 208 ['Invalid amount "-10." should throw', null, function() {
214 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' -10.'})) 209 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': '-10.'}))
215 }], 210 }],
216 ['Invalid amount "-.99" should throw', null, function() { 211 ['Invalid amount "-.99" should throw', null, function() {
217 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' -.99'})) 212 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': '-.99'}))
218 }], 213 }],
219 ['Invalid amount "10-" should throw', null, function() { 214 ['Invalid amount "10-" should throw', null, function() {
220 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' 10-'})) 215 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': '10-'}))
221 }], 216 }],
222 ['Invalid amount "1-0" should throw', null, function() { 217 ['Invalid amount "1-0" should throw', null, function() {
223 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' 1-0'})) 218 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': '1-0'}))
224 }], 219 }],
225 ['Invalid amount "1.0.0" should throw', null, function() { 220 ['Invalid amount "1.0.0" should throw', null, function() {
226 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' 1.0.0'})) 221 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': '1.0.0'}))
227 }], 222 }],
228 ['Invalid amount "1/3" should throw', null, function() { 223 ['Invalid amount "1/3" should throw', null, function() {
229 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' 1/3'})) 224 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': '1/3'}))
230 }], 225 }],
231 ['Empty amount should throw', null, function() { 226 ['Empty amount should throw', null, function() {
232 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' '})) 227 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': ''}))
233 }], 228 }],
234 ['Null amount should throw', null, function() { 229 ['Null amount should throw', null, function() {
235 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': n ull})) 230 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': null}))
236 }], 231 }],
237 ['Undefined amount should throw', null, function() { 232 ['Undefined amount should throw', null, function() {
238 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': u ndefined})) 233 new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(det ailNames[i], {'value': undefined}))
239 }], 234 }],
240 ]); 235 ]);
241 } 236 }
242 </script> 237 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698