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

Side by Side Diff: components/suggestions/suggestions_service_unittest.cc

Issue 2211473003: Remove calls to deprecated MessageLoop methods on Windows and Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/suggestions/suggestions_service.h" 5 #include "components/suggestions/suggestions_service.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // Expectations. 333 // Expectations.
334 EXPECT_CALL(*mock_thumbnail_manager_, Initialize(_)); 334 EXPECT_CALL(*mock_thumbnail_manager_, Initialize(_));
335 EXPECT_CALL(*mock_blacklist_store_, FilterSuggestions(_)); 335 EXPECT_CALL(*mock_blacklist_store_, FilterSuggestions(_));
336 EXPECT_CALL(*mock_blacklist_store_, GetTimeUntilReadyForUpload(_)) 336 EXPECT_CALL(*mock_blacklist_store_, GetTimeUntilReadyForUpload(_))
337 .WillOnce(Return(false)); 337 .WillOnce(Return(false));
338 338
339 // Send the request. The data should be returned to the callback. 339 // Send the request. The data should be returned to the callback.
340 suggestions_service->FetchSuggestionsData(); 340 suggestions_service->FetchSuggestionsData();
341 341
342 // Let the network request run. 342 // Let the network request run.
343 io_message_loop_.RunUntilIdle(); 343 base::RunLoop().RunUntilIdle();
344 344
345 // Ensure that CheckCallback() ran once. 345 // Ensure that CheckCallback() ran once.
346 EXPECT_EQ(1, suggestions_data_callback_count_); 346 EXPECT_EQ(1, suggestions_data_callback_count_);
347 347
348 CheckSuggestionsData(); 348 CheckSuggestionsData();
349 } 349 }
350 350
351 TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) { 351 TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) {
352 std::unique_ptr<SuggestionsService> suggestions_service( 352 std::unique_ptr<SuggestionsService> suggestions_service(
353 CreateSuggestionsServiceWithMocks()); 353 CreateSuggestionsServiceWithMocks());
354 ASSERT_TRUE(suggestions_service != nullptr); 354 ASSERT_TRUE(suggestions_service != nullptr);
355 EXPECT_CALL(*mock_sync_service_, IsSyncActive()) 355 EXPECT_CALL(*mock_sync_service_, IsSyncActive())
356 .WillRepeatedly(Return(false)); 356 .WillRepeatedly(Return(false));
357 357
358 auto subscription = suggestions_service->AddCallback(base::Bind( 358 auto subscription = suggestions_service->AddCallback(base::Bind(
359 &SuggestionsServiceTest::CheckCallback, base::Unretained(this))); 359 &SuggestionsServiceTest::CheckCallback, base::Unretained(this)));
360 360
361 // Try to fetch suggestions. Since sync is not active, no network request 361 // Try to fetch suggestions. Since sync is not active, no network request
362 // should be sent. 362 // should be sent.
363 suggestions_service->FetchSuggestionsData(); 363 suggestions_service->FetchSuggestionsData();
364 364
365 // Let any network request run. 365 // Let any network request run.
366 io_message_loop_.RunUntilIdle(); 366 base::RunLoop().RunUntilIdle();
367 367
368 // Ensure that CheckCallback() didn't run. 368 // Ensure that CheckCallback() didn't run.
369 EXPECT_EQ(0, suggestions_data_callback_count_); 369 EXPECT_EQ(0, suggestions_data_callback_count_);
370 370
371 // |test_suggestions_store_| should still contain the default values. 371 // |test_suggestions_store_| should still contain the default values.
372 SuggestionsProfile suggestions; 372 SuggestionsProfile suggestions;
373 test_suggestions_store_->LoadSuggestions(&suggestions); 373 test_suggestions_store_->LoadSuggestions(&suggestions);
374 EXPECT_EQ(CreateSuggestionsProfile().SerializeAsString(), 374 EXPECT_EQ(CreateSuggestionsProfile().SerializeAsString(),
375 suggestions.SerializeAsString()); 375 suggestions.SerializeAsString());
376 } 376 }
(...skipping 14 matching lines...) Expand all
391 391
392 // Ensure that CheckCallback ran once with empty data. 392 // Ensure that CheckCallback ran once with empty data.
393 EXPECT_EQ(1, suggestions_data_callback_count_); 393 EXPECT_EQ(1, suggestions_data_callback_count_);
394 EXPECT_EQ(1, suggestions_empty_data_count_); 394 EXPECT_EQ(1, suggestions_empty_data_count_);
395 395
396 // Try to fetch suggestions. Since sync is not active, no network request 396 // Try to fetch suggestions. Since sync is not active, no network request
397 // should be sent. 397 // should be sent.
398 suggestions_service->FetchSuggestionsData(); 398 suggestions_service->FetchSuggestionsData();
399 399
400 // Let any network request run. 400 // Let any network request run.
401 io_message_loop_.RunUntilIdle(); 401 base::RunLoop().RunUntilIdle();
402 402
403 // Ensure that CheckCallback didn't run again. 403 // Ensure that CheckCallback didn't run again.
404 EXPECT_EQ(1, suggestions_data_callback_count_); 404 EXPECT_EQ(1, suggestions_data_callback_count_);
405 } 405 }
406 406
407 TEST_F(SuggestionsServiceTest, FetchSuggestionsDataNoAccessToken) { 407 TEST_F(SuggestionsServiceTest, FetchSuggestionsDataNoAccessToken) {
408 token_service_.RevokeCredentials(kAccountId); 408 token_service_.RevokeCredentials(kAccountId);
409 409
410 std::unique_ptr<SuggestionsService> suggestions_service( 410 std::unique_ptr<SuggestionsService> suggestions_service(
411 CreateSuggestionsServiceWithMocks()); 411 CreateSuggestionsServiceWithMocks());
412 ASSERT_TRUE(suggestions_service != nullptr); 412 ASSERT_TRUE(suggestions_service != nullptr);
413 413
414 auto subscription = suggestions_service->AddCallback(base::Bind( 414 auto subscription = suggestions_service->AddCallback(base::Bind(
415 &SuggestionsServiceTest::CheckCallback, base::Unretained(this))); 415 &SuggestionsServiceTest::CheckCallback, base::Unretained(this)));
416 416
417 EXPECT_CALL(*mock_blacklist_store_, GetTimeUntilReadyForUpload(_)) 417 EXPECT_CALL(*mock_blacklist_store_, GetTimeUntilReadyForUpload(_))
418 .WillOnce(Return(false)); 418 .WillOnce(Return(false));
419 419
420 suggestions_service->FetchSuggestionsData(); 420 suggestions_service->FetchSuggestionsData();
421 421
422 // No network request should be sent. 422 // No network request should be sent.
423 io_message_loop_.RunUntilIdle(); 423 base::RunLoop().RunUntilIdle();
424 EXPECT_FALSE(HasPendingSuggestionsRequest(suggestions_service.get())); 424 EXPECT_FALSE(HasPendingSuggestionsRequest(suggestions_service.get()));
425 EXPECT_EQ(0, suggestions_data_callback_count_); 425 EXPECT_EQ(0, suggestions_data_callback_count_);
426 } 426 }
427 427
428 TEST_F(SuggestionsServiceTest, IssueRequestIfNoneOngoingError) { 428 TEST_F(SuggestionsServiceTest, IssueRequestIfNoneOngoingError) {
429 std::unique_ptr<SuggestionsService> suggestions_service( 429 std::unique_ptr<SuggestionsService> suggestions_service(
430 CreateSuggestionsServiceWithMocks()); 430 CreateSuggestionsServiceWithMocks());
431 ASSERT_TRUE(suggestions_service != nullptr); 431 ASSERT_TRUE(suggestions_service != nullptr);
432 432
433 // Fake a request error. 433 // Fake a request error.
434 factory_.SetFakeResponse(SuggestionsService::BuildSuggestionsURL(), 434 factory_.SetFakeResponse(SuggestionsService::BuildSuggestionsURL(),
435 "irrelevant", net::HTTP_OK, 435 "irrelevant", net::HTTP_OK,
436 net::URLRequestStatus::FAILED); 436 net::URLRequestStatus::FAILED);
437 437
438 EXPECT_CALL(*mock_blacklist_store_, GetTimeUntilReadyForUpload(_)) 438 EXPECT_CALL(*mock_blacklist_store_, GetTimeUntilReadyForUpload(_))
439 .WillOnce(Return(false)); 439 .WillOnce(Return(false));
440 440
441 // Send the request. Empty data will be returned to the callback. 441 // Send the request. Empty data will be returned to the callback.
442 suggestions_service->IssueRequestIfNoneOngoing( 442 suggestions_service->IssueRequestIfNoneOngoing(
443 SuggestionsService::BuildSuggestionsURL()); 443 SuggestionsService::BuildSuggestionsURL());
444 444
445 // (Testing only) wait until suggestion fetch is complete. 445 // (Testing only) wait until suggestion fetch is complete.
446 io_message_loop_.RunUntilIdle(); 446 base::RunLoop().RunUntilIdle();
447 } 447 }
448 448
449 TEST_F(SuggestionsServiceTest, IssueRequestIfNoneOngoingResponseNotOK) { 449 TEST_F(SuggestionsServiceTest, IssueRequestIfNoneOngoingResponseNotOK) {
450 std::unique_ptr<SuggestionsService> suggestions_service( 450 std::unique_ptr<SuggestionsService> suggestions_service(
451 CreateSuggestionsServiceWithMocks()); 451 CreateSuggestionsServiceWithMocks());
452 ASSERT_TRUE(suggestions_service != nullptr); 452 ASSERT_TRUE(suggestions_service != nullptr);
453 453
454 // Fake a non-200 response code. 454 // Fake a non-200 response code.
455 factory_.SetFakeResponse(SuggestionsService::BuildSuggestionsURL(), 455 factory_.SetFakeResponse(SuggestionsService::BuildSuggestionsURL(),
456 "irrelevant", net::HTTP_BAD_REQUEST, 456 "irrelevant", net::HTTP_BAD_REQUEST,
457 net::URLRequestStatus::SUCCESS); 457 net::URLRequestStatus::SUCCESS);
458 458
459 // Expect that an upload to the blacklist is scheduled. 459 // Expect that an upload to the blacklist is scheduled.
460 EXPECT_CALL(*mock_blacklist_store_, GetTimeUntilReadyForUpload(_)) 460 EXPECT_CALL(*mock_blacklist_store_, GetTimeUntilReadyForUpload(_))
461 .WillOnce(Return(false)); 461 .WillOnce(Return(false));
462 462
463 // Send the request. Empty data will be returned to the callback. 463 // Send the request. Empty data will be returned to the callback.
464 suggestions_service->IssueRequestIfNoneOngoing( 464 suggestions_service->IssueRequestIfNoneOngoing(
465 SuggestionsService::BuildSuggestionsURL()); 465 SuggestionsService::BuildSuggestionsURL());
466 466
467 // (Testing only) wait until suggestion fetch is complete. 467 // (Testing only) wait until suggestion fetch is complete.
468 io_message_loop_.RunUntilIdle(); 468 base::RunLoop().RunUntilIdle();
469 469
470 // Expect no suggestions in the cache. 470 // Expect no suggestions in the cache.
471 SuggestionsProfile empty_suggestions; 471 SuggestionsProfile empty_suggestions;
472 EXPECT_FALSE(test_suggestions_store_->LoadSuggestions(&empty_suggestions)); 472 EXPECT_FALSE(test_suggestions_store_->LoadSuggestions(&empty_suggestions));
473 } 473 }
474 474
475 TEST_F(SuggestionsServiceTest, BlacklistURL) { 475 TEST_F(SuggestionsServiceTest, BlacklistURL) {
476 std::unique_ptr<SuggestionsService> suggestions_service( 476 std::unique_ptr<SuggestionsService> suggestions_service(
477 CreateSuggestionsServiceWithMocks()); 477 CreateSuggestionsServiceWithMocks());
478 EXPECT_TRUE(suggestions_service != nullptr); 478 EXPECT_TRUE(suggestions_service != nullptr);
(...skipping 25 matching lines...) Expand all
504 .WillOnce(Return(true)); 504 .WillOnce(Return(true));
505 505
506 Blacklist(suggestions_service.get(), blacklisted_url); 506 Blacklist(suggestions_service.get(), blacklisted_url);
507 EXPECT_EQ(1, suggestions_data_callback_count_); 507 EXPECT_EQ(1, suggestions_data_callback_count_);
508 508
509 // Wait on the upload task. This only works when the scheduling task is not 509 // Wait on the upload task. This only works when the scheduling task is not
510 // for future execution (note how both the SuggestionsService's scheduling 510 // for future execution (note how both the SuggestionsService's scheduling
511 // delay and the BlacklistStore's candidacy delay are zero). Then wait on 511 // delay and the BlacklistStore's candidacy delay are zero). Then wait on
512 // the blacklist request, then again on the next blacklist scheduling task. 512 // the blacklist request, then again on the next blacklist scheduling task.
513 base::RunLoop().RunUntilIdle(); 513 base::RunLoop().RunUntilIdle();
514 io_message_loop_.RunUntilIdle(); 514 base::RunLoop().RunUntilIdle();
515 base::RunLoop().RunUntilIdle(); 515 base::RunLoop().RunUntilIdle();
516 516
517 EXPECT_EQ(2, suggestions_data_callback_count_); 517 EXPECT_EQ(2, suggestions_data_callback_count_);
518 EXPECT_FALSE(blacklisting_failed_); 518 EXPECT_FALSE(blacklisting_failed_);
519 CheckSuggestionsData(); 519 CheckSuggestionsData();
520 } 520 }
521 521
522 TEST_F(SuggestionsServiceTest, BlacklistURLFails) { 522 TEST_F(SuggestionsServiceTest, BlacklistURLFails) {
523 std::unique_ptr<SuggestionsService> suggestions_service( 523 std::unique_ptr<SuggestionsService> suggestions_service(
524 CreateSuggestionsServiceWithMocks()); 524 CreateSuggestionsServiceWithMocks());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 // Blacklist call, first request attempt. 584 // Blacklist call, first request attempt.
585 Blacklist(suggestions_service.get(), blacklisted_url); 585 Blacklist(suggestions_service.get(), blacklisted_url);
586 EXPECT_EQ(1, suggestions_data_callback_count_); 586 EXPECT_EQ(1, suggestions_data_callback_count_);
587 EXPECT_FALSE(blacklisting_failed_); 587 EXPECT_FALSE(blacklisting_failed_);
588 588
589 // Wait for the first scheduling, the first request, the second scheduling, 589 // Wait for the first scheduling, the first request, the second scheduling,
590 // second request and the third scheduling. Again, note that calling 590 // second request and the third scheduling. Again, note that calling
591 // RunUntilIdle on the MessageLoop only works when the task is not posted for 591 // RunUntilIdle on the MessageLoop only works when the task is not posted for
592 // the future. 592 // the future.
593 base::RunLoop().RunUntilIdle(); 593 base::RunLoop().RunUntilIdle();
594 io_message_loop_.RunUntilIdle();
595 base::RunLoop().RunUntilIdle(); 594 base::RunLoop().RunUntilIdle();
596 io_message_loop_.RunUntilIdle(); 595 base::RunLoop().RunUntilIdle();
596 base::RunLoop().RunUntilIdle();
597 base::RunLoop().RunUntilIdle(); 597 base::RunLoop().RunUntilIdle();
gab 2016/08/05 01:09:57 This doesn't make sense anymore (I guess the logic
fdoray 2016/08/05 16:10:35 Multiple RunUntilIdle in a row really doesn't make
598 CheckSuggestionsData(); 598 CheckSuggestionsData();
599 } 599 }
600 600
601 TEST_F(SuggestionsServiceTest, UndoBlacklistURL) { 601 TEST_F(SuggestionsServiceTest, UndoBlacklistURL) {
602 std::unique_ptr<SuggestionsService> suggestions_service( 602 std::unique_ptr<SuggestionsService> suggestions_service(
603 CreateSuggestionsServiceWithMocks()); 603 CreateSuggestionsServiceWithMocks());
604 ASSERT_TRUE(suggestions_service != nullptr); 604 ASSERT_TRUE(suggestions_service != nullptr);
605 // Ensure scheduling the request doesn't happen before undo. 605 // Ensure scheduling the request doesn't happen before undo.
606 base::TimeDelta delay = base::TimeDelta::FromHours(1); 606 base::TimeDelta delay = base::TimeDelta::FromHours(1);
607 suggestions_service->set_blacklist_delay(delay); 607 suggestions_service->set_blacklist_delay(delay);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 suggestions_service->GetPageThumbnail(test_url, dummy_callback); 750 suggestions_service->GetPageThumbnail(test_url, dummy_callback);
751 751
752 EXPECT_CALL(*mock_thumbnail_manager_, AddImageURL(test_url, thumbnail_url)); 752 EXPECT_CALL(*mock_thumbnail_manager_, AddImageURL(test_url, thumbnail_url));
753 EXPECT_CALL(*mock_thumbnail_manager_, GetImageForURL(test_url, _)); 753 EXPECT_CALL(*mock_thumbnail_manager_, GetImageForURL(test_url, _));
754 suggestions_service->GetPageThumbnailWithURL(test_url, thumbnail_url, 754 suggestions_service->GetPageThumbnailWithURL(test_url, thumbnail_url,
755 dummy_callback); 755 dummy_callback);
756 756
757 } 757 }
758 758
759 } // namespace suggestions 759 } // namespace suggestions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698