OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/prefs/testing_pref_service.h" | 8 #include "base/prefs/testing_pref_service.h" |
9 #include "base/string16.h" | 9 #include "base/string16.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/webdata/autofill_web_data_service_impl.h" | 11 #include "chrome/browser/webdata/autofill_web_data_service_impl.h" |
12 #include "chrome/browser/webdata/web_data_service.h" | |
13 #include "chrome/browser/webdata/web_data_service_factory.h" | 12 #include "chrome/browser/webdata/web_data_service_factory.h" |
14 #include "chrome/browser/webdata/web_data_service_test_util.h" | 13 #include "chrome/browser/webdata/web_data_service_test_util.h" |
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
16 #include "chrome/test/base/testing_browser_process.h" | 15 #include "chrome/test/base/testing_browser_process.h" |
17 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
18 #include "components/autofill/browser/autocomplete_history_manager.h" | 17 #include "components/autofill/browser/autocomplete_history_manager.h" |
19 #include "components/autofill/browser/autofill_external_delegate.h" | 18 #include "components/autofill/browser/autofill_external_delegate.h" |
20 #include "components/autofill/browser/autofill_manager.h" | 19 #include "components/autofill/browser/autofill_manager.h" |
21 #include "components/autofill/browser/test_autofill_manager_delegate.h" | 20 #include "components/autofill/browser/test_autofill_manager_delegate.h" |
22 #include "components/autofill/common/form_data.h" | 21 #include "components/autofill/common/form_data.h" |
23 #include "content/public/test/test_browser_thread.h" | 22 #include "content/public/test/test_browser_thread.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "ui/gfx/rect.h" | 25 #include "ui/gfx/rect.h" |
27 | 26 |
28 using content::BrowserThread; | 27 using content::BrowserThread; |
29 using content::WebContents; | 28 using content::WebContents; |
30 using testing::_; | 29 using testing::_; |
31 | 30 |
32 namespace { | 31 namespace { |
33 | 32 |
34 class MockWebDataService : public WebDataService { | 33 class MockWebDataService : public AutofillWebDataServiceImpl { |
35 public: | 34 public: |
36 MockWebDataService() { | 35 MockWebDataService() |
| 36 : AutofillWebDataServiceImpl( |
| 37 NULL, WebDataServiceBase::ProfileErrorCallback()) { |
37 current_mock_web_data_service_ = this; | 38 current_mock_web_data_service_ = this; |
38 } | 39 } |
39 | 40 |
40 MOCK_METHOD1(AddFormFields, void(const std::vector<FormFieldData>&)); | 41 MOCK_METHOD1(AddFormFields, void(const std::vector<FormFieldData>&)); |
41 | 42 |
42 static scoped_refptr<MockWebDataService> GetCurrent() { | 43 static scoped_refptr<MockWebDataService> GetCurrent() { |
43 if (!current_mock_web_data_service_) { | 44 if (!current_mock_web_data_service_) { |
44 return new MockWebDataService(); | 45 return new MockWebDataService(); |
45 } | 46 } |
46 return current_mock_web_data_service_; | 47 return current_mock_web_data_service_; |
(...skipping 11 matching lines...) Expand all Loading... |
58 MockWebDataService* MockWebDataService::current_mock_web_data_service_ = NULL; | 59 MockWebDataService* MockWebDataService::current_mock_web_data_service_ = NULL; |
59 | 60 |
60 class MockWebDataServiceWrapperCurrent : public MockWebDataServiceWrapperBase { | 61 class MockWebDataServiceWrapperCurrent : public MockWebDataServiceWrapperBase { |
61 public: | 62 public: |
62 static ProfileKeyedService* Build(Profile* profile) { | 63 static ProfileKeyedService* Build(Profile* profile) { |
63 return new MockWebDataServiceWrapperCurrent(); | 64 return new MockWebDataServiceWrapperCurrent(); |
64 } | 65 } |
65 | 66 |
66 MockWebDataServiceWrapperCurrent() {} | 67 MockWebDataServiceWrapperCurrent() {} |
67 | 68 |
68 scoped_refptr<WebDataService> GetWebData() OVERRIDE { | 69 scoped_refptr<AutofillWebDataService> GetAutofillWebData() OVERRIDE { |
69 return MockWebDataService::GetCurrent(); | 70 return MockWebDataService::GetCurrent(); |
70 } | 71 } |
71 | 72 |
72 private: | 73 private: |
73 DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapperCurrent); | 74 DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapperCurrent); |
74 }; | 75 }; |
75 | 76 |
76 class MockAutofillManagerDelegate | 77 class MockAutofillManagerDelegate |
77 : public autofill::TestAutofillManagerDelegate { | 78 : public autofill::TestAutofillManagerDelegate { |
78 public: | 79 public: |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 AutofillManager::CreateForWebContentsAndDelegate( | 252 AutofillManager::CreateForWebContentsAndDelegate( |
252 web_contents(), &manager_delegate); | 253 web_contents(), &manager_delegate); |
253 | 254 |
254 MockAutofillExternalDelegate external_delegate(web_contents()); | 255 MockAutofillExternalDelegate external_delegate(web_contents()); |
255 autocomplete_history_manager.SetExternalDelegate(&external_delegate); | 256 autocomplete_history_manager.SetExternalDelegate(&external_delegate); |
256 | 257 |
257 // Should trigger a call to OnSuggestionsReturned, verified by the mock. | 258 // Should trigger a call to OnSuggestionsReturned, verified by the mock. |
258 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); | 259 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); |
259 autocomplete_history_manager.SendSuggestions(NULL); | 260 autocomplete_history_manager.SendSuggestions(NULL); |
260 } | 261 } |
OLD | NEW |