1 // Copyright (c) 2013 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 #import "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h"
7 #include "base/message_loop/message_loop.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/common/pref_names.h"
14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "components/autofill/core/browser/autofill_test_utils.h"
16 #include "components/autofill/core/common/form_data.h"
17 #include "content/public/browser/web_contents.h"
18 #include "content/public/test/test_utils.h"
19 #include "testing/gtest/include/gtest/gtest.h"
25 void MockCallback(AutofillManagerDelegate::RequestAutocompleteResult result,
26 const base::string16&,
27 const FormStructure*) {}
29 class TestAutofillDialogController : public AutofillDialogControllerImpl {
31 TestAutofillDialogController(
32 content::WebContents* contents,
33 const FormData& form_structure,
34 const AutofillMetrics& metric_logger,
35 scoped_refptr<content::MessageLoopRunner> runner)
36 : AutofillDialogControllerImpl(contents,
39 base::Bind(MockCallback)),
40 metric_logger_(metric_logger) ,
43 virtual ~TestAutofillDialogController() {}
45 virtual void ViewClosed() OVERRIDE {
46 DCHECK(runner_.get());
48 AutofillDialogControllerImpl::ViewClosed();
51 AutofillDialogCocoa* GetView() {
52 return static_cast<AutofillDialogCocoa*>(
53 AutofillDialogControllerImpl::view());
57 // To specify our own metric logger.
58 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE {
59 return metric_logger_;
62 const AutofillMetrics& metric_logger_;
63 scoped_refptr<content::MessageLoopRunner> runner_;
65 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController);
68 class AutofillDialogCocoaBrowserTest : public InProcessBrowserTest {
70 AutofillDialogCocoaBrowserTest() : InProcessBrowserTest() {}
72 virtual ~AutofillDialogCocoaBrowserTest() {}
74 virtual void SetUpOnMainThread() OVERRIDE {
75 // Ensure Mac OS X does not pop up a modal dialog for the Address Book.
76 autofill::test::DisableSystemServices(browser()->profile()->GetPrefs());
78 // Stick to local autofill mode.
79 browser()->profile()->GetPrefs()->SetBoolean(
80 ::prefs::kAutofillDialogPayWithoutWallet, true);
83 field.autocomplete_attribute = "cc-number";
85 form_data.fields.push_back(field);
86 runner_ = new content::MessageLoopRunner;
87 controller_ = new TestAutofillDialogController(
88 browser()->tab_strip_model()->GetActiveWebContents(),
94 TestAutofillDialogController* controller() { return controller_; }
96 void RunMessageLoop() {
97 DCHECK(runner_.get());
102 // The controller owns itself.
103 TestAutofillDialogController* controller_;
105 // The following members must outlive the controller.
106 AutofillMetrics metric_logger_;
107 scoped_refptr<content::MessageLoopRunner> runner_;
109 DISALLOW_COPY_AND_ASSIGN(AutofillDialogCocoaBrowserTest);
112 IN_PROC_BROWSER_TEST_F(AutofillDialogCocoaBrowserTest, DisplayUI) {
113 controller()->Show();
114 controller()->OnCancel();
115 controller()->Hide();
122 } // namespace autofill