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

Side by Side Diff: components/doodle/doodle_fetcher_impl_unittest.cc

Issue 2768333002: [Doodle] Pass parameters to the server endpoint (Closed)
Patch Set: ifdef android Created 3 years, 9 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/doodle/doodle_fetcher_impl.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/doodle/doodle_fetcher_impl.h" 5 #include "components/doodle/doodle_fetcher_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 16 matching lines...) Expand all
27 27
28 using testing::_; 28 using testing::_;
29 using testing::DoAll; 29 using testing::DoAll;
30 using testing::Eq; 30 using testing::Eq;
31 using testing::SaveArg; 31 using testing::SaveArg;
32 32
33 namespace doodle { 33 namespace doodle {
34 34
35 namespace { 35 namespace {
36 36
37 const char kDoodleConfigPath[] = "/async/ddljson"; 37 const char kDoodleConfigPath[] = "/async/ddljson?async=ntp:1,graybg:1";
38 const char kDoodleConfigPathNoGrayBg[] = "/async/ddljson?async=ntp:1,graybg:0";
38 39
39 // Required to instantiate a GoogleUrlTracker in UNIT_TEST_MODE. 40 // Required to instantiate a GoogleUrlTracker in UNIT_TEST_MODE.
40 class GoogleURLTrackerClientStub : public GoogleURLTrackerClient { 41 class GoogleURLTrackerClientStub : public GoogleURLTrackerClient {
41 public: 42 public:
42 GoogleURLTrackerClientStub() {} 43 GoogleURLTrackerClientStub() {}
43 ~GoogleURLTrackerClientStub() override {} 44 ~GoogleURLTrackerClientStub() override {}
44 45
45 bool IsBackgroundNetworkingEnabled() override { return true; } 46 bool IsBackgroundNetworkingEnabled() override { return true; }
46 47
47 PrefService* GetPrefs() override { return nullptr; } 48 PrefService* GetPrefs() override { return nullptr; }
(...skipping 12 matching lines...) Expand all
60 std::unique_ptr<base::Value> value = json_reader.ReadToValue(json); 61 std::unique_ptr<base::Value> value = json_reader.ReadToValue(json);
61 if (value) { 62 if (value) {
62 success.Run(std::move(value)); 63 success.Run(std::move(value));
63 } else { 64 } else {
64 error.Run(json_reader.GetErrorMessage()); 65 error.Run(json_reader.GetErrorMessage());
65 } 66 }
66 } 67 }
67 68
68 } // namespace 69 } // namespace
69 70
70 class DoodleFetcherImplTest : public testing::Test { 71 class DoodleFetcherImplTestBase : public testing::Test {
71 public: 72 public:
72 DoodleFetcherImplTest() 73 DoodleFetcherImplTestBase(bool gray_background)
73 : google_url_tracker_(base::MakeUnique<GoogleURLTrackerClientStub>(), 74 : google_url_tracker_(base::MakeUnique<GoogleURLTrackerClientStub>(),
74 GoogleURLTracker::UNIT_TEST_MODE), 75 GoogleURLTracker::UNIT_TEST_MODE),
75 doodle_fetcher_( 76 doodle_fetcher_(
76 new net::TestURLRequestContextGetter(message_loop_.task_runner()), 77 new net::TestURLRequestContextGetter(message_loop_.task_runner()),
77 &google_url_tracker_, 78 &google_url_tracker_,
78 base::Bind(ParseJson)) {} 79 base::Bind(ParseJson),
80 gray_background) {}
79 81
80 void RespondWithData(const std::string& data) { 82 void RespondWithData(const std::string& data) {
81 net::TestURLFetcher* url_fetcher = GetRunningFetcher(); 83 net::TestURLFetcher* url_fetcher = GetRunningFetcher();
82 url_fetcher->set_status(net::URLRequestStatus()); 84 url_fetcher->set_status(net::URLRequestStatus());
83 url_fetcher->set_response_code(net::HTTP_OK); 85 url_fetcher->set_response_code(net::HTTP_OK);
84 url_fetcher->SetResponseString(data); 86 url_fetcher->SetResponseString(data);
85 // Call the URLFetcher delegate to continue the test. 87 // Call the URLFetcher delegate to continue the test.
86 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher); 88 url_fetcher->delegate()->OnURLFetchComplete(url_fetcher);
87 } 89 }
88 90
(...skipping 20 matching lines...) Expand all
109 return GetGoogleBaseURL().Resolve(relative_url); 111 return GetGoogleBaseURL().Resolve(relative_url);
110 } 112 }
111 113
112 private: 114 private:
113 base::MessageLoop message_loop_; 115 base::MessageLoop message_loop_;
114 net::TestURLFetcherFactory url_fetcher_factory_; 116 net::TestURLFetcherFactory url_fetcher_factory_;
115 GoogleURLTracker google_url_tracker_; 117 GoogleURLTracker google_url_tracker_;
116 DoodleFetcherImpl doodle_fetcher_; 118 DoodleFetcherImpl doodle_fetcher_;
117 }; 119 };
118 120
121 class DoodleFetcherImplTest : public DoodleFetcherImplTestBase {
122 public:
123 DoodleFetcherImplTest()
124 : DoodleFetcherImplTestBase(/*gray_background=*/true) {}
125 };
126
119 TEST_F(DoodleFetcherImplTest, ReturnsFromFetchWithoutError) { 127 TEST_F(DoodleFetcherImplTest, ReturnsFromFetchWithoutError) {
120 base::MockCallback<DoodleFetcherImpl::FinishedCallback> callback; 128 base::MockCallback<DoodleFetcherImpl::FinishedCallback> callback;
121 doodle_fetcher()->FetchDoodle(callback.Get()); 129 doodle_fetcher()->FetchDoodle(callback.Get());
122 130
123 DoodleState state = DoodleState::NO_DOODLE; 131 DoodleState state = DoodleState::NO_DOODLE;
124 base::Optional<DoodleConfig> response; 132 base::Optional<DoodleConfig> response;
125 EXPECT_CALL(callback, Run(_, _, _)) 133 EXPECT_CALL(callback, Run(_, _, _))
126 .WillOnce(DoAll(SaveArg<0>(&state), SaveArg<2>(&response))); 134 .WillOnce(DoAll(SaveArg<0>(&state), SaveArg<2>(&response)));
127 RespondWithData(R"json({"ddljson": { 135 RespondWithData(R"json({"ddljson": {
128 "time_to_live_ms":55000, 136 "time_to_live_ms":55000,
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 } 424 }
417 425
418 TEST_F(DoodleFetcherImplTest, ReceivesBaseUrlFromTracker) { 426 TEST_F(DoodleFetcherImplTest, ReceivesBaseUrlFromTracker) {
419 base::MockCallback<DoodleFetcherImpl::FinishedCallback> callback; 427 base::MockCallback<DoodleFetcherImpl::FinishedCallback> callback;
420 doodle_fetcher()->FetchDoodle(callback.Get()); 428 doodle_fetcher()->FetchDoodle(callback.Get());
421 429
422 // TODO(treib,fhorschig): This doesn't really test anything useful, since the 430 // TODO(treib,fhorschig): This doesn't really test anything useful, since the
423 // Google base URL is the default anyway. Find a way to set the base URL in 431 // Google base URL is the default anyway. Find a way to set the base URL in
424 // the tracker. 432 // the tracker.
425 EXPECT_THAT(GetRunningFetcher()->GetOriginalURL(), 433 EXPECT_THAT(GetRunningFetcher()->GetOriginalURL(),
426 Eq(GetGoogleBaseURL().Resolve(kDoodleConfigPath))); 434 Eq(Resolve(kDoodleConfigPath)));
427 } 435 }
428 436
429 TEST_F(DoodleFetcherImplTest, OverridesBaseUrlWithCommandLineArgument) { 437 TEST_F(DoodleFetcherImplTest, OverridesBaseUrlWithCommandLineArgument) {
430 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 438 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
431 switches::kGoogleBaseURL, "http://www.google.kz"); 439 switches::kGoogleBaseURL, "http://www.google.kz");
432 440
433 base::MockCallback<DoodleFetcherImpl::FinishedCallback> callback; 441 base::MockCallback<DoodleFetcherImpl::FinishedCallback> callback;
434 doodle_fetcher()->FetchDoodle(callback.Get()); 442 doodle_fetcher()->FetchDoodle(callback.Get());
435 443
436 EXPECT_THAT(GetRunningFetcher()->GetOriginalURL(), 444 EXPECT_THAT(GetRunningFetcher()->GetOriginalURL(),
437 Eq(GURL("http://www.google.kz").Resolve(kDoodleConfigPath))); 445 Eq(GURL("http://www.google.kz").Resolve(kDoodleConfigPath)));
438 } 446 }
439 447
448 class DoodleFetcherImplNoGrayBgTest : public DoodleFetcherImplTestBase {
449 public:
450 DoodleFetcherImplNoGrayBgTest()
451 : DoodleFetcherImplTestBase(/*gray_background=*/false) {}
452 };
453
454 TEST_F(DoodleFetcherImplNoGrayBgTest, PassesNoGrayBgParam) {
455 base::MockCallback<DoodleFetcherImpl::FinishedCallback> callback;
456 doodle_fetcher()->FetchDoodle(callback.Get());
457
458 EXPECT_THAT(GetRunningFetcher()->GetOriginalURL(),
459 Eq(Resolve(kDoodleConfigPathNoGrayBg)));
460 }
461
440 } // namespace doodle 462 } // namespace doodle
OLDNEW
« no previous file with comments | « components/doodle/doodle_fetcher_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698