| OLD | NEW |
| 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" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 class FakeGetDataRequest : public GetDataRequest { | 23 class FakeGetDataRequest : public GetDataRequest { |
| 24 public: | 24 public: |
| 25 explicit FakeGetDataRequest(RequestSender* runner, | 25 explicit FakeGetDataRequest(RequestSender* runner, |
| 26 const GetDataCallback& callback) | 26 const GetDataCallback& callback) |
| 27 : GetDataRequest(runner, NULL, callback) { | 27 : GetDataRequest(runner, NULL, callback) { |
| 28 } | 28 } |
| 29 | 29 |
| 30 virtual ~FakeGetDataRequest() { | 30 virtual ~FakeGetDataRequest() { |
| 31 } | 31 } |
| 32 | 32 |
| 33 using RequestRegistry::Request::NotifyStart; | |
| 34 | |
| 35 protected: | 33 protected: |
| 36 virtual GURL GetURL() const OVERRIDE { | 34 virtual GURL GetURL() const OVERRIDE { |
| 37 NOTREACHED(); // This method is not called in tests. | 35 NOTREACHED(); // This method is not called in tests. |
| 38 return GURL(); | 36 return GURL(); |
| 39 } | 37 } |
| 40 }; | 38 }; |
| 41 | 39 |
| 42 } // namespace | 40 } // namespace |
| 43 | 41 |
| 44 class BaseRequestsTest : public testing::Test { | 42 class BaseRequestsTest : public testing::Test { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 ASSERT_TRUE(parse_json_callback_called_); | 110 ASSERT_TRUE(parse_json_callback_called_); |
| 113 ASSERT_FALSE(parse_json_result_.get()); | 111 ASSERT_FALSE(parse_json_result_.get()); |
| 114 } | 112 } |
| 115 | 113 |
| 116 TEST_F(BaseRequestsTest, GetDataRequestParseValidResponse) { | 114 TEST_F(BaseRequestsTest, GetDataRequestParseValidResponse) { |
| 117 FakeGetDataRequest* get_data_request = | 115 FakeGetDataRequest* get_data_request = |
| 118 new FakeGetDataRequest( | 116 new FakeGetDataRequest( |
| 119 runner_.get(), | 117 runner_.get(), |
| 120 base::Bind(&BaseRequestsTest::GetDataCallback, | 118 base::Bind(&BaseRequestsTest::GetDataCallback, |
| 121 base::Unretained(this))); | 119 base::Unretained(this))); |
| 122 get_data_request->NotifyStart(); | |
| 123 | 120 |
| 124 get_data_request->ParseResponse(HTTP_SUCCESS, kValidJsonString); | 121 get_data_request->ParseResponse(HTTP_SUCCESS, kValidJsonString); |
| 125 // Should wait for a blocking pool task, as the JSON parsing is done in the | 122 // Should wait for a blocking pool task, as the JSON parsing is done in the |
| 126 // blocking pool. | 123 // blocking pool. |
| 127 test_util::RunBlockingPoolTask(); | 124 test_util::RunBlockingPoolTask(); |
| 128 | 125 |
| 129 ASSERT_TRUE(get_data_callback_called_); | 126 ASSERT_TRUE(get_data_callback_called_); |
| 130 ASSERT_EQ(HTTP_SUCCESS, get_data_result_error_); | 127 ASSERT_EQ(HTTP_SUCCESS, get_data_result_error_); |
| 131 ASSERT_TRUE(get_data_result_value_.get()); | 128 ASSERT_TRUE(get_data_result_value_.get()); |
| 132 } | 129 } |
| 133 | 130 |
| 134 TEST_F(BaseRequestsTest, GetDataRequestParseInvalidResponse) { | 131 TEST_F(BaseRequestsTest, GetDataRequestParseInvalidResponse) { |
| 135 FakeGetDataRequest* get_data_request = | 132 FakeGetDataRequest* get_data_request = |
| 136 new FakeGetDataRequest( | 133 new FakeGetDataRequest( |
| 137 runner_.get(), | 134 runner_.get(), |
| 138 base::Bind(&BaseRequestsTest::GetDataCallback, | 135 base::Bind(&BaseRequestsTest::GetDataCallback, |
| 139 base::Unretained(this))); | 136 base::Unretained(this))); |
| 140 get_data_request->NotifyStart(); | |
| 141 | 137 |
| 142 get_data_request->ParseResponse(HTTP_SUCCESS, kInvalidJsonString); | 138 get_data_request->ParseResponse(HTTP_SUCCESS, kInvalidJsonString); |
| 143 // Should wait for a blocking pool task, as the JSON parsing is done in the | 139 // Should wait for a blocking pool task, as the JSON parsing is done in the |
| 144 // blocking pool. | 140 // blocking pool. |
| 145 test_util::RunBlockingPoolTask(); | 141 test_util::RunBlockingPoolTask(); |
| 146 | 142 |
| 147 ASSERT_TRUE(get_data_callback_called_); | 143 ASSERT_TRUE(get_data_callback_called_); |
| 148 ASSERT_EQ(GDATA_PARSE_ERROR, get_data_result_error_); | 144 ASSERT_EQ(GDATA_PARSE_ERROR, get_data_result_error_); |
| 149 ASSERT_FALSE(get_data_result_value_.get()); | 145 ASSERT_FALSE(get_data_result_value_.get()); |
| 150 } | 146 } |
| 151 | 147 |
| 152 } // namespace google_apis | 148 } // namespace google_apis |
| OLD | NEW |