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 "google_apis/drive/base_requests.h" | 5 #include "google_apis/drive/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" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 base::MessageLoopForIO message_loop_; | 102 base::MessageLoopForIO message_loop_; |
103 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; | 103 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; |
104 scoped_ptr<RequestSender> sender_; | 104 scoped_ptr<RequestSender> sender_; |
105 net::test_server::EmbeddedTestServer test_server_; | 105 net::test_server::EmbeddedTestServer test_server_; |
106 | 106 |
107 net::HttpStatusCode response_code_; | 107 net::HttpStatusCode response_code_; |
108 std::string response_body_; | 108 std::string response_body_; |
109 }; | 109 }; |
110 | 110 |
111 TEST_F(BaseRequestsTest, ParseValidJson) { | 111 TEST_F(BaseRequestsTest, ParseValidJson) { |
112 scoped_ptr<base::Value> json; | 112 scoped_ptr<base::Value> json(ParseJson(kValidJsonString)); |
113 ParseJson(message_loop_.message_loop_proxy(), | |
114 kValidJsonString, | |
115 base::Bind(test_util::CreateCopyResultCallback(&json))); | |
116 base::RunLoop().RunUntilIdle(); | |
117 | 113 |
118 base::DictionaryValue* root_dict = NULL; | 114 base::DictionaryValue* root_dict = NULL; |
119 ASSERT_TRUE(json); | 115 ASSERT_TRUE(json); |
120 ASSERT_TRUE(json->GetAsDictionary(&root_dict)); | 116 ASSERT_TRUE(json->GetAsDictionary(&root_dict)); |
121 | 117 |
122 int int_value = 0; | 118 int int_value = 0; |
123 ASSERT_TRUE(root_dict->GetInteger("test", &int_value)); | 119 ASSERT_TRUE(root_dict->GetInteger("test", &int_value)); |
124 EXPECT_EQ(123, int_value); | 120 EXPECT_EQ(123, int_value); |
125 } | 121 } |
126 | 122 |
127 TEST_F(BaseRequestsTest, ParseInvalidJson) { | 123 TEST_F(BaseRequestsTest, ParseInvalidJson) { |
128 // Initialize with a valid pointer to verify that null is indeed assigned. | 124 EXPECT_FALSE(ParseJson(kInvalidJsonString)); |
129 scoped_ptr<base::Value> json(base::Value::CreateNullValue()); | |
130 ParseJson(message_loop_.message_loop_proxy(), | |
131 kInvalidJsonString, | |
132 base::Bind(test_util::CreateCopyResultCallback(&json))); | |
133 base::RunLoop().RunUntilIdle(); | |
134 | |
135 EXPECT_FALSE(json); | |
136 } | 125 } |
137 | 126 |
138 TEST_F(BaseRequestsTest, UrlFetchRequestBaseResponseCodeOverride) { | 127 TEST_F(BaseRequestsTest, UrlFetchRequestBaseResponseCodeOverride) { |
139 response_code_ = net::HTTP_FORBIDDEN; | 128 response_code_ = net::HTTP_FORBIDDEN; |
140 response_body_ = | 129 response_body_ = |
141 "{\"error\": {\n" | 130 "{\"error\": {\n" |
142 " \"errors\": [\n" | 131 " \"errors\": [\n" |
143 " {\n" | 132 " {\n" |
144 " \"domain\": \"usageLimits\",\n" | 133 " \"domain\": \"usageLimits\",\n" |
145 " \"reason\": \"rateLimitExceeded\",\n" | 134 " \"reason\": \"rateLimitExceeded\",\n" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 test_util::CreateQuitCallback( | 184 test_util::CreateQuitCallback( |
196 &run_loop, test_util::CreateCopyResultCallback(&error, &value)), | 185 &run_loop, test_util::CreateCopyResultCallback(&error, &value)), |
197 test_server_.base_url())); | 186 test_server_.base_url())); |
198 run_loop.Run(); | 187 run_loop.Run(); |
199 | 188 |
200 EXPECT_EQ(GDATA_PARSE_ERROR, error); | 189 EXPECT_EQ(GDATA_PARSE_ERROR, error); |
201 EXPECT_FALSE(value); | 190 EXPECT_FALSE(value); |
202 } | 191 } |
203 | 192 |
204 } // namespace google_apis | 193 } // namespace google_apis |
OLD | NEW |