Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / autofill / autofill_dialog_cocoa_browsertest.mm
blob692aaaca06d7dd86824faf8a5f9753644936ab85
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"
6 #include "base/bind.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"
21 namespace autofill {
23 namespace {
25 void MockCallback(AutofillClient::RequestAutocompleteResult result,
26                   const base::string16&,
27                   const FormStructure*) {
30 class TestAutofillDialogController : public AutofillDialogControllerImpl {
31  public:
32   TestAutofillDialogController(
33       content::WebContents* contents,
34       const FormData& form_structure,
35       scoped_refptr<content::MessageLoopRunner> runner)
36       : AutofillDialogControllerImpl(contents,
37                                      form_structure,
38                                      GURL(),
39                                      base::Bind(MockCallback)),
40         runner_(runner) {}
42   ~TestAutofillDialogController() override {}
44   void ViewClosed() override {
45     DCHECK(runner_.get());
46     runner_->Quit();
47     AutofillDialogControllerImpl::ViewClosed();
48   }
50   AutofillDialogCocoa* GetView() {
51     return static_cast<AutofillDialogCocoa*>(
52         AutofillDialogControllerImpl::view());
53   }
55  private:
56   scoped_refptr<content::MessageLoopRunner> runner_;
58   DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController);
61 class AutofillDialogCocoaBrowserTest : public InProcessBrowserTest {
62  public:
63   AutofillDialogCocoaBrowserTest() {}
65   void SetUpOnMainThread() override {
66     // Ensure Mac OS X does not pop up a modal dialog for the Address Book.
67     autofill::test::DisableSystemServices(browser()->profile()->GetPrefs());
69     // Stick to local autofill mode.
70     browser()->profile()->GetPrefs()->SetBoolean(
71         ::prefs::kAutofillDialogPayWithoutWallet, true);
73     FormFieldData field;
74     field.autocomplete_attribute = "cc-number";
75     FormData form_data;
76     form_data.fields.push_back(field);
77     runner_ = new content::MessageLoopRunner;
78     controller_ = new TestAutofillDialogController(
79         browser()->tab_strip_model()->GetActiveWebContents(),
80         form_data,
81         runner_);
82   }
84   TestAutofillDialogController* controller() { return controller_; }
86   void RunMessageLoop() {
87     DCHECK(runner_.get());
88     runner_->Run();
89   }
91  private:
92   // The controller owns itself.
93   TestAutofillDialogController* controller_;
95   scoped_refptr<content::MessageLoopRunner> runner_;
97   DISALLOW_COPY_AND_ASSIGN(AutofillDialogCocoaBrowserTest);
100 IN_PROC_BROWSER_TEST_F(AutofillDialogCocoaBrowserTest, DisplayUI) {
101   controller()->Show();
102   controller()->OnCancel();
103   controller()->Hide();
105   RunMessageLoop();
108 }  // namespace
110 }  // namespace autofill