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

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

Powered by Google App Engine
This is Rietveld 408576698