Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_impl.h" | 5 #include "components/suggestions/suggestions_service_impl.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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 .Times(AnyNumber()) | 300 .Times(AnyNumber()) |
| 301 .WillRepeatedly(Return(syncer::ModelTypeSet( | 301 .WillRepeatedly(Return(syncer::ModelTypeSet( |
| 302 syncer::HISTORY_DELETE_DIRECTIVES, syncer::BOOKMARKS))); | 302 syncer::HISTORY_DELETE_DIRECTIVES, syncer::BOOKMARKS))); |
| 303 EXPECT_CALL(callback, Run(_)).Times(0); | 303 EXPECT_CALL(callback, Run(_)).Times(0); |
| 304 suggestions_service_->OnStateChanged(&mock_sync_service_); | 304 suggestions_service_->OnStateChanged(&mock_sync_service_); |
| 305 | 305 |
| 306 // Let any network request run (there shouldn't be one). | 306 // Let any network request run (there shouldn't be one). |
| 307 base::RunLoop().RunUntilIdle(); | 307 base::RunLoop().RunUntilIdle(); |
| 308 } | 308 } |
| 309 | 309 |
| 310 // During startup, the state changes from NOT_INITIALIZED_ENABLED to | |
| 311 // INITIALIZED_ENABLED_HISTORY (for a signed-in user with history sync enabled). | |
| 312 // This should *not* result in an automatic fetch. | |
| 313 TEST_F(SuggestionsServiceTest, DoesNotFetchOnStartup) { | |
| 314 // The sync service starts out inactive. | |
| 315 EXPECT_CALL(mock_sync_service_, IsSyncActive()).WillRepeatedly(Return(false)); | |
| 316 suggestions_service_->OnStateChanged(&mock_sync_service_); | |
| 317 | |
| 318 ASSERT_EQ(SuggestionsServiceImpl::NOT_INITIALIZED_ENABLED, | |
| 319 suggestions_service_->ComputeSyncState()); | |
| 320 | |
| 321 base::MockCallback<SuggestionsService::ResponseCallback> callback; | |
| 322 auto subscription = suggestions_service_->AddCallback(callback.Get()); | |
| 323 | |
| 324 factory_.SetFakeResponse(SuggestionsServiceImpl::BuildSuggestionsURL(), | |
| 325 CreateSuggestionsProfile().SerializeAsString(), | |
| 326 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | |
| 327 | |
| 328 // Sync getting enabled should not result in a fetch. | |
| 329 EXPECT_CALL(mock_sync_service_, IsSyncActive()).WillRepeatedly(Return(true)); | |
| 330 EXPECT_CALL(callback, Run(_)).Times(0); | |
|
mastiz
2017/05/08 14:18:32
I should've mentioned this earlier (as part of the
Marc Treib
2017/05/08 14:57:46
Done.
| |
| 331 suggestions_service_->OnStateChanged(&mock_sync_service_); | |
| 332 | |
| 333 ASSERT_EQ(SuggestionsServiceImpl::INITIALIZED_ENABLED_HISTORY, | |
| 334 suggestions_service_->ComputeSyncState()); | |
| 335 | |
| 336 // Let any network request run (there shouldn't be one). | |
| 337 base::RunLoop().RunUntilIdle(); | |
| 338 } | |
| 339 | |
| 310 TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) { | 340 TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) { |
| 311 EXPECT_CALL(mock_sync_service_, IsSyncActive()).WillRepeatedly(Return(false)); | 341 EXPECT_CALL(mock_sync_service_, IsSyncActive()).WillRepeatedly(Return(false)); |
| 312 suggestions_service_->OnStateChanged(&mock_sync_service_); | 342 suggestions_service_->OnStateChanged(&mock_sync_service_); |
| 313 | 343 |
| 314 base::MockCallback<SuggestionsService::ResponseCallback> callback; | 344 base::MockCallback<SuggestionsService::ResponseCallback> callback; |
| 315 auto subscription = suggestions_service_->AddCallback(callback.Get()); | 345 auto subscription = suggestions_service_->AddCallback(callback.Get()); |
| 316 | 346 |
| 317 // Try to fetch suggestions. Since sync is not active, no network request | 347 // Try to fetch suggestions. Since sync is not active, no network request |
| 318 // should be sent. | 348 // should be sent. |
| 319 EXPECT_CALL(callback, Run(_)).Times(0); | 349 EXPECT_CALL(callback, Run(_)).Times(0); |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 704 EXPECT_CALL(*mock_thumbnail_manager_, GetImageForURL(test_url, _)); | 734 EXPECT_CALL(*mock_thumbnail_manager_, GetImageForURL(test_url, _)); |
| 705 suggestions_service_->GetPageThumbnail(test_url, dummy_callback); | 735 suggestions_service_->GetPageThumbnail(test_url, dummy_callback); |
| 706 | 736 |
| 707 EXPECT_CALL(*mock_thumbnail_manager_, AddImageURL(test_url, thumbnail_url)); | 737 EXPECT_CALL(*mock_thumbnail_manager_, AddImageURL(test_url, thumbnail_url)); |
| 708 EXPECT_CALL(*mock_thumbnail_manager_, GetImageForURL(test_url, _)); | 738 EXPECT_CALL(*mock_thumbnail_manager_, GetImageForURL(test_url, _)); |
| 709 suggestions_service_->GetPageThumbnailWithURL(test_url, thumbnail_url, | 739 suggestions_service_->GetPageThumbnailWithURL(test_url, thumbnail_url, |
| 710 dummy_callback); | 740 dummy_callback); |
| 711 } | 741 } |
| 712 | 742 |
| 713 } // namespace suggestions | 743 } // namespace suggestions |
| OLD | NEW |