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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/payments/CurrencyFormatterTest.java

Issue 2629883004: [Payment Request] Update the CurrencyStringFormatter to call the native impl. (Closed)
Patch Set: CurrencyStringFormatter -> CurrencyFormatter Created 3 years, 11 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 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.payments;
6
7 import android.support.test.filters.MediumTest;
8
9 import junit.framework.Assert;
10
11 import org.chromium.base.LocaleUtils;
12 import org.chromium.content.browser.test.NativeLibraryTestBase;
13
14 import java.util.Arrays;
15 import java.util.List;
16
17 /**
18 * A lightweight integration test for CurrencyFormatter to run on an Android dev ice.
19 */
20 public class CurrencyFormatterTest extends NativeLibraryTestBase {
21 /**
22 * Unicode non-breaking space.
23 */
24 private static final String SPACE = "\u00A0";
25
26 @Override
27 protected void setUp() throws Exception {
28 super.setUp();
29 loadNativeLibraryAndInitBrowserProcess();
30 }
31
32 private static String longStringOfLength(int len) {
33 StringBuilder currency = new StringBuilder();
34 for (int i = 0; i < len; i++) {
35 currency.append("A");
36 }
37 return currency.toString();
38 }
39
40 @MediumTest
41 public void testMultipleConversions() throws Exception {
42 // Note, all spaces are expected to be unicode non-breaking spaces. Here they are shown as
43 // normal spaces.
44 List<Object[]> testCases = Arrays.asList(new Object[][] {
45 {"55.00", "USD", "en-US", "USD", "$55.00"},
46 {"55.00", "USD", "en-CA", "USD", "$55.00"},
47 {"55.00", "USD", "fr-CA", "USD", "55,00 $"},
48 {"55.00", "USD", "fr-FR", "USD", "55,00 $"},
49 {"1234", "USD", "fr-FR", "USD", "1 234,00 $"},
50
51 {"55.5", "USD", "en-US", "USD", "$55.50"}, {"55", "USD", "en-US" , "USD", "$55.00"},
52 {"-123", "USD", "en-US", "USD", "-$123.00"},
53 {"-1234", "USD", "en-US", "USD", "-$1,234.00"},
54 {"0.1234", "USD", "en-US", "USD", "$0.1234"},
55
56 {"55.00", "EUR", "en-US", "EUR", "€55.00"},
57 {"55.00", "EUR", "en-CA", "EUR", "€55.00"},
58 {"55.00", "EUR", "fr-CA", "EUR", "55,00 €"},
59 {"55.00", "EUR", "fr-FR", "EUR", "55,00 €"},
60
61 {"55.00", "CAD", "en-US", "CAD", "$55.00"},
62 {"55.00", "CAD", "en-CA", "CAD", "$55.00"},
63 {"55.00", "CAD", "fr-CA", "CAD", "55,00 $"},
64 {"55.00", "CAD", "fr-FR", "CAD", "55,00 $"},
65
66 {"55", "JPY", "ja-JP", "JPY", "¥55"}, {"55.0", "JPY", "ja-JP", " JPY", "¥55"},
67 {"55.00", "JPY", "ja-JP", "JPY", "¥55"},
68 {"55.12", "JPY", "ja-JP", "JPY", "¥55.12"},
69 {"55.49", "JPY", "ja-JP", "JPY", "¥55.49"},
70 {"55.50", "JPY", "ja-JP", "JPY", "¥55.5"},
71 {"55.9999", "JPY", "ja-JP", "JPY", "¥55.9999"},
72
73 // Unofficial ISO 4217 currency code.
74 {"55.00", "BTX", "en-US", "BTX", "55.00"},
75 {"-0.00000001", "BTX", "en-US", "BTX", "-0.00000001"},
76 {"-55.00", "BTX", "fr-FR", "BTX", "-55,00"},
77
78 {"123456789012345678901234567890.123456789012345678901234567890" , "USD", "fr-FR",
79 "USD", "123 456 789 012 345 678 901 234 567 890,12345678 9 $"},
80 {"123456789012345678901234567890.123456789012345678901234567890" , "USD", "en-US",
81 "USD", "$123,456,789,012,345,678,901,234,567,890.1234567 89"},
82
83 // Any string of at most 2048 characters can be valid amount cur rency codes.
84 {"55.00", "", "en-US", "", "55.00"},
85 {"55.00", "ABCDEF", "en-US", "ABCDE\u2026", "55.00"},
86 // Currency code more than 6 character is formatted to first 5 c haracters and
87 // ellipsis. "\u2026" is unicode for ellipsis.
88 {"55.00", longStringOfLength(2048), "en-US", "AAAAA\u2026", "55. 00"},
89 });
90
91 for (int i = 0; i < testCases.size(); i++) {
92 Object[] testCase = testCases.get(i);
93
94 String amount = (String) testCase[0];
95 String currency = (String) testCase[1];
96 String locale = (String) testCase[2];
97 String expectedCurrencyFormatting = (String) testCase[3];
98 String expectedAmountFormatting = (String) testCase[4];
99
100 CurrencyFormatter formatter =
101 new CurrencyFormatter(currency, null, LocaleUtils.forLanguag eTag(locale));
102
103 String formattedAmount = formatter.format(amount).replace(SPACE, " " );
104 Assert.assertEquals("\"" + currency + "\" \"" + amount + "\" (\"" + locale
105 + "\" locale) should be formatted into \"" + expecte dAmountFormatting
106 + "\"",
107 expectedAmountFormatting, formattedAmount);
108 Assert.assertEquals("\"" + currency + "\""
109 + " should be formatted into \"" + expectedCurrencyF ormatting + "\"",
110 expectedCurrencyFormatting, formatter.getFormattedCurrencyCo de());
111 }
112 }
113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698