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

Side by Side Diff: chrome/browser/google_apis/base_requests_unittest.cc

Issue 18316002: Move URLRequestContextGetter to RequestSender in c/b/google_apis. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/google_apis/base_requests.h" 5 #include "chrome/browser/google_apis/base_requests.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/google_apis/request_sender.h" 10 #include "chrome/browser/google_apis/request_sender.h"
11 #include "chrome/browser/google_apis/test_util.h" 11 #include "chrome/browser/google_apis/test_util.h"
12 #include "chrome/test/base/testing_profile.h" 12 #include "chrome/test/base/testing_profile.h"
13 #include "content/public/test/test_browser_thread_bundle.h" 13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace google_apis { 16 namespace google_apis {
17 17
18 namespace { 18 namespace {
19 19
20 const char kValidJsonString[] = "{ \"test\": 123 }"; 20 const char kValidJsonString[] = "{ \"test\": 123 }";
21 const char kInvalidJsonString[] = "$$$"; 21 const char kInvalidJsonString[] = "$$$";
22 22
23 class FakeGetDataRequest : public GetDataRequest { 23 class FakeGetDataRequest : public GetDataRequest {
24 public: 24 public:
25 explicit FakeGetDataRequest(RequestSender* runner, 25 explicit FakeGetDataRequest(RequestSender* sender,
26 const GetDataCallback& callback) 26 const GetDataCallback& callback)
27 : GetDataRequest(runner, NULL, callback) { 27 : GetDataRequest(sender, callback) {
28 } 28 }
29 29
30 virtual ~FakeGetDataRequest() { 30 virtual ~FakeGetDataRequest() {
31 } 31 }
32 32
33 protected: 33 protected:
34 virtual GURL GetURL() const OVERRIDE { 34 virtual GURL GetURL() const OVERRIDE {
35 NOTREACHED(); // This method is not called in tests. 35 NOTREACHED(); // This method is not called in tests.
36 return GURL(); 36 return GURL();
37 } 37 }
38 }; 38 };
39 39
40 } // namespace 40 } // namespace
41 41
42 class BaseRequestsTest : public testing::Test { 42 class BaseRequestsTest : public testing::Test {
43 public: 43 public:
44 virtual void SetUp() OVERRIDE { 44 virtual void SetUp() OVERRIDE {
45 profile_.reset(new TestingProfile); 45 profile_.reset(new TestingProfile);
46 runner_.reset(new RequestSender(profile_.get(), 46 sender_.reset(new RequestSender(profile_.get(),
47 NULL /* url_request_context_getter */, 47 NULL /* url_request_context_getter */,
48 std::vector<std::string>() /* scopes */, 48 std::vector<std::string>() /* scopes */,
49 std::string() /* custom user agent */)); 49 std::string() /* custom user agent */));
50 runner_->Initialize(); 50 sender_->Initialize();
51 } 51 }
52 52
53 content::TestBrowserThreadBundle thread_bundle_; 53 content::TestBrowserThreadBundle thread_bundle_;
54 scoped_ptr<TestingProfile> profile_; 54 scoped_ptr<TestingProfile> profile_;
55 scoped_ptr<RequestSender> runner_; 55 scoped_ptr<RequestSender> sender_;
56 }; 56 };
57 57
58 TEST_F(BaseRequestsTest, ParseValidJson) { 58 TEST_F(BaseRequestsTest, ParseValidJson) {
59 scoped_ptr<base::Value> json; 59 scoped_ptr<base::Value> json;
60 ParseJson(kValidJsonString, 60 ParseJson(kValidJsonString,
61 base::Bind(test_util::CreateCopyResultCallback(&json))); 61 base::Bind(test_util::CreateCopyResultCallback(&json)));
62 // Should wait for a blocking pool task, as the JSON parsing is done in the 62 // Should wait for a blocking pool task, as the JSON parsing is done in the
63 // blocking pool. 63 // blocking pool.
64 test_util::RunBlockingPoolTask(); 64 test_util::RunBlockingPoolTask();
65 65
(...skipping 16 matching lines...) Expand all
82 test_util::RunBlockingPoolTask(); 82 test_util::RunBlockingPoolTask();
83 83
84 EXPECT_FALSE(json); 84 EXPECT_FALSE(json);
85 } 85 }
86 86
87 TEST_F(BaseRequestsTest, GetDataRequestParseValidResponse) { 87 TEST_F(BaseRequestsTest, GetDataRequestParseValidResponse) {
88 GDataErrorCode error = GDATA_OTHER_ERROR; 88 GDataErrorCode error = GDATA_OTHER_ERROR;
89 scoped_ptr<base::Value> value; 89 scoped_ptr<base::Value> value;
90 FakeGetDataRequest* get_data_request = 90 FakeGetDataRequest* get_data_request =
91 new FakeGetDataRequest( 91 new FakeGetDataRequest(
92 runner_.get(), 92 sender_.get(),
93 base::Bind(test_util::CreateCopyResultCallback(&error, &value))); 93 base::Bind(test_util::CreateCopyResultCallback(&error, &value)));
94 94
95 get_data_request->ParseResponse(HTTP_SUCCESS, kValidJsonString); 95 get_data_request->ParseResponse(HTTP_SUCCESS, kValidJsonString);
96 // Should wait for a blocking pool task, as the JSON parsing is done in the 96 // Should wait for a blocking pool task, as the JSON parsing is done in the
97 // blocking pool. 97 // blocking pool.
98 test_util::RunBlockingPoolTask(); 98 test_util::RunBlockingPoolTask();
99 99
100 EXPECT_EQ(HTTP_SUCCESS, error); 100 EXPECT_EQ(HTTP_SUCCESS, error);
101 EXPECT_TRUE(value); 101 EXPECT_TRUE(value);
102 } 102 }
103 103
104 TEST_F(BaseRequestsTest, GetDataRequestParseInvalidResponse) { 104 TEST_F(BaseRequestsTest, GetDataRequestParseInvalidResponse) {
105 GDataErrorCode error = GDATA_OTHER_ERROR; 105 GDataErrorCode error = GDATA_OTHER_ERROR;
106 scoped_ptr<base::Value> value; 106 scoped_ptr<base::Value> value;
107 FakeGetDataRequest* get_data_request = 107 FakeGetDataRequest* get_data_request =
108 new FakeGetDataRequest( 108 new FakeGetDataRequest(
109 runner_.get(), 109 sender_.get(),
110 base::Bind(test_util::CreateCopyResultCallback(&error, &value))); 110 base::Bind(test_util::CreateCopyResultCallback(&error, &value)));
111 111
112 get_data_request->ParseResponse(HTTP_SUCCESS, kInvalidJsonString); 112 get_data_request->ParseResponse(HTTP_SUCCESS, kInvalidJsonString);
113 // Should wait for a blocking pool task, as the JSON parsing is done in the 113 // Should wait for a blocking pool task, as the JSON parsing is done in the
114 // blocking pool. 114 // blocking pool.
115 test_util::RunBlockingPoolTask(); 115 test_util::RunBlockingPoolTask();
116 116
117 EXPECT_EQ(GDATA_PARSE_ERROR, error); 117 EXPECT_EQ(GDATA_PARSE_ERROR, error);
118 EXPECT_FALSE(value); 118 EXPECT_FALSE(value);
119 } 119 }
120 120
121 } // namespace google_apis 121 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/base_requests_server_unittest.cc ('k') | chrome/browser/google_apis/drive_api_requests.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698