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.
5 #include "chrome/browser/ui/views/autofill/autofill_dialog_view_tester_views.h"
7 #include "base/logging.h"
8 #include "chrome/browser/ui/views/autofill/autofill_dialog_views.h"
9 #include "chrome/browser/ui/views/autofill/decorated_textfield.h"
10 #include "ui/base/models/combobox_model.h"
11 #include "ui/views/controls/combobox/combobox.h"
12 #include "ui/views/controls/textfield/textfield.h"
13 #include "ui/views/controls/webview/webview.h"
14 #include "ui/views/widget/widget.h"
15 #include "ui/views/window/dialog_client_view.h"
19 scoped_ptr<AutofillDialogViewTester> AutofillDialogViewTester::For(
20 AutofillDialogView* view) {
21 return scoped_ptr<AutofillDialogViewTester>(new
22 AutofillDialogViewTesterViews(static_cast<AutofillDialogViews*>(view)));
25 AutofillDialogViewTesterViews::AutofillDialogViewTesterViews(
26 AutofillDialogViews* view)
29 AutofillDialogViewTesterViews::~AutofillDialogViewTesterViews() {}
31 void AutofillDialogViewTesterViews::SubmitForTesting() {
35 void AutofillDialogViewTesterViews::CancelForTesting() {
36 view_->GetDialogClientView()->CancelWindow();
39 base::string16 AutofillDialogViewTesterViews::GetTextContentsOfInput(
40 ServerFieldType type) {
41 views::Textfield* textfield = view_->TextfieldForType(type);
43 return textfield->text();
45 views::Combobox* combobox = view_->ComboboxForType(type);
47 return combobox->model()->GetItemAt(combobox->selected_index());
50 return base::string16();
53 void AutofillDialogViewTesterViews::SetTextContentsOfInput(
55 const base::string16& contents) {
56 views::Textfield* textfield = view_->TextfieldForType(type);
58 textfield->SetText(contents);
62 views::Combobox* combobox = view_->ComboboxForType(type);
64 if (!combobox->SelectValue(contents))
65 combobox->SetSelectedIndex(combobox->model()->GetDefaultIndex());
72 void AutofillDialogViewTesterViews::SetTextContentsOfSuggestionInput(
73 DialogSection section,
74 const base::string16& text) {
75 view_->GroupForSection(section)->suggested_info->decorated_textfield()->
79 void AutofillDialogViewTesterViews::ActivateInput(ServerFieldType type) {
80 view_->InputEditedOrActivated(type, gfx::Rect(), false);
83 gfx::Size AutofillDialogViewTesterViews::GetSize() const {
84 return view_->GetWidget() ? view_->GetWidget()->GetRootView()->size() :
88 content::WebContents* AutofillDialogViewTesterViews::GetSignInWebContents() {
89 return view_->sign_in_web_view_->web_contents();
92 bool AutofillDialogViewTesterViews::IsShowingOverlay() const {
93 return view_->overlay_view_->visible();
96 bool AutofillDialogViewTesterViews::IsShowingSection(DialogSection section)
98 return view_->GroupForSection(section)->container->visible();
101 } // namespace autofill