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(AutofillClient::RequestAutocompleteResult result,
26 const base::string16&,
27 const FormStructure*) {
30 class TestAutofillDialogController : public AutofillDialogControllerImpl {
32 TestAutofillDialogController(
33 content::WebContents* contents,
34 const FormData& form_structure,
35 const AutofillMetrics& metric_logger,
36 scoped_refptr<content::MessageLoopRunner> runner)
37 : AutofillDialogControllerImpl(contents,
40 base::Bind(MockCallback)),
41 metric_logger_(metric_logger) ,
44 ~TestAutofillDialogController() override {}
46 void ViewClosed() override {
47 DCHECK(runner_.get());
49 AutofillDialogControllerImpl::ViewClosed();
52 AutofillDialogCocoa* GetView() {
53 return static_cast<AutofillDialogCocoa*>(
54 AutofillDialogControllerImpl::view());
58 // To specify our own metric logger.
59 const AutofillMetrics& GetMetricLogger() const override {
60 return metric_logger_;
63 const AutofillMetrics& metric_logger_;
64 scoped_refptr<content::MessageLoopRunner> runner_;
66 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController);
69 class AutofillDialogCocoaBrowserTest : public InProcessBrowserTest {
71 AutofillDialogCocoaBrowserTest() : InProcessBrowserTest() {}
73 virtual ~AutofillDialogCocoaBrowserTest() {}
75 void SetUpOnMainThread() override {
76 // Ensure Mac OS X does not pop up a modal dialog for the Address Book.
77 autofill::test::DisableSystemServices(browser()->profile()->GetPrefs());
79 // Stick to local autofill mode.
80 browser()->profile()->GetPrefs()->SetBoolean(
81 ::prefs::kAutofillDialogPayWithoutWallet, true);
84 field.autocomplete_attribute = "cc-number";
86 form_data.fields.push_back(field);
87 runner_ = new content::MessageLoopRunner;
88 controller_ = new TestAutofillDialogController(
89 browser()->tab_strip_model()->GetActiveWebContents(),
95 TestAutofillDialogController* controller() { return controller_; }
97 void RunMessageLoop() {
98 DCHECK(runner_.get());
103 // The controller owns itself.
104 TestAutofillDialogController* controller_;
106 // The following members must outlive the controller.
107 AutofillMetrics metric_logger_;
108 scoped_refptr<content::MessageLoopRunner> runner_;
110 DISALLOW_COPY_AND_ASSIGN(AutofillDialogCocoaBrowserTest);
113 IN_PROC_BROWSER_TEST_F(AutofillDialogCocoaBrowserTest, DisplayUI) {
114 controller()->Show();
115 controller()->OnCancel();
116 controller()->Hide();
123 } // namespace autofill