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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/payment-request/payment-request-constructor.https.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
(Empty)
1 <!DOCTYPE html>
2 <!-- Copyright © 2017 Chromium authors and World Wide Web Consortium, (Massachus etts Institute of Technology, ERCIM, Keio University, Beihang). -->
3 <meta charset="utf-8">
4 <title>Test for PaymentRequest Constructor</title>
5 <link rel="help" href="https://w3c.github.io/browser-payment-api/#constructor">
6 <script src="/resources/testharness.js"></script>
7 <script src="/resources/testharnessreport.js"></script>
8 <script>
9 'use strict';
10
11 test(() => {
12 assert_equals((new PaymentRequest([{
13 supportedMethods: ['basic-card'],
14 }], {
15 id: 'foo',
16 total: {
17 label: '',
18 amount: {
19 currency: 'USD',
20 value: '1.00',
21 },
22 },
23 })).id, 'foo');
24 }, 'Use provided request ID');
25
26 test(() => {
27 assert_throws({
28 name: 'TypeError',
29 },
30 () => {
31 new PaymentRequest([], {
32 total: {
33 label: '',
34 amount: {
35 currency: 'USD',
36 value: '1.00',
37 },
38 },
39 });
40 });
41 }, 'If the length of the methodData sequence is zero, then throw a TypeError');
42
43 test(() => {
44 assert_throws({
45 name: 'TypeError',
46 },
47 () => {
48 new PaymentRequest([{
49 supportedMethods: [],
50 }], {
51 total: {
52 label: '',
53 amount: {
54 currency: 'USD',
55 value: '1.00',
56 },
57 },
58 });
59 });
60 }, 'If the length of the paymentMethod.supportedMethods sequence is zero, ' +
61 'then throw a TypeError');
62
63 const invalidMonetaryAmounts = ['-', 'notdigits', 'ALSONOTDIGITS', '10.', '.99',
64 '-10.', '-.99', '10-', '1-0', '1.0.0', '1/3', '', null,
65 ];
66 for (const amount of invalidMonetaryAmounts) {
67 test(() => {
68 assert_throws({
69 name: 'TypeError',
70 },
71 () => {
72 new PaymentRequest([{
73 supportedMethods: ['basic-card'],
74 }], {
75 total: {
76 label: '',
77 amount: {
78 currency: 'USD',
79 value: amount,
80 },
81 },
82 });
83 });
84 }, 'If details.total.amount.value is not a valid decimal monetary value ' +
85 '(in this case "' + amount + '"), then throw a TypeError');
86 }
87
88 test(() => {
89 assert_throws({
90 name: 'TypeError',
91 },
92 () => {
93 new PaymentRequest([{
94 supportedMethods: ['basic-card'],
95 }], {
96 total: {
97 label: '',
98 amount: {
99 currency: 'USD',
100 value: '-1.00',
101 },
102 },
103 });
104 });
105 }, 'If the first character of details.total.amount.value is ' +
106 'U+002D HYPHEN-MINUS, then throw a TypeError');
107
108 for (const amount of invalidMonetaryAmounts) {
109 test(() => {
110 assert_throws({
111 name: 'TypeError',
112 },
113 () => {
114 new PaymentRequest([{
115 supportedMethods: ['basic-card'],
116 }], {
117 total: {
118 label: '',
119 amount: {
120 currency: 'USD',
121 value: '1.00',
122 },
123 },
124 displayItems: [{
125 label: '',
126 amount: {
127 currency: 'USD',
128 value: amount,
129 },
130 }],
131 });
132 });
133 }, 'For each item in details.displayItems: if item.amount.value is not ' +
134 'a valid decimal monetary value (in this case "' + amount +
135 '"), then throw a TypeError');
136 }
137
138 test(() => {
139 assert_throws({
140 name: 'TypeError',
141 },
142 () => {
143 new PaymentRequest([{
144 supportedMethods: ['basic-card'],
145 }], {});
146 });
147 }, 'Total is required');
148
149 test(() => {
150 assert_throws({
151 name: 'TypeError',
152 },
153 () => {
154 new PaymentRequest([{
155 supportedMethods: ['basic-card'],
156 }], {
157 total: {
158 amount: {
159 currency: 'USD',
160 value: '1.00',
161 },
162 },
163 });
164 });
165 }, 'Label is required');
166
167 test(() => {
168 assert_throws({
169 name: 'TypeError',
170 },
171 () => {
172 new PaymentRequest([{
173 supportedMethods: ['basic-card'],
174 }], {
175 total: {
176 label: '',
177 },
178 });
179 });
180 }, 'Amount is required');
181
182 test(() => {
183 assert_throws({
184 name: 'TypeError',
185 },
186 () => {
187 new PaymentRequest([{
188 supportedMethods: ['basic-card'],
189 }], {
190 total: {
191 label: '',
192 amount: {
193 currency: 'USD',
194 },
195 },
196 });
197 });
198 }, 'Amount value is required');
199
200 test(() => {
201 assert_throws({
202 name: 'TypeError',
203 },
204 () => {
205 new PaymentRequest([{
206 supportedMethods: ['basic-card'],
207 }], {
208 total: {
209 label: '',
210 amount: {
211 value: '1.00',
212 },
213 },
214 });
215 });
216 }, 'Amount currency is required');
217
218 test(() => {
219 assert_throws({
220 name: 'TypeError',
221 },
222 () => {
223 new PaymentRequest([{
224 supportedMethods: ['basic-card'],
225 }], {
226 total: {
227 label: '',
228 amount: {
229 currency: 'USD',
230 value: '1.00',
231 },
232 },
233 }, {
234 shippingType: 'invalid',
235 });
236 });
237 }, 'Shipping type should be valid');
238 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698