| 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 // Ensure that CheckCallback() ran once. | 335 // Ensure that CheckCallback() ran once. |
| 333 EXPECT_EQ(1, suggestions_data_callback_count_); | 336 EXPECT_EQ(1, suggestions_data_callback_count_); |
| 334 | 337 |
| 335 test_suggestions_store_->LoadSuggestions(&suggestions_profile); | 338 test_suggestions_store_->LoadSuggestions(&suggestions_profile); |
| 336 ASSERT_EQ(1, suggestions_profile.suggestions_size()); | 339 ASSERT_EQ(1, suggestions_profile.suggestions_size()); |
| 337 EXPECT_EQ(kTestTitle, suggestions_profile.suggestions(0).title()); | 340 EXPECT_EQ(kTestTitle, suggestions_profile.suggestions(0).title()); |
| 338 EXPECT_EQ(kTestUrl, suggestions_profile.suggestions(0).url()); | 341 EXPECT_EQ(kTestUrl, suggestions_profile.suggestions(0).url()); |
| 339 EXPECT_EQ(kTestFaviconUrl, suggestions_profile.suggestions(0).favicon_url()); | 342 EXPECT_EQ(kTestFaviconUrl, suggestions_profile.suggestions(0).favicon_url()); |
| 340 } | 343 } |
| 341 | 344 |
| 345 TEST_F(SuggestionsServiceTest, BuildUrlWithAllParameterForFewFeature) { |
| 346 base::test::ScopedFeatureList scoped_feature_list; |
| 347 scoped_feature_list.InitAndEnableFeature(kUseSuggestionsEvenIfFewFeature); |
| 348 std::string unused_value; |
| 349 EXPECT_TRUE(net::GetValueForKeyInQuery( |
| 350 SuggestionsServiceImpl::BuildSuggestionsURL(), "all", &unused_value)); |
| 351 } |
| 352 |
| 342 TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) { | 353 TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) { |
| 343 std::unique_ptr<SuggestionsService> suggestions_service( | 354 std::unique_ptr<SuggestionsService> suggestions_service( |
| 344 CreateSuggestionsServiceWithMocks()); | 355 CreateSuggestionsServiceWithMocks()); |
| 345 EXPECT_CALL(*mock_sync_service_, IsSyncActive()) | 356 EXPECT_CALL(*mock_sync_service_, IsSyncActive()) |
| 346 .WillRepeatedly(Return(false)); | 357 .WillRepeatedly(Return(false)); |
| 347 | 358 |
| 348 auto subscription = suggestions_service->AddCallback(base::Bind( | 359 auto subscription = suggestions_service->AddCallback(base::Bind( |
| 349 &SuggestionsServiceTest::CheckCallback, base::Unretained(this))); | 360 &SuggestionsServiceTest::CheckCallback, base::Unretained(this))); |
| 350 | 361 |
| 351 // Try to fetch suggestions. Since sync is not active, no network request | 362 // Try to fetch suggestions. Since sync is not active, no network request |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 EXPECT_CALL(*mock_thumbnail_manager_, GetImageForURL(test_url, _)); | 739 EXPECT_CALL(*mock_thumbnail_manager_, GetImageForURL(test_url, _)); |
| 729 suggestions_service->GetPageThumbnail(test_url, dummy_callback); | 740 suggestions_service->GetPageThumbnail(test_url, dummy_callback); |
| 730 | 741 |
| 731 EXPECT_CALL(*mock_thumbnail_manager_, AddImageURL(test_url, thumbnail_url)); | 742 EXPECT_CALL(*mock_thumbnail_manager_, AddImageURL(test_url, thumbnail_url)); |
| 732 EXPECT_CALL(*mock_thumbnail_manager_, GetImageForURL(test_url, _)); | 743 EXPECT_CALL(*mock_thumbnail_manager_, GetImageForURL(test_url, _)); |
| 733 suggestions_service->GetPageThumbnailWithURL(test_url, thumbnail_url, | 744 suggestions_service->GetPageThumbnailWithURL(test_url, thumbnail_url, |
| 734 dummy_callback); | 745 dummy_callback); |
| 735 } | 746 } |
| 736 | 747 |
| 737 } // namespace suggestions | 748 } // namespace suggestions |
| OLD | NEW |