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

Side by Side Diff: chrome/browser/password_manager/password_store_win_unittest.cc

Issue 2799883003: Switch from TestBrowserThread to TestBrowserThreadBundle in chrome. (Closed)
Patch Set: fix-string Created 3 years, 7 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
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 "chrome/browser/password_manager/password_store_win.h" 5 #include "chrome/browser/password_manager/password_store_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 13 matching lines...) Expand all
24 #include "base/time/time.h" 24 #include "base/time/time.h"
25 #include "chrome/test/base/testing_profile.h" 25 #include "chrome/test/base/testing_profile.h"
26 #include "components/os_crypt/ie7_password_win.h" 26 #include "components/os_crypt/ie7_password_win.h"
27 #include "components/password_manager/core/browser/password_manager_test_utils.h " 27 #include "components/password_manager/core/browser/password_manager_test_utils.h "
28 #include "components/password_manager/core/browser/password_store_consumer.h" 28 #include "components/password_manager/core/browser/password_store_consumer.h"
29 #include "components/password_manager/core/browser/webdata/logins_table.h" 29 #include "components/password_manager/core/browser/webdata/logins_table.h"
30 #include "components/password_manager/core/browser/webdata/password_web_data_ser vice_win.h" 30 #include "components/password_manager/core/browser/webdata/password_web_data_ser vice_win.h"
31 #include "components/password_manager/core/common/password_manager_pref_names.h" 31 #include "components/password_manager/core/common/password_manager_pref_names.h"
32 #include "components/prefs/pref_service.h" 32 #include "components/prefs/pref_service.h"
33 #include "components/webdata/common/web_database_service.h" 33 #include "components/webdata/common/web_database_service.h"
34 #include "content/public/test/test_browser_thread.h" 34 #include "content/public/browser/browser_thread.h"
35 #include "content/public/test/test_browser_thread_bundle.h"
35 #include "crypto/wincrypt_shim.h" 36 #include "crypto/wincrypt_shim.h"
36 #include "testing/gmock/include/gmock/gmock.h" 37 #include "testing/gmock/include/gmock/gmock.h"
37 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
38 39
39 using autofill::PasswordForm; 40 using autofill::PasswordForm;
40 using base::WaitableEvent; 41 using base::WaitableEvent;
41 using content::BrowserThread; 42 using content::BrowserThread;
42 using password_manager::LoginDatabase; 43 using password_manager::LoginDatabase;
43 using password_manager::PasswordFormData; 44 using password_manager::PasswordFormData;
44 using password_manager::PasswordStore; 45 using password_manager::PasswordStore;
(...skipping 27 matching lines...) Expand all
72 std::unique_ptr<WDTypedResult> result) { 73 std::unique_ptr<WDTypedResult> result) {
73 OnWebDataServiceRequestDoneStub(); 74 OnWebDataServiceRequestDoneStub();
74 } 75 }
75 }; 76 };
76 77
77 } // anonymous namespace 78 } // anonymous namespace
78 79
79 class PasswordStoreWinTest : public testing::Test { 80 class PasswordStoreWinTest : public testing::Test {
80 protected: 81 protected:
81 PasswordStoreWinTest() 82 PasswordStoreWinTest()
82 : ui_thread_(BrowserThread::UI, &message_loop_), 83 : test_browser_thread_bundle_(
83 db_thread_(BrowserThread::DB) {} 84 content::TestBrowserThreadBundle::REAL_DB_THREAD) {}
84 85
85 bool CreateIE7PasswordInfo(const std::wstring& url, 86 bool CreateIE7PasswordInfo(const std::wstring& url,
86 const base::Time& created, 87 const base::Time& created,
87 IE7PasswordInfo* info) { 88 IE7PasswordInfo* info) {
88 // Copied from chrome/browser/importer/importer_unittest.cc 89 // Copied from chrome/browser/importer/importer_unittest.cc
89 // The username is "abcdefgh" and the password "abcdefghijkl". 90 // The username is "abcdefgh" and the password "abcdefghijkl".
90 unsigned char data[] = 91 unsigned char data[] =
91 "\x0c\x00\x00\x00\x38\x00\x00\x00\x2c\x00\x00\x00" 92 "\x0c\x00\x00\x00\x38\x00\x00\x00\x2c\x00\x00\x00"
92 "\x57\x49\x43\x4b\x18\x00\x00\x00\x02\x00\x00\x00" 93 "\x57\x49\x43\x4b\x18\x00\x00\x00\x02\x00\x00\x00"
93 "\x67\x00\x72\x00\x01\x00\x00\x00\x00\x00\x00\x00" 94 "\x67\x00\x72\x00\x01\x00\x00\x00\x00\x00\x00\x00"
(...skipping 27 matching lines...) Expand all
121 LocalFree(output.pbData); 122 LocalFree(output.pbData);
122 123
123 info->url_hash = ie7_password::GetUrlHash(url); 124 info->url_hash = ie7_password::GetUrlHash(url);
124 info->encrypted_data = encrypted_data; 125 info->encrypted_data = encrypted_data;
125 info->date_created = created; 126 info->date_created = created;
126 127
127 return true; 128 return true;
128 } 129 }
129 130
130 void SetUp() override { 131 void SetUp() override {
131 ASSERT_TRUE(db_thread_.Start());
132 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 132 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
133 133
134 profile_.reset(new TestingProfile()); 134 profile_.reset(new TestingProfile());
135 135
136 base::FilePath path = temp_dir_.GetPath().AppendASCII("web_data_test"); 136 base::FilePath path = temp_dir_.GetPath().AppendASCII("web_data_test");
137 wdbs_ = new WebDatabaseService( 137 wdbs_ = new WebDatabaseService(
138 path, BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), 138 path, BrowserThread::GetTaskRunnerForThread(BrowserThread::UI),
139 BrowserThread::GetTaskRunnerForThread(BrowserThread::DB)); 139 BrowserThread::GetTaskRunnerForThread(BrowserThread::DB));
140 // Need to add at least one table so the database gets created. 140 // Need to add at least one table so the database gets created.
141 wdbs_->AddTable(std::unique_ptr<WebDatabaseTable>(new LoginsTable())); 141 wdbs_->AddTable(std::unique_ptr<WebDatabaseTable>(new LoginsTable()));
(...skipping 14 matching lines...) Expand all
156 if (wdbs_) { 156 if (wdbs_) {
157 wdbs_->ShutdownDatabase(); 157 wdbs_->ShutdownDatabase();
158 wdbs_ = nullptr; 158 wdbs_ = nullptr;
159 } 159 }
160 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, 160 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC,
161 base::WaitableEvent::InitialState::NOT_SIGNALED); 161 base::WaitableEvent::InitialState::NOT_SIGNALED);
162 BrowserThread::PostTask( 162 BrowserThread::PostTask(
163 BrowserThread::DB, FROM_HERE, 163 BrowserThread::DB, FROM_HERE,
164 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); 164 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
165 done.Wait(); 165 done.Wait();
166 base::ThreadTaskRunnerHandle::Get()->PostTask(
167 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
168 base::RunLoop().Run();
169 db_thread_.Stop();
170 } 166 }
171 167
172 base::FilePath test_login_db_file_path() const { 168 base::FilePath test_login_db_file_path() const {
173 return temp_dir_.GetPath().Append(FILE_PATH_LITERAL("login_test")); 169 return temp_dir_.GetPath().Append(FILE_PATH_LITERAL("login_test"));
174 } 170 }
175 171
176 PasswordStoreWin* CreatePasswordStore() { 172 PasswordStoreWin* CreatePasswordStore() {
177 return new PasswordStoreWin( 173 return new PasswordStoreWin(
178 base::ThreadTaskRunnerHandle::Get(), 174 base::ThreadTaskRunnerHandle::Get(),
179 BrowserThread::GetTaskRunnerForThread(BrowserThread::DB), 175 BrowserThread::GetTaskRunnerForThread(BrowserThread::DB),
180 base::MakeUnique<LoginDatabase>(test_login_db_file_path()), wds_.get()); 176 base::MakeUnique<LoginDatabase>(test_login_db_file_path()), wds_.get());
181 } 177 }
182 178
183 base::MessageLoopForUI message_loop_; 179 content::TestBrowserThreadBundle test_browser_thread_bundle_;
184 content::TestBrowserThread ui_thread_;
185 // PasswordStore, WDS schedule work on this thread.
186 content::TestBrowserThread db_thread_;
187 180
188 base::ScopedTempDir temp_dir_; 181 base::ScopedTempDir temp_dir_;
189 std::unique_ptr<TestingProfile> profile_; 182 std::unique_ptr<TestingProfile> profile_;
190 scoped_refptr<PasswordWebDataService> wds_; 183 scoped_refptr<PasswordWebDataService> wds_;
191 scoped_refptr<WebDatabaseService> wdbs_; 184 scoped_refptr<WebDatabaseService> wdbs_;
192 scoped_refptr<PasswordStore> store_; 185 scoped_refptr<PasswordStore> store_;
193 }; 186 };
194 187
195 ACTION(QuitUIMessageLoop) { 188 ACTION(QuitUIMessageLoop) {
196 DCHECK_CURRENTLY_ON(BrowserThread::UI); 189 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 440
448 // Make sure we quit the MessageLoop even if the test fails. 441 // Make sure we quit the MessageLoop even if the test fails.
449 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) 442 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_))
450 .WillByDefault(QuitUIMessageLoop()); 443 .WillByDefault(QuitUIMessageLoop());
451 444
452 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); 445 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty()));
453 446
454 store_->GetAutofillableLogins(&consumer); 447 store_->GetAutofillableLogins(&consumer);
455 base::RunLoop().Run(); 448 base::RunLoop().Run();
456 } 449 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698