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

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: Allow null as per spec 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 of at most 2048 characters can be valid amount currenc y 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", longStringOfLength(2048), "en-US", "55.00", ExpectedValidi ty.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", longStringOfLength(2049), "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 longStringOfLength(int len) {
107 StringBuilder currency = new StringBuilder();
108 for (int i = 0; i < len; i++) {
109 currency.append("A");
110 }
111 return currency.toString();
112 }
113
105 public CurrencyStringFormatterTest(String amount, String currency, String la nguageTag, 114 public CurrencyStringFormatterTest(String amount, String currency, String la nguageTag,
106 String expectedFormatting, ExpectedValidity expectedValidity) { 115 String expectedFormatting, ExpectedValidity expectedValidity) {
107 mAmount = amount; 116 mAmount = amount;
108 mCurrency = currency; 117 mCurrency = currency;
109 mLanguageTag = languageTag; 118 mLanguageTag = languageTag;
110 mExpectedFormatting = expectedFormatting; 119 mExpectedFormatting = expectedFormatting;
111 mExpectedValidity = expectedValidity; 120 mExpectedValidity = expectedValidity;
112 } 121 }
113 122
114 @Test 123 @Test
(...skipping 17 matching lines...) Expand all
132 formatter.isValidAmountValue(mAmount)); 141 formatter.isValidAmountValue(mAmount));
133 } 142 }
134 143
135 if (mExpectedValidity == ExpectedValidity.VALID_AMOUNT) { 144 if (mExpectedValidity == ExpectedValidity.VALID_AMOUNT) {
136 Assert.assertEquals("\"" + mCurrency + "\" \"" + mAmount + "\" (\"" + mLanguageTag 145 Assert.assertEquals("\"" + mCurrency + "\" \"" + mAmount + "\" (\"" + mLanguageTag
137 + "\" locale) should be formatted into \"" + mExpect edFormatting + "\"", 146 + "\" locale) should be formatted into \"" + mExpect edFormatting + "\"",
138 mExpectedFormatting, formatter.format(mAmount)); 147 mExpectedFormatting, formatter.format(mAmount));
139 } 148 }
140 } 149 }
141 } 150 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698