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/browser/web_contents_view.h"
19 #include "content/public/test/test_utils.h"
20 #include "testing/gtest/include/gtest/gtest.h"
26 void MockCallback(const FormStructure*) {}
28 class TestAutofillDialogController : public AutofillDialogControllerImpl {
30 TestAutofillDialogController(
31 content::WebContents* contents,
32 const FormData& form_structure,
33 const AutofillMetrics& metric_logger,
34 scoped_refptr<content::MessageLoopRunner> runner)
35 : AutofillDialogControllerImpl(contents,
38 base::Bind(MockCallback)),
39 metric_logger_(metric_logger) ,
42 virtual ~TestAutofillDialogController() {}
44 virtual void ViewClosed() OVERRIDE {
45 DCHECK(runner_.get());
47 AutofillDialogControllerImpl::ViewClosed();
50 AutofillDialogCocoa* GetView() {
51 return static_cast<AutofillDialogCocoa*>(
52 AutofillDialogControllerImpl::view());
56 // To specify our own metric logger.
57 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE {
58 return metric_logger_;
61 const AutofillMetrics& metric_logger_;
62 scoped_refptr<content::MessageLoopRunner> runner_;
64 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController);
67 class AutofillDialogCocoaBrowserTest : public InProcessBrowserTest {
69 AutofillDialogCocoaBrowserTest() : InProcessBrowserTest() {}
71 virtual ~AutofillDialogCocoaBrowserTest() {}
73 virtual void SetUpOnMainThread() OVERRIDE {
74 // Ensure Mac OS X does not pop up a modal dialog for the Address Book.
75 autofill::test::DisableSystemServices(browser()->profile());
77 // Stick to local autofill mode.
78 browser()->profile()->GetPrefs()->SetBoolean(
79 ::prefs::kAutofillDialogPayWithoutWallet, true);
82 field.autocomplete_attribute = "cc-number";
84 form_data.fields.push_back(field);
85 runner_ = new content::MessageLoopRunner;
86 controller_ = new TestAutofillDialogController(
87 browser()->tab_strip_model()->GetActiveWebContents(),
93 TestAutofillDialogController* controller() { return controller_; }
95 void RunMessageLoop() {
96 DCHECK(runner_.get());
101 // The controller owns itself.
102 TestAutofillDialogController* controller_;
104 // The following members must outlive the controller.
105 AutofillMetrics metric_logger_;
106 scoped_refptr<content::MessageLoopRunner> runner_;
108 DISALLOW_COPY_AND_ASSIGN(AutofillDialogCocoaBrowserTest);
111 IN_PROC_BROWSER_TEST_F(AutofillDialogCocoaBrowserTest, DisplayUI) {
112 controller()->Show();
113 controller()->OnCancel();
114 controller()->Hide();
121 } // namespace autofill