| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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 "chrome/browser/ui/cocoa/autofill/autofill_dialog_view_tester_cocoa.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 | |
| 9 #include "base/strings/sys_string_conversions.h" | |
| 10 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h" | |
| 11 #import "chrome/browser/ui/cocoa/autofill/autofill_dialog_window_controller.h" | |
| 12 #import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h" | |
| 13 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h" | |
| 14 | |
| 15 | |
| 16 // Mirrors the AutofillDialogViewTester API on the C++ side. | |
| 17 @interface AutofillDialogWindowController (AutofillDialogViewTesterCocoa) | |
| 18 | |
| 19 - (void)setTextContents:(NSString*)text | |
| 20 forType:(autofill::ServerFieldType)type; | |
| 21 - (void)setTextContents:(NSString*)text | |
| 22 ofSuggestionForSection:(autofill::DialogSection)section; | |
| 23 - (void)activateFieldForType:(autofill::ServerFieldType)type; | |
| 24 - (BOOL)isShowingSection:(autofill::DialogSection)section; | |
| 25 | |
| 26 @end | |
| 27 | |
| 28 | |
| 29 @implementation AutofillDialogWindowController (AutofillDialogViewTesterCocoa) | |
| 30 | |
| 31 - (void)setTextContents:(NSString*)text | |
| 32 forType:(autofill::ServerFieldType)type { | |
| 33 for (size_t i = autofill::SECTION_MIN; i <= autofill::SECTION_MAX; ++i) { | |
| 34 autofill::DialogSection section = static_cast<autofill::DialogSection>(i); | |
| 35 if (!dialog_->delegate()->SectionIsActive(section)) | |
| 36 continue; | |
| 37 // TODO(groby): Need to find the section for an input directly - wasteful. | |
| 38 [[mainContainer_ sectionForId:section] setFieldValue:text forType:type]; | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 - (void)setTextContents:(NSString*)text | |
| 43 ofSuggestionForSection:(autofill::DialogSection)section { | |
| 44 [[mainContainer_ sectionForId:section] setSuggestionFieldValue:text]; | |
| 45 } | |
| 46 | |
| 47 - (void)activateFieldForType:(autofill::ServerFieldType)type { | |
| 48 for (size_t i = autofill::SECTION_MIN; i <= autofill::SECTION_MAX; ++i) { | |
| 49 autofill::DialogSection section = static_cast<autofill::DialogSection>(i); | |
| 50 if (!dialog_->delegate()->SectionIsActive(section)) | |
| 51 continue; | |
| 52 [[mainContainer_ sectionForId:section] activateFieldForType:type]; | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 - (BOOL)isShowingSection:(autofill::DialogSection)section { | |
| 57 return ![[[mainContainer_ sectionForId:section] view] isHidden]; | |
| 58 } | |
| 59 | |
| 60 @end | |
| 61 | |
| 62 namespace autofill { | |
| 63 | |
| 64 std::unique_ptr<AutofillDialogViewTester> AutofillDialogViewTester::For( | |
| 65 AutofillDialogView* dialog) { | |
| 66 return std::unique_ptr<AutofillDialogViewTester>( | |
| 67 new AutofillDialogViewTesterCocoa( | |
| 68 static_cast<AutofillDialogCocoa*>(dialog))); | |
| 69 } | |
| 70 | |
| 71 AutofillDialogViewTesterCocoa::AutofillDialogViewTesterCocoa( | |
| 72 AutofillDialogCocoa* dialog) | |
| 73 : dialog_(dialog) {} | |
| 74 | |
| 75 AutofillDialogViewTesterCocoa::~AutofillDialogViewTesterCocoa() {} | |
| 76 | |
| 77 void AutofillDialogViewTesterCocoa::SubmitForTesting() { | |
| 78 [controller() accept:nil]; | |
| 79 } | |
| 80 | |
| 81 void AutofillDialogViewTesterCocoa::CancelForTesting() { | |
| 82 [controller() cancel:nil]; | |
| 83 } | |
| 84 | |
| 85 base::string16 AutofillDialogViewTesterCocoa::GetTextContentsOfInput( | |
| 86 ServerFieldType type) { | |
| 87 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | |
| 88 DialogSection section = static_cast<DialogSection>(i); | |
| 89 if (!dialog_->delegate()->SectionIsActive(section)) | |
| 90 continue; | |
| 91 FieldValueMap contents; | |
| 92 [controller() getInputs:&contents forSection:section]; | |
| 93 FieldValueMap::const_iterator it = contents.find(type); | |
| 94 if (it != contents.end()) | |
| 95 return it->second; | |
| 96 } | |
| 97 | |
| 98 NOTREACHED(); | |
| 99 return base::string16(); | |
| 100 } | |
| 101 | |
| 102 void AutofillDialogViewTesterCocoa::SetTextContentsOfInput( | |
| 103 ServerFieldType type, | |
| 104 const base::string16& contents) { | |
| 105 [controller() setTextContents:base::SysUTF16ToNSString(contents) | |
| 106 forType:type]; | |
| 107 } | |
| 108 | |
| 109 void AutofillDialogViewTesterCocoa::SetTextContentsOfSuggestionInput( | |
| 110 DialogSection section, | |
| 111 const base::string16& text) { | |
| 112 [controller() setTextContents:base::SysUTF16ToNSString(text) | |
| 113 ofSuggestionForSection:section]; | |
| 114 } | |
| 115 | |
| 116 void AutofillDialogViewTesterCocoa::ActivateInput(ServerFieldType type) { | |
| 117 [controller() activateFieldForType:type]; | |
| 118 } | |
| 119 | |
| 120 gfx::Size AutofillDialogViewTesterCocoa::GetSize() const { | |
| 121 return gfx::Size(NSSizeToCGSize([[controller() window] frame].size)); | |
| 122 } | |
| 123 | |
| 124 bool AutofillDialogViewTesterCocoa::IsShowingSection( | |
| 125 autofill::DialogSection section) const { | |
| 126 return [controller() isShowingSection:section]; | |
| 127 } | |
| 128 | |
| 129 AutofillDialogWindowController* | |
| 130 AutofillDialogViewTesterCocoa::controller() const { | |
| 131 return dialog_->sheet_delegate_; | |
| 132 } | |
| 133 | |
| 134 } // namespace autofill | |
| OLD | NEW |