OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
groby-ooo-7-16
2013/12/05 02:56:10
Think you could add a test for the field replaceme
| |
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 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h" | 5 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h" |
6 | 6 |
7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" | 10 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" |
11 #include "chrome/browser/ui/autofill/mock_autofill_dialog_view_delegate.h" | 11 #include "chrome/browser/ui/autofill/mock_autofill_dialog_view_delegate.h" |
12 #import "chrome/browser/ui/cocoa/autofill/autofill_input_field.h" | 12 #import "chrome/browser/ui/cocoa/autofill/autofill_input_field.h" |
13 #import "chrome/browser/ui/cocoa/autofill/layout_view.h" | 13 #import "chrome/browser/ui/cocoa/autofill/layout_view.h" |
14 #import "chrome/browser/ui/cocoa/menu_button.h" | 14 #import "chrome/browser/ui/cocoa/menu_button.h" |
15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "testing/gtest_mac.h" | 17 #include "testing/gtest_mac.h" |
18 #include "testing/platform_test.h" | 18 #include "testing/platform_test.h" |
19 #include "ui/base/l10n/l10n_util.h" | |
19 #include "ui/base/models/combobox_model.h" | 20 #include "ui/base/models/combobox_model.h" |
20 #include "ui/base/models/simple_menu_model.h" | 21 #include "ui/base/models/simple_menu_model.h" |
21 #import "ui/base/test/ui_cocoa_test_helper.h" | 22 #import "ui/base/test/ui_cocoa_test_helper.h" |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 class AutofillSectionContainerTest : public ui::CocoaTest { | 26 class AutofillSectionContainerTest : public ui::CocoaTest { |
26 public: | 27 public: |
27 AutofillSectionContainerTest() : section_(autofill::SECTION_BILLING) {} | 28 AutofillSectionContainerTest() : section_(autofill::SECTION_BILLING) {} |
28 virtual void SetUp() { | 29 virtual void SetUp() { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 EXPECT_NSEQ(@"Year", [yearPopup itemTitleAtIndex:0]); | 113 EXPECT_NSEQ(@"Year", [yearPopup itemTitleAtIndex:0]); |
113 }; | 114 }; |
114 | 115 |
115 TEST_F(AutofillSectionContainerTest, OutputMatchesDefinition) { | 116 TEST_F(AutofillSectionContainerTest, OutputMatchesDefinition) { |
116 using namespace autofill; | 117 using namespace autofill; |
117 using namespace testing; | 118 using namespace testing; |
118 | 119 |
119 const DetailInput kTestInputs[] = { | 120 const DetailInput kTestInputs[] = { |
120 { DetailInput::LONG, | 121 { DetailInput::LONG, |
121 EMAIL_ADDRESS, | 122 EMAIL_ADDRESS, |
122 IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, | 123 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL) }, |
123 { DetailInput::SHORT, CREDIT_CARD_EXP_MONTH }, | 124 { DetailInput::SHORT, CREDIT_CARD_EXP_MONTH }, |
124 }; | 125 }; |
125 autofill::MonthComboboxModel comboModel; | 126 autofill::MonthComboboxModel comboModel; |
126 DetailInputs inputs; | 127 DetailInputs inputs; |
127 inputs.push_back(kTestInputs[0]); | 128 inputs.push_back(kTestInputs[0]); |
128 inputs.push_back(kTestInputs[1]); | 129 inputs.push_back(kTestInputs[1]); |
129 | 130 |
130 EXPECT_CALL(delegate_, RequestedFieldsForSection(section_)) | 131 EXPECT_CALL(delegate_, RequestedFieldsForSection(section_)) |
131 .WillOnce(ReturnRef(inputs)); | 132 .WillOnce(ReturnRef(inputs)); |
132 EXPECT_CALL(delegate_, ComboboxModelForAutofillType(EMAIL_ADDRESS)) | 133 EXPECT_CALL(delegate_, ComboboxModelForAutofillType(EMAIL_ADDRESS)) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 EXPECT_NSEQ(@"b", [[menu itemAtIndex:2] title]); | 178 EXPECT_NSEQ(@"b", [[menu itemAtIndex:2] title]); |
178 } | 179 } |
179 | 180 |
180 TEST_F(AutofillSectionContainerTest, FieldsAreInitiallyValid) { | 181 TEST_F(AutofillSectionContainerTest, FieldsAreInitiallyValid) { |
181 using namespace autofill; | 182 using namespace autofill; |
182 using namespace testing; | 183 using namespace testing; |
183 | 184 |
184 const DetailInput kTestInputs[] = { | 185 const DetailInput kTestInputs[] = { |
185 { DetailInput::LONG, | 186 { DetailInput::LONG, |
186 EMAIL_ADDRESS, | 187 EMAIL_ADDRESS, |
187 IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, | 188 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL) }, |
188 { DetailInput::SHORT, CREDIT_CARD_EXP_MONTH }, | 189 { DetailInput::SHORT, CREDIT_CARD_EXP_MONTH }, |
189 }; | 190 }; |
190 | 191 |
191 MonthComboboxModel comboModel; | 192 MonthComboboxModel comboModel; |
192 DetailInputs inputs; | 193 DetailInputs inputs; |
193 inputs.push_back(kTestInputs[0]); | 194 inputs.push_back(kTestInputs[0]); |
194 inputs.push_back(kTestInputs[1]); | 195 inputs.push_back(kTestInputs[1]); |
195 | 196 |
196 EXPECT_CALL(delegate_, RequestedFieldsForSection(section_)) | 197 EXPECT_CALL(delegate_, RequestedFieldsForSection(section_)) |
197 .WillOnce(ReturnRef(inputs)); | 198 .WillOnce(ReturnRef(inputs)); |
198 EXPECT_CALL(delegate_, ComboboxModelForAutofillType(EMAIL_ADDRESS)) | 199 EXPECT_CALL(delegate_, ComboboxModelForAutofillType(EMAIL_ADDRESS)) |
199 .WillRepeatedly(ReturnNull()); | 200 .WillRepeatedly(ReturnNull()); |
200 EXPECT_CALL(delegate_, ComboboxModelForAutofillType(CREDIT_CARD_EXP_MONTH)) | 201 EXPECT_CALL(delegate_, ComboboxModelForAutofillType(CREDIT_CARD_EXP_MONTH)) |
201 .WillRepeatedly(Return(&comboModel)); | 202 .WillRepeatedly(Return(&comboModel)); |
202 | 203 |
203 ResetContainer(); | 204 ResetContainer(); |
204 NSControl<AutofillInputField>* field = [container_ getField:EMAIL_ADDRESS]; | 205 NSControl<AutofillInputField>* field = [container_ getField:EMAIL_ADDRESS]; |
205 EXPECT_FALSE([field invalid]); | 206 EXPECT_FALSE([field invalid]); |
206 field = [container_ getField:CREDIT_CARD_EXP_MONTH]; | 207 field = [container_ getField:CREDIT_CARD_EXP_MONTH]; |
207 EXPECT_FALSE([field invalid]); | 208 EXPECT_FALSE([field invalid]); |
208 } | 209 } |
209 | 210 |
210 TEST_F(AutofillSectionContainerTest, ControllerInformsValidity) { | 211 TEST_F(AutofillSectionContainerTest, ControllerInformsValidity) { |
211 using namespace autofill; | 212 using namespace autofill; |
212 using namespace testing; | 213 using namespace testing; |
213 | 214 |
214 const DetailInput kTestInputs[] = { | 215 const DetailInput kTestInputs[] = { |
215 { DetailInput::LONG, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, | 216 { DetailInput::LONG, |
217 EMAIL_ADDRESS, | |
218 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL) }, | |
216 { DetailInput::SHORT, CREDIT_CARD_EXP_MONTH } | 219 { DetailInput::SHORT, CREDIT_CARD_EXP_MONTH } |
217 }; | 220 }; |
218 | 221 |
219 MonthComboboxModel comboModel; | 222 MonthComboboxModel comboModel; |
220 DetailInputs inputs; | 223 DetailInputs inputs; |
221 inputs.push_back(kTestInputs[0]); | 224 inputs.push_back(kTestInputs[0]); |
222 inputs.push_back(kTestInputs[1]); | 225 inputs.push_back(kTestInputs[1]); |
223 | 226 |
224 ValidityMessages validity, validity2; | 227 ValidityMessages validity, validity2; |
225 | 228 |
(...skipping 20 matching lines...) Expand all Loading... | |
246 EXPECT_TRUE([field invalid]); | 249 EXPECT_TRUE([field invalid]); |
247 field = [container_ getField:CREDIT_CARD_EXP_MONTH]; | 250 field = [container_ getField:CREDIT_CARD_EXP_MONTH]; |
248 EXPECT_FALSE([field invalid]); | 251 EXPECT_FALSE([field invalid]); |
249 | 252 |
250 [container_ validateFor:VALIDATE_FINAL]; | 253 [container_ validateFor:VALIDATE_FINAL]; |
251 field = [container_ getField:EMAIL_ADDRESS]; | 254 field = [container_ getField:EMAIL_ADDRESS]; |
252 EXPECT_FALSE([field invalid]); | 255 EXPECT_FALSE([field invalid]); |
253 field = [container_ getField:CREDIT_CARD_EXP_MONTH]; | 256 field = [container_ getField:CREDIT_CARD_EXP_MONTH]; |
254 EXPECT_TRUE([field invalid]); | 257 EXPECT_TRUE([field invalid]); |
255 } | 258 } |
OLD | NEW |