OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/autofill/content/browser/content_autofill_driver.h" | 5 #include "components/autofill/content/browser/content_autofill_driver.h" |
6 #include "components/autofill/content/browser/request_autocomplete_manager.h" | 6 #include "components/autofill/content/browser/request_autocomplete_manager.h" |
7 #include "components/autofill/content/common/autofill_messages.h" | 7 #include "components/autofill/content/common/autofill_messages.h" |
8 #include "components/autofill/core/browser/test_autofill_client.h" | 8 #include "components/autofill/core/browser/test_autofill_client.h" |
9 #include "content/public/test/mock_render_process_host.h" | 9 #include "content/public/test/mock_render_process_host.h" |
10 #include "content/public/test/test_renderer_host.h" | 10 #include "content/public/test/test_renderer_host.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace autofill { | 13 namespace autofill { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 const char kAppLocale[] = "en-US"; | 17 const char kAppLocale[] = "en-US"; |
18 const AutofillManager::AutofillDownloadManagerState kDownloadState = | 18 const AutofillManager::AutofillDownloadManagerState kDownloadState = |
19 AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER; | 19 AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER; |
20 | 20 |
21 class TestAutofillManager : public AutofillManager { | 21 class TestAutofillManager : public AutofillManager { |
22 public: | 22 public: |
23 TestAutofillManager(AutofillDriver* driver, AutofillClient* client) | 23 TestAutofillManager(AutofillDriver* driver, AutofillClient* client) |
24 : AutofillManager(driver, client, kAppLocale, kDownloadState), | 24 : AutofillManager(driver, client, kAppLocale, kDownloadState), |
25 autofill_enabled_(true) {} | 25 autofill_enabled_(true) {} |
26 virtual ~TestAutofillManager() {} | 26 ~TestAutofillManager() override {} |
27 | 27 |
28 virtual bool IsAutofillEnabled() const override { return autofill_enabled_; } | 28 bool IsAutofillEnabled() const override { return autofill_enabled_; } |
29 | 29 |
30 void set_autofill_enabled(bool autofill_enabled) { | 30 void set_autofill_enabled(bool autofill_enabled) { |
31 autofill_enabled_ = autofill_enabled; | 31 autofill_enabled_ = autofill_enabled; |
32 } | 32 } |
33 | 33 |
34 private: | 34 private: |
35 bool autofill_enabled_; | 35 bool autofill_enabled_; |
36 | 36 |
37 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 37 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
38 }; | 38 }; |
39 | 39 |
40 class CustomTestAutofillClient : public TestAutofillClient { | 40 class CustomTestAutofillClient : public TestAutofillClient { |
41 public: | 41 public: |
42 CustomTestAutofillClient() : should_simulate_success_(true) {} | 42 CustomTestAutofillClient() : should_simulate_success_(true) {} |
43 | 43 |
44 virtual ~CustomTestAutofillClient() {} | 44 ~CustomTestAutofillClient() override {} |
45 | 45 |
46 virtual void ShowRequestAutocompleteDialog( | 46 void ShowRequestAutocompleteDialog(const FormData& form, |
47 const FormData& form, | 47 const GURL& source_url, |
48 const GURL& source_url, | 48 const ResultCallback& callback) override { |
49 const ResultCallback& callback) override { | |
50 if (should_simulate_success_) { | 49 if (should_simulate_success_) { |
51 FormStructure form_structure(form); | 50 FormStructure form_structure(form); |
52 callback.Run( | 51 callback.Run( |
53 AutocompleteResultSuccess, base::string16(), &form_structure); | 52 AutocompleteResultSuccess, base::string16(), &form_structure); |
54 } else { | 53 } else { |
55 callback.Run(AutofillClient::AutocompleteResultErrorDisabled, | 54 callback.Run(AutofillClient::AutocompleteResultErrorDisabled, |
56 base::string16(), | 55 base::string16(), |
57 NULL); | 56 NULL); |
58 } | 57 } |
59 } | 58 } |
(...skipping 11 matching lines...) Expand all Loading... |
71 }; | 70 }; |
72 | 71 |
73 class TestContentAutofillDriver : public ContentAutofillDriver { | 72 class TestContentAutofillDriver : public ContentAutofillDriver { |
74 public: | 73 public: |
75 TestContentAutofillDriver(content::WebContents* contents, | 74 TestContentAutofillDriver(content::WebContents* contents, |
76 AutofillClient* client) | 75 AutofillClient* client) |
77 : ContentAutofillDriver(contents, client, kAppLocale, kDownloadState) { | 76 : ContentAutofillDriver(contents, client, kAppLocale, kDownloadState) { |
78 SetAutofillManager(make_scoped_ptr<AutofillManager>( | 77 SetAutofillManager(make_scoped_ptr<AutofillManager>( |
79 new TestAutofillManager(this, client))); | 78 new TestAutofillManager(this, client))); |
80 } | 79 } |
81 virtual ~TestContentAutofillDriver() {} | 80 ~TestContentAutofillDriver() override {} |
82 | 81 |
83 TestAutofillManager* mock_autofill_manager() { | 82 TestAutofillManager* mock_autofill_manager() { |
84 return static_cast<TestAutofillManager*>(autofill_manager()); | 83 return static_cast<TestAutofillManager*>(autofill_manager()); |
85 } | 84 } |
86 | 85 |
87 using ContentAutofillDriver::DidNavigateMainFrame; | 86 using ContentAutofillDriver::DidNavigateMainFrame; |
88 | 87 |
89 DISALLOW_COPY_AND_ASSIGN(TestContentAutofillDriver); | 88 DISALLOW_COPY_AND_ASSIGN(TestContentAutofillDriver); |
90 }; | 89 }; |
91 | 90 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 TEST_F(RequestAutocompleteManagerTest, | 159 TEST_F(RequestAutocompleteManagerTest, |
161 OnRequestAutocompleteWithAutofillDisabled) { | 160 OnRequestAutocompleteWithAutofillDisabled) { |
162 blink::WebFormElement::AutocompleteResult result; | 161 blink::WebFormElement::AutocompleteResult result; |
163 driver_->mock_autofill_manager()->set_autofill_enabled(false); | 162 driver_->mock_autofill_manager()->set_autofill_enabled(false); |
164 request_autocomplete_manager_->OnRequestAutocomplete(FormData(), GURL()); | 163 request_autocomplete_manager_->OnRequestAutocomplete(FormData(), GURL()); |
165 EXPECT_TRUE(GetAutocompleteResultMessage(&result)); | 164 EXPECT_TRUE(GetAutocompleteResultMessage(&result)); |
166 EXPECT_EQ(blink::WebFormElement::AutocompleteResultSuccess, result); | 165 EXPECT_EQ(blink::WebFormElement::AutocompleteResultSuccess, result); |
167 } | 166 } |
168 | 167 |
169 } // namespace autofill | 168 } // namespace autofill |
OLD | NEW |