1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/cocoa/autofill/autofill_dialog_view_tester_cocoa.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_dialog_window_controller.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h"
// Mirrors the AutofillDialogViewTester API on the C++ side.
@interface AutofillDialogWindowController (AutofillDialogViewTesterCocoa)
- (void)setTextContents:(NSString*)text
forType:(autofill::ServerFieldType)type;
- (void)setTextContents:(NSString*)text
ofSuggestionForSection:(autofill::DialogSection)section;
- (void)activateFieldForType:(autofill::ServerFieldType)type;
- (content::WebContents*)getSignInWebContents;
- (BOOL)isShowingOverlay;
- (BOOL)isShowingSection:(autofill::DialogSection)section;
@end
@implementation AutofillDialogWindowController (AutofillDialogViewTesterCocoa)
- (void)setTextContents:(NSString*)text
forType:(autofill::ServerFieldType)type {
for (size_t i = autofill::SECTION_MIN; i <= autofill::SECTION_MAX; ++i) {
autofill::DialogSection section = static_cast<autofill::DialogSection>(i);
if (!dialog_->delegate()->SectionIsActive(section))
continue;
// TODO(groby): Need to find the section for an input directly - wasteful.
[[mainContainer_ sectionForId:section] setFieldValue:text forType:type];
}
}
- (void)setTextContents:(NSString*)text
ofSuggestionForSection:(autofill::DialogSection)section {
[[mainContainer_ sectionForId:section] setSuggestionFieldValue:text];
}
- (void)activateFieldForType:(autofill::ServerFieldType)type {
for (size_t i = autofill::SECTION_MIN; i <= autofill::SECTION_MAX; ++i) {
autofill::DialogSection section = static_cast<autofill::DialogSection>(i);
if (!dialog_->delegate()->SectionIsActive(section))
continue;
[[mainContainer_ sectionForId:section] activateFieldForType:type];
}
}
- (content::WebContents*)getSignInWebContents {
return [signInContainer_ webContents];
}
- (BOOL)isShowingOverlay {
return ![[overlayController_ view] isHidden];
}
- (BOOL)isShowingSection:(autofill::DialogSection)section {
return ![[[mainContainer_ sectionForId:section] view] isHidden];
}
@end
namespace autofill {
scoped_ptr<AutofillDialogViewTester> AutofillDialogViewTester::For(
AutofillDialogView* dialog) {
return scoped_ptr<AutofillDialogViewTester>(
new AutofillDialogViewTesterCocoa(
static_cast<AutofillDialogCocoa*>(dialog)));
}
AutofillDialogViewTesterCocoa::AutofillDialogViewTesterCocoa(
AutofillDialogCocoa* dialog)
: dialog_(dialog) {}
AutofillDialogViewTesterCocoa::~AutofillDialogViewTesterCocoa() {}
void AutofillDialogViewTesterCocoa::SubmitForTesting() {
[controller() accept:nil];
}
void AutofillDialogViewTesterCocoa::CancelForTesting() {
[controller() cancel:nil];
}
base::string16 AutofillDialogViewTesterCocoa::GetTextContentsOfInput(
ServerFieldType type) {
for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
DialogSection section = static_cast<DialogSection>(i);
if (!dialog_->delegate()->SectionIsActive(section))
continue;
FieldValueMap contents;
[controller() getInputs:&contents forSection:section];
FieldValueMap::const_iterator it = contents.find(type);
if (it != contents.end())
return it->second;
}
NOTREACHED();
return base::string16();
}
void AutofillDialogViewTesterCocoa::SetTextContentsOfInput(
ServerFieldType type,
const base::string16& contents) {
[controller() setTextContents:base::SysUTF16ToNSString(contents)
forType:type];
}
void AutofillDialogViewTesterCocoa::SetTextContentsOfSuggestionInput(
DialogSection section,
const base::string16& text) {
[controller() setTextContents:base::SysUTF16ToNSString(text)
ofSuggestionForSection:section];
}
void AutofillDialogViewTesterCocoa::ActivateInput(ServerFieldType type) {
[controller() activateFieldForType:type];
}
gfx::Size AutofillDialogViewTesterCocoa::GetSize() const {
return gfx::Size(NSSizeToCGSize([[controller() window] frame].size));
}
content::WebContents* AutofillDialogViewTesterCocoa::GetSignInWebContents() {
return [controller() getSignInWebContents];
}
bool AutofillDialogViewTesterCocoa::IsShowingOverlay() const {
return [controller() isShowingOverlay];
}
bool AutofillDialogViewTesterCocoa::IsShowingSection(
autofill::DialogSection section) const {
return [controller() isShowingSection:section];
}
AutofillDialogWindowController*
AutofillDialogViewTesterCocoa::controller() const {
return dialog_->sheet_delegate_;
}
} // namespace autofill
|