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

Side by Side Diff: chrome/android/junit/src/org/chromium/chrome/browser/payments/CurrencyStringFormatterTest.java

Issue 2271113002: Accept any string for currency code in PaymentRequest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added browser side validation Created 4 years, 3 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.payments; 5 package org.chromium.chrome.browser.payments;
6 6
7 import org.junit.Assert; 7 import org.junit.Assert;
8 import org.junit.Test; 8 import org.junit.Test;
9 import org.junit.runner.RunWith; 9 import org.junit.runner.RunWith;
10 import org.junit.runners.Parameterized; 10 import org.junit.runners.Parameterized;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 67
68 {"123456789012345678901234567890.123456789012345678901234567890", "U SD", "fr-FR", 68 {"123456789012345678901234567890.123456789012345678901234567890", "U SD", "fr-FR",
69 "$123" + SPACE + "456" + SPACE + "789" + SPACE + "012" + SPA CE + "345" 69 "$123" + SPACE + "456" + SPACE + "789" + SPACE + "012" + SPA CE + "345"
70 + SPACE + "678" + SPACE + "901" + SPACE + "234" + SP ACE + "567" 70 + SPACE + "678" + SPACE + "901" + SPACE + "234" + SP ACE + "567"
71 + SPACE + "890,123456789012345678901234567890", 71 + SPACE + "890,123456789012345678901234567890",
72 ExpectedValidity.VALID_AMOUNT}, 72 ExpectedValidity.VALID_AMOUNT},
73 {"123456789012345678901234567890.123456789012345678901234567890", "U SD", "en-US", 73 {"123456789012345678901234567890.123456789012345678901234567890", "U SD", "en-US",
74 "$123,456,789,012,345,678,901,234,567,890.123456789012345678 901234567890", 74 "$123,456,789,012,345,678,901,234,567,890.123456789012345678 901234567890",
75 ExpectedValidity.VALID_AMOUNT}, 75 ExpectedValidity.VALID_AMOUNT},
76 76
77 // Any string can be valid amount currency codes.
78 {"55.00", "", "en-US", "55.00", ExpectedValidity.VALID_AMOUNT},
79 {"55.00", "ABCDEF", "en-US", "55.00", ExpectedValidity.VALID_AMOUNT} ,
80 {"55.00", longString2048(), "en-US", "55.00", ExpectedValidity.VALID _AMOUNT},
81
77 // Invalid amount currency codes. 82 // Invalid amount currency codes.
78 {"55.00", "", "en-US", null, ExpectedValidity.INVALID_AMOUNT_CURRENC Y_CODE}, 83 {"55.00", longString2049(), "en-US", null,
79 {"55.00", "usd", "en-US", null, ExpectedValidity.INVALID_AMOUNT_CURR ENCY_CODE}, 84 ExpectedValidity.INVALID_AMOUNT_CURRENCY_CODE},
80 {"55.00", "US8", "en-US", null, ExpectedValidity.INVALID_AMOUNT_CURR ENCY_CODE},
81 {"55.00", "US", "en-US", null, ExpectedValidity.INVALID_AMOUNT_CURRE NCY_CODE},
82 {"55.00", "USDR", "en-US", null, ExpectedValidity.INVALID_AMOUNT_CUR RENCY_CODE},
83 {"55.00", "USDr", "en-US", null, ExpectedValidity.INVALID_AMOUNT_CUR RENCY_CODE},
84 85
85 // Invalid amount values. 86 // Invalid amount values.
86 {"", "USD", "en-US", null, ExpectedValidity.INVALID_AMOUNT_VALUE}, 87 {"", "USD", "en-US", null, ExpectedValidity.INVALID_AMOUNT_VALUE},
87 {"-", "USD", "en-US", null, ExpectedValidity.INVALID_AMOUNT_VALUE}, 88 {"-", "USD", "en-US", null, ExpectedValidity.INVALID_AMOUNT_VALUE},
88 {"notdigits", "USD", "en-US", null, ExpectedValidity.INVALID_AMOUNT_ VALUE}, 89 {"notdigits", "USD", "en-US", null, ExpectedValidity.INVALID_AMOUNT_ VALUE},
89 {"ALSONOTDIGITS", "USD", "en-US", null, ExpectedValidity.INVALID_AMO UNT_VALUE}, 90 {"ALSONOTDIGITS", "USD", "en-US", null, ExpectedValidity.INVALID_AMO UNT_VALUE},
90 {"10.", "USD", "en-US", null, ExpectedValidity.INVALID_AMOUNT_VALUE} , 91 {"10.", "USD", "en-US", null, ExpectedValidity.INVALID_AMOUNT_VALUE} ,
91 {".99", "USD", "en-US", null, ExpectedValidity.INVALID_AMOUNT_VALUE} , 92 {".99", "USD", "en-US", null, ExpectedValidity.INVALID_AMOUNT_VALUE} ,
92 {"10-", "USD", "en-US", null, ExpectedValidity.INVALID_AMOUNT_VALUE} , 93 {"10-", "USD", "en-US", null, ExpectedValidity.INVALID_AMOUNT_VALUE} ,
93 {"1-0", "USD", "en-US", null, ExpectedValidity.INVALID_AMOUNT_VALUE} , 94 {"1-0", "USD", "en-US", null, ExpectedValidity.INVALID_AMOUNT_VALUE} ,
94 {"1.0.0", "USD", "en-US", null, ExpectedValidity.INVALID_AMOUNT_VALU E}, 95 {"1.0.0", "USD", "en-US", null, ExpectedValidity.INVALID_AMOUNT_VALU E},
95 {"1/3", "USD", "en-US", null, ExpectedValidity.INVALID_AMOUNT_VALUE} , 96 {"1/3", "USD", "en-US", null, ExpectedValidity.INVALID_AMOUNT_VALUE} ,
96 }); 97 });
97 } 98 }
98 99
99 private final String mAmount; 100 private final String mAmount;
100 private final String mCurrency; 101 private final String mCurrency;
101 private final String mLanguageTag; 102 private final String mLanguageTag;
102 private final String mExpectedFormatting; 103 private final String mExpectedFormatting;
103 private final ExpectedValidity mExpectedValidity; 104 private final ExpectedValidity mExpectedValidity;
104 105
106 private static String longString2048() {
please use gerrit instead 2016/08/29 14:23:40 This creates 2049 objects. Use https://docs.oracle
pals 2016/08/30 09:02:09 Done.
107 String currency = "";
108 for (int i = 0; i < 2048; i++) {
109 currency = currency + "A";
110 }
111 return currency;
112 }
113
114 private static String longString2049() {
please use gerrit instead 2016/08/29 14:23:40 Ditto.
pals 2016/08/30 09:02:09 Done.
115 String currency = "";
116 for (int i = 0; i < 2049; i++) {
117 currency = currency + "A";
118 }
119 return currency;
120 }
121
122
105 public CurrencyStringFormatterTest(String amount, String currency, String la nguageTag, 123 public CurrencyStringFormatterTest(String amount, String currency, String la nguageTag,
106 String expectedFormatting, ExpectedValidity expectedValidity) { 124 String expectedFormatting, ExpectedValidity expectedValidity) {
107 mAmount = amount; 125 mAmount = amount;
108 mCurrency = currency; 126 mCurrency = currency;
109 mLanguageTag = languageTag; 127 mLanguageTag = languageTag;
110 mExpectedFormatting = expectedFormatting; 128 mExpectedFormatting = expectedFormatting;
111 mExpectedValidity = expectedValidity; 129 mExpectedValidity = expectedValidity;
112 } 130 }
113 131
114 @Test 132 @Test
(...skipping 17 matching lines...) Expand all
132 formatter.isValidAmountValue(mAmount)); 150 formatter.isValidAmountValue(mAmount));
133 } 151 }
134 152
135 if (mExpectedValidity == ExpectedValidity.VALID_AMOUNT) { 153 if (mExpectedValidity == ExpectedValidity.VALID_AMOUNT) {
136 Assert.assertEquals("\"" + mCurrency + "\" \"" + mAmount + "\" (\"" + mLanguageTag 154 Assert.assertEquals("\"" + mCurrency + "\" \"" + mAmount + "\" (\"" + mLanguageTag
137 + "\" locale) should be formatted into \"" + mExpect edFormatting + "\"", 155 + "\" locale) should be formatted into \"" + mExpect edFormatting + "\"",
138 mExpectedFormatting, formatter.format(mAmount)); 156 mExpectedFormatting, formatter.format(mAmount));
139 } 157 }
140 } 158 }
141 } 159 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698