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

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

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again 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 <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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 if (store_.get()) 130 if (store_.get())
131 store_->ShutdownOnUIThread(); 131 store_->ShutdownOnUIThread();
132 wds_->ShutdownOnUIThread(); 132 wds_->ShutdownOnUIThread();
133 wdbs_->ShutdownDatabase(); 133 wdbs_->ShutdownDatabase();
134 wds_ = NULL; 134 wds_ = NULL;
135 wdbs_ = NULL; 135 wdbs_ = NULL;
136 base::WaitableEvent done(false, false); 136 base::WaitableEvent done(false, false);
137 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 137 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
138 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); 138 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
139 done.Wait(); 139 done.Wait();
140 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 140 base::MessageLoop::current()->PostTask(FROM_HERE,
141 MessageLoop::current()->Run(); 141 base::MessageLoop::QuitClosure());
142 base::MessageLoop::current()->Run();
142 db_thread_.Stop(); 143 db_thread_.Stop();
143 } 144 }
144 145
145 MessageLoopForUI message_loop_; 146 base::MessageLoopForUI message_loop_;
146 content::TestBrowserThread ui_thread_; 147 content::TestBrowserThread ui_thread_;
147 // PasswordStore, WDS schedule work on this thread. 148 // PasswordStore, WDS schedule work on this thread.
148 content::TestBrowserThread db_thread_; 149 content::TestBrowserThread db_thread_;
149 150
150 scoped_ptr<LoginDatabase> login_db_; 151 scoped_ptr<LoginDatabase> login_db_;
151 scoped_ptr<TestingProfile> profile_; 152 scoped_ptr<TestingProfile> profile_;
152 scoped_refptr<WebDataService> wds_; 153 scoped_refptr<WebDataService> wds_;
153 scoped_refptr<WebDatabaseService> wdbs_; 154 scoped_refptr<WebDatabaseService> wdbs_;
154 scoped_refptr<PasswordStore> store_; 155 scoped_refptr<PasswordStore> store_;
155 base::ScopedTempDir temp_dir_; 156 base::ScopedTempDir temp_dir_;
156 }; 157 };
157 158
158 ACTION(STLDeleteElements0) { 159 ACTION(STLDeleteElements0) {
159 STLDeleteContainerPointers(arg0.begin(), arg0.end()); 160 STLDeleteContainerPointers(arg0.begin(), arg0.end());
160 } 161 }
161 162
162 ACTION(QuitUIMessageLoop) { 163 ACTION(QuitUIMessageLoop) {
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
164 MessageLoop::current()->Quit(); 165 base::MessageLoop::current()->Quit();
165 } 166 }
166 167
167 MATCHER(EmptyWDResult, "") { 168 MATCHER(EmptyWDResult, "") {
168 return static_cast<const WDResult<std::vector<PasswordForm*> >*>( 169 return static_cast<const WDResult<std::vector<PasswordForm*> >*>(
169 arg)->GetValue().empty(); 170 arg)->GetValue().empty();
170 } 171 }
171 172
172 // Hangs flakily, http://crbug.com/71385. 173 // Hangs flakily, http://crbug.com/71385.
173 TEST_F(PasswordStoreWinTest, DISABLED_ConvertIE7Login) { 174 TEST_F(PasswordStoreWinTest, DISABLED_ConvertIE7Login) {
174 IE7PasswordInfo password_info; 175 IE7PasswordInfo password_info;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 }; 228 };
228 std::vector<PasswordForm*> forms; 229 std::vector<PasswordForm*> forms;
229 forms.push_back(CreatePasswordFormFromData(expected_form_data)); 230 forms.push_back(CreatePasswordFormFromData(expected_form_data));
230 231
231 // The IE7 password should be returned. 232 // The IE7 password should be returned.
232 EXPECT_CALL(consumer, 233 EXPECT_CALL(consumer,
233 OnGetPasswordStoreResults(ContainsAllPasswordForms(forms))) 234 OnGetPasswordStoreResults(ContainsAllPasswordForms(forms)))
234 .WillOnce(QuitUIMessageLoop()); 235 .WillOnce(QuitUIMessageLoop());
235 236
236 store_->GetLogins(*form, &consumer); 237 store_->GetLogins(*form, &consumer);
237 MessageLoop::current()->Run(); 238 base::MessageLoop::current()->Run();
238 239
239 STLDeleteElements(&forms); 240 STLDeleteElements(&forms);
240 } 241 }
241 242
242 // Crashy. http://crbug.com/86558 243 // Crashy. http://crbug.com/86558
243 TEST_F(PasswordStoreWinTest, DISABLED_OutstandingWDSQueries) { 244 TEST_F(PasswordStoreWinTest, DISABLED_OutstandingWDSQueries) {
244 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(), 245 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(),
245 wds_.get()); 246 wds_.get());
246 EXPECT_TRUE(store_->Init()); 247 EXPECT_TRUE(store_->Init());
247 248
(...skipping 12 matching lines...) Expand all
260 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data)); 261 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data));
261 262
262 MockPasswordStoreConsumer consumer; 263 MockPasswordStoreConsumer consumer;
263 store_->GetLogins(*form, &consumer); 264 store_->GetLogins(*form, &consumer);
264 265
265 // Release the PSW and the WDS before the query can return. 266 // Release the PSW and the WDS before the query can return.
266 store_->ShutdownOnUIThread(); 267 store_->ShutdownOnUIThread();
267 store_ = NULL; 268 store_ = NULL;
268 wds_ = NULL; 269 wds_ = NULL;
269 270
270 MessageLoop::current()->RunUntilIdle(); 271 base::MessageLoop::current()->RunUntilIdle();
271 } 272 }
272 273
273 // Hangs flakily, see http://crbug.com/43836. 274 // Hangs flakily, see http://crbug.com/43836.
274 TEST_F(PasswordStoreWinTest, DISABLED_MultipleWDSQueriesOnDifferentThreads) { 275 TEST_F(PasswordStoreWinTest, DISABLED_MultipleWDSQueriesOnDifferentThreads) {
275 IE7PasswordInfo password_info; 276 IE7PasswordInfo password_info;
276 ASSERT_TRUE(CreateIE7PasswordInfo(L"http://example.com/origin", 277 ASSERT_TRUE(CreateIE7PasswordInfo(L"http://example.com/origin",
277 base::Time::FromDoubleT(1), 278 base::Time::FromDoubleT(1),
278 &password_info)); 279 &password_info));
279 wds_->AddIE7Login(password_info); 280 wds_->AddIE7Login(password_info);
280 281
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 335
335 EXPECT_CALL(wds_consumer, 336 EXPECT_CALL(wds_consumer,
336 OnWebDataServiceRequestDone(_, _)) 337 OnWebDataServiceRequestDone(_, _))
337 .WillOnce(QuitUIMessageLoop()); 338 .WillOnce(QuitUIMessageLoop());
338 339
339 wds_->GetIE7Login(password_info, &wds_consumer); 340 wds_->GetIE7Login(password_info, &wds_consumer);
340 341
341 // Run the MessageLoop twice: once for the GetIE7Login that PasswordStoreWin 342 // 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 343 // schedules on the DB thread and once for the one we just scheduled on the UI
343 // thread. 344 // thread.
344 MessageLoop::current()->Run(); 345 base::MessageLoop::current()->Run();
345 MessageLoop::current()->Run(); 346 base::MessageLoop::current()->Run();
346 347
347 STLDeleteElements(&forms); 348 STLDeleteElements(&forms);
348 } 349 }
349 350
350 TEST_F(PasswordStoreWinTest, EmptyLogins) { 351 TEST_F(PasswordStoreWinTest, EmptyLogins) {
351 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(), 352 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(),
352 wds_.get()); 353 wds_.get());
353 store_->Init(); 354 store_->Init();
354 355
355 PasswordFormData form_data = { 356 PasswordFormData form_data = {
(...skipping 16 matching lines...) Expand all
372 ON_CALL(consumer, OnGetPasswordStoreResults(_)) 373 ON_CALL(consumer, OnGetPasswordStoreResults(_))
373 .WillByDefault(QuitUIMessageLoop()); 374 .WillByDefault(QuitUIMessageLoop());
374 375
375 VectorOfForms expect_none; 376 VectorOfForms expect_none;
376 // expect that we get no results; 377 // expect that we get no results;
377 EXPECT_CALL(consumer, 378 EXPECT_CALL(consumer,
378 OnGetPasswordStoreResults(ContainsAllPasswordForms(expect_none))) 379 OnGetPasswordStoreResults(ContainsAllPasswordForms(expect_none)))
379 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); 380 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop()));
380 381
381 store_->GetLogins(*form, &consumer); 382 store_->GetLogins(*form, &consumer);
382 MessageLoop::current()->Run(); 383 base::MessageLoop::current()->Run();
383 } 384 }
384 385
385 TEST_F(PasswordStoreWinTest, EmptyBlacklistLogins) { 386 TEST_F(PasswordStoreWinTest, EmptyBlacklistLogins) {
386 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(), 387 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(),
387 wds_.get()); 388 wds_.get());
388 store_->Init(); 389 store_->Init();
389 390
390 MockPasswordStoreConsumer consumer; 391 MockPasswordStoreConsumer consumer;
391 392
392 // Make sure we quit the MessageLoop even if the test fails. 393 // Make sure we quit the MessageLoop even if the test fails.
393 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _)) 394 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _))
394 .WillByDefault(QuitUIMessageLoop()); 395 .WillByDefault(QuitUIMessageLoop());
395 396
396 VectorOfForms expect_none; 397 VectorOfForms expect_none;
397 // expect that we get no results; 398 // expect that we get no results;
398 EXPECT_CALL( 399 EXPECT_CALL(
399 consumer, 400 consumer,
400 OnPasswordStoreRequestDone(_, ContainsAllPasswordForms(expect_none))) 401 OnPasswordStoreRequestDone(_, ContainsAllPasswordForms(expect_none)))
401 .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop())); 402 .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop()));
402 403
403 store_->GetBlacklistLogins(&consumer); 404 store_->GetBlacklistLogins(&consumer);
404 MessageLoop::current()->Run(); 405 base::MessageLoop::current()->Run();
405 } 406 }
406 407
407 TEST_F(PasswordStoreWinTest, EmptyAutofillableLogins) { 408 TEST_F(PasswordStoreWinTest, EmptyAutofillableLogins) {
408 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(), 409 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(),
409 wds_.get()); 410 wds_.get());
410 store_->Init(); 411 store_->Init();
411 412
412 MockPasswordStoreConsumer consumer; 413 MockPasswordStoreConsumer consumer;
413 414
414 // Make sure we quit the MessageLoop even if the test fails. 415 // Make sure we quit the MessageLoop even if the test fails.
415 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _)) 416 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _))
416 .WillByDefault(QuitUIMessageLoop()); 417 .WillByDefault(QuitUIMessageLoop());
417 418
418 VectorOfForms expect_none; 419 VectorOfForms expect_none;
419 // expect that we get no results; 420 // expect that we get no results;
420 EXPECT_CALL( 421 EXPECT_CALL(
421 consumer, 422 consumer,
422 OnPasswordStoreRequestDone(_, ContainsAllPasswordForms(expect_none))) 423 OnPasswordStoreRequestDone(_, ContainsAllPasswordForms(expect_none)))
423 .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop())); 424 .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop()));
424 425
425 store_->GetAutofillableLogins(&consumer); 426 store_->GetAutofillableLogins(&consumer);
426 MessageLoop::current()->Run(); 427 base::MessageLoop::current()->Run();
427 } 428 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698