Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Side by Side Diff: components/search_provider_logos/logo_tracker_unittest.cc

Issue 1962013002: Adding a parameter that will be used to request a transparent doodle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/search_provider_logos/logo_tracker.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/search_provider_logos/logo_tracker.h" 5 #include "components/search_provider_logos/logo_tracker.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <vector> 10 #include <vector>
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 fake_url_fetcher_factory_(NULL) { 322 fake_url_fetcher_factory_(NULL) {
323 test_clock_->SetNow(base::Time::FromJsTime(INT64_C(1388686828000))); 323 test_clock_->SetNow(base::Time::FromJsTime(INT64_C(1388686828000)));
324 logo_tracker_ = 324 logo_tracker_ =
325 new LogoTracker(base::FilePath(), base::ThreadTaskRunnerHandle::Get(), 325 new LogoTracker(base::FilePath(), base::ThreadTaskRunnerHandle::Get(),
326 base::ThreadTaskRunnerHandle::Get(), 326 base::ThreadTaskRunnerHandle::Get(),
327 new net::TestURLRequestContextGetter( 327 new net::TestURLRequestContextGetter(
328 base::ThreadTaskRunnerHandle::Get()), 328 base::ThreadTaskRunnerHandle::Get()),
329 std::unique_ptr<LogoDelegate>(new TestLogoDelegate())); 329 std::unique_ptr<LogoDelegate>(new TestLogoDelegate()));
330 logo_tracker_->SetServerAPI(logo_url_, base::Bind(&GoogleParseLogoResponse), 330 logo_tracker_->SetServerAPI(logo_url_, base::Bind(&GoogleParseLogoResponse),
331 base::Bind(&GoogleAppendQueryparamsToLogoURL), 331 base::Bind(&GoogleAppendQueryparamsToLogoURL),
332 false,
332 false); 333 false);
333 logo_tracker_->SetClockForTests(std::unique_ptr<base::Clock>(test_clock_)); 334 logo_tracker_->SetClockForTests(std::unique_ptr<base::Clock>(test_clock_));
334 logo_tracker_->SetLogoCacheForTests( 335 logo_tracker_->SetLogoCacheForTests(
335 std::unique_ptr<LogoCache>(logo_cache_)); 336 std::unique_ptr<LogoCache>(logo_cache_));
336 } 337 }
337 338
338 virtual void TearDown() { 339 virtual void TearDown() {
339 // logo_tracker_ owns logo_cache_, which gets destructed on the file thread 340 // logo_tracker_ owns logo_cache_, which gets destructed on the file thread
340 // after logo_tracker_'s destruction. Ensure that logo_cache_ is actually 341 // after logo_tracker_'s destruction. Ensure that logo_cache_ is actually
341 // destructed before the test ends to make gmock happy. 342 // destructed before the test ends to make gmock happy.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 fake_url_fetcher_factory_.SetFakeResponse( 389 fake_url_fetcher_factory_.SetFakeResponse(
389 logo_url_, response, response_code, request_status); 390 logo_url_, response, response_code, request_status);
390 } 391 }
391 392
392 void LogoTrackerTest::SetServerResponseWhenFingerprint( 393 void LogoTrackerTest::SetServerResponseWhenFingerprint(
393 const std::string& fingerprint, 394 const std::string& fingerprint,
394 const std::string& response_when_fingerprint, 395 const std::string& response_when_fingerprint,
395 net::URLRequestStatus::Status request_status, 396 net::URLRequestStatus::Status request_status,
396 net::HttpStatusCode response_code) { 397 net::HttpStatusCode response_code) {
397 GURL url_with_fp = 398 GURL url_with_fp =
398 GoogleAppendQueryparamsToLogoURL(logo_url_, fingerprint, false); 399 GoogleAppendQueryparamsToLogoURL(logo_url_, fingerprint, false, false);
399 fake_url_fetcher_factory_.SetFakeResponse( 400 fake_url_fetcher_factory_.SetFakeResponse(
400 url_with_fp, response_when_fingerprint, response_code, request_status); 401 url_with_fp, response_when_fingerprint, response_code, request_status);
401 } 402 }
402 403
403 void LogoTrackerTest::GetLogo() { 404 void LogoTrackerTest::GetLogo() {
404 logo_tracker_->GetLogo(&observer_); 405 logo_tracker_->GetLogo(&observer_);
405 base::RunLoop().RunUntilIdle(); 406 base::RunLoop().RunUntilIdle();
406 } 407 }
407 408
408 // Tests ----------------------------------------------------------------------- 409 // Tests -----------------------------------------------------------------------
409 410
410 TEST_F(LogoTrackerTest, FingerprintURLHasColon) { 411 TEST_F(LogoTrackerTest, FingerprintURLHasColon) {
411 GURL url_with_fp = GoogleAppendQueryparamsToLogoURL( 412 GURL url_with_fp = GoogleAppendQueryparamsToLogoURL(
412 GURL("http://logourl.com/path"), "abc123", false); 413 GURL("http://logourl.com/path"), "abc123", false, false);
413 EXPECT_EQ("http://logourl.com/path?async=es_dfp:abc123", url_with_fp.spec()); 414 EXPECT_EQ("http://logourl.com/path?async=es_dfp:abc123", url_with_fp.spec());
414 415
415 url_with_fp = GoogleAppendQueryparamsToLogoURL( 416 url_with_fp = GoogleAppendQueryparamsToLogoURL(
416 GURL("http://logourl.com/?a=b"), "cafe0", false); 417 GURL("http://logourl.com/?a=b"), "cafe0", false, false);
417 EXPECT_EQ("http://logourl.com/?a=b&async=es_dfp:cafe0", url_with_fp.spec()); 418 EXPECT_EQ("http://logourl.com/?a=b&async=es_dfp:cafe0", url_with_fp.spec());
418 } 419 }
419 420
420 TEST_F(LogoTrackerTest, CTAURLHasComma) { 421 TEST_F(LogoTrackerTest, CTAURLHasComma) {
421 GURL url_with_fp = GoogleAppendQueryparamsToLogoURL( 422 GURL url_with_fp = GoogleAppendQueryparamsToLogoURL(
422 GURL("http://logourl.com/path"), "abc123", true); 423 GURL("http://logourl.com/path"), "abc123", true, false);
423 EXPECT_EQ("http://logourl.com/path?async=es_dfp:abc123,cta:1", 424 EXPECT_EQ("http://logourl.com/path?async=es_dfp:abc123,cta:1",
424 url_with_fp.spec()); 425 url_with_fp.spec());
425 426
426 url_with_fp = GoogleAppendQueryparamsToLogoURL( 427 url_with_fp = GoogleAppendQueryparamsToLogoURL(
427 GURL("http://logourl.com/?a=b"), "", true); 428 GURL("http://logourl.com/?a=b"), "", true, false);
428 EXPECT_EQ("http://logourl.com/?a=b&async=cta:1", url_with_fp.spec()); 429 EXPECT_EQ("http://logourl.com/?a=b&async=cta:1", url_with_fp.spec());
429 } 430 }
430 431
432 TEST_F(LogoTrackerTest, CTATransparentHasCommas) {
433 GURL url_with_fp = GoogleAppendQueryparamsToLogoURL(
434 GURL("http://logourl.com/path"), "abc123", true, true);
435 EXPECT_EQ("http://logourl.com/path?async=es_dfp:abc123,cta:1,transp:1",
436 url_with_fp.spec());
437
438 url_with_fp = GoogleAppendQueryparamsToLogoURL(
439 GURL("http://logourl.com/?a=b"), "", true, true);
440 EXPECT_EQ("http://logourl.com/?a=b&async=cta:1,transp:1", url_with_fp.spec());
441 }
442
431 TEST_F(LogoTrackerTest, DownloadAndCacheLogo) { 443 TEST_F(LogoTrackerTest, DownloadAndCacheLogo) {
432 Logo logo = GetSampleLogo(logo_url_, test_clock_->Now()); 444 Logo logo = GetSampleLogo(logo_url_, test_clock_->Now());
433 SetServerResponse(ServerResponse(logo)); 445 SetServerResponse(ServerResponse(logo));
434 logo_cache_->ExpectSetCachedLogo(&logo); 446 logo_cache_->ExpectSetCachedLogo(&logo);
435 observer_.ExpectFreshLogo(&logo); 447 observer_.ExpectFreshLogo(&logo);
436 GetLogo(); 448 GetLogo();
437 } 449 }
438 450
439 TEST_F(LogoTrackerTest, EmptyCacheAndFailedDownload) { 451 TEST_F(LogoTrackerTest, EmptyCacheAndFailedDownload) {
440 EXPECT_CALL(*logo_cache_, UpdateCachedLogoMetadata(_)).Times(0); 452 EXPECT_CALL(*logo_cache_, UpdateCachedLogoMetadata(_)).Times(0);
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 } 737 }
726 738
727 TEST_F(LogoTrackerTest, DeleteObserversWhenLogoURLChanged) { 739 TEST_F(LogoTrackerTest, DeleteObserversWhenLogoURLChanged) {
728 MockLogoObserver listener1; 740 MockLogoObserver listener1;
729 listener1.ExpectNoLogo(); 741 listener1.ExpectNoLogo();
730 logo_tracker_->GetLogo(&listener1); 742 logo_tracker_->GetLogo(&listener1);
731 743
732 logo_url_ = GURL("http://example.com/new-logo-url"); 744 logo_url_ = GURL("http://example.com/new-logo-url");
733 logo_tracker_->SetServerAPI(logo_url_, base::Bind(&GoogleParseLogoResponse), 745 logo_tracker_->SetServerAPI(logo_url_, base::Bind(&GoogleParseLogoResponse),
734 base::Bind(&GoogleAppendQueryparamsToLogoURL), 746 base::Bind(&GoogleAppendQueryparamsToLogoURL),
747 false,
735 false); 748 false);
736 Logo logo = GetSampleLogo(logo_url_, test_clock_->Now()); 749 Logo logo = GetSampleLogo(logo_url_, test_clock_->Now());
737 SetServerResponse(ServerResponse(logo)); 750 SetServerResponse(ServerResponse(logo));
738 751
739 MockLogoObserver listener2; 752 MockLogoObserver listener2;
740 listener2.ExpectFreshLogo(&logo); 753 listener2.ExpectFreshLogo(&logo);
741 logo_tracker_->GetLogo(&listener2); 754 logo_tracker_->GetLogo(&listener2);
742 755
743 base::RunLoop().RunUntilIdle(); 756 base::RunLoop().RunUntilIdle();
744 } 757 }
745 758
746 } // namespace 759 } // namespace
747 760
748 } // namespace search_provider_logos 761 } // namespace search_provider_logos
OLDNEW
« no previous file with comments | « components/search_provider_logos/logo_tracker.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698