| 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 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/metrics/field_trial.h" | |
| 14 #include "base/strings/utf_string_conversions.h" | |
| 15 #include "components/suggestions/blacklist_store.h" | 13 #include "components/suggestions/blacklist_store.h" |
| 16 #include "components/suggestions/image_manager.h" | 14 #include "components/suggestions/image_manager.h" |
| 17 #include "components/suggestions/proto/suggestions.pb.h" | 15 #include "components/suggestions/proto/suggestions.pb.h" |
| 18 #include "components/suggestions/suggestions_store.h" | 16 #include "components/suggestions/suggestions_store.h" |
| 19 #include "components/suggestions/suggestions_utils.h" | 17 #include "components/suggestions/suggestions_utils.h" |
| 20 #include "components/variations/entropy_provider.h" | |
| 21 #include "components/variations/variations_associated_data.h" | |
| 22 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
| 23 #include "net/http/http_status_code.h" | 19 #include "net/http/http_status_code.h" |
| 24 #include "net/url_request/test_url_fetcher_factory.h" | 20 #include "net/url_request/test_url_fetcher_factory.h" |
| 25 #include "net/url_request/url_request_status.h" | 21 #include "net/url_request/url_request_status.h" |
| 26 #include "net/url_request/url_request_test_util.h" | 22 #include "net/url_request/url_request_test_util.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 25 |
| 30 using std::string; | 26 using std::string; |
| 31 using testing::DoAll; | 27 using testing::DoAll; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 mock_blacklist_store_(NULL), | 188 mock_blacklist_store_(NULL), |
| 193 test_suggestions_store_(NULL) {} | 189 test_suggestions_store_(NULL) {} |
| 194 | 190 |
| 195 ~SuggestionsServiceTest() override {} | 191 ~SuggestionsServiceTest() override {} |
| 196 | 192 |
| 197 void SetUp() override { | 193 void SetUp() override { |
| 198 request_context_ = new net::TestURLRequestContextGetter( | 194 request_context_ = new net::TestURLRequestContextGetter( |
| 199 io_message_loop_.message_loop_proxy()); | 195 io_message_loop_.message_loop_proxy()); |
| 200 } | 196 } |
| 201 | 197 |
| 202 void EnableFieldTrial(bool control_group) { | |
| 203 // Clear the existing |field_trial_list_| to avoid firing a DCHECK. | |
| 204 field_trial_list_.reset(NULL); | |
| 205 field_trial_list_.reset( | |
| 206 new base::FieldTrialList(new metrics::SHA1EntropyProvider("foo"))); | |
| 207 | |
| 208 variations::testing::ClearAllVariationParams(); | |
| 209 std::map<std::string, std::string> params; | |
| 210 params[kSuggestionsFieldTrialStateParam] = | |
| 211 kSuggestionsFieldTrialStateEnabled; | |
| 212 if (control_group) { | |
| 213 params[kSuggestionsFieldTrialControlParam] = | |
| 214 kSuggestionsFieldTrialStateEnabled; | |
| 215 } | |
| 216 variations::AssociateVariationParams(kSuggestionsFieldTrialName, "Group1", | |
| 217 params); | |
| 218 field_trial_ = base::FieldTrialList::CreateFieldTrial( | |
| 219 kSuggestionsFieldTrialName, "Group1"); | |
| 220 field_trial_->group(); | |
| 221 } | |
| 222 | |
| 223 void FetchSuggestionsDataHelper(SyncState sync_state) { | 198 void FetchSuggestionsDataHelper(SyncState sync_state) { |
| 224 scoped_ptr<SuggestionsService> suggestions_service( | 199 scoped_ptr<SuggestionsService> suggestions_service( |
| 225 CreateSuggestionsServiceWithMocks()); | 200 CreateSuggestionsServiceWithMocks()); |
| 226 EXPECT_TRUE(suggestions_service != NULL); | 201 EXPECT_TRUE(suggestions_service != NULL); |
| 227 | 202 |
| 228 // Add some suggestions in the cache. | 203 // Add some suggestions in the cache. |
| 229 FillSuggestionsStore(); | 204 FillSuggestionsStore(); |
| 230 SuggestionsProfile suggestions_profile; | 205 SuggestionsProfile suggestions_profile; |
| 231 test_suggestions_store_->LoadSuggestions(&suggestions_profile); | 206 test_suggestions_store_->LoadSuggestions(&suggestions_profile); |
| 232 | 207 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 protected: | 311 protected: |
| 337 base::MessageLoopForIO io_message_loop_; | 312 base::MessageLoopForIO io_message_loop_; |
| 338 net::FakeURLFetcherFactory factory_; | 313 net::FakeURLFetcherFactory factory_; |
| 339 // Only used if the SuggestionsService is built with mocks. Not owned. | 314 // Only used if the SuggestionsService is built with mocks. Not owned. |
| 340 MockImageManager* mock_thumbnail_manager_; | 315 MockImageManager* mock_thumbnail_manager_; |
| 341 MockBlacklistStore* mock_blacklist_store_; | 316 MockBlacklistStore* mock_blacklist_store_; |
| 342 TestSuggestionsStore* test_suggestions_store_; | 317 TestSuggestionsStore* test_suggestions_store_; |
| 343 scoped_refptr<net::TestURLRequestContextGetter> request_context_; | 318 scoped_refptr<net::TestURLRequestContextGetter> request_context_; |
| 344 | 319 |
| 345 private: | 320 private: |
| 346 scoped_ptr<base::FieldTrialList> field_trial_list_; | |
| 347 scoped_refptr<base::FieldTrial> field_trial_; | |
| 348 | |
| 349 DISALLOW_COPY_AND_ASSIGN(SuggestionsServiceTest); | 321 DISALLOW_COPY_AND_ASSIGN(SuggestionsServiceTest); |
| 350 }; | 322 }; |
| 351 | 323 |
| 352 TEST_F(SuggestionsServiceTest, IsControlGroup) { | |
| 353 EnableFieldTrial(false); | |
| 354 EXPECT_FALSE(SuggestionsService::IsControlGroup()); | |
| 355 | |
| 356 EnableFieldTrial(true); | |
| 357 EXPECT_TRUE(SuggestionsService::IsControlGroup()); | |
| 358 } | |
| 359 | |
| 360 TEST_F(SuggestionsServiceTest, FetchSuggestionsData) { | 324 TEST_F(SuggestionsServiceTest, FetchSuggestionsData) { |
| 361 EnableFieldTrial(false); | |
| 362 FetchSuggestionsDataHelper(INITIALIZED_ENABLED_HISTORY); | 325 FetchSuggestionsDataHelper(INITIALIZED_ENABLED_HISTORY); |
| 363 } | 326 } |
| 364 | 327 |
| 365 TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) { | 328 TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) { |
| 366 EnableFieldTrial(false); | |
| 367 FetchSuggestionsDataHelper(NOT_INITIALIZED_ENABLED); | 329 FetchSuggestionsDataHelper(NOT_INITIALIZED_ENABLED); |
| 368 } | 330 } |
| 369 | 331 |
| 370 TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncDisabled) { | 332 TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncDisabled) { |
| 371 EnableFieldTrial(false); | |
| 372 scoped_ptr<SuggestionsService> suggestions_service( | 333 scoped_ptr<SuggestionsService> suggestions_service( |
| 373 CreateSuggestionsServiceWithMocks()); | 334 CreateSuggestionsServiceWithMocks()); |
| 374 EXPECT_TRUE(suggestions_service != NULL); | 335 EXPECT_TRUE(suggestions_service != NULL); |
| 375 | 336 |
| 376 FillSuggestionsStore(); | 337 FillSuggestionsStore(); |
| 377 | 338 |
| 378 // Send the request. Cache is cleared and empty data will be returned to the | 339 // Send the request. Cache is cleared and empty data will be returned to the |
| 379 // callback. | 340 // callback. |
| 380 suggestions_service->FetchSuggestionsData( | 341 suggestions_service->FetchSuggestionsData( |
| 381 SYNC_OR_HISTORY_SYNC_DISABLED, | 342 SYNC_OR_HISTORY_SYNC_DISABLED, |
| 382 base::Bind(&SuggestionsServiceTest::ExpectEmptySuggestionsProfile, | 343 base::Bind(&SuggestionsServiceTest::ExpectEmptySuggestionsProfile, |
| 383 base::Unretained(this))); | 344 base::Unretained(this))); |
| 384 | 345 |
| 385 // Ensure that ExpectEmptySuggestionsProfile ran once. | 346 // Ensure that ExpectEmptySuggestionsProfile ran once. |
| 386 EXPECT_EQ(1, suggestions_empty_data_count_); | 347 EXPECT_EQ(1, suggestions_empty_data_count_); |
| 387 } | 348 } |
| 388 | 349 |
| 389 TEST_F(SuggestionsServiceTest, IssueRequestIfNoneOngoingError) { | 350 TEST_F(SuggestionsServiceTest, IssueRequestIfNoneOngoingError) { |
| 390 EnableFieldTrial(false); | |
| 391 scoped_ptr<SuggestionsService> suggestions_service( | 351 scoped_ptr<SuggestionsService> suggestions_service( |
| 392 CreateSuggestionsServiceWithMocks()); | 352 CreateSuggestionsServiceWithMocks()); |
| 393 EXPECT_TRUE(suggestions_service != NULL); | 353 EXPECT_TRUE(suggestions_service != NULL); |
| 394 | 354 |
| 395 // Fake a request error. | 355 // Fake a request error. |
| 396 factory_.SetFakeResponse(GURL(kSuggestionsURL), "irrelevant", net::HTTP_OK, | 356 factory_.SetFakeResponse(GURL(kSuggestionsURL), "irrelevant", net::HTTP_OK, |
| 397 net::URLRequestStatus::FAILED); | 357 net::URLRequestStatus::FAILED); |
| 398 | 358 |
| 399 EXPECT_CALL(*mock_blacklist_store_, GetTimeUntilReadyForUpload(_)) | 359 EXPECT_CALL(*mock_blacklist_store_, GetTimeUntilReadyForUpload(_)) |
| 400 .WillOnce(Return(false)); | 360 .WillOnce(Return(false)); |
| 401 | 361 |
| 402 // Send the request. Empty data will be returned to the callback. | 362 // Send the request. Empty data will be returned to the callback. |
| 403 suggestions_service->IssueRequestIfNoneOngoing(GURL(kSuggestionsURL)); | 363 suggestions_service->IssueRequestIfNoneOngoing(GURL(kSuggestionsURL)); |
| 404 | 364 |
| 405 // (Testing only) wait until suggestion fetch is complete. | 365 // (Testing only) wait until suggestion fetch is complete. |
| 406 io_message_loop_.RunUntilIdle(); | 366 io_message_loop_.RunUntilIdle(); |
| 407 } | 367 } |
| 408 | 368 |
| 409 TEST_F(SuggestionsServiceTest, IssueRequestIfNoneOngoingResponseNotOK) { | 369 TEST_F(SuggestionsServiceTest, IssueRequestIfNoneOngoingResponseNotOK) { |
| 410 EnableFieldTrial(false); | |
| 411 scoped_ptr<SuggestionsService> suggestions_service( | 370 scoped_ptr<SuggestionsService> suggestions_service( |
| 412 CreateSuggestionsServiceWithMocks()); | 371 CreateSuggestionsServiceWithMocks()); |
| 413 EXPECT_TRUE(suggestions_service != NULL); | 372 EXPECT_TRUE(suggestions_service != NULL); |
| 414 | 373 |
| 415 // Add some suggestions in the cache. | 374 // Add some suggestions in the cache. |
| 416 FillSuggestionsStore(); | 375 FillSuggestionsStore(); |
| 417 | 376 |
| 418 // Fake a non-200 response code. | 377 // Fake a non-200 response code. |
| 419 factory_.SetFakeResponse(GURL(kSuggestionsURL), "irrelevant", | 378 factory_.SetFakeResponse(GURL(kSuggestionsURL), "irrelevant", |
| 420 net::HTTP_BAD_REQUEST, | 379 net::HTTP_BAD_REQUEST, |
| 421 net::URLRequestStatus::SUCCESS); | 380 net::URLRequestStatus::SUCCESS); |
| 422 | 381 |
| 423 // Expect that an upload to the blacklist is scheduled. | 382 // Expect that an upload to the blacklist is scheduled. |
| 424 EXPECT_CALL(*mock_blacklist_store_, GetTimeUntilReadyForUpload(_)) | 383 EXPECT_CALL(*mock_blacklist_store_, GetTimeUntilReadyForUpload(_)) |
| 425 .WillOnce(Return(false)); | 384 .WillOnce(Return(false)); |
| 426 | 385 |
| 427 // Send the request. Empty data will be returned to the callback. | 386 // Send the request. Empty data will be returned to the callback. |
| 428 suggestions_service->IssueRequestIfNoneOngoing(GURL(kSuggestionsURL)); | 387 suggestions_service->IssueRequestIfNoneOngoing(GURL(kSuggestionsURL)); |
| 429 | 388 |
| 430 // (Testing only) wait until suggestion fetch is complete. | 389 // (Testing only) wait until suggestion fetch is complete. |
| 431 io_message_loop_.RunUntilIdle(); | 390 io_message_loop_.RunUntilIdle(); |
| 432 | 391 |
| 433 // Expect no suggestions in the cache. | 392 // Expect no suggestions in the cache. |
| 434 SuggestionsProfile empty_suggestions; | 393 SuggestionsProfile empty_suggestions; |
| 435 EXPECT_FALSE(test_suggestions_store_->LoadSuggestions(&empty_suggestions)); | 394 EXPECT_FALSE(test_suggestions_store_->LoadSuggestions(&empty_suggestions)); |
| 436 } | 395 } |
| 437 | 396 |
| 438 TEST_F(SuggestionsServiceTest, BlacklistURL) { | 397 TEST_F(SuggestionsServiceTest, BlacklistURL) { |
| 439 EnableFieldTrial(false); | |
| 440 scoped_ptr<SuggestionsService> suggestions_service( | 398 scoped_ptr<SuggestionsService> suggestions_service( |
| 441 CreateSuggestionsServiceWithMocks()); | 399 CreateSuggestionsServiceWithMocks()); |
| 442 EXPECT_TRUE(suggestions_service != NULL); | 400 EXPECT_TRUE(suggestions_service != NULL); |
| 443 base::TimeDelta no_delay = base::TimeDelta::FromSeconds(0); | 401 base::TimeDelta no_delay = base::TimeDelta::FromSeconds(0); |
| 444 suggestions_service->set_blacklist_delay(no_delay); | 402 suggestions_service->set_blacklist_delay(no_delay); |
| 445 | 403 |
| 446 GURL blacklist_url(kBlacklistUrl); | 404 GURL blacklist_url(kBlacklistUrl); |
| 447 std::string request_url = GetExpectedBlacklistRequestUrl(blacklist_url); | 405 std::string request_url = GetExpectedBlacklistRequestUrl(blacklist_url); |
| 448 SuggestionsProfile suggestions_profile = CreateSuggestionsProfile(); | 406 SuggestionsProfile suggestions_profile = CreateSuggestionsProfile(); |
| 449 factory_.SetFakeResponse(GURL(request_url), | 407 factory_.SetFakeResponse(GURL(request_url), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 473 base::MessageLoop::current()->RunUntilIdle(); | 431 base::MessageLoop::current()->RunUntilIdle(); |
| 474 io_message_loop_.RunUntilIdle(); | 432 io_message_loop_.RunUntilIdle(); |
| 475 base::MessageLoop::current()->RunUntilIdle(); | 433 base::MessageLoop::current()->RunUntilIdle(); |
| 476 | 434 |
| 477 // Ensure that CheckSuggestionsData() ran once. | 435 // Ensure that CheckSuggestionsData() ran once. |
| 478 EXPECT_EQ(1, suggestions_data_check_count_); | 436 EXPECT_EQ(1, suggestions_data_check_count_); |
| 479 EXPECT_FALSE(blacklisting_failed_); | 437 EXPECT_FALSE(blacklisting_failed_); |
| 480 } | 438 } |
| 481 | 439 |
| 482 TEST_F(SuggestionsServiceTest, BlacklistURLFails) { | 440 TEST_F(SuggestionsServiceTest, BlacklistURLFails) { |
| 483 EnableFieldTrial(false); | |
| 484 scoped_ptr<SuggestionsService> suggestions_service( | 441 scoped_ptr<SuggestionsService> suggestions_service( |
| 485 CreateSuggestionsServiceWithMocks()); | 442 CreateSuggestionsServiceWithMocks()); |
| 486 EXPECT_TRUE(suggestions_service != NULL); | 443 EXPECT_TRUE(suggestions_service != NULL); |
| 487 GURL blacklist_url(kBlacklistUrl); | 444 GURL blacklist_url(kBlacklistUrl); |
| 488 EXPECT_CALL(*mock_blacklist_store_, BlacklistUrl(Eq(blacklist_url))) | 445 EXPECT_CALL(*mock_blacklist_store_, BlacklistUrl(Eq(blacklist_url))) |
| 489 .WillOnce(Return(false)); | 446 .WillOnce(Return(false)); |
| 490 | 447 |
| 491 Blacklist(suggestions_service.get(), blacklist_url); | 448 Blacklist(suggestions_service.get(), blacklist_url); |
| 492 | 449 |
| 493 EXPECT_TRUE(blacklisting_failed_); | 450 EXPECT_TRUE(blacklisting_failed_); |
| 494 EXPECT_EQ(0, suggestions_data_check_count_); | 451 EXPECT_EQ(0, suggestions_data_check_count_); |
| 495 } | 452 } |
| 496 | 453 |
| 497 // Initial blacklist request fails, triggering a second which succeeds. | 454 // Initial blacklist request fails, triggering a second which succeeds. |
| 498 TEST_F(SuggestionsServiceTest, BlacklistURLRequestFails) { | 455 TEST_F(SuggestionsServiceTest, BlacklistURLRequestFails) { |
| 499 EnableFieldTrial(false); | |
| 500 scoped_ptr<SuggestionsService> suggestions_service( | 456 scoped_ptr<SuggestionsService> suggestions_service( |
| 501 CreateSuggestionsServiceWithMocks()); | 457 CreateSuggestionsServiceWithMocks()); |
| 502 EXPECT_TRUE(suggestions_service != NULL); | 458 EXPECT_TRUE(suggestions_service != NULL); |
| 503 base::TimeDelta no_delay = base::TimeDelta::FromSeconds(0); | 459 base::TimeDelta no_delay = base::TimeDelta::FromSeconds(0); |
| 504 suggestions_service->set_blacklist_delay(no_delay); | 460 suggestions_service->set_blacklist_delay(no_delay); |
| 505 | 461 |
| 506 GURL blacklist_url(kBlacklistUrl); | 462 GURL blacklist_url(kBlacklistUrl); |
| 507 std::string request_url = GetExpectedBlacklistRequestUrl(blacklist_url); | 463 std::string request_url = GetExpectedBlacklistRequestUrl(blacklist_url); |
| 508 GURL blacklist_url_alt(kBlacklistUrlAlt); | 464 GURL blacklist_url_alt(kBlacklistUrlAlt); |
| 509 std::string request_url_alt = GetExpectedBlacklistRequestUrl( | 465 std::string request_url_alt = GetExpectedBlacklistRequestUrl( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 // RunUntilIdle on the MessageLoop only works when the task is not posted for | 502 // RunUntilIdle on the MessageLoop only works when the task is not posted for |
| 547 // the future. | 503 // the future. |
| 548 base::MessageLoop::current()->RunUntilIdle(); | 504 base::MessageLoop::current()->RunUntilIdle(); |
| 549 io_message_loop_.RunUntilIdle(); | 505 io_message_loop_.RunUntilIdle(); |
| 550 base::MessageLoop::current()->RunUntilIdle(); | 506 base::MessageLoop::current()->RunUntilIdle(); |
| 551 io_message_loop_.RunUntilIdle(); | 507 io_message_loop_.RunUntilIdle(); |
| 552 base::MessageLoop::current()->RunUntilIdle(); | 508 base::MessageLoop::current()->RunUntilIdle(); |
| 553 } | 509 } |
| 554 | 510 |
| 555 TEST_F(SuggestionsServiceTest, UndoBlacklistURL) { | 511 TEST_F(SuggestionsServiceTest, UndoBlacklistURL) { |
| 556 EnableFieldTrial(false); | |
| 557 scoped_ptr<SuggestionsService> suggestions_service( | 512 scoped_ptr<SuggestionsService> suggestions_service( |
| 558 CreateSuggestionsServiceWithMocks()); | 513 CreateSuggestionsServiceWithMocks()); |
| 559 EXPECT_TRUE(suggestions_service != NULL); | 514 EXPECT_TRUE(suggestions_service != NULL); |
| 560 // Ensure scheduling the request doesn't happen before undo. | 515 // Ensure scheduling the request doesn't happen before undo. |
| 561 base::TimeDelta delay = base::TimeDelta::FromHours(1); | 516 base::TimeDelta delay = base::TimeDelta::FromHours(1); |
| 562 suggestions_service->set_blacklist_delay(delay); | 517 suggestions_service->set_blacklist_delay(delay); |
| 563 SuggestionsProfile suggestions_profile = CreateSuggestionsProfile(); | 518 SuggestionsProfile suggestions_profile = CreateSuggestionsProfile(); |
| 564 GURL blacklist_url(kBlacklistUrl); | 519 GURL blacklist_url(kBlacklistUrl); |
| 565 | 520 |
| 566 // Blacklist expectations. | 521 // Blacklist expectations. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 583 Blacklist(suggestions_service.get(), blacklist_url); | 538 Blacklist(suggestions_service.get(), blacklist_url); |
| 584 UndoBlacklist(suggestions_service.get(), blacklist_url); | 539 UndoBlacklist(suggestions_service.get(), blacklist_url); |
| 585 | 540 |
| 586 EXPECT_EQ(2, suggestions_data_check_count_); | 541 EXPECT_EQ(2, suggestions_data_check_count_); |
| 587 EXPECT_FALSE(blacklisting_failed_); | 542 EXPECT_FALSE(blacklisting_failed_); |
| 588 EXPECT_FALSE(undo_blacklisting_failed_); | 543 EXPECT_FALSE(undo_blacklisting_failed_); |
| 589 } | 544 } |
| 590 | 545 |
| 591 | 546 |
| 592 TEST_F(SuggestionsServiceTest, UndoBlacklistURLFailsIfNotInBlacklist) { | 547 TEST_F(SuggestionsServiceTest, UndoBlacklistURLFailsIfNotInBlacklist) { |
| 593 EnableFieldTrial(false); | |
| 594 UndoBlacklistURLFailsHelper(true); | 548 UndoBlacklistURLFailsHelper(true); |
| 595 } | 549 } |
| 596 | 550 |
| 597 TEST_F(SuggestionsServiceTest, UndoBlacklistURLFailsIfAlreadyCandidate) { | 551 TEST_F(SuggestionsServiceTest, UndoBlacklistURLFailsIfAlreadyCandidate) { |
| 598 EnableFieldTrial(false); | |
| 599 UndoBlacklistURLFailsHelper(false); | 552 UndoBlacklistURLFailsHelper(false); |
| 600 } | 553 } |
| 601 | 554 |
| 602 TEST_F(SuggestionsServiceTest, GetBlacklistedUrl) { | 555 TEST_F(SuggestionsServiceTest, GetBlacklistedUrl) { |
| 603 EnableFieldTrial(false); | |
| 604 scoped_ptr<GURL> request_url; | 556 scoped_ptr<GURL> request_url; |
| 605 scoped_ptr<net::FakeURLFetcher> fetcher; | 557 scoped_ptr<net::FakeURLFetcher> fetcher; |
| 606 GURL retrieved_url; | 558 GURL retrieved_url; |
| 607 | 559 |
| 608 // Not a blacklist request. | 560 // Not a blacklist request. |
| 609 request_url.reset(new GURL("http://not-blacklisting.com/a?b=c")); | 561 request_url.reset(new GURL("http://not-blacklisting.com/a?b=c")); |
| 610 fetcher = CreateURLFetcher(*request_url, NULL, "", net::HTTP_OK, | 562 fetcher = CreateURLFetcher(*request_url, NULL, "", net::HTTP_OK, |
| 611 net::URLRequestStatus::SUCCESS); | 563 net::URLRequestStatus::SUCCESS); |
| 612 EXPECT_FALSE(SuggestionsService::GetBlacklistedUrl(*fetcher, &retrieved_url)); | 564 EXPECT_FALSE(SuggestionsService::GetBlacklistedUrl(*fetcher, &retrieved_url)); |
| 613 | 565 |
| 614 // An actual blacklist request. | 566 // An actual blacklist request. |
| 615 string blacklisted_url = "http://blacklisted.com/a?b=c&d=e"; | 567 string blacklisted_url = "http://blacklisted.com/a?b=c&d=e"; |
| 616 string encoded_blacklisted_url = | 568 string encoded_blacklisted_url = |
| 617 "http%3A%2F%2Fblacklisted.com%2Fa%3Fb%3Dc%26d%3De"; | 569 "http%3A%2F%2Fblacklisted.com%2Fa%3Fb%3Dc%26d%3De"; |
| 618 string blacklist_request_prefix(kSuggestionsBlacklistURLPrefix); | 570 string blacklist_request_prefix(kSuggestionsBlacklistURLPrefix); |
| 619 request_url.reset( | 571 request_url.reset( |
| 620 new GURL(blacklist_request_prefix + encoded_blacklisted_url)); | 572 new GURL(blacklist_request_prefix + encoded_blacklisted_url)); |
| 621 fetcher.reset(); | 573 fetcher.reset(); |
| 622 fetcher = CreateURLFetcher(*request_url, NULL, "", net::HTTP_OK, | 574 fetcher = CreateURLFetcher(*request_url, NULL, "", net::HTTP_OK, |
| 623 net::URLRequestStatus::SUCCESS); | 575 net::URLRequestStatus::SUCCESS); |
| 624 EXPECT_TRUE(SuggestionsService::GetBlacklistedUrl(*fetcher, &retrieved_url)); | 576 EXPECT_TRUE(SuggestionsService::GetBlacklistedUrl(*fetcher, &retrieved_url)); |
| 625 EXPECT_EQ(blacklisted_url, retrieved_url.spec()); | 577 EXPECT_EQ(blacklisted_url, retrieved_url.spec()); |
| 626 } | 578 } |
| 627 | 579 |
| 628 TEST_F(SuggestionsServiceTest, UpdateBlacklistDelay) { | 580 TEST_F(SuggestionsServiceTest, UpdateBlacklistDelay) { |
| 629 EnableFieldTrial(false); | |
| 630 scoped_ptr<SuggestionsService> suggestions_service( | 581 scoped_ptr<SuggestionsService> suggestions_service( |
| 631 CreateSuggestionsServiceWithMocks()); | 582 CreateSuggestionsServiceWithMocks()); |
| 632 base::TimeDelta initial_delay = suggestions_service->blacklist_delay(); | 583 base::TimeDelta initial_delay = suggestions_service->blacklist_delay(); |
| 633 | 584 |
| 634 // Delay unchanged on success. | 585 // Delay unchanged on success. |
| 635 suggestions_service->UpdateBlacklistDelay(true); | 586 suggestions_service->UpdateBlacklistDelay(true); |
| 636 EXPECT_EQ(initial_delay, suggestions_service->blacklist_delay()); | 587 EXPECT_EQ(initial_delay, suggestions_service->blacklist_delay()); |
| 637 | 588 |
| 638 // Delay increases on failure. | 589 // Delay increases on failure. |
| 639 suggestions_service->UpdateBlacklistDelay(false); | 590 suggestions_service->UpdateBlacklistDelay(false); |
| 640 EXPECT_GT(suggestions_service->blacklist_delay(), initial_delay); | 591 EXPECT_GT(suggestions_service->blacklist_delay(), initial_delay); |
| 641 | 592 |
| 642 // Delay resets on success. | 593 // Delay resets on success. |
| 643 suggestions_service->UpdateBlacklistDelay(true); | 594 suggestions_service->UpdateBlacklistDelay(true); |
| 644 EXPECT_EQ(initial_delay, suggestions_service->blacklist_delay()); | 595 EXPECT_EQ(initial_delay, suggestions_service->blacklist_delay()); |
| 645 } | 596 } |
| 646 | 597 |
| 647 TEST_F(SuggestionsServiceTest, CheckDefaultTimeStamps) { | 598 TEST_F(SuggestionsServiceTest, CheckDefaultTimeStamps) { |
| 648 EnableFieldTrial(false); | |
| 649 scoped_ptr<SuggestionsService> suggestions_service( | 599 scoped_ptr<SuggestionsService> suggestions_service( |
| 650 CreateSuggestionsServiceWithMocks()); | 600 CreateSuggestionsServiceWithMocks()); |
| 651 SuggestionsProfile suggestions = | 601 SuggestionsProfile suggestions = |
| 652 CreateSuggestionsProfileWithExpiryTimestamps(); | 602 CreateSuggestionsProfileWithExpiryTimestamps(); |
| 653 suggestions_service->SetDefaultExpiryTimestamp(&suggestions, | 603 suggestions_service->SetDefaultExpiryTimestamp(&suggestions, |
| 654 kTestDefaultExpiry); | 604 kTestDefaultExpiry); |
| 655 EXPECT_EQ(kTestSetExpiry, suggestions.suggestions(0).expiry_ts()); | 605 EXPECT_EQ(kTestSetExpiry, suggestions.suggestions(0).expiry_ts()); |
| 656 EXPECT_EQ(kTestDefaultExpiry, suggestions.suggestions(1).expiry_ts()); | 606 EXPECT_EQ(kTestDefaultExpiry, suggestions.suggestions(1).expiry_ts()); |
| 657 } | 607 } |
| 658 } // namespace suggestions | 608 } // namespace suggestions |
| OLD | NEW |