| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #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_controller.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/models/combobox_model.h" | 19 #include "ui/base/models/combobox_model.h" |
| 20 #include "ui/base/models/simple_menu_model.h" | 20 #include "ui/base/models/simple_menu_model.h" |
| 21 #import "ui/base/test/ui_cocoa_test_helper.h" | 21 #import "ui/base/test/ui_cocoa_test_helper.h" |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 class AutofillSectionContainerTest : public ui::CocoaTest { | 25 class AutofillSectionContainerTest : public ui::CocoaTest { |
| 26 public: | 26 public: |
| 27 AutofillSectionContainerTest() : section_(autofill::SECTION_BILLING) {} | 27 AutofillSectionContainerTest() : section_(autofill::SECTION_BILLING) {} |
| 28 virtual void SetUp() { | 28 virtual void SetUp() { |
| 29 CocoaTest::SetUp(); | 29 CocoaTest::SetUp(); |
| 30 ResetContainer(); | 30 ResetContainer(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void ResetContainer() { | 33 void ResetContainer() { |
| 34 container_.reset( | 34 container_.reset( |
| 35 [[AutofillSectionContainer alloc] | 35 [[AutofillSectionContainer alloc] |
| 36 initWithController:&controller_ | 36 initWithDelegate:&delegate_ |
| 37 forSection:section_]); | 37 forSection:section_]); |
| 38 [[test_window() contentView] setSubviews:@[ [container_ view] ]]; | 38 [[test_window() contentView] setSubviews:@[ [container_ view] ]]; |
| 39 } | 39 } |
| 40 | 40 |
| 41 protected: | 41 protected: |
| 42 base::scoped_nsobject<AutofillSectionContainer> container_; | 42 base::scoped_nsobject<AutofillSectionContainer> container_; |
| 43 testing::NiceMock<autofill::MockAutofillDialogController> controller_; | 43 testing::NiceMock<autofill::MockAutofillDialogViewDelegate> delegate_; |
| 44 autofill::DialogSection section_; | 44 autofill::DialogSection section_; |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 } // namespace | 47 } // namespace |
| 48 | 48 |
| 49 TEST_VIEW(AutofillSectionContainerTest, [container_ view]) | 49 TEST_VIEW(AutofillSectionContainerTest, [container_ view]) |
| 50 | 50 |
| 51 TEST_F(AutofillSectionContainerTest, HasSubviews) { | 51 TEST_F(AutofillSectionContainerTest, HasSubviews) { |
| 52 bool hasLayoutView = false; | 52 bool hasLayoutView = false; |
| 53 bool hasTextField = false; | 53 bool hasTextField = false; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 78 using namespace testing; | 78 using namespace testing; |
| 79 | 79 |
| 80 const DetailInput kTestInputs[] = { | 80 const DetailInput kTestInputs[] = { |
| 81 { 2, CREDIT_CARD_EXP_MONTH } | 81 { 2, CREDIT_CARD_EXP_MONTH } |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 DetailInputs inputs; | 84 DetailInputs inputs; |
| 85 inputs.push_back(kTestInputs[0]); | 85 inputs.push_back(kTestInputs[0]); |
| 86 | 86 |
| 87 autofill::MonthComboboxModel comboModel; | 87 autofill::MonthComboboxModel comboModel; |
| 88 EXPECT_CALL(controller_, RequestedFieldsForSection(section_)) | 88 EXPECT_CALL(delegate_, RequestedFieldsForSection(section_)) |
| 89 .WillOnce(ReturnRef(inputs)); | 89 .WillOnce(ReturnRef(inputs)); |
| 90 EXPECT_CALL(controller_, ComboboxModelForAutofillType(CREDIT_CARD_EXP_MONTH)) | 90 EXPECT_CALL(delegate_, ComboboxModelForAutofillType(CREDIT_CARD_EXP_MONTH)) |
| 91 .WillRepeatedly(Return(&comboModel)); | 91 .WillRepeatedly(Return(&comboModel)); |
| 92 ResetContainer(); | 92 ResetContainer(); |
| 93 | 93 |
| 94 NSPopUpButton* popup = base::mac::ObjCCastStrict<NSPopUpButton>( | 94 NSPopUpButton* popup = base::mac::ObjCCastStrict<NSPopUpButton>( |
| 95 [container_ getField:CREDIT_CARD_EXP_MONTH]); | 95 [container_ getField:CREDIT_CARD_EXP_MONTH]); |
| 96 EXPECT_EQ(13, [popup numberOfItems]); | 96 EXPECT_EQ(13, [popup numberOfItems]); |
| 97 EXPECT_NSEQ(@"", [popup itemTitleAtIndex:0]); | 97 EXPECT_NSEQ(@"", [popup itemTitleAtIndex:0]); |
| 98 EXPECT_NSEQ(@"01", [popup itemTitleAtIndex:1]); | 98 EXPECT_NSEQ(@"01", [popup itemTitleAtIndex:1]); |
| 99 EXPECT_NSEQ(@"02", [popup itemTitleAtIndex:2]); | 99 EXPECT_NSEQ(@"02", [popup itemTitleAtIndex:2]); |
| 100 EXPECT_NSEQ(@"03", [popup itemTitleAtIndex:3]); | 100 EXPECT_NSEQ(@"03", [popup itemTitleAtIndex:3]); |
| 101 EXPECT_NSEQ(@"12", [popup itemTitleAtIndex:12]); | 101 EXPECT_NSEQ(@"12", [popup itemTitleAtIndex:12]); |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 TEST_F(AutofillSectionContainerTest, OutputMatchesDefinition) { | 104 TEST_F(AutofillSectionContainerTest, OutputMatchesDefinition) { |
| 105 using namespace autofill; | 105 using namespace autofill; |
| 106 using namespace testing; | 106 using namespace testing; |
| 107 | 107 |
| 108 const DetailInput kTestInputs[] = { | 108 const DetailInput kTestInputs[] = { |
| 109 { 1, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, | 109 { 1, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, |
| 110 { 2, CREDIT_CARD_EXP_MONTH } | 110 { 2, CREDIT_CARD_EXP_MONTH } |
| 111 }; | 111 }; |
| 112 autofill::MonthComboboxModel comboModel; | 112 autofill::MonthComboboxModel comboModel; |
| 113 DetailInputs inputs; | 113 DetailInputs inputs; |
| 114 inputs.push_back(kTestInputs[0]); | 114 inputs.push_back(kTestInputs[0]); |
| 115 inputs.push_back(kTestInputs[1]); | 115 inputs.push_back(kTestInputs[1]); |
| 116 | 116 |
| 117 EXPECT_CALL(controller_, RequestedFieldsForSection(section_)) | 117 EXPECT_CALL(delegate_, RequestedFieldsForSection(section_)) |
| 118 .WillOnce(ReturnRef(inputs)); | 118 .WillOnce(ReturnRef(inputs)); |
| 119 EXPECT_CALL(controller_, ComboboxModelForAutofillType(EMAIL_ADDRESS)) | 119 EXPECT_CALL(delegate_, ComboboxModelForAutofillType(EMAIL_ADDRESS)) |
| 120 .WillRepeatedly(ReturnNull()); | 120 .WillRepeatedly(ReturnNull()); |
| 121 EXPECT_CALL(controller_, ComboboxModelForAutofillType(CREDIT_CARD_EXP_MONTH)) | 121 EXPECT_CALL(delegate_, ComboboxModelForAutofillType(CREDIT_CARD_EXP_MONTH)) |
| 122 .WillRepeatedly(Return(&comboModel)); | 122 .WillRepeatedly(Return(&comboModel)); |
| 123 | 123 |
| 124 ResetContainer(); | 124 ResetContainer(); |
| 125 | 125 |
| 126 NSPopUpButton* popup = base::mac::ObjCCastStrict<NSPopUpButton>( | 126 NSPopUpButton* popup = base::mac::ObjCCastStrict<NSPopUpButton>( |
| 127 [container_ getField:CREDIT_CARD_EXP_MONTH]); | 127 [container_ getField:CREDIT_CARD_EXP_MONTH]); |
| 128 [popup selectItemWithTitle:@"02"]; | 128 [popup selectItemWithTitle:@"02"]; |
| 129 [[container_ getField:EMAIL_ADDRESS] setStringValue:@"magic@example.org"]; | 129 [[container_ getField:EMAIL_ADDRESS] setStringValue:@"magic@example.org"]; |
| 130 | 130 |
| 131 autofill::DetailOutputMap output; | 131 autofill::DetailOutputMap output; |
| 132 [container_ getInputs:&output]; | 132 [container_ getInputs:&output]; |
| 133 | 133 |
| 134 ASSERT_EQ(inputs.size(), output.size()); | 134 ASSERT_EQ(inputs.size(), output.size()); |
| 135 EXPECT_EQ(ASCIIToUTF16("magic@example.org"), output[&inputs[0]]); | 135 EXPECT_EQ(ASCIIToUTF16("magic@example.org"), output[&inputs[0]]); |
| 136 EXPECT_EQ(ASCIIToUTF16("02"), output[&inputs[1]]); | 136 EXPECT_EQ(ASCIIToUTF16("02"), output[&inputs[1]]); |
| 137 } | 137 } |
| 138 | 138 |
| 139 TEST_F(AutofillSectionContainerTest, SuggestionsPopulatedByController) { | 139 TEST_F(AutofillSectionContainerTest, SuggestionsPopulatedByController) { |
| 140 ui::SimpleMenuModel model(NULL); | 140 ui::SimpleMenuModel model(NULL); |
| 141 model.AddItem(10, ASCIIToUTF16("a")); | 141 model.AddItem(10, ASCIIToUTF16("a")); |
| 142 model.AddItem(11, ASCIIToUTF16("b")); | 142 model.AddItem(11, ASCIIToUTF16("b")); |
| 143 | 143 |
| 144 using namespace autofill; | 144 using namespace autofill; |
| 145 using namespace testing; | 145 using namespace testing; |
| 146 | 146 |
| 147 EXPECT_CALL(controller_, MenuModelForSection(section_)) | 147 EXPECT_CALL(delegate_, MenuModelForSection(section_)) |
| 148 .WillOnce(Return(&model)); | 148 .WillOnce(Return(&model)); |
| 149 | 149 |
| 150 ResetContainer(); | 150 ResetContainer(); |
| 151 MenuButton* button = nil; | 151 MenuButton* button = nil; |
| 152 for (id item in [[container_ view] subviews]) { | 152 for (id item in [[container_ view] subviews]) { |
| 153 if ([item isKindOfClass:[MenuButton class]]) { | 153 if ([item isKindOfClass:[MenuButton class]]) { |
| 154 button = item; | 154 button = item; |
| 155 break; | 155 break; |
| 156 } | 156 } |
| 157 } | 157 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 171 const DetailInput kTestInputs[] = { | 171 const DetailInput kTestInputs[] = { |
| 172 { 1, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, | 172 { 1, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, |
| 173 { 2, CREDIT_CARD_EXP_MONTH } | 173 { 2, CREDIT_CARD_EXP_MONTH } |
| 174 }; | 174 }; |
| 175 | 175 |
| 176 MonthComboboxModel comboModel; | 176 MonthComboboxModel comboModel; |
| 177 DetailInputs inputs; | 177 DetailInputs inputs; |
| 178 inputs.push_back(kTestInputs[0]); | 178 inputs.push_back(kTestInputs[0]); |
| 179 inputs.push_back(kTestInputs[1]); | 179 inputs.push_back(kTestInputs[1]); |
| 180 | 180 |
| 181 EXPECT_CALL(controller_, RequestedFieldsForSection(section_)) | 181 EXPECT_CALL(delegate_, RequestedFieldsForSection(section_)) |
| 182 .WillOnce(ReturnRef(inputs)); | 182 .WillOnce(ReturnRef(inputs)); |
| 183 EXPECT_CALL(controller_, ComboboxModelForAutofillType(EMAIL_ADDRESS)) | 183 EXPECT_CALL(delegate_, ComboboxModelForAutofillType(EMAIL_ADDRESS)) |
| 184 .WillRepeatedly(ReturnNull()); | 184 .WillRepeatedly(ReturnNull()); |
| 185 EXPECT_CALL(controller_, ComboboxModelForAutofillType(CREDIT_CARD_EXP_MONTH)) | 185 EXPECT_CALL(delegate_, ComboboxModelForAutofillType(CREDIT_CARD_EXP_MONTH)) |
| 186 .WillRepeatedly(Return(&comboModel)); | 186 .WillRepeatedly(Return(&comboModel)); |
| 187 | 187 |
| 188 ResetContainer(); | 188 ResetContainer(); |
| 189 NSControl<AutofillInputField>* field = [container_ getField:EMAIL_ADDRESS]; | 189 NSControl<AutofillInputField>* field = [container_ getField:EMAIL_ADDRESS]; |
| 190 EXPECT_FALSE([field invalid]); | 190 EXPECT_FALSE([field invalid]); |
| 191 field = [container_ getField:CREDIT_CARD_EXP_MONTH]; | 191 field = [container_ getField:CREDIT_CARD_EXP_MONTH]; |
| 192 EXPECT_FALSE([field invalid]); | 192 EXPECT_FALSE([field invalid]); |
| 193 } | 193 } |
| 194 | 194 |
| 195 TEST_F(AutofillSectionContainerTest, ControllerInformsValidity) { | 195 TEST_F(AutofillSectionContainerTest, ControllerInformsValidity) { |
| 196 using namespace autofill; | 196 using namespace autofill; |
| 197 using namespace testing; | 197 using namespace testing; |
| 198 | 198 |
| 199 const DetailInput kTestInputs[] = { | 199 const DetailInput kTestInputs[] = { |
| 200 { 1, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, | 200 { 1, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, |
| 201 { 2, CREDIT_CARD_EXP_MONTH } | 201 { 2, CREDIT_CARD_EXP_MONTH } |
| 202 }; | 202 }; |
| 203 | 203 |
| 204 MonthComboboxModel comboModel; | 204 MonthComboboxModel comboModel; |
| 205 DetailInputs inputs; | 205 DetailInputs inputs; |
| 206 inputs.push_back(kTestInputs[0]); | 206 inputs.push_back(kTestInputs[0]); |
| 207 inputs.push_back(kTestInputs[1]); | 207 inputs.push_back(kTestInputs[1]); |
| 208 | 208 |
| 209 DetailOutputMap output; | 209 DetailOutputMap output; |
| 210 ValidityData validity, validity2; | 210 ValidityData validity, validity2; |
| 211 | 211 |
| 212 validity[EMAIL_ADDRESS] = ASCIIToUTF16("Some error message"); | 212 validity[EMAIL_ADDRESS] = ASCIIToUTF16("Some error message"); |
| 213 validity2[CREDIT_CARD_EXP_MONTH ] = ASCIIToUTF16("Some other error message"); | 213 validity2[CREDIT_CARD_EXP_MONTH ] = ASCIIToUTF16("Some other error message"); |
| 214 EXPECT_CALL(controller_, RequestedFieldsForSection(section_)) | 214 EXPECT_CALL(delegate_, RequestedFieldsForSection(section_)) |
| 215 .WillOnce(ReturnRef(inputs)); | 215 .WillOnce(ReturnRef(inputs)); |
| 216 EXPECT_CALL(controller_, ComboboxModelForAutofillType(EMAIL_ADDRESS)) | 216 EXPECT_CALL(delegate_, ComboboxModelForAutofillType(EMAIL_ADDRESS)) |
| 217 .WillRepeatedly(ReturnNull()); | 217 .WillRepeatedly(ReturnNull()); |
| 218 EXPECT_CALL(controller_, ComboboxModelForAutofillType(CREDIT_CARD_EXP_MONTH)) | 218 EXPECT_CALL(delegate_, ComboboxModelForAutofillType(CREDIT_CARD_EXP_MONTH)) |
| 219 .WillRepeatedly(Return(&comboModel)); | 219 .WillRepeatedly(Return(&comboModel)); |
| 220 | 220 |
| 221 ResetContainer(); | 221 ResetContainer(); |
| 222 [container_ getInputs:&output]; | 222 [container_ getInputs:&output]; |
| 223 EXPECT_CALL(controller_, InputsAreValid(section_, output, VALIDATE_FINAL)) | 223 EXPECT_CALL(delegate_, InputsAreValid(section_, output, VALIDATE_FINAL)) |
| 224 .WillOnce(Return(validity)) | 224 .WillOnce(Return(validity)) |
| 225 .WillOnce(Return(validity2)); | 225 .WillOnce(Return(validity2)); |
| 226 | 226 |
| 227 [container_ validateFor:VALIDATE_FINAL]; | 227 [container_ validateFor:VALIDATE_FINAL]; |
| 228 NSControl<AutofillInputField>* field = [container_ getField:EMAIL_ADDRESS]; | 228 NSControl<AutofillInputField>* field = [container_ getField:EMAIL_ADDRESS]; |
| 229 EXPECT_TRUE([field invalid]); | 229 EXPECT_TRUE([field invalid]); |
| 230 field = [container_ getField:CREDIT_CARD_EXP_MONTH]; | 230 field = [container_ getField:CREDIT_CARD_EXP_MONTH]; |
| 231 EXPECT_FALSE([field invalid]); | 231 EXPECT_FALSE([field invalid]); |
| 232 | 232 |
| 233 | 233 |
| 234 [container_ validateFor:VALIDATE_FINAL]; | 234 [container_ validateFor:VALIDATE_FINAL]; |
| 235 field = [container_ getField:EMAIL_ADDRESS]; | 235 field = [container_ getField:EMAIL_ADDRESS]; |
| 236 EXPECT_FALSE([field invalid]); | 236 EXPECT_FALSE([field invalid]); |
| 237 field = [container_ getField:CREDIT_CARD_EXP_MONTH]; | 237 field = [container_ getField:CREDIT_CARD_EXP_MONTH]; |
| 238 EXPECT_TRUE([field invalid]); | 238 EXPECT_TRUE([field invalid]); |
| 239 } | 239 } |
| OLD | NEW |