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

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

Issue 16424004: google_apis: Rename base_operations.h/cc to base_requests.h/cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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_operations.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/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/google_apis/operation_runner.h" 11 #include "chrome/browser/google_apis/operation_runner.h"
12 #include "chrome/browser/google_apis/test_util.h" 12 #include "chrome/browser/google_apis/test_util.h"
13 #include "chrome/test/base/testing_profile.h" 13 #include "chrome/test/base/testing_profile.h"
14 #include "content/public/test/test_browser_thread.h" 14 #include "content/public/test/test_browser_thread.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace google_apis { 17 namespace google_apis {
18 18
19 namespace { 19 namespace {
20 20
21 const char kValidJsonString[] = "{ \"test\": 123 }"; 21 const char kValidJsonString[] = "{ \"test\": 123 }";
22 const char kInvalidJsonString[] = "$$$"; 22 const char kInvalidJsonString[] = "$$$";
23 23
24 class FakeGetDataOperation : public GetDataOperation { 24 class FakeGetDataRequest : public GetDataRequest {
25 public: 25 public:
26 explicit FakeGetDataOperation(OperationRunner* runner, 26 explicit FakeGetDataRequest(OperationRunner* runner,
27 const GetDataCallback& callback) 27 const GetDataCallback& callback)
28 : GetDataOperation(runner, NULL, callback) { 28 : GetDataRequest(runner, NULL, callback) {
29 } 29 }
30 30
31 virtual ~FakeGetDataOperation() { 31 virtual ~FakeGetDataRequest() {
32 } 32 }
33 33
34 void NotifyStart() { 34 void NotifyStart() {
35 NotifyStartToOperationRegistry(); 35 NotifyStartToOperationRegistry();
36 } 36 }
37 37
38 protected: 38 protected:
39 virtual GURL GetURL() const OVERRIDE { 39 virtual GURL GetURL() const OVERRIDE {
40 NOTREACHED(); // This method is not called in tests. 40 NOTREACHED(); // This method is not called in tests.
41 return GURL(); 41 return GURL();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 base::Bind(&BaseOperationsTest::ParseJsonCallback, 111 base::Bind(&BaseOperationsTest::ParseJsonCallback,
112 base::Unretained(this))); 112 base::Unretained(this)));
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 ASSERT_TRUE(parse_json_callback_called_); 117 ASSERT_TRUE(parse_json_callback_called_);
118 ASSERT_FALSE(parse_json_result_.get()); 118 ASSERT_FALSE(parse_json_result_.get());
119 } 119 }
120 120
121 TEST_F(BaseOperationsTest, GetDataOperationParseValidResponse) { 121 TEST_F(BaseOperationsTest, GetDataRequestParseValidResponse) {
122 FakeGetDataOperation* get_data_operation = 122 FakeGetDataRequest* get_data_operation =
123 new FakeGetDataOperation( 123 new FakeGetDataRequest(
124 runner_.get(), 124 runner_.get(),
125 base::Bind(&BaseOperationsTest::GetDataCallback, 125 base::Bind(&BaseOperationsTest::GetDataCallback,
126 base::Unretained(this))); 126 base::Unretained(this)));
127 get_data_operation->NotifyStart(); 127 get_data_operation->NotifyStart();
128 128
129 get_data_operation->ParseResponse(HTTP_SUCCESS, kValidJsonString); 129 get_data_operation->ParseResponse(HTTP_SUCCESS, kValidJsonString);
130 // Should wait for a blocking pool task, as the JSON parsing is done in the 130 // Should wait for a blocking pool task, as the JSON parsing is done in the
131 // blocking pool. 131 // blocking pool.
132 test_util::RunBlockingPoolTask(); 132 test_util::RunBlockingPoolTask();
133 133
134 ASSERT_TRUE(get_data_callback_called_); 134 ASSERT_TRUE(get_data_callback_called_);
135 ASSERT_EQ(HTTP_SUCCESS, get_data_result_error_); 135 ASSERT_EQ(HTTP_SUCCESS, get_data_result_error_);
136 ASSERT_TRUE(get_data_result_value_.get()); 136 ASSERT_TRUE(get_data_result_value_.get());
137 } 137 }
138 138
139 TEST_F(BaseOperationsTest, GetDataOperationParseInvalidResponse) { 139 TEST_F(BaseOperationsTest, GetDataRequestParseInvalidResponse) {
140 FakeGetDataOperation* get_data_operation = 140 FakeGetDataRequest* get_data_operation =
141 new FakeGetDataOperation( 141 new FakeGetDataRequest(
142 runner_.get(), 142 runner_.get(),
143 base::Bind(&BaseOperationsTest::GetDataCallback, 143 base::Bind(&BaseOperationsTest::GetDataCallback,
144 base::Unretained(this))); 144 base::Unretained(this)));
145 get_data_operation->NotifyStart(); 145 get_data_operation->NotifyStart();
146 146
147 get_data_operation->ParseResponse(HTTP_SUCCESS, kInvalidJsonString); 147 get_data_operation->ParseResponse(HTTP_SUCCESS, kInvalidJsonString);
148 // Should wait for a blocking pool task, as the JSON parsing is done in the 148 // Should wait for a blocking pool task, as the JSON parsing is done in the
149 // blocking pool. 149 // blocking pool.
150 test_util::RunBlockingPoolTask(); 150 test_util::RunBlockingPoolTask();
151 151
152 ASSERT_TRUE(get_data_callback_called_); 152 ASSERT_TRUE(get_data_callback_called_);
153 ASSERT_EQ(GDATA_PARSE_ERROR, get_data_result_error_); 153 ASSERT_EQ(GDATA_PARSE_ERROR, get_data_result_error_);
154 ASSERT_FALSE(get_data_result_value_.get()); 154 ASSERT_FALSE(get_data_result_value_.get());
155 } 155 }
156 156
157 } // namespace google_apis 157 } // 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_operations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698