| OLD | NEW |
| (Empty) |
| 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" | |
| 5 | |
| 6 #include "base/bind.h" | |
| 7 #include "base/macros.h" | |
| 8 #include "base/message_loop/message_loop.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 "components/prefs/pref_service.h" | |
| 18 #include "content/public/browser/web_contents.h" | |
| 19 #include "content/public/test/test_utils.h" | |
| 20 #include "testing/gtest/include/gtest/gtest.h" | |
| 21 | |
| 22 namespace autofill { | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 void MockCallback(AutofillClient::RequestAutocompleteResult result, | |
| 27 const base::string16&, | |
| 28 const FormStructure*) { | |
| 29 } | |
| 30 | |
| 31 class TestAutofillDialogController : public AutofillDialogControllerImpl { | |
| 32 public: | |
| 33 TestAutofillDialogController( | |
| 34 content::WebContents* contents, | |
| 35 const FormData& form_structure, | |
| 36 scoped_refptr<content::MessageLoopRunner> runner) | |
| 37 : AutofillDialogControllerImpl(contents, | |
| 38 form_structure, | |
| 39 GURL(), | |
| 40 base::Bind(MockCallback)), | |
| 41 runner_(runner) {} | |
| 42 | |
| 43 ~TestAutofillDialogController() override {} | |
| 44 | |
| 45 void ViewClosed() override { | |
| 46 DCHECK(runner_.get()); | |
| 47 runner_->Quit(); | |
| 48 AutofillDialogControllerImpl::ViewClosed(); | |
| 49 } | |
| 50 | |
| 51 AutofillDialogCocoa* GetView() { | |
| 52 return static_cast<AutofillDialogCocoa*>( | |
| 53 AutofillDialogControllerImpl::view()); | |
| 54 } | |
| 55 | |
| 56 private: | |
| 57 scoped_refptr<content::MessageLoopRunner> runner_; | |
| 58 | |
| 59 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); | |
| 60 }; | |
| 61 | |
| 62 class AutofillDialogCocoaBrowserTest : public InProcessBrowserTest { | |
| 63 public: | |
| 64 AutofillDialogCocoaBrowserTest() {} | |
| 65 | |
| 66 void SetUpOnMainThread() override { | |
| 67 // Ensure Mac OS X does not pop up a modal dialog for the Address Book. | |
| 68 autofill::test::DisableSystemServices(browser()->profile()->GetPrefs()); | |
| 69 | |
| 70 // Stick to local autofill mode. | |
| 71 browser()->profile()->GetPrefs()->SetBoolean( | |
| 72 ::prefs::kAutofillDialogPayWithoutWallet, true); | |
| 73 | |
| 74 FormFieldData field; | |
| 75 field.autocomplete_attribute = "cc-number"; | |
| 76 FormData form_data; | |
| 77 form_data.fields.push_back(field); | |
| 78 runner_ = new content::MessageLoopRunner; | |
| 79 controller_ = new TestAutofillDialogController( | |
| 80 browser()->tab_strip_model()->GetActiveWebContents(), | |
| 81 form_data, | |
| 82 runner_); | |
| 83 } | |
| 84 | |
| 85 TestAutofillDialogController* controller() { return controller_; } | |
| 86 | |
| 87 void RunMessageLoop() { | |
| 88 DCHECK(runner_.get()); | |
| 89 runner_->Run(); | |
| 90 } | |
| 91 | |
| 92 private: | |
| 93 // The controller owns itself. | |
| 94 TestAutofillDialogController* controller_; | |
| 95 | |
| 96 scoped_refptr<content::MessageLoopRunner> runner_; | |
| 97 | |
| 98 DISALLOW_COPY_AND_ASSIGN(AutofillDialogCocoaBrowserTest); | |
| 99 }; | |
| 100 | |
| 101 IN_PROC_BROWSER_TEST_F(AutofillDialogCocoaBrowserTest, DisplayUI) { | |
| 102 controller()->Show(); | |
| 103 controller()->OnCancel(); | |
| 104 controller()->Hide(); | |
| 105 | |
| 106 RunMessageLoop(); | |
| 107 } | |
| 108 | |
| 109 } // namespace | |
| 110 | |
| 111 } // namespace autofill | |
| OLD | NEW |