| 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/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 "base/run_loop.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" |
| 28 #include "net/base/escape.h" | 30 #include "net/base/escape.h" |
| 31 #include "net/base/url_util.h" |
| 29 #include "net/http/http_response_headers.h" | 32 #include "net/http/http_response_headers.h" |
| 30 #include "net/http/http_status_code.h" | 33 #include "net/http/http_status_code.h" |
| 31 #include "net/url_request/test_url_fetcher_factory.h" | 34 #include "net/url_request/test_url_fetcher_factory.h" |
| 32 #include "net/url_request/url_request_status.h" | 35 #include "net/url_request/url_request_status.h" |
| 33 #include "net/url_request/url_request_test_util.h" | 36 #include "net/url_request/url_request_test_util.h" |
| 34 #include "testing/gmock/include/gmock/gmock.h" | 37 #include "testing/gmock/include/gmock/gmock.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 36 #include "ui/gfx/image/image.h" | 39 #include "ui/gfx/image/image.h" |
| 37 | 40 |
| 38 using sync_preferences::TestingPrefServiceSyncable; | 41 using sync_preferences::TestingPrefServiceSyncable; |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 syncer::HISTORY_DELETE_DIRECTIVES, syncer::BOOKMARKS))); | 326 syncer::HISTORY_DELETE_DIRECTIVES, syncer::BOOKMARKS))); |
| 324 suggestions_service_->OnStateChanged(&mock_sync_service_); | 327 suggestions_service_->OnStateChanged(&mock_sync_service_); |
| 325 | 328 |
| 326 // Let any network request run (there shouldn't be one). | 329 // Let any network request run (there shouldn't be one). |
| 327 base::RunLoop().RunUntilIdle(); | 330 base::RunLoop().RunUntilIdle(); |
| 328 | 331 |
| 329 // Ensure that we weren't called back. | 332 // Ensure that we weren't called back. |
| 330 EXPECT_EQ(0, suggestions_data_callback_count_); | 333 EXPECT_EQ(0, suggestions_data_callback_count_); |
| 331 } | 334 } |
| 332 | 335 |
| 336 TEST_F(SuggestionsServiceTest, BuildUrlWithMinEqualsZeroParamForFewFeature) { |
| 337 base::test::ScopedFeatureList scoped_feature_list; |
| 338 scoped_feature_list.InitAndEnableFeature(kUseSuggestionsEvenIfFewFeature); |
| 339 std::string min_suggestions; |
| 340 EXPECT_TRUE(net::GetValueForKeyInQuery( |
| 341 SuggestionsServiceImpl::BuildSuggestionsURL(), "min", &min_suggestions)); |
| 342 EXPECT_EQ(min_suggestions, "0"); |
| 343 } |
| 344 |
| 333 TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) { | 345 TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) { |
| 334 EXPECT_CALL(mock_sync_service_, IsSyncActive()).WillRepeatedly(Return(false)); | 346 EXPECT_CALL(mock_sync_service_, IsSyncActive()).WillRepeatedly(Return(false)); |
| 335 suggestions_service_->OnStateChanged(&mock_sync_service_); | 347 suggestions_service_->OnStateChanged(&mock_sync_service_); |
| 336 | 348 |
| 337 auto subscription = suggestions_service_->AddCallback(base::Bind( | 349 auto subscription = suggestions_service_->AddCallback(base::Bind( |
| 338 &SuggestionsServiceTest::CheckCallback, base::Unretained(this))); | 350 &SuggestionsServiceTest::CheckCallback, base::Unretained(this))); |
| 339 | 351 |
| 340 // Try to fetch suggestions. Since sync is not active, no network request | 352 // Try to fetch suggestions. Since sync is not active, no network request |
| 341 // should be sent. | 353 // should be sent. |
| 342 suggestions_service_->FetchSuggestionsData(); | 354 suggestions_service_->FetchSuggestionsData(); |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 EXPECT_CALL(*mock_thumbnail_manager_, GetImageForURL(test_url, _)); | 754 EXPECT_CALL(*mock_thumbnail_manager_, GetImageForURL(test_url, _)); |
| 743 suggestions_service_->GetPageThumbnail(test_url, dummy_callback); | 755 suggestions_service_->GetPageThumbnail(test_url, dummy_callback); |
| 744 | 756 |
| 745 EXPECT_CALL(*mock_thumbnail_manager_, AddImageURL(test_url, thumbnail_url)); | 757 EXPECT_CALL(*mock_thumbnail_manager_, AddImageURL(test_url, thumbnail_url)); |
| 746 EXPECT_CALL(*mock_thumbnail_manager_, GetImageForURL(test_url, _)); | 758 EXPECT_CALL(*mock_thumbnail_manager_, GetImageForURL(test_url, _)); |
| 747 suggestions_service_->GetPageThumbnailWithURL(test_url, thumbnail_url, | 759 suggestions_service_->GetPageThumbnailWithURL(test_url, thumbnail_url, |
| 748 dummy_callback); | 760 dummy_callback); |
| 749 } | 761 } |
| 750 | 762 |
| 751 } // namespace suggestions | 763 } // namespace suggestions |
| OLD | NEW |