Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: components/autofill/browser/autocomplete_history_manager_unittest.cc

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged ToT Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/run_loop.h"
9 #include "base/string16.h" 10 #include "base/string16.h"
10 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
11 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/webdata/web_data_service_factory.h" 13 #include "chrome/browser/webdata/web_data_service_factory.h"
13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
14 #include "chrome/test/base/testing_browser_process.h" 15 #include "chrome/test/base/testing_browser_process.h"
15 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
16 #include "components/autofill/browser/autocomplete_history_manager.h" 17 #include "components/autofill/browser/autocomplete_history_manager.h"
17 #include "components/autofill/browser/autofill_external_delegate.h" 18 #include "components/autofill/browser/autofill_external_delegate.h"
18 #include "components/autofill/browser/autofill_manager.h" 19 #include "components/autofill/browser/autofill_manager.h"
19 #include "components/autofill/browser/test_autofill_manager_delegate.h" 20 #include "components/autofill/browser/test_autofill_manager_delegate.h"
20 #include "components/autofill/browser/webdata/autofill_webdata_service.h" 21 #include "components/autofill/browser/webdata/autofill_webdata_service.h"
21 #include "components/autofill/common/form_data.h" 22 #include "components/autofill/common/form_data.h"
22 #include "components/webdata/common/web_data_service_test_util.h" 23 #include "components/webdata/common/web_data_service_test_util.h"
23 #include "content/public/test/test_browser_thread.h" 24 #include "content/public/test/test_browser_thread.h"
24 #include "content/public/test/test_utils.h" 25 #include "content/public/test/test_utils.h"
25 #include "testing/gmock/include/gmock/gmock.h" 26 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
27 #include "ui/gfx/rect.h" 28 #include "ui/gfx/rect.h"
28 29
29 using content::BrowserThread;
30 using content::WebContents; 30 using content::WebContents;
31 using testing::_; 31 using testing::_;
32 32
33 namespace autofill { 33 namespace autofill {
34 34
35 namespace { 35 namespace {
36 36
37 class MockWebDataService : public AutofillWebDataService { 37 class MockWebDataService : public AutofillWebDataService {
38 public: 38 public:
39 MockWebDataService() 39 MockWebDataService()
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 private: 87 private:
88 TestingPrefServiceSimple prefs_; 88 TestingPrefServiceSimple prefs_;
89 89
90 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); 90 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate);
91 }; 91 };
92 92
93 } // namespace 93 } // namespace
94 94
95 class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness { 95 class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness {
96 protected: 96 protected:
97 AutocompleteHistoryManagerTest()
98 : ui_thread_(BrowserThread::UI, &message_loop_),
99 db_thread_(BrowserThread::DB) {
100 }
101
102 virtual void SetUp() OVERRIDE { 97 virtual void SetUp() OVERRIDE {
103 db_thread_.Start();
104 ChromeRenderViewHostTestHarness::SetUp(); 98 ChromeRenderViewHostTestHarness::SetUp();
105 web_data_service_ = new MockWebDataService(); 99 web_data_service_ = new MockWebDataService();
106 WebDataServiceFactory::GetInstance()->SetTestingFactory( 100 WebDataServiceFactory::GetInstance()->SetTestingFactory(
107 profile(), MockWebDataServiceWrapperCurrent::Build); 101 profile(), MockWebDataServiceWrapperCurrent::Build);
108 autocomplete_manager_.reset(new AutocompleteHistoryManager(web_contents())); 102 autocomplete_manager_.reset(new AutocompleteHistoryManager(web_contents()));
109 } 103 }
110 104
111 virtual void TearDown() OVERRIDE { 105 virtual void TearDown() OVERRIDE {
112 autocomplete_manager_.reset(); 106 autocomplete_manager_.reset();
113 web_data_service_ = NULL; 107 web_data_service_ = NULL;
114 ChromeRenderViewHostTestHarness::TearDown(); 108 ChromeRenderViewHostTestHarness::TearDown();
115 content::RunAllPendingInMessageLoop(BrowserThread::DB);
116 message_loop_.RunUntilIdle();
117
118 } 109 }
119 110
120 content::TestBrowserThread ui_thread_;
121 content::TestBrowserThread db_thread_;
122 scoped_refptr<MockWebDataService> web_data_service_; 111 scoped_refptr<MockWebDataService> web_data_service_;
123 scoped_ptr<AutocompleteHistoryManager> autocomplete_manager_; 112 scoped_ptr<AutocompleteHistoryManager> autocomplete_manager_;
124 MockAutofillManagerDelegate manager_delegate; 113 MockAutofillManagerDelegate manager_delegate;
125 }; 114 };
126 115
127 // Tests that credit card numbers are not sent to the WebDatabase to be saved. 116 // Tests that credit card numbers are not sent to the WebDatabase to be saved.
128 TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) { 117 TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) {
129 FormData form; 118 FormData form;
130 form.name = ASCIIToUTF16("MyForm"); 119 form.name = ASCIIToUTF16("MyForm");
131 form.method = ASCIIToUTF16("POST"); 120 form.method = ASCIIToUTF16("POST");
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 251
263 MockAutofillExternalDelegate external_delegate(web_contents()); 252 MockAutofillExternalDelegate external_delegate(web_contents());
264 autocomplete_history_manager.SetExternalDelegate(&external_delegate); 253 autocomplete_history_manager.SetExternalDelegate(&external_delegate);
265 254
266 // Should trigger a call to OnSuggestionsReturned, verified by the mock. 255 // Should trigger a call to OnSuggestionsReturned, verified by the mock.
267 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); 256 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _));
268 autocomplete_history_manager.SendSuggestions(NULL); 257 autocomplete_history_manager.SendSuggestions(NULL);
269 } 258 }
270 259
271 } // namespace autofill 260 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698