Home | History | Annotate | Download | only in autofill
      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/views/autofill/autofill_dialog_view_tester_views.h"
      6 
      7 #include "base/logging.h"
      8 #include "chrome/browser/ui/views/autofill/autofill_dialog_views.h"
      9 #include "chrome/browser/ui/views/autofill/expanding_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"
     16 
     17 namespace autofill {
     18 
     19 scoped_ptr<AutofillDialogViewTester> AutofillDialogViewTester::For(
     20     AutofillDialogView* view) {
     21   return scoped_ptr<AutofillDialogViewTester>(new
     22       AutofillDialogViewTesterViews(static_cast<AutofillDialogViews*>(view)));
     23 }
     24 
     25 AutofillDialogViewTesterViews::AutofillDialogViewTesterViews(
     26     AutofillDialogViews* view)
     27     : view_(view) {}
     28 
     29 AutofillDialogViewTesterViews::~AutofillDialogViewTesterViews() {}
     30 
     31 void AutofillDialogViewTesterViews::SubmitForTesting() {
     32   view_->Accept();
     33 }
     34 
     35 void AutofillDialogViewTesterViews::CancelForTesting() {
     36   view_->GetDialogClientView()->CancelWindow();
     37 }
     38 
     39 base::string16 AutofillDialogViewTesterViews::GetTextContentsOfInput(
     40     ServerFieldType type) {
     41   ExpandingTextfield* textfield = view_->TextfieldForType(type);
     42   if (textfield)
     43     return textfield->GetText();
     44 
     45   views::Combobox* combobox = view_->ComboboxForType(type);
     46   if (combobox)
     47     return combobox->model()->GetItemAt(combobox->selected_index());
     48 
     49   NOTREACHED();
     50   return base::string16();
     51 }
     52 
     53 void AutofillDialogViewTesterViews::SetTextContentsOfInput(
     54     ServerFieldType type,
     55     const base::string16& contents) {
     56   ExpandingTextfield* textfield = view_->TextfieldForType(type);
     57   if (textfield) {
     58     textfield->SetText(contents);
     59     return;
     60   }
     61 
     62   views::Combobox* combobox = view_->ComboboxForType(type);
     63   if (combobox) {
     64     if (!combobox->SelectValue(contents))
     65       combobox->SetSelectedIndex(combobox->model()->GetDefaultIndex());
     66     return;
     67   }
     68 
     69   NOTREACHED();
     70 }
     71 
     72 void AutofillDialogViewTesterViews::SetTextContentsOfSuggestionInput(
     73     DialogSection section,
     74     const base::string16& text) {
     75   view_->GroupForSection(section)->suggested_info->textfield()->SetText(text);
     76 }
     77 
     78 void AutofillDialogViewTesterViews::ActivateInput(ServerFieldType type) {
     79   view_->InputEditedOrActivated(type, gfx::Rect(), false);
     80 }
     81 
     82 gfx::Size AutofillDialogViewTesterViews::GetSize() const {
     83   return view_->GetWidget() ? view_->GetWidget()->GetRootView()->size() :
     84                               gfx::Size();
     85 }
     86 
     87 content::WebContents* AutofillDialogViewTesterViews::GetSignInWebContents() {
     88   return view_->sign_in_web_view_->web_contents();
     89 }
     90 
     91 bool AutofillDialogViewTesterViews::IsShowingOverlay() const {
     92   return view_->overlay_view_->visible();
     93 }
     94 
     95 bool AutofillDialogViewTesterViews::IsShowingSection(DialogSection section)
     96     const {
     97   return view_->GroupForSection(section)->container->visible();
     98 }
     99 
    100 }  // namespace autofill
    101