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 "net/base/url_util.h" |
28 #include "net/http/http_response_headers.h" | 31 #include "net/http/http_response_headers.h" |
29 #include "net/http/http_status_code.h" | 32 #include "net/http/http_status_code.h" |
30 #include "net/url_request/test_url_fetcher_factory.h" | 33 #include "net/url_request/test_url_fetcher_factory.h" |
31 #include "net/url_request/url_request_status.h" | 34 #include "net/url_request/url_request_status.h" |
32 #include "net/url_request/url_request_test_util.h" | 35 #include "net/url_request/url_request_test_util.h" |
33 #include "testing/gmock/include/gmock/gmock.h" | 36 #include "testing/gmock/include/gmock/gmock.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
35 #include "ui/gfx/image/image.h" | 38 #include "ui/gfx/image/image.h" |
36 | 39 |
37 using sync_preferences::TestingPrefServiceSyncable; | 40 using sync_preferences::TestingPrefServiceSyncable; |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 // Sync getting enabled should not result in a fetch. | 318 // Sync getting enabled should not result in a fetch. |
316 EXPECT_CALL(*sync_service(), IsSyncActive()).WillRepeatedly(Return(true)); | 319 EXPECT_CALL(*sync_service(), IsSyncActive()).WillRepeatedly(Return(true)); |
317 static_cast<SyncServiceObserver*>(suggestions_service()) | 320 static_cast<SyncServiceObserver*>(suggestions_service()) |
318 ->OnStateChanged(sync_service()); | 321 ->OnStateChanged(sync_service()); |
319 | 322 |
320 // Wait for eventual (but unexpected) network requests. | 323 // Wait for eventual (but unexpected) network requests. |
321 base::RunLoop().RunUntilIdle(); | 324 base::RunLoop().RunUntilIdle(); |
322 EXPECT_FALSE(suggestions_service()->has_pending_request_for_testing()); | 325 EXPECT_FALSE(suggestions_service()->has_pending_request_for_testing()); |
323 } | 326 } |
324 | 327 |
| 328 TEST_F(SuggestionsServiceTest, BuildUrlWithDefaultMinZeroParamForFewFeature) { |
| 329 base::test::ScopedFeatureList scoped_feature_list; |
| 330 scoped_feature_list.InitAndEnableFeature(kUseSuggestionsEvenIfFewFeature); |
| 331 |
| 332 EXPECT_CALL(*thumbnail_manager(), Initialize(_)); |
| 333 EXPECT_CALL(*blacklist_store(), FilterSuggestions(_)); |
| 334 EXPECT_CALL(*blacklist_store(), GetTimeUntilReadyForUpload(_)) |
| 335 .WillOnce(Return(false)); |
| 336 |
| 337 // Send the request. The data should be returned to the callback. |
| 338 suggestions_service()->FetchSuggestionsData(); |
| 339 |
| 340 // Wait for the eventual network request. |
| 341 base::RunLoop().RunUntilIdle(); |
| 342 ASSERT_TRUE(GetCurrentlyQueriedUrl().is_valid()); |
| 343 EXPECT_EQ(GetCurrentlyQueriedUrl().path(), kSuggestionsUrlPath); |
| 344 std::string min_suggestions; |
| 345 EXPECT_TRUE(net::GetValueForKeyInQuery(GetCurrentlyQueriedUrl(), "min", |
| 346 &min_suggestions)); |
| 347 EXPECT_EQ(min_suggestions, "0"); |
| 348 RespondToFetchWithProfile(CreateSuggestionsProfile()); |
| 349 } |
| 350 |
325 TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) { | 351 TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) { |
326 EXPECT_CALL(*sync_service(), IsSyncActive()).WillRepeatedly(Return(false)); | 352 EXPECT_CALL(*sync_service(), IsSyncActive()).WillRepeatedly(Return(false)); |
327 static_cast<SyncServiceObserver*>(suggestions_service()) | 353 static_cast<SyncServiceObserver*>(suggestions_service()) |
328 ->OnStateChanged(sync_service()); | 354 ->OnStateChanged(sync_service()); |
329 | 355 |
330 base::MockCallback<SuggestionsService::ResponseCallback> callback; | 356 base::MockCallback<SuggestionsService::ResponseCallback> callback; |
331 EXPECT_CALL(callback, Run(_)).Times(0); | 357 EXPECT_CALL(callback, Run(_)).Times(0); |
332 auto subscription = suggestions_service()->AddCallback(callback.Get()); | 358 auto subscription = suggestions_service()->AddCallback(callback.Get()); |
333 | 359 |
334 // Try to fetch suggestions. Since sync is not active, no network request | 360 // Try to fetch suggestions. Since sync is not active, no network request |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 EXPECT_CALL(*thumbnail_manager(), GetImageForURL(test_url, _)); | 739 EXPECT_CALL(*thumbnail_manager(), GetImageForURL(test_url, _)); |
714 suggestions_service()->GetPageThumbnail(test_url, dummy_callback); | 740 suggestions_service()->GetPageThumbnail(test_url, dummy_callback); |
715 | 741 |
716 EXPECT_CALL(*thumbnail_manager(), AddImageURL(test_url, thumbnail_url)); | 742 EXPECT_CALL(*thumbnail_manager(), AddImageURL(test_url, thumbnail_url)); |
717 EXPECT_CALL(*thumbnail_manager(), GetImageForURL(test_url, _)); | 743 EXPECT_CALL(*thumbnail_manager(), GetImageForURL(test_url, _)); |
718 suggestions_service()->GetPageThumbnailWithURL(test_url, thumbnail_url, | 744 suggestions_service()->GetPageThumbnailWithURL(test_url, thumbnail_url, |
719 dummy_callback); | 745 dummy_callback); |
720 } | 746 } |
721 | 747 |
722 } // namespace suggestions | 748 } // namespace suggestions |
OLD | NEW |