| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 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 "base/strings/sys_string_conversions.h" |
| 8 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h" |
| 9 #import "chrome/browser/ui/cocoa/autofill/autofill_dialog_window_controller.h" |
| 10 #import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h" |
| 11 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h" |
| 12 #import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h" |
| 13 |
| 14 |
| 15 // Mirrors the AutofillDialogViewTester API on the C++ side. |
| 16 @interface AutofillDialogWindowController (AutofillDialogViewTesterCocoa) |
| 17 |
| 18 - (void)setTextContents:(NSString*)text |
| 19 forType:(autofill::ServerFieldType)type; |
| 20 - (void)setTextContents:(NSString*)text |
| 21 ofSuggestionForSection:(autofill::DialogSection)section; |
| 22 - (void)activateFieldForType:(autofill::ServerFieldType)type; |
| 23 - (content::WebContents*)getSignInWebContents; |
| 24 - (BOOL)isShowingOverlay; |
| 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 // TODO(groby): Need to find the section for an input directly - wasteful. |
| 36 [[mainContainer_ sectionForId:section] setFieldValue:text forType:type]; |
| 37 } |
| 38 } |
| 39 |
| 40 - (void)setTextContents:(NSString*)text |
| 41 ofSuggestionForSection:(autofill::DialogSection)section { |
| 42 [[mainContainer_ sectionForId:section] setSuggestionFieldValue:text]; |
| 43 } |
| 44 |
| 45 - (void)activateFieldForType:(autofill::ServerFieldType)type { |
| 46 for (size_t i = autofill::SECTION_MIN; i <= autofill::SECTION_MAX; ++i) { |
| 47 autofill::DialogSection section = static_cast<autofill::DialogSection>(i); |
| 48 [[mainContainer_ sectionForId:section] activateFieldForType:type]; |
| 49 } |
| 50 } |
| 51 |
| 52 - (content::WebContents*)getSignInWebContents { |
| 53 return [signInContainer_ webContents]; |
| 54 } |
| 55 |
| 56 - (BOOL)isShowingOverlay { |
| 57 return ![[overlayController_ view] isHidden]; |
| 58 } |
| 59 |
| 60 @end |
| 61 |
| 62 namespace autofill { |
| 63 |
| 64 scoped_ptr<AutofillDialogViewTester> AutofillDialogViewTester::For( |
| 65 AutofillDialogView* dialog) { |
| 66 return scoped_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 FieldValueMap contents; |
| 90 [controller() getInputs:&contents forSection:section]; |
| 91 FieldValueMap::const_iterator it = contents.find(type); |
| 92 if (it != contents.end()) |
| 93 return it->second; |
| 94 } |
| 95 |
| 96 NOTREACHED(); |
| 97 return base::string16(); |
| 98 } |
| 99 |
| 100 void AutofillDialogViewTesterCocoa::SetTextContentsOfInput( |
| 101 ServerFieldType type, |
| 102 const base::string16& contents) { |
| 103 [controller() setTextContents:base::SysUTF16ToNSString(contents) |
| 104 forType:type]; |
| 105 } |
| 106 |
| 107 void AutofillDialogViewTesterCocoa::SetTextContentsOfSuggestionInput( |
| 108 DialogSection section, |
| 109 const base::string16& text) { |
| 110 [controller() setTextContents:base::SysUTF16ToNSString(text) |
| 111 ofSuggestionForSection:section]; |
| 112 } |
| 113 |
| 114 void AutofillDialogViewTesterCocoa::ActivateInput(ServerFieldType type) { |
| 115 [controller() activateFieldForType:type]; |
| 116 } |
| 117 |
| 118 gfx::Size AutofillDialogViewTesterCocoa::GetSize() const { |
| 119 return gfx::Size(NSSizeToCGSize([[controller() window] frame].size)); |
| 120 } |
| 121 |
| 122 content::WebContents* AutofillDialogViewTesterCocoa::GetSignInWebContents() { |
| 123 return [controller() getSignInWebContents]; |
| 124 } |
| 125 |
| 126 bool AutofillDialogViewTesterCocoa::IsShowingOverlay() const { |
| 127 return [controller() isShowingOverlay]; |
| 128 } |
| 129 |
| 130 AutofillDialogWindowController* |
| 131 AutofillDialogViewTesterCocoa::controller() const { |
| 132 return dialog_->sheet_delegate_; |
| 133 } |
| 134 |
| 135 } // namespace autofill |
| OLD | NEW |