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/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/google_apis/dummy_auth_service.h" |
12 #include "chrome/browser/google_apis/request_sender.h" | 13 #include "chrome/browser/google_apis/request_sender.h" |
13 #include "chrome/browser/google_apis/test_util.h" | 14 #include "chrome/browser/google_apis/test_util.h" |
14 #include "chrome/test/base/testing_profile.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 FakeGetDataRequest : public GetDataRequest { | 24 class FakeGetDataRequest : public GetDataRequest { |
(...skipping 11 matching lines...) Expand all Loading... |
36 NOTREACHED(); // This method is not called in tests. | 36 NOTREACHED(); // This method is not called in tests. |
37 return GURL(); | 37 return GURL(); |
38 } | 38 } |
39 }; | 39 }; |
40 | 40 |
41 } // namespace | 41 } // namespace |
42 | 42 |
43 class BaseRequestsTest : public testing::Test { | 43 class BaseRequestsTest : public testing::Test { |
44 public: | 44 public: |
45 virtual void SetUp() OVERRIDE { | 45 virtual void SetUp() OVERRIDE { |
46 profile_.reset(new TestingProfile); | 46 sender_.reset(new RequestSender(new DummyAuthService, |
47 sender_.reset(new RequestSender(profile_.get(), | |
48 NULL /* url_request_context_getter */, | 47 NULL /* url_request_context_getter */, |
49 message_loop_.message_loop_proxy(), | 48 message_loop_.message_loop_proxy(), |
50 std::vector<std::string>() /* scopes */, | |
51 std::string() /* custom user agent */)); | 49 std::string() /* custom user agent */)); |
52 sender_->Initialize(); | |
53 } | 50 } |
54 | 51 |
55 base::MessageLoop message_loop_; | 52 base::MessageLoop message_loop_; |
56 scoped_ptr<TestingProfile> profile_; | |
57 scoped_ptr<RequestSender> sender_; | 53 scoped_ptr<RequestSender> sender_; |
58 }; | 54 }; |
59 | 55 |
60 TEST_F(BaseRequestsTest, ParseValidJson) { | 56 TEST_F(BaseRequestsTest, ParseValidJson) { |
61 scoped_ptr<base::Value> json; | 57 scoped_ptr<base::Value> json; |
62 ParseJson(message_loop_.message_loop_proxy(), | 58 ParseJson(message_loop_.message_loop_proxy(), |
63 kValidJsonString, | 59 kValidJsonString, |
64 base::Bind(test_util::CreateCopyResultCallback(&json))); | 60 base::Bind(test_util::CreateCopyResultCallback(&json))); |
65 base::RunLoop().RunUntilIdle(); | 61 base::RunLoop().RunUntilIdle(); |
66 | 62 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 base::Bind(test_util::CreateCopyResultCallback(&error, &value))); | 104 base::Bind(test_util::CreateCopyResultCallback(&error, &value))); |
109 | 105 |
110 get_data_request->ParseResponse(HTTP_SUCCESS, kInvalidJsonString); | 106 get_data_request->ParseResponse(HTTP_SUCCESS, kInvalidJsonString); |
111 base::RunLoop().RunUntilIdle(); | 107 base::RunLoop().RunUntilIdle(); |
112 | 108 |
113 EXPECT_EQ(GDATA_PARSE_ERROR, error); | 109 EXPECT_EQ(GDATA_PARSE_ERROR, error); |
114 EXPECT_FALSE(value); | 110 EXPECT_FALSE(value); |
115 } | 111 } |
116 | 112 |
117 } // namespace google_apis | 113 } // namespace google_apis |
OLD | NEW |