| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/test/mock_callback.h" | 16 #include "base/test/mock_callback.h" |
| 17 #include "base/test/scoped_feature_list.h" |
| 17 #include "components/signin/core/browser/account_tracker_service.h" | 18 #include "components/signin/core/browser/account_tracker_service.h" |
| 18 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" | 19 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" |
| 19 #include "components/signin/core/browser/fake_signin_manager.h" | 20 #include "components/signin/core/browser/fake_signin_manager.h" |
| 20 #include "components/signin/core/browser/test_signin_client.h" | 21 #include "components/signin/core/browser/test_signin_client.h" |
| 21 #include "components/suggestions/blacklist_store.h" | 22 #include "components/suggestions/blacklist_store.h" |
| 23 #include "components/suggestions/features.h" |
| 22 #include "components/suggestions/image_manager.h" | 24 #include "components/suggestions/image_manager.h" |
| 23 #include "components/suggestions/proto/suggestions.pb.h" | 25 #include "components/suggestions/proto/suggestions.pb.h" |
| 24 #include "components/suggestions/suggestions_store.h" | 26 #include "components/suggestions/suggestions_store.h" |
| 25 #include "components/sync/driver/fake_sync_service.h" | 27 #include "components/sync/driver/fake_sync_service.h" |
| 26 #include "components/sync/driver/sync_service.h" | 28 #include "components/sync/driver/sync_service.h" |
| 27 #include "components/sync_preferences/testing_pref_service_syncable.h" | 29 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 30 #include "components/variations/variations_params_manager.h" |
| 31 #include "net/base/url_util.h" |
| 28 #include "net/http/http_response_headers.h" | 32 #include "net/http/http_response_headers.h" |
| 29 #include "net/http/http_status_code.h" | 33 #include "net/http/http_status_code.h" |
| 30 #include "net/url_request/test_url_fetcher_factory.h" | 34 #include "net/url_request/test_url_fetcher_factory.h" |
| 31 #include "net/url_request/url_request_status.h" | 35 #include "net/url_request/url_request_status.h" |
| 32 #include "net/url_request/url_request_test_util.h" | 36 #include "net/url_request/url_request_test_util.h" |
| 33 #include "testing/gmock/include/gmock/gmock.h" | 37 #include "testing/gmock/include/gmock/gmock.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 35 #include "ui/gfx/image/image.h" | 39 #include "ui/gfx/image/image.h" |
| 36 | 40 |
| 37 using sync_preferences::TestingPrefServiceSyncable; | 41 using sync_preferences::TestingPrefServiceSyncable; |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 EXPECT_CALL(mock_sync_service_, IsSyncActive()).WillRepeatedly(Return(true)); | 334 EXPECT_CALL(mock_sync_service_, IsSyncActive()).WillRepeatedly(Return(true)); |
| 331 suggestions_service_->OnStateChanged(&mock_sync_service_); | 335 suggestions_service_->OnStateChanged(&mock_sync_service_); |
| 332 | 336 |
| 333 ASSERT_EQ(SuggestionsServiceImpl::INITIALIZED_ENABLED_HISTORY, | 337 ASSERT_EQ(SuggestionsServiceImpl::INITIALIZED_ENABLED_HISTORY, |
| 334 suggestions_service_->ComputeSyncState()); | 338 suggestions_service_->ComputeSyncState()); |
| 335 | 339 |
| 336 // Let any network request run (there shouldn't be one). | 340 // Let any network request run (there shouldn't be one). |
| 337 base::RunLoop().RunUntilIdle(); | 341 base::RunLoop().RunUntilIdle(); |
| 338 } | 342 } |
| 339 | 343 |
| 344 TEST_F(SuggestionsServiceTest, BuildUrlWithDefaultMinZeroParamForFewFeature) { |
| 345 base::test::ScopedFeatureList scoped_feature_list; |
| 346 scoped_feature_list.InitAndEnableFeature(kUseSuggestionsEvenIfFewFeature); |
| 347 std::string min_suggestions; |
| 348 EXPECT_TRUE(net::GetValueForKeyInQuery( |
| 349 SuggestionsServiceImpl::BuildSuggestionsURL(), "min", &min_suggestions)); |
| 350 EXPECT_EQ(min_suggestions, "0"); |
| 351 } |
| 352 |
| 340 TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) { | 353 TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) { |
| 341 EXPECT_CALL(mock_sync_service_, IsSyncActive()).WillRepeatedly(Return(false)); | 354 EXPECT_CALL(mock_sync_service_, IsSyncActive()).WillRepeatedly(Return(false)); |
| 342 suggestions_service_->OnStateChanged(&mock_sync_service_); | 355 suggestions_service_->OnStateChanged(&mock_sync_service_); |
| 343 | 356 |
| 344 base::MockCallback<SuggestionsService::ResponseCallback> callback; | 357 base::MockCallback<SuggestionsService::ResponseCallback> callback; |
| 345 EXPECT_CALL(callback, Run(_)).Times(0); | 358 EXPECT_CALL(callback, Run(_)).Times(0); |
| 346 auto subscription = suggestions_service_->AddCallback(callback.Get()); | 359 auto subscription = suggestions_service_->AddCallback(callback.Get()); |
| 347 | 360 |
| 348 // 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 |
| 349 // should be sent. | 362 // should be sent. |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 EXPECT_CALL(*mock_thumbnail_manager_, GetImageForURL(test_url, _)); | 746 EXPECT_CALL(*mock_thumbnail_manager_, GetImageForURL(test_url, _)); |
| 734 suggestions_service_->GetPageThumbnail(test_url, dummy_callback); | 747 suggestions_service_->GetPageThumbnail(test_url, dummy_callback); |
| 735 | 748 |
| 736 EXPECT_CALL(*mock_thumbnail_manager_, AddImageURL(test_url, thumbnail_url)); | 749 EXPECT_CALL(*mock_thumbnail_manager_, AddImageURL(test_url, thumbnail_url)); |
| 737 EXPECT_CALL(*mock_thumbnail_manager_, GetImageForURL(test_url, _)); | 750 EXPECT_CALL(*mock_thumbnail_manager_, GetImageForURL(test_url, _)); |
| 738 suggestions_service_->GetPageThumbnailWithURL(test_url, thumbnail_url, | 751 suggestions_service_->GetPageThumbnailWithURL(test_url, thumbnail_url, |
| 739 dummy_callback); | 752 dummy_callback); |
| 740 } | 753 } |
| 741 | 754 |
| 742 } // namespace suggestions | 755 } // namespace suggestions |
| OLD | NEW |