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/synchronization/waitable_event.h" | |
10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/webdata/web_data_service_factory.h" | 12 #include "chrome/browser/webdata/web_data_service_factory.h" |
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
13 #include "chrome/test/base/testing_browser_process.h" | 14 #include "chrome/test/base/testing_browser_process.h" |
14 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
15 #include "components/autofill/browser/autocomplete_history_manager.h" | 16 #include "components/autofill/browser/autocomplete_history_manager.h" |
16 #include "components/autofill/browser/autofill_external_delegate.h" | 17 #include "components/autofill/browser/autofill_external_delegate.h" |
17 #include "components/autofill/browser/autofill_manager.h" | 18 #include "components/autofill/browser/autofill_manager.h" |
18 #include "components/autofill/browser/test_autofill_manager_delegate.h" | 19 #include "components/autofill/browser/test_autofill_manager_delegate.h" |
19 #include "components/autofill/browser/webdata/autofill_webdata_service.h" | 20 #include "components/autofill/browser/webdata/autofill_webdata_service.h" |
20 #include "components/autofill/common/form_data.h" | 21 #include "components/autofill/common/form_data.h" |
21 #include "components/webdata/common/web_data_service_test_util.h" | 22 #include "components/webdata/common/web_data_service_test_util.h" |
22 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "ui/gfx/rect.h" | 26 #include "ui/gfx/rect.h" |
26 | 27 |
27 using content::BrowserThread; | 28 using content::BrowserThread; |
28 using content::WebContents; | 29 using content::WebContents; |
29 using testing::_; | 30 using testing::_; |
30 | 31 |
31 namespace autofill { | 32 namespace autofill { |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
35 class MockWebDataService : public AutofillWebDataService { | 36 class MockWebDataService : public AutofillWebDataService { |
36 public: | 37 public: |
37 MockWebDataService() | 38 MockWebDataService() |
38 : AutofillWebDataService( | 39 : AutofillWebDataService() { |
39 NULL, WebDataServiceBase::ProfileErrorCallback()) { | |
40 current_mock_web_data_service_ = this; | 40 current_mock_web_data_service_ = this; |
41 } | 41 } |
42 | 42 |
43 MOCK_METHOD1(AddFormFields, void(const std::vector<FormFieldData>&)); | 43 MOCK_METHOD1(AddFormFields, void(const std::vector<FormFieldData>&)); |
44 | 44 |
45 static scoped_refptr<MockWebDataService> GetCurrent() { | 45 static scoped_refptr<MockWebDataService> GetCurrent() { |
46 if (!current_mock_web_data_service_) { | 46 if (!current_mock_web_data_service_) { |
47 return new MockWebDataService(); | 47 return new MockWebDataService(); |
48 } | 48 } |
49 return current_mock_web_data_service_; | 49 return current_mock_web_data_service_; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 } // namespace | 92 } // namespace |
93 | 93 |
94 class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness { | 94 class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness { |
95 protected: | 95 protected: |
96 AutocompleteHistoryManagerTest() | 96 AutocompleteHistoryManagerTest() |
97 : ui_thread_(BrowserThread::UI, &message_loop_), | 97 : ui_thread_(BrowserThread::UI, &message_loop_), |
98 db_thread_(BrowserThread::DB) { | 98 db_thread_(BrowserThread::DB) { |
99 } | 99 } |
100 | 100 |
101 virtual void SetUp() OVERRIDE { | 101 virtual void SetUp() OVERRIDE { |
102 db_thread_.Start(); | |
102 ChromeRenderViewHostTestHarness::SetUp(); | 103 ChromeRenderViewHostTestHarness::SetUp(); |
103 web_data_service_ = new MockWebDataService(); | 104 web_data_service_ = new MockWebDataService(); |
104 WebDataServiceFactory::GetInstance()->SetTestingFactory( | 105 WebDataServiceFactory::GetInstance()->SetTestingFactory( |
105 profile(), MockWebDataServiceWrapperCurrent::Build); | 106 profile(), MockWebDataServiceWrapperCurrent::Build); |
106 autocomplete_manager_.reset(new AutocompleteHistoryManager(web_contents())); | 107 autocomplete_manager_.reset(new AutocompleteHistoryManager(web_contents())); |
107 } | 108 } |
108 | 109 |
109 virtual void TearDown() OVERRIDE { | 110 virtual void TearDown() OVERRIDE { |
110 autocomplete_manager_.reset(); | 111 autocomplete_manager_.reset(); |
111 web_data_service_ = NULL; | 112 web_data_service_ = NULL; |
112 ChromeRenderViewHostTestHarness::TearDown(); | 113 ChromeRenderViewHostTestHarness::TearDown(); |
114 base::WaitableEvent done(false, false); | |
115 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | |
116 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); | |
117 done.Wait(); | |
118 db_thread_.Stop(); | |
Ilya Sherman
2013/04/30 00:14:08
Hmm, can you just use content::RunAllPendingInMess
Cait (Slow)
2013/04/30 22:24:40
Done.
| |
113 message_loop_.RunUntilIdle(); | 119 message_loop_.RunUntilIdle(); |
114 | 120 |
115 } | 121 } |
116 | 122 |
117 content::TestBrowserThread ui_thread_; | 123 content::TestBrowserThread ui_thread_; |
118 content::TestBrowserThread db_thread_; | 124 content::TestBrowserThread db_thread_; |
119 scoped_refptr<MockWebDataService> web_data_service_; | 125 scoped_refptr<MockWebDataService> web_data_service_; |
120 scoped_ptr<AutocompleteHistoryManager> autocomplete_manager_; | 126 scoped_ptr<AutocompleteHistoryManager> autocomplete_manager_; |
121 MockAutofillManagerDelegate manager_delegate; | 127 MockAutofillManagerDelegate manager_delegate; |
122 }; | 128 }; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 | 262 |
257 MockAutofillExternalDelegate external_delegate(web_contents()); | 263 MockAutofillExternalDelegate external_delegate(web_contents()); |
258 autocomplete_history_manager.SetExternalDelegate(&external_delegate); | 264 autocomplete_history_manager.SetExternalDelegate(&external_delegate); |
259 | 265 |
260 // Should trigger a call to OnSuggestionsReturned, verified by the mock. | 266 // Should trigger a call to OnSuggestionsReturned, verified by the mock. |
261 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); | 267 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); |
262 autocomplete_history_manager.SendSuggestions(NULL); | 268 autocomplete_history_manager.SendSuggestions(NULL); |
263 } | 269 } |
264 | 270 |
265 } // namespace autofill | 271 } // namespace autofill |
OLD | NEW |