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

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

Issue 1753543002: PaymentRequest Mojo bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@interface
Patch Set: haraken@'s + esprehn@'s comments Created 4 years, 8 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 test(function() { 7 function substitute(originalObject, substituteKeyValuePair) {
8 new PaymentRequest([], {}, {}, {}); 8 for (var key in originalObject) {
9 if (originalObject.hasOwnProperty(key) && substituteKeyValuePair.hasOwnP roperty(key)) {
10 originalObject[key] = substituteKeyValuePair[key];
11 }
12 }
13 }
14
15 function buildItem(optionalSubstituteKeyValuePair) {
16 var item = {'id': 'item_id', 'label': 'Item Description', 'amount': {'curren cyCode': 'USD', 'value': '10.00'}};
17
18 if (optionalSubstituteKeyValuePair) {
19 substitute(item, optionalSubstituteKeyValuePair);
20 substitute(item['amount'], optionalSubstituteKeyValuePair);
21 }
22
23 return item;
24 }
25
26 function buildDetails(optionalDetailName, optionalSubstituteKeyValuePair) {
27 var details = {};
28 var detailNames = ['items', 'shippingOptions'];
29
30 for (var i in detailNames) {
31 if (optionalDetailName == detailNames[i]) {
32 details[detailNames[i]] = [buildItem(optionalSubstituteKeyValuePair) ];
33 } else {
34 details[detailNames[i]] = [buildItem()];
35 }
36 }
37
38 return details;
39 }
40
41 test(function() {
42 new PaymentRequest(['foo'], buildDetails(), {}, {});
9 }, 'Creating a PaymentRequest with empty parameters should not throw or crash.') ; 43 }, 'Creating a PaymentRequest with empty parameters should not throw or crash.') ;
10 44
11 test(function() { 45 test(function() {
12 new PaymentRequest([], {}, {}, {}, ''); 46 new PaymentRequest(['foo'], buildDetails(), {}, {}, '');
13 }, 'Creating a PaymentRequest with extra parameters should not throw or crash.') ; 47 }, 'Creating a PaymentRequest with extra parameters should not throw or crash.') ;
14 48
15 test(function() { 49 test(function() {
16 new PaymentRequest([], {}); 50 new PaymentRequest(['foo'], buildDetails());
17 }, '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.');
18 52
19 test(function() { 53 test(function() {
20 new PaymentRequest([], {}, undefined, undefined); 54 new PaymentRequest(['foo'], buildDetails(), undefined, undefined);
21 }, '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.');
22 56
23 test(function() { 57 test(function() {
24 new PaymentRequest([], {}, null, null); 58 new PaymentRequest(['foo'], buildDetails(), null, null);
25 }, '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.');
26 60
61 test(function() {
62 var request = new PaymentRequest(['foo'], buildDetails());
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.');
65 }, 'PaymentRequest should have readonly shippingAddress and shippingOption prope rties.');
66
67 test(function() {
68 var request = new PaymentRequest(['foo'], buildDetails());
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.');
71 }, 'PaymentRequest should have onShippingAddressChange and onShippingOptionChang e events.');
72
73 test(function() {
74 var request = new PaymentRequest(['foo'], buildDetails());
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.');
77 }, 'PaymentRequest should have methods abort() and show().');
78
79 test(function() {
80 var request = new PaymentRequest(['foo'], buildDetails());
81 request.show();
82 request.abort();
83 }, 'PaymentRequest.abort() and PaymentRequest.show() should take no parameters.' );
84
85 test(function() {
86 var request = new PaymentRequest(['foo'], buildDetails(), {'requestShipping' : true}, {'foo': {'gateway': 'bar'}});
87 request.show();
88 request.abort();
89 }, 'Valid data causes no errors.');
90
91 test(function() {
92 var request = new PaymentRequest(['foo'], buildDetails('shippingOptions', {' id': 'standard'}));
93 assert_equals('standard', request.shippingOption);
94 }, 'Shipping option identifier should default to the single provided option.');
95
96 test(function() {
97 var request = new PaymentRequest(['foo'], {"items": [buildItem()]});
98 assert_equals(null, request.shippingOption);
99 }, 'Shipping option identifier should be null when no shipping options are provi ded.');
100
101 test(function() {
102 var request = new PaymentRequest(['foo'], {'items': [buildItem()], 'shipping Options': [buildItem({'id': 'standard'}), buildItem({'id': 'express'})]});
103 assert_equals(null, request.shippingOption);
104 }, 'Shipping option identifier should be null at first when multiple shipping op tions are provided.');
105
106
27 generate_tests(assert_throws, [ 107 generate_tests(assert_throws, [
28 ['PaymentRequest constructor should throw for incorrect parameter types.', n ull, function() { 108 ['PaymentRequest constructor should throw for incorrect parameter types.', n ull, function() {
29 new PaymentRequest('', '', '', '') 109 new PaymentRequest('', '', '', '')
30 }], 110 }],
31 ['PaymentRequest constructor should throw for undefined required parameters. ', null, function() { 111 ['PaymentRequest constructor should throw for undefined required parameters. ', null, function() {
32 new PaymentRequest(undefined, undefined) 112 new PaymentRequest(undefined, undefined)
33 }], 113 }],
34 ['PaymentRequest constructor should throw for null required parameter.', nul l, function() { 114 ['PaymentRequest constructor should throw for null required parameter.', nul l, function() {
35 new PaymentRequest(null, null) 115 new PaymentRequest(null, null)
36 }] 116 }],
117 ['Empty list of supported payment method identifiers should throw.', null, f unction() {
118 new PaymentRequest([], buildDetails())
119 }],
120 ['Keys in payment method specific data object should match accepted method i dentifiers.', null, function() {
121 new PaymentRequest(['foo'], buildDetails(), {}, {'bar': {'gateway': 'baz '}})
122 }],
123 ['Empty details should throw', null, function() {
124 new PaymentRequest(['foo'], {})
125 }],
126 ['Empty items should throw', null, function() {
127 new PaymentRequest(['foo'], {'items': []})
128 }],
129 ['Aborting before showing should throw.', null, function() {
130 new PaymentRequest(['foo'], buildDetails()).abort()
131 }],
132
133 // Payment method specific data should be a JSON-serializable object.
134 ['Array value for payment method specific data parameter should throw', null , function() {
135 new PaymentRequest(['foo'], buildDetails(), {}, [])
136 }],
137 ['String value for payment method specific data parameter should throw', nul l, function() {
138 new PaymentRequest(['foo'], buildDetails(), {}, 'foo')
139 }],
140 ['Numeric value for payment method specific data parameter should throw', nu ll, function() {
141 new PaymentRequest(['foo'], buildDetails(), {}, 42)
142 }],
143 ['Infinite JSON value for one of the payment method specific data pieces sho uld throw', null, function() {
144 var infiniteData = {'foo': {}};
145 infiniteData.foo = infiniteData;
146 new PaymentRequest(['foo'], buildDetails(), {}, infiniteData)
147 }],
148
149 // Values in payment method specific data object should be JSON-serializable objects.
150 ['Array value for one of the payment method specific data pieces should thro w', null, function() {
151 new PaymentRequest(['foo'], buildDetails(), {}, {'foo': []})
152 }],
153 ['String value for one of the payment method specific data pieces should thr ow', null, function() {
154 new PaymentRequest(['foo'], buildDetails(), {}, {'foo': 'bar'})
155 }],
156 ['Numeric value for one of the payment method specific data pieces should th row', null, function() {
157 new PaymentRequest(['foo'], buildDetails(), {}, {'foo': 42})
158 }],
37 ]); 159 ]);
38 160
39 test(function() { 161 var detailNames = ['items', 'shippingOptions'];
40 var request = new PaymentRequest([], {}); 162 for (var i in detailNames) {
41 assert_readonly(request, "shippingAddress", 'PaymentRequest should have a re adonly shippingAddress property.'); 163 generate_tests(assert_throws, [
42 assert_readonly(request, "shippingOption", 'PaymentRequest should have a rea donly shippingOption property.'); 164 // Invalid currency code formats.
43 }, 'PaymentRequest should have readonly shippingAddress and shippingOption prope rties.'); 165 ['Invalid currency code US1 should throw', null, function() {
44 166 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currencyC ode': 'US1'}))
45 test(function() { 167 }],
46 var request = new PaymentRequest([], {}); 168 ['Invalid currency code US should throw', null, function() {
47 assert_not_equals(request.onshippingaddresschange, undefined, 'PaymentReques t should have onShippingAddressChange event.'); 169 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currencyC ode': 'US'}))
48 assert_not_equals(request.onshippingoptionchange, undefined, 'PaymentRequest should have onShippingOptionChange event.'); 170 }],
49 }, 'PaymentRequest should have onShippingAddressChange and onShippingOptionChang e events.'); 171 ['Invalid currency code USDO should throw', null, function() {
50 172 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currencyC ode': 'USDO'}))
51 173 }],
52 test(function() { 174 ['Invalid currency code usd should throw', null, function() {
53 var request = new PaymentRequest([], {}); 175 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currencyC ode': 'usd'}))
54 assert_not_equals(request.abort, undefined, 'PaymentRequest should have abor t() method.'); 176 }],
55 assert_not_equals(request.show, undefined, 'PaymentRequest should have show( ) method.'); 177 ['Empty currency code should throw', null, function() {
56 }, 'PaymentRequest should have methods abort() and show().'); 178 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currencyC ode': ''}))
57 179 }],
58 test(function() { 180 ['Null currency code should throw', null, function() {
59 var request = new PaymentRequest([], {}); 181 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currencyC ode': null}))
60 request.abort(); 182 }],
61 request.show(); 183 ['Undefined currency code should throw', null, function() {
62 }, 'PaymentRequest.abort() and PaymentRequest.show() should take no parameters.' ); 184 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'currencyC ode': undefined}))
185 }],
186
187 // Invalid amount formats.
188 ['Invalid amount "-" should throw', null, function() {
189 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' -'}))
190 }],
191 ['Invalid amount "notdigits" should throw', null, function() {
192 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' notdigits'}))
193 }],
194 ['Invalid amount "ALSONOTDIGITS" should throw', null, function() {
195 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' ALSONOTDIGITS'}))
196 }],
197 ['Invalid amount "10." should throw', null, function() {
198 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' 10.'}))
199 }],
200 ['Invalid amount ".99" should throw', null, function() {
201 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' .99'}))
202 }],
203 ['Invalid amount "-10." should throw', null, function() {
204 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' -10.'}))
205 }],
206 ['Invalid amount "-.99" should throw', null, function() {
207 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' -.99'}))
208 }],
209 ['Invalid amount "10-" should throw', null, function() {
210 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' 10-'}))
211 }],
212 ['Invalid amount "1-0" should throw', null, function() {
213 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' 1-0'}))
214 }],
215 ['Invalid amount "1.0.0" should throw', null, function() {
216 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' 1.0.0'}))
217 }],
218 ['Invalid amount "1/3" should throw', null, function() {
219 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' 1/3'}))
220 }],
221 ['Empty amount should throw', null, function() {
222 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': ' '}))
223 }],
224 ['Null amount should throw', null, function() {
225 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': n ull}))
226 }],
227 ['Undefined amount should throw', null, function() {
228 new PaymentRequest(['foo'], buildDetails(detailNames[i], {'value': u ndefined}))
229 }],
230 ]);
231 }
63 </script> 232 </script>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/ScriptRegexp.h » ('j') | third_party/WebKit/Source/platform/DEPS » ('J')

Powered by Google App Engine
This is Rietveld 408576698