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

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

Issue 2053913002: Remove MessageLoop::current()->RunUntilIdle() in components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
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>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/feature_list.h" 13 #include "base/feature_list.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/run_loop.h"
16 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" 17 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
17 #include "components/suggestions/blacklist_store.h" 18 #include "components/suggestions/blacklist_store.h"
18 #include "components/suggestions/image_manager.h" 19 #include "components/suggestions/image_manager.h"
19 #include "components/suggestions/proto/suggestions.pb.h" 20 #include "components/suggestions/proto/suggestions.pb.h"
20 #include "components/suggestions/suggestions_store.h" 21 #include "components/suggestions/suggestions_store.h"
21 #include "components/sync_driver/fake_sync_service.h" 22 #include "components/sync_driver/fake_sync_service.h"
22 #include "components/sync_driver/sync_service.h" 23 #include "components/sync_driver/sync_service.h"
23 #include "net/base/escape.h" 24 #include "net/base/escape.h"
24 #include "net/http/http_response_headers.h" 25 #include "net/http/http_response_headers.h"
25 #include "net/http/http_status_code.h" 26 #include "net/http/http_status_code.h"
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 EXPECT_CALL(*mock_blacklist_store_, RemoveUrl(Eq(blacklisted_url))) 503 EXPECT_CALL(*mock_blacklist_store_, RemoveUrl(Eq(blacklisted_url)))
503 .WillOnce(Return(true)); 504 .WillOnce(Return(true));
504 505
505 Blacklist(suggestions_service.get(), blacklisted_url); 506 Blacklist(suggestions_service.get(), blacklisted_url);
506 EXPECT_EQ(1, suggestions_data_callback_count_); 507 EXPECT_EQ(1, suggestions_data_callback_count_);
507 508
508 // 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
509 // for future execution (note how both the SuggestionsService's scheduling 510 // for future execution (note how both the SuggestionsService's scheduling
510 // 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
511 // the blacklist request, then again on the next blacklist scheduling task. 512 // the blacklist request, then again on the next blacklist scheduling task.
512 base::MessageLoop::current()->RunUntilIdle(); 513 base::RunLoop().RunUntilIdle();
513 io_message_loop_.RunUntilIdle(); 514 io_message_loop_.RunUntilIdle();
514 base::MessageLoop::current()->RunUntilIdle(); 515 base::RunLoop().RunUntilIdle();
515 516
516 EXPECT_EQ(2, suggestions_data_callback_count_); 517 EXPECT_EQ(2, suggestions_data_callback_count_);
517 EXPECT_FALSE(blacklisting_failed_); 518 EXPECT_FALSE(blacklisting_failed_);
518 CheckSuggestionsData(); 519 CheckSuggestionsData();
519 } 520 }
520 521
521 TEST_F(SuggestionsServiceTest, BlacklistURLFails) { 522 TEST_F(SuggestionsServiceTest, BlacklistURLFails) {
522 std::unique_ptr<SuggestionsService> suggestions_service( 523 std::unique_ptr<SuggestionsService> suggestions_service(
523 CreateSuggestionsServiceWithMocks()); 524 CreateSuggestionsServiceWithMocks());
524 ASSERT_TRUE(suggestions_service != nullptr); 525 ASSERT_TRUE(suggestions_service != nullptr);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 583
583 // Blacklist call, first request attempt. 584 // Blacklist call, first request attempt.
584 Blacklist(suggestions_service.get(), blacklisted_url); 585 Blacklist(suggestions_service.get(), blacklisted_url);
585 EXPECT_EQ(1, suggestions_data_callback_count_); 586 EXPECT_EQ(1, suggestions_data_callback_count_);
586 EXPECT_FALSE(blacklisting_failed_); 587 EXPECT_FALSE(blacklisting_failed_);
587 588
588 // Wait for the first scheduling, the first request, the second scheduling, 589 // Wait for the first scheduling, the first request, the second scheduling,
589 // second request and the third scheduling. Again, note that calling 590 // second request and the third scheduling. Again, note that calling
590 // 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
591 // the future. 592 // the future.
592 base::MessageLoop::current()->RunUntilIdle(); 593 base::RunLoop().RunUntilIdle();
593 io_message_loop_.RunUntilIdle(); 594 io_message_loop_.RunUntilIdle();
594 base::MessageLoop::current()->RunUntilIdle(); 595 base::RunLoop().RunUntilIdle();
595 io_message_loop_.RunUntilIdle(); 596 io_message_loop_.RunUntilIdle();
596 base::MessageLoop::current()->RunUntilIdle(); 597 base::RunLoop().RunUntilIdle();
597 CheckSuggestionsData(); 598 CheckSuggestionsData();
598 } 599 }
599 600
600 TEST_F(SuggestionsServiceTest, UndoBlacklistURL) { 601 TEST_F(SuggestionsServiceTest, UndoBlacklistURL) {
601 std::unique_ptr<SuggestionsService> suggestions_service( 602 std::unique_ptr<SuggestionsService> suggestions_service(
602 CreateSuggestionsServiceWithMocks()); 603 CreateSuggestionsServiceWithMocks());
603 ASSERT_TRUE(suggestions_service != nullptr); 604 ASSERT_TRUE(suggestions_service != nullptr);
604 // Ensure scheduling the request doesn't happen before undo. 605 // Ensure scheduling the request doesn't happen before undo.
605 base::TimeDelta delay = base::TimeDelta::FromHours(1); 606 base::TimeDelta delay = base::TimeDelta::FromHours(1);
606 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
749 suggestions_service->GetPageThumbnail(test_url, dummy_callback); 750 suggestions_service->GetPageThumbnail(test_url, dummy_callback);
750 751
751 EXPECT_CALL(*mock_thumbnail_manager_, AddImageURL(test_url, thumbnail_url)); 752 EXPECT_CALL(*mock_thumbnail_manager_, AddImageURL(test_url, thumbnail_url));
752 EXPECT_CALL(*mock_thumbnail_manager_, GetImageForURL(test_url, _)); 753 EXPECT_CALL(*mock_thumbnail_manager_, GetImageForURL(test_url, _));
753 suggestions_service->GetPageThumbnailWithURL(test_url, thumbnail_url, 754 suggestions_service->GetPageThumbnailWithURL(test_url, thumbnail_url,
754 dummy_callback); 755 dummy_callback);
755 756
756 } 757 }
757 758
758 } // namespace suggestions 759 } // namespace suggestions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698