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.h" | 5 #include "components/suggestions/suggestions_service.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <sstream> | 8 #include <sstream> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 EXPECT_CALL(*mock_thumbnail_manager_, Initialize(_)); | 319 EXPECT_CALL(*mock_thumbnail_manager_, Initialize(_)); |
320 | 320 |
321 // Expect a call to the blacklist store. Return that there's nothing to | 321 // Expect a call to the blacklist store. Return that there's nothing to |
322 // blacklist. | 322 // blacklist. |
323 EXPECT_CALL(*mock_blacklist_store_, FilterSuggestions(_)); | 323 EXPECT_CALL(*mock_blacklist_store_, FilterSuggestions(_)); |
324 EXPECT_CALL(*mock_blacklist_store_, GetFirstUrlFromBlacklist(_)) | 324 EXPECT_CALL(*mock_blacklist_store_, GetFirstUrlFromBlacklist(_)) |
325 .WillOnce(Return(false)); | 325 .WillOnce(Return(false)); |
326 | 326 |
327 // Send the request. Empty data will be returned to the callback. | 327 // Send the request. Empty data will be returned to the callback. |
328 suggestions_service->FetchSuggestionsData( | 328 suggestions_service->FetchSuggestionsData( |
329 true /* sync_initialized */, | |
330 true /* history sync enabled */, | |
329 base::Bind(&SuggestionsServiceTest::ExpectEmptySuggestionsProfile, | 331 base::Bind(&SuggestionsServiceTest::ExpectEmptySuggestionsProfile, |
330 base::Unretained(this))); | 332 base::Unretained(this))); |
331 | 333 |
332 // (Testing only) wait until suggestion fetch is complete. | 334 // (Testing only) wait until suggestion fetch is complete. |
333 io_message_loop_.RunUntilIdle(); | 335 io_message_loop_.RunUntilIdle(); |
334 | 336 |
335 // Ensure that ExpectEmptySuggestionsProfile ran once. | 337 // Ensure that ExpectEmptySuggestionsProfile ran once. |
336 EXPECT_EQ(1, suggestions_empty_data_count_); | 338 EXPECT_EQ(1, suggestions_empty_data_count_); |
337 } | 339 } |
338 | 340 |
(...skipping 15 matching lines...) Expand all Loading... | |
354 // Set up expectations on the SuggestionsStore. | 356 // Set up expectations on the SuggestionsStore. |
355 EXPECT_CALL(*mock_suggestions_store_, ClearSuggestions()); | 357 EXPECT_CALL(*mock_suggestions_store_, ClearSuggestions()); |
356 | 358 |
357 // Expect a call to the blacklist store. Return that there's nothing to | 359 // Expect a call to the blacklist store. Return that there's nothing to |
358 // blacklist. | 360 // blacklist. |
359 EXPECT_CALL(*mock_blacklist_store_, GetFirstUrlFromBlacklist(_)) | 361 EXPECT_CALL(*mock_blacklist_store_, GetFirstUrlFromBlacklist(_)) |
360 .WillOnce(Return(false)); | 362 .WillOnce(Return(false)); |
361 | 363 |
362 // Send the request. Empty data will be returned to the callback. | 364 // Send the request. Empty data will be returned to the callback. |
363 suggestions_service->FetchSuggestionsData( | 365 suggestions_service->FetchSuggestionsData( |
366 true /* sync_initialized */, | |
367 true /* history sync enabled */, | |
364 base::Bind(&SuggestionsServiceTest::ExpectEmptySuggestionsProfile, | 368 base::Bind(&SuggestionsServiceTest::ExpectEmptySuggestionsProfile, |
365 base::Unretained(this))); | 369 base::Unretained(this))); |
366 | 370 |
367 // (Testing only) wait until suggestion fetch is complete. | 371 // (Testing only) wait until suggestion fetch is complete. |
368 io_message_loop_.RunUntilIdle(); | 372 io_message_loop_.RunUntilIdle(); |
369 | 373 |
370 // Ensure that ExpectEmptySuggestionsProfile ran once. | 374 // Ensure that ExpectEmptySuggestionsProfile ran once. |
371 EXPECT_EQ(1, suggestions_empty_data_count_); | 375 EXPECT_EQ(1, suggestions_empty_data_count_); |
372 } | 376 } |
373 | 377 |
378 TEST_F(SuggestionsServiceTest, FetchSuggestionsDataHistorySyncNotEnabled) { | |
379 // Field trial enabled with a specific suggestions URL. | |
380 EnableFieldTrial(kFakeSuggestionsURL, kFakeSuggestionsCommonParams, | |
381 kFakeBlacklistPath, kFakeBlacklistUrlParam, false); | |
382 scoped_ptr<SuggestionsService> suggestions_service( | |
383 CreateSuggestionsServiceWithMocks()); | |
384 EXPECT_TRUE(suggestions_service != NULL); | |
385 | |
386 // Send the request. Empty data will be returned to the callback. | |
387 suggestions_service->FetchSuggestionsData( | |
388 true /* sync_initialized */, | |
389 false /* history sync disabled */, | |
390 base::Bind(&SuggestionsServiceTest::ExpectEmptySuggestionsProfile, | |
391 base::Unretained(this))); | |
392 | |
manzagop (departed)
2014/08/15 13:01:52
Test the cache was cleared by calling a second tim
Mathieu
2014/08/20 14:21:32
Done.
| |
393 // Wait for posted task to complete. | |
394 base::MessageLoop::current()->RunUntilIdle(); | |
395 | |
396 // Ensure that ExpectEmptySuggestionsProfile ran once. | |
397 EXPECT_EQ(1, suggestions_empty_data_count_); | |
398 } | |
399 | |
400 TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitialized) { | |
401 // Field trial enabled with a specific suggestions URL. | |
402 EnableFieldTrial(kFakeSuggestionsURL, kFakeSuggestionsCommonParams, | |
403 kFakeBlacklistPath, kFakeBlacklistUrlParam, false); | |
404 scoped_ptr<SuggestionsService> suggestions_service( | |
405 CreateSuggestionsServiceWithMocks()); | |
406 EXPECT_TRUE(suggestions_service != NULL); | |
407 scoped_ptr<SuggestionsProfile> suggestions_profile( | |
408 CreateSuggestionsProfile()); | |
409 | |
410 // Expectations. | |
411 EXPECT_CALL(*mock_suggestions_store_, LoadSuggestions(_)) | |
412 .WillOnce(DoAll(SetArgPointee<0>(*suggestions_profile), Return(true))); | |
413 EXPECT_CALL(*mock_thumbnail_manager_, | |
414 Initialize(EqualsProto(*suggestions_profile))); | |
415 EXPECT_CALL(*mock_blacklist_store_, FilterSuggestions(_)); | |
416 | |
417 // Send the request. Empty data will be returned to the callback. | |
418 suggestions_service->FetchSuggestionsData( | |
419 false /* sync_initialized */, | |
420 false /* history sync disabled (doesn't matter) */, | |
421 base::Bind(&SuggestionsServiceTest::CheckSuggestionsData, | |
422 base::Unretained(this))); | |
423 | |
424 // Wait for posted task to complete. | |
425 base::MessageLoop::current()->RunUntilIdle(); | |
426 | |
427 // Ensure that CheckSuggestionsData ran once. | |
428 EXPECT_EQ(1, suggestions_data_check_count_); | |
429 } | |
430 | |
374 TEST_F(SuggestionsServiceTest, BlacklistURL) { | 431 TEST_F(SuggestionsServiceTest, BlacklistURL) { |
375 EnableFieldTrial(kFakeSuggestionsURL, kFakeSuggestionsCommonParams, | 432 EnableFieldTrial(kFakeSuggestionsURL, kFakeSuggestionsCommonParams, |
376 kFakeBlacklistPath, kFakeBlacklistUrlParam, false); | 433 kFakeBlacklistPath, kFakeBlacklistUrlParam, false); |
377 scoped_ptr<SuggestionsService> suggestions_service( | 434 scoped_ptr<SuggestionsService> suggestions_service( |
378 CreateSuggestionsServiceWithMocks()); | 435 CreateSuggestionsServiceWithMocks()); |
379 EXPECT_TRUE(suggestions_service != NULL); | 436 EXPECT_TRUE(suggestions_service != NULL); |
380 | 437 |
381 GURL blacklist_url(kBlacklistUrl); | 438 GURL blacklist_url(kBlacklistUrl); |
382 std::string request_url = GetExpectedBlacklistRequestUrl(blacklist_url); | 439 std::string request_url = GetExpectedBlacklistRequestUrl(blacklist_url); |
383 scoped_ptr<SuggestionsProfile> suggestions_profile( | 440 scoped_ptr<SuggestionsProfile> suggestions_profile( |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
529 scoped_ptr<SuggestionsService> suggestions_service( | 586 scoped_ptr<SuggestionsService> suggestions_service( |
530 CreateSuggestionsServiceWithMocks()); | 587 CreateSuggestionsServiceWithMocks()); |
531 SuggestionsProfile suggestions = | 588 SuggestionsProfile suggestions = |
532 CreateSuggestionsProfileWithExpiryTimestamps(); | 589 CreateSuggestionsProfileWithExpiryTimestamps(); |
533 suggestions_service->SetDefaultExpiryTimestamp(&suggestions, | 590 suggestions_service->SetDefaultExpiryTimestamp(&suggestions, |
534 kTestDefaultExpiry); | 591 kTestDefaultExpiry); |
535 EXPECT_EQ(kTestSetExpiry, suggestions.suggestions(0).expiry_ts()); | 592 EXPECT_EQ(kTestSetExpiry, suggestions.suggestions(0).expiry_ts()); |
536 EXPECT_EQ(kTestDefaultExpiry, suggestions.suggestions(1).expiry_ts()); | 593 EXPECT_EQ(kTestDefaultExpiry, suggestions.suggestions(1).expiry_ts()); |
537 } | 594 } |
538 } // namespace suggestions | 595 } // namespace suggestions |
OLD | NEW |