OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 #include "base/scoped_nsobject.h" | |
6 #include "base/utf_string_conversions.h" | |
7 #import "chrome/browser/autofill/autofill_address_model_mac.h" | |
8 #include "chrome/browser/autofill/autofill_common_test.h" | |
9 #include "chrome/browser/autofill/autofill_profile.h" | |
10 #include "chrome/browser/ui/cocoa/browser_test_helper.h" | |
11 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 namespace { | |
15 | |
16 typedef CocoaTest AutoFillAddressModelTest; | |
17 | |
18 TEST(AutoFillAddressModelTest, Basic) { | |
19 // A basic test that creates a new instance and releases. | |
20 // Aids valgrind leak detection. | |
21 AutoFillProfile profile; | |
22 scoped_nsobject<AutoFillAddressModel> model([[AutoFillAddressModel alloc] | |
23 initWithProfile:profile]); | |
24 EXPECT_TRUE(model.get()); | |
25 } | |
26 | |
27 TEST(AutoFillAddressModelTest, InitializationFromProfile) { | |
28 AutoFillProfile profile; | |
29 autofill_test::SetProfileInfo( | |
30 &profile, | |
31 "Marion", | |
32 "Mitchell", | |
33 "Morrison", | |
34 "johnwayne@me.xyz", | |
35 "Fox", | |
36 "123 Zoo St.", | |
37 "unit 5", | |
38 "Hollywood", "CA", | |
39 "91601", | |
40 "United States", | |
41 "12345678910", | |
42 "01987654321"); | |
43 scoped_nsobject<AutoFillAddressModel> model([[AutoFillAddressModel alloc] | |
44 initWithProfile:profile]); | |
45 EXPECT_TRUE(model.get()); | |
46 | |
47 EXPECT_TRUE([[model fullName] isEqualToString:@"Marion Mitchell Morrison"]); | |
48 EXPECT_TRUE([[model email] isEqualToString:@"johnwayne@me.xyz"]); | |
49 EXPECT_TRUE([[model companyName] isEqualToString:@"Fox"]); | |
50 EXPECT_TRUE([[model addressLine1] isEqualToString:@"123 Zoo St."]); | |
51 EXPECT_TRUE([[model addressLine2] isEqualToString:@"unit 5"]); | |
52 EXPECT_TRUE([[model addressCity] isEqualToString:@"Hollywood"]); | |
53 EXPECT_TRUE([[model addressState] isEqualToString:@"CA"]); | |
54 EXPECT_TRUE([[model addressZip] isEqualToString:@"91601"]); | |
55 EXPECT_TRUE([[model addressCountry] isEqualToString:@"United States"]); | |
56 EXPECT_TRUE([[model phoneWholeNumber] isEqualToString:@"12345678910"]); | |
57 EXPECT_TRUE([[model faxWholeNumber] isEqualToString:@"01987654321"]); | |
58 } | |
59 | |
60 TEST(AutoFillAddressModelTest, CopyModelToProfile) { | |
61 AutoFillProfile profile; | |
62 autofill_test::SetProfileInfo( | |
63 &profile, | |
64 "Marion", | |
65 "Mitchell", | |
66 "Morrison", | |
67 "johnwayne@me.xyz", | |
68 "Fox", | |
69 "123 Zoo St.", | |
70 "unit 5", | |
71 "Hollywood", "CA", | |
72 "91601", | |
73 "United States", | |
74 "12345678910", | |
75 "01987654321"); | |
76 scoped_nsobject<AutoFillAddressModel> model([[AutoFillAddressModel alloc] | |
77 initWithProfile:profile]); | |
78 EXPECT_TRUE(model.get()); | |
79 | |
80 [model setFullName:@"MarionX MitchellX MorrisonX"]; | |
81 [model setEmail:@"trigger@me.xyz"]; | |
82 [model setCompanyName:@"FoxX"]; | |
83 [model setAddressLine1:@"123 Xoo St."]; | |
84 [model setAddressLine2:@"unit 5X"]; | |
85 [model setAddressCity:@"Seattle"]; | |
86 [model setAddressState:@"WA"]; | |
87 [model setAddressZip:@"81601"]; | |
88 [model setAddressCountry:@"Canada"]; | |
89 [model setPhoneWholeNumber:@"23346678910"]; | |
90 [model setFaxWholeNumber:@"12988654321"]; | |
91 | |
92 [model copyModelToProfile:&profile]; | |
93 | |
94 EXPECT_EQ(ASCIIToUTF16("MarionX"), | |
95 profile.GetFieldText(AutofillType(NAME_FIRST))); | |
96 EXPECT_EQ(ASCIIToUTF16("MitchellX"), | |
97 profile.GetFieldText(AutofillType(NAME_MIDDLE))); | |
98 EXPECT_EQ(ASCIIToUTF16("MorrisonX"), | |
99 profile.GetFieldText(AutofillType(NAME_LAST))); | |
100 EXPECT_EQ(ASCIIToUTF16("MarionX MitchellX MorrisonX"), | |
101 profile.GetFieldText(AutofillType(NAME_FULL))); | |
102 EXPECT_EQ(ASCIIToUTF16("trigger@me.xyz"), | |
103 profile.GetFieldText(AutofillType(EMAIL_ADDRESS))); | |
104 EXPECT_EQ(ASCIIToUTF16("FoxX"), | |
105 profile.GetFieldText(AutofillType(COMPANY_NAME))); | |
106 EXPECT_EQ(ASCIIToUTF16("123 Xoo St."), | |
107 profile.GetFieldText(AutofillType(ADDRESS_HOME_LINE1))); | |
108 EXPECT_EQ(ASCIIToUTF16("unit 5X"), | |
109 profile.GetFieldText(AutofillType(ADDRESS_HOME_LINE2))); | |
110 EXPECT_EQ(ASCIIToUTF16("Seattle"), | |
111 profile.GetFieldText(AutofillType(ADDRESS_HOME_CITY))); | |
112 EXPECT_EQ(ASCIIToUTF16("WA"), | |
113 profile.GetFieldText(AutofillType(ADDRESS_HOME_STATE))); | |
114 EXPECT_EQ(ASCIIToUTF16("81601"), | |
115 profile.GetFieldText(AutofillType(ADDRESS_HOME_ZIP))); | |
116 EXPECT_EQ(ASCIIToUTF16("Canada"), | |
117 profile.GetFieldText(AutofillType(ADDRESS_HOME_COUNTRY))); | |
118 EXPECT_EQ(ASCIIToUTF16("23346678910"), | |
119 profile.GetFieldText(AutofillType(PHONE_HOME_WHOLE_NUMBER))); | |
120 EXPECT_EQ(ASCIIToUTF16("12988654321"), | |
121 profile.GetFieldText(AutofillType(PHONE_FAX_WHOLE_NUMBER))); | |
122 } | |
123 | |
124 } // namespace | |
OLD | NEW |