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

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

Issue 1904553003: Java implementation of PaymentRequest mojo service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address 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
(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 org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
8 import org.chromium.mojom.payments.ShippingAddress;
9 import org.chromium.testing.local.LocalRobolectricTestRunner;
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.junit.runner.RunWith;
13 import org.robolectric.annotation.Config;
14
15 import java.util.regex.Pattern;
16
17 /**
18 * Unit tests for the AutofillAddress class.
19 */
20 @RunWith(LocalRobolectricTestRunner.class)
21 @Config(manifest = Config.NONE)
22 public class AutofillAddressTest {
23 @Test
24 public void testRegionCodePattern() {
25 Pattern pattern = Pattern.compile(AutofillAddress.REGION_CODE_PATTERN);
26
27 Assert.assertTrue(pattern.matcher("US").matches());
28 Assert.assertTrue(pattern.matcher("GB").matches());
29
30 Assert.assertFalse(pattern.matcher("USA").matches());
31 Assert.assertFalse(pattern.matcher("gb").matches());
32 Assert.assertFalse(pattern.matcher("U2").matches());
33 Assert.assertFalse(pattern.matcher("").matches());
34 }
35
36 @Test
37 public void testToShippingAddress() {
38 AutofillAddress input = new AutofillAddress(new AutofillProfile("guid", "origin",
39 true /* isLocal */, "full name", "company name", "street\naddres s", "region",
40 "locality", "dependent locality", "postal code", "sorting code", "US",
41 "phone number", "email@address.com", "en-Latn-US"));
42 ShippingAddress output = input.toShippingAddress();
43 Assert.assertEquals("US", output.regionCode);
44 Assert.assertArrayEquals(new String[]{"street", "address"}, output.addre ssLine);
45 Assert.assertEquals("region", output.administrativeArea);
46 Assert.assertEquals("locality", output.locality);
47 Assert.assertEquals("dependent locality", output.dependentLocality);
48 Assert.assertEquals("postal code", output.postalCode);
49 Assert.assertEquals("sorting code", output.sortingCode);
50 Assert.assertEquals("company name", output.organization);
51 Assert.assertEquals("full name", output.recipient);
52 Assert.assertEquals("en", output.languageCode);
53 Assert.assertEquals("Latn", output.scriptCode);
54 }
55
56 @Test
57 public void testToShippingAddressWithoutMatchingLanguageScriptCode() {
58 AutofillAddress input = new AutofillAddress(new AutofillProfile("guid", "origin",
59 true /* isLocal */, "full name", "company name", "street\naddres s", "region",
60 "locality", "dependent locality", "postal code", "sorting code", "US",
61 "phone number", "email@address.com", "language-code"));
62 ShippingAddress output = input.toShippingAddress();
63 Assert.assertEquals("", output.languageCode);
64 Assert.assertEquals("", output.scriptCode);
65 }
66
67 @Test
68 public void testToShippingAddressWithoutAnyLanguageScriptCode() {
69 AutofillAddress input = new AutofillAddress(new AutofillProfile("guid", "origin",
70 true /* isLocal */, "full name", "company name", "street\naddres s", "region",
71 "locality", "dependent locality", "postal code", "sorting code", "US",
72 "phone number", "email@address.com", ""));
73 ShippingAddress output = input.toShippingAddress();
74 Assert.assertEquals("", output.languageCode);
75 Assert.assertEquals("", output.scriptCode);
76 }
77
78 @Test
79 public void testToShippingAddressWithNullLanguageScriptCode() {
80 AutofillAddress input = new AutofillAddress(new AutofillProfile("guid", "origin",
81 true /* isLocal */, "full name", "company name", "street\naddres s", "region",
82 "locality", "dependent locality", "postal code", "sorting code", "US",
83 "phone number", "email@address.com", null));
84 ShippingAddress output = input.toShippingAddress();
85 Assert.assertEquals("", output.languageCode);
86 Assert.assertEquals("", output.scriptCode);
87 }
88
89 @Test
90 public void testToShippingAddressTwice() {
91 AutofillAddress input = new AutofillAddress(new AutofillProfile("guid", "origin",
92 true /* isLocal */, "full name", "company name", "street\naddres s", "region",
93 "locality", "dependent locality", "postal code", "sorting code", "US",
94 "phone number", "email@address.com", "en-Latn"));
95 ShippingAddress output1 = input.toShippingAddress();
96 ShippingAddress output2 = input.toShippingAddress();
97 Assert.assertEquals("en", output1.languageCode);
98 Assert.assertEquals("en", output2.languageCode);
99 Assert.assertEquals("Latn", output1.scriptCode);
100 Assert.assertEquals("Latn", output2.scriptCode);
101 }
102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698