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

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

Issue 1066923002: [LogoTracker] Correct fingerprint append in async parameter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change append_fingerprint_func_ to append_queryparams_func_. Created 5 years, 8 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
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 <vector> 7 #include <vector>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 test_clock_(new base::SimpleTestClock()), 310 test_clock_(new base::SimpleTestClock()),
311 logo_cache_(new NiceMock<MockLogoCache>()), 311 logo_cache_(new NiceMock<MockLogoCache>()),
312 fake_url_fetcher_factory_(NULL) { 312 fake_url_fetcher_factory_(NULL) {
313 test_clock_->SetNow(base::Time::FromJsTime(GG_INT64_C(1388686828000))); 313 test_clock_->SetNow(base::Time::FromJsTime(GG_INT64_C(1388686828000)));
314 logo_tracker_ = new LogoTracker( 314 logo_tracker_ = new LogoTracker(
315 base::FilePath(), 315 base::FilePath(),
316 base::MessageLoopProxy::current(), 316 base::MessageLoopProxy::current(),
317 base::MessageLoopProxy::current(), 317 base::MessageLoopProxy::current(),
318 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()), 318 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()),
319 scoped_ptr<LogoDelegate>(new TestLogoDelegate())); 319 scoped_ptr<LogoDelegate>(new TestLogoDelegate()));
320 logo_tracker_->SetServerAPI(logo_url_, 320 logo_tracker_->SetServerAPI(logo_url_, base::Bind(&GoogleParseLogoResponse),
321 base::Bind(&GoogleParseLogoResponse), 321 base::Bind(&GoogleAppendQueryparamsToLogoURL),
322 base::Bind(&GoogleAppendFingerprintToLogoURL)); 322 false);
323 logo_tracker_->SetClockForTests(scoped_ptr<base::Clock>(test_clock_)); 323 logo_tracker_->SetClockForTests(scoped_ptr<base::Clock>(test_clock_));
324 logo_tracker_->SetLogoCacheForTests(scoped_ptr<LogoCache>(logo_cache_)); 324 logo_tracker_->SetLogoCacheForTests(scoped_ptr<LogoCache>(logo_cache_));
325 } 325 }
326 326
327 virtual void TearDown() { 327 virtual void TearDown() {
328 // logo_tracker_ owns logo_cache_, which gets destructed on the file thread 328 // logo_tracker_ owns logo_cache_, which gets destructed on the file thread
329 // after logo_tracker_'s destruction. Ensure that logo_cache_ is actually 329 // after logo_tracker_'s destruction. Ensure that logo_cache_ is actually
330 // destructed before the test ends to make gmock happy. 330 // destructed before the test ends to make gmock happy.
331 delete logo_tracker_; 331 delete logo_tracker_;
332 message_loop_->RunUntilIdle(); 332 message_loop_->RunUntilIdle();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 net::HttpStatusCode response_code) { 376 net::HttpStatusCode response_code) {
377 fake_url_fetcher_factory_.SetFakeResponse( 377 fake_url_fetcher_factory_.SetFakeResponse(
378 logo_url_, response, response_code, request_status); 378 logo_url_, response, response_code, request_status);
379 } 379 }
380 380
381 void LogoTrackerTest::SetServerResponseWhenFingerprint( 381 void LogoTrackerTest::SetServerResponseWhenFingerprint(
382 const std::string& fingerprint, 382 const std::string& fingerprint,
383 const std::string& response_when_fingerprint, 383 const std::string& response_when_fingerprint,
384 net::URLRequestStatus::Status request_status, 384 net::URLRequestStatus::Status request_status,
385 net::HttpStatusCode response_code) { 385 net::HttpStatusCode response_code) {
386 GURL url_with_fp = GoogleAppendFingerprintToLogoURL(logo_url_, fingerprint); 386 GURL url_with_fp =
387 GoogleAppendQueryparamsToLogoURL(logo_url_, fingerprint, false);
387 fake_url_fetcher_factory_.SetFakeResponse( 388 fake_url_fetcher_factory_.SetFakeResponse(
388 url_with_fp, response_when_fingerprint, response_code, request_status); 389 url_with_fp, response_when_fingerprint, response_code, request_status);
389 } 390 }
390 391
391 void LogoTrackerTest::GetLogo() { 392 void LogoTrackerTest::GetLogo() {
392 logo_tracker_->GetLogo(&observer_); 393 logo_tracker_->GetLogo(&observer_);
393 base::RunLoop().RunUntilIdle(); 394 base::RunLoop().RunUntilIdle();
394 } 395 }
395 396
396 // Tests ----------------------------------------------------------------------- 397 // Tests -----------------------------------------------------------------------
397 398
398 TEST_F(LogoTrackerTest, FingerprintURLHasColon) { 399 TEST_F(LogoTrackerTest, FingerprintURLHasColon) {
399 GURL url_with_fp = GoogleAppendFingerprintToLogoURL( 400 GURL url_with_fp = GoogleAppendQueryparamsToLogoURL(
400 GURL("http://logourl.com/path"), "abc123"); 401 GURL("http://logourl.com/path"), "abc123", false);
401 EXPECT_EQ("http://logourl.com/path?async=es_dfp:abc123", url_with_fp.spec()); 402 EXPECT_EQ("http://logourl.com/path?async=es_dfp:abc123", url_with_fp.spec());
402 403
403 url_with_fp = GoogleAppendFingerprintToLogoURL( 404 url_with_fp = GoogleAppendQueryparamsToLogoURL(
404 GURL("http://logourl.com/?a=b"), "cafe0"); 405 GURL("http://logourl.com/?a=b"), "cafe0", false);
405 EXPECT_EQ("http://logourl.com/?a=b&async=es_dfp:cafe0", url_with_fp.spec()); 406 EXPECT_EQ("http://logourl.com/?a=b&async=es_dfp:cafe0", url_with_fp.spec());
406 } 407 }
407 408
409 TEST_F(LogoTrackerTest, CTAURLHasComma) {
410 GURL url_with_fp = GoogleAppendQueryparamsToLogoURL(
411 GURL("http://logourl.com/path"), "abc123", true);
412 EXPECT_EQ("http://logourl.com/path?async=es_dfp:abc123,cta:1",
413 url_with_fp.spec());
414
415 url_with_fp = GoogleAppendQueryparamsToLogoURL(
416 GURL("http://logourl.com/?a=b"), "", true);
417 EXPECT_EQ("http://logourl.com/?a=b&async=cta:1", url_with_fp.spec());
418 }
419
408 TEST_F(LogoTrackerTest, DownloadAndCacheLogo) { 420 TEST_F(LogoTrackerTest, DownloadAndCacheLogo) {
409 Logo logo = GetSampleLogo(logo_url_, test_clock_->Now()); 421 Logo logo = GetSampleLogo(logo_url_, test_clock_->Now());
410 SetServerResponse(ServerResponse(logo)); 422 SetServerResponse(ServerResponse(logo));
411 logo_cache_->ExpectSetCachedLogo(&logo); 423 logo_cache_->ExpectSetCachedLogo(&logo);
412 observer_.ExpectFreshLogo(&logo); 424 observer_.ExpectFreshLogo(&logo);
413 GetLogo(); 425 GetLogo();
414 } 426 }
415 427
416 TEST_F(LogoTrackerTest, EmptyCacheAndFailedDownload) { 428 TEST_F(LogoTrackerTest, EmptyCacheAndFailedDownload) {
417 EXPECT_CALL(*logo_cache_, UpdateCachedLogoMetadata(_)).Times(0); 429 EXPECT_CALL(*logo_cache_, UpdateCachedLogoMetadata(_)).Times(0);
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 677
666 base::RunLoop().RunUntilIdle(); 678 base::RunLoop().RunUntilIdle();
667 } 679 }
668 680
669 TEST_F(LogoTrackerTest, DeleteObserversWhenLogoURLChanged) { 681 TEST_F(LogoTrackerTest, DeleteObserversWhenLogoURLChanged) {
670 MockLogoObserver listener1; 682 MockLogoObserver listener1;
671 listener1.ExpectNoLogo(); 683 listener1.ExpectNoLogo();
672 logo_tracker_->GetLogo(&listener1); 684 logo_tracker_->GetLogo(&listener1);
673 685
674 logo_url_ = GURL("http://example.com/new-logo-url"); 686 logo_url_ = GURL("http://example.com/new-logo-url");
675 logo_tracker_->SetServerAPI(logo_url_, 687 logo_tracker_->SetServerAPI(logo_url_, base::Bind(&GoogleParseLogoResponse),
676 base::Bind(&GoogleParseLogoResponse), 688 base::Bind(&GoogleAppendQueryparamsToLogoURL),
677 base::Bind(&GoogleAppendFingerprintToLogoURL)); 689 false);
678 Logo logo = GetSampleLogo(logo_url_, test_clock_->Now()); 690 Logo logo = GetSampleLogo(logo_url_, test_clock_->Now());
679 SetServerResponse(ServerResponse(logo)); 691 SetServerResponse(ServerResponse(logo));
680 692
681 MockLogoObserver listener2; 693 MockLogoObserver listener2;
682 listener2.ExpectFreshLogo(&logo); 694 listener2.ExpectFreshLogo(&logo);
683 logo_tracker_->GetLogo(&listener2); 695 logo_tracker_->GetLogo(&listener2);
684 696
685 base::RunLoop().RunUntilIdle(); 697 base::RunLoop().RunUntilIdle();
686 } 698 }
687 699
688 } // namespace 700 } // namespace
689 701
690 } // namespace search_provider_logos 702 } // namespace search_provider_logos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698