| 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <wincrypt.h> | 6 #include <wincrypt.h> |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 base::WaitableEvent done(false, false); | 135 base::WaitableEvent done(false, false); |
| 136 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 136 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 137 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); | 137 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
| 138 done.Wait(); | 138 done.Wait(); |
| 139 base::MessageLoop::current()->PostTask(FROM_HERE, | 139 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 140 base::MessageLoop::QuitClosure()); | 140 base::MessageLoop::QuitClosure()); |
| 141 base::MessageLoop::current()->Run(); | 141 base::MessageLoop::current()->Run(); |
| 142 db_thread_.Stop(); | 142 db_thread_.Stop(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 PasswordStoreWin* CreatePasswordStore() { |
| 146 return new PasswordStoreWin( |
| 147 base::MessageLoopProxy::current(), |
| 148 base::MessageLoopProxy::current(), |
| 149 login_db_.release(), |
| 150 profile_.get(), |
| 151 wds_.get()); |
| 152 } |
| 153 |
| 145 base::MessageLoopForUI message_loop_; | 154 base::MessageLoopForUI message_loop_; |
| 146 content::TestBrowserThread ui_thread_; | 155 content::TestBrowserThread ui_thread_; |
| 147 // PasswordStore, WDS schedule work on this thread. | 156 // PasswordStore, WDS schedule work on this thread. |
| 148 content::TestBrowserThread db_thread_; | 157 content::TestBrowserThread db_thread_; |
| 149 | 158 |
| 150 base::ScopedTempDir temp_dir_; | 159 base::ScopedTempDir temp_dir_; |
| 151 scoped_ptr<TestingProfile> profile_; | 160 scoped_ptr<TestingProfile> profile_; |
| 152 scoped_ptr<LoginDatabase> login_db_; | 161 scoped_ptr<LoginDatabase> login_db_; |
| 153 scoped_refptr<WebDataService> wds_; | 162 scoped_refptr<WebDataService> wds_; |
| 154 scoped_refptr<WebDatabaseService> wdbs_; | 163 scoped_refptr<WebDatabaseService> wdbs_; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 182 // This IE7 password will be retrieved by the GetLogins call. | 191 // This IE7 password will be retrieved by the GetLogins call. |
| 183 wds_->AddIE7Login(password_info); | 192 wds_->AddIE7Login(password_info); |
| 184 | 193 |
| 185 // The WDS schedules tasks to run on the DB thread so we schedule yet another | 194 // The WDS schedules tasks to run on the DB thread so we schedule yet another |
| 186 // task to notify us that it's safe to carry on with the test. | 195 // task to notify us that it's safe to carry on with the test. |
| 187 WaitableEvent done(false, false); | 196 WaitableEvent done(false, false); |
| 188 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 197 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 189 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); | 198 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
| 190 done.Wait(); | 199 done.Wait(); |
| 191 | 200 |
| 192 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(), | 201 store_ = CreatePasswordStore(); |
| 193 wds_.get()); | |
| 194 EXPECT_TRUE(store_->Init()); | 202 EXPECT_TRUE(store_->Init()); |
| 195 | 203 |
| 196 MockPasswordStoreConsumer consumer; | 204 MockPasswordStoreConsumer consumer; |
| 197 | 205 |
| 198 // Make sure we quit the MessageLoop even if the test fails. | 206 // Make sure we quit the MessageLoop even if the test fails. |
| 199 ON_CALL(consumer, OnGetPasswordStoreResults(_)) | 207 ON_CALL(consumer, OnGetPasswordStoreResults(_)) |
| 200 .WillByDefault(QuitUIMessageLoop()); | 208 .WillByDefault(QuitUIMessageLoop()); |
| 201 | 209 |
| 202 PasswordFormData form_data = { | 210 PasswordFormData form_data = { |
| 203 PasswordForm::SCHEME_HTML, | 211 PasswordForm::SCHEME_HTML, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 234 .WillOnce(QuitUIMessageLoop()); | 242 .WillOnce(QuitUIMessageLoop()); |
| 235 | 243 |
| 236 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); | 244 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); |
| 237 base::MessageLoop::current()->Run(); | 245 base::MessageLoop::current()->Run(); |
| 238 | 246 |
| 239 STLDeleteElements(&forms); | 247 STLDeleteElements(&forms); |
| 240 } | 248 } |
| 241 | 249 |
| 242 // Crashy. http://crbug.com/86558 | 250 // Crashy. http://crbug.com/86558 |
| 243 TEST_F(PasswordStoreWinTest, DISABLED_OutstandingWDSQueries) { | 251 TEST_F(PasswordStoreWinTest, DISABLED_OutstandingWDSQueries) { |
| 244 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(), | 252 store_ = CreatePasswordStore(); |
| 245 wds_.get()); | |
| 246 EXPECT_TRUE(store_->Init()); | 253 EXPECT_TRUE(store_->Init()); |
| 247 | 254 |
| 248 PasswordFormData form_data = { | 255 PasswordFormData form_data = { |
| 249 PasswordForm::SCHEME_HTML, | 256 PasswordForm::SCHEME_HTML, |
| 250 "http://example.com/", | 257 "http://example.com/", |
| 251 "http://example.com/origin", | 258 "http://example.com/origin", |
| 252 "http://example.com/action", | 259 "http://example.com/action", |
| 253 L"submit_element", | 260 L"submit_element", |
| 254 L"username_element", | 261 L"username_element", |
| 255 L"password_element", | 262 L"password_element", |
| (...skipping 22 matching lines...) Expand all Loading... |
| 278 &password_info)); | 285 &password_info)); |
| 279 wds_->AddIE7Login(password_info); | 286 wds_->AddIE7Login(password_info); |
| 280 | 287 |
| 281 // The WDS schedules tasks to run on the DB thread so we schedule yet another | 288 // The WDS schedules tasks to run on the DB thread so we schedule yet another |
| 282 // task to notify us that it's safe to carry on with the test. | 289 // task to notify us that it's safe to carry on with the test. |
| 283 WaitableEvent done(false, false); | 290 WaitableEvent done(false, false); |
| 284 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 291 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 285 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); | 292 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
| 286 done.Wait(); | 293 done.Wait(); |
| 287 | 294 |
| 288 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(), | 295 store_ = CreatePasswordStore(); |
| 289 wds_.get()); | |
| 290 EXPECT_TRUE(store_->Init()); | 296 EXPECT_TRUE(store_->Init()); |
| 291 | 297 |
| 292 MockPasswordStoreConsumer password_consumer; | 298 MockPasswordStoreConsumer password_consumer; |
| 293 // Make sure we quit the MessageLoop even if the test fails. | 299 // Make sure we quit the MessageLoop even if the test fails. |
| 294 ON_CALL(password_consumer, OnGetPasswordStoreResults(_)) | 300 ON_CALL(password_consumer, OnGetPasswordStoreResults(_)) |
| 295 .WillByDefault(QuitUIMessageLoop()); | 301 .WillByDefault(QuitUIMessageLoop()); |
| 296 | 302 |
| 297 PasswordFormData form_data = { | 303 PasswordFormData form_data = { |
| 298 PasswordForm::SCHEME_HTML, | 304 PasswordForm::SCHEME_HTML, |
| 299 "http://example.com/", | 305 "http://example.com/", |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 // Run the MessageLoop twice: once for the GetIE7Login that PasswordStoreWin | 347 // Run the MessageLoop twice: once for the GetIE7Login that PasswordStoreWin |
| 342 // schedules on the DB thread and once for the one we just scheduled on the UI | 348 // schedules on the DB thread and once for the one we just scheduled on the UI |
| 343 // thread. | 349 // thread. |
| 344 base::MessageLoop::current()->Run(); | 350 base::MessageLoop::current()->Run(); |
| 345 base::MessageLoop::current()->Run(); | 351 base::MessageLoop::current()->Run(); |
| 346 | 352 |
| 347 STLDeleteElements(&forms); | 353 STLDeleteElements(&forms); |
| 348 } | 354 } |
| 349 | 355 |
| 350 TEST_F(PasswordStoreWinTest, EmptyLogins) { | 356 TEST_F(PasswordStoreWinTest, EmptyLogins) { |
| 351 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(), | 357 store_ = CreatePasswordStore(); |
| 352 wds_.get()); | |
| 353 store_->Init(); | 358 store_->Init(); |
| 354 | 359 |
| 355 PasswordFormData form_data = { | 360 PasswordFormData form_data = { |
| 356 PasswordForm::SCHEME_HTML, | 361 PasswordForm::SCHEME_HTML, |
| 357 "http://example.com/", | 362 "http://example.com/", |
| 358 "http://example.com/origin", | 363 "http://example.com/origin", |
| 359 "http://example.com/action", | 364 "http://example.com/action", |
| 360 L"submit_element", | 365 L"submit_element", |
| 361 L"username_element", | 366 L"username_element", |
| 362 L"password_element", | 367 L"password_element", |
| (...skipping 13 matching lines...) Expand all Loading... |
| 376 // expect that we get no results; | 381 // expect that we get no results; |
| 377 EXPECT_CALL(consumer, | 382 EXPECT_CALL(consumer, |
| 378 OnGetPasswordStoreResults(ContainsAllPasswordForms(expect_none))) | 383 OnGetPasswordStoreResults(ContainsAllPasswordForms(expect_none))) |
| 379 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); | 384 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); |
| 380 | 385 |
| 381 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); | 386 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); |
| 382 base::MessageLoop::current()->Run(); | 387 base::MessageLoop::current()->Run(); |
| 383 } | 388 } |
| 384 | 389 |
| 385 TEST_F(PasswordStoreWinTest, EmptyBlacklistLogins) { | 390 TEST_F(PasswordStoreWinTest, EmptyBlacklistLogins) { |
| 386 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(), | 391 store_ = CreatePasswordStore(); |
| 387 wds_.get()); | |
| 388 store_->Init(); | 392 store_->Init(); |
| 389 | 393 |
| 390 MockPasswordStoreConsumer consumer; | 394 MockPasswordStoreConsumer consumer; |
| 391 | 395 |
| 392 // Make sure we quit the MessageLoop even if the test fails. | 396 // Make sure we quit the MessageLoop even if the test fails. |
| 393 ON_CALL(consumer, OnGetPasswordStoreResults(_)) | 397 ON_CALL(consumer, OnGetPasswordStoreResults(_)) |
| 394 .WillByDefault(QuitUIMessageLoop()); | 398 .WillByDefault(QuitUIMessageLoop()); |
| 395 | 399 |
| 396 VectorOfForms expect_none; | 400 VectorOfForms expect_none; |
| 397 // expect that we get no results; | 401 // expect that we get no results; |
| 398 EXPECT_CALL( | 402 EXPECT_CALL( |
| 399 consumer, | 403 consumer, |
| 400 OnGetPasswordStoreResults(ContainsAllPasswordForms(expect_none))) | 404 OnGetPasswordStoreResults(ContainsAllPasswordForms(expect_none))) |
| 401 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); | 405 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); |
| 402 | 406 |
| 403 store_->GetBlacklistLogins(&consumer); | 407 store_->GetBlacklistLogins(&consumer); |
| 404 base::MessageLoop::current()->Run(); | 408 base::MessageLoop::current()->Run(); |
| 405 } | 409 } |
| 406 | 410 |
| 407 TEST_F(PasswordStoreWinTest, EmptyAutofillableLogins) { | 411 TEST_F(PasswordStoreWinTest, EmptyAutofillableLogins) { |
| 408 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(), | 412 store_ = CreatePasswordStore(); |
| 409 wds_.get()); | |
| 410 store_->Init(); | 413 store_->Init(); |
| 411 | 414 |
| 412 MockPasswordStoreConsumer consumer; | 415 MockPasswordStoreConsumer consumer; |
| 413 | 416 |
| 414 // Make sure we quit the MessageLoop even if the test fails. | 417 // Make sure we quit the MessageLoop even if the test fails. |
| 415 ON_CALL(consumer, OnGetPasswordStoreResults(_)) | 418 ON_CALL(consumer, OnGetPasswordStoreResults(_)) |
| 416 .WillByDefault(QuitUIMessageLoop()); | 419 .WillByDefault(QuitUIMessageLoop()); |
| 417 | 420 |
| 418 VectorOfForms expect_none; | 421 VectorOfForms expect_none; |
| 419 // expect that we get no results; | 422 // expect that we get no results; |
| 420 EXPECT_CALL( | 423 EXPECT_CALL( |
| 421 consumer, | 424 consumer, |
| 422 OnGetPasswordStoreResults(ContainsAllPasswordForms(expect_none))) | 425 OnGetPasswordStoreResults(ContainsAllPasswordForms(expect_none))) |
| 423 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); | 426 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); |
| 424 | 427 |
| 425 store_->GetAutofillableLogins(&consumer); | 428 store_->GetAutofillableLogins(&consumer); |
| 426 base::MessageLoop::current()->Run(); | 429 base::MessageLoop::current()->Run(); |
| 427 } | 430 } |
| OLD | NEW |