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 | 5 |
6 #include <fcntl.h> | 6 #include <fcntl.h> |
7 #include <gmock/gmock.h> | 7 #include <gmock/gmock.h> |
8 #include <ppapi/c/ppb_file_io.h> | 8 #include <ppapi/c/ppb_file_io.h> |
9 #include <ppapi/c/pp_errors.h> | 9 #include <ppapi/c/pp_errors.h> |
10 #include <ppapi/c/pp_instance.h> | 10 #include <ppapi/c/pp_instance.h> |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 class MountHttpNodeTest : public MountHttpTest { | 169 class MountHttpNodeTest : public MountHttpTest { |
170 public: | 170 public: |
171 MountHttpNodeTest(); | 171 MountHttpNodeTest(); |
172 virtual void TearDown(); | 172 virtual void TearDown(); |
173 | 173 |
174 void SetMountArgs(const StringMap_t& args); | 174 void SetMountArgs(const StringMap_t& args); |
175 void ExpectOpen(const char* method); | 175 void ExpectOpen(const char* method); |
176 void ExpectHeaders(const char* headers); | 176 void ExpectHeaders(const char* headers); |
177 void OpenNode(); | 177 void OpenNode(); |
178 void SetResponse(int status_code, const char* headers); | 178 void SetResponse(int status_code, const char* headers); |
| 179 // Set a response code, but expect the request to fail. Certain function calls |
| 180 // expected by SetResponse are not expected here. |
| 181 void SetResponseExpectFail(int status_code, const char* headers); |
179 void SetResponseBody(const char* body); | 182 void SetResponseBody(const char* body); |
180 void ResetMocks(); | 183 void ResetMocks(); |
181 | 184 |
182 protected: | 185 protected: |
183 MountHttpMock* mnt_; | 186 MountHttpMock* mnt_; |
184 MountNode* node_; | 187 MountNode* node_; |
185 | 188 |
186 VarInterfaceMock* var_; | 189 VarInterfaceMock* var_; |
187 URLLoaderInterfaceMock* loader_; | 190 URLLoaderInterfaceMock* loader_; |
188 URLRequestInfoInterfaceMock* request_; | 191 URLRequestInfoInterfaceMock* request_; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 PP_URLRESPONSEPROPERTY_STATUSCODE)) | 279 PP_URLRESPONSEPROPERTY_STATUSCODE)) |
277 .WillOnce(Return(PP_MakeInt32(status_code))); | 280 .WillOnce(Return(PP_MakeInt32(status_code))); |
278 EXPECT_CALL(*response_, | 281 EXPECT_CALL(*response_, |
279 GetProperty(response_resource_, PP_URLRESPONSEPROPERTY_HEADERS)) | 282 GetProperty(response_resource_, PP_URLRESPONSEPROPERTY_HEADERS)) |
280 .WillOnce(Return(var_headers)); | 283 .WillOnce(Return(var_headers)); |
281 EXPECT_CALL(*var_, VarToUtf8(IsEqualToVar(var_headers), _)) | 284 EXPECT_CALL(*var_, VarToUtf8(IsEqualToVar(var_headers), _)) |
282 .WillOnce(DoAll(SetArgPointee<1>(strlen(headers)), | 285 .WillOnce(DoAll(SetArgPointee<1>(strlen(headers)), |
283 Return(headers))); | 286 Return(headers))); |
284 } | 287 } |
285 | 288 |
| 289 void MountHttpNodeTest::SetResponseExpectFail(int status_code, |
| 290 const char* headers) { |
| 291 ON_CALL(*response_, GetProperty(response_resource_, _)) |
| 292 .WillByDefault(Return(PP_MakeUndefined())); |
| 293 |
| 294 PP_Var var_headers = MakeString(348); |
| 295 EXPECT_CALL(*response_, |
| 296 GetProperty(response_resource_, |
| 297 PP_URLRESPONSEPROPERTY_STATUSCODE)) |
| 298 .WillOnce(Return(PP_MakeInt32(status_code))); |
| 299 } |
| 300 |
286 ACTION_P3(ReadResponseBodyAction, offset, body, body_length) { | 301 ACTION_P3(ReadResponseBodyAction, offset, body, body_length) { |
287 char* buf = static_cast<char*>(arg1); | 302 char* buf = static_cast<char*>(arg1); |
288 size_t read_length = arg2; | 303 size_t read_length = arg2; |
289 PP_CompletionCallback callback = arg3; | 304 PP_CompletionCallback callback = arg3; |
290 if (*offset >= body_length) | 305 if (*offset >= body_length) |
291 return 0; | 306 return 0; |
292 | 307 |
293 read_length = std::min(read_length, body_length - *offset); | 308 read_length = std::min(read_length, body_length - *offset); |
294 memcpy(buf, body + *offset, read_length); | 309 memcpy(buf, body + *offset, read_length); |
295 *offset += read_length; | 310 *offset += read_length; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 TEST_F(MountHttpNodeTest, OpenAndCloseNoCache) { | 345 TEST_F(MountHttpNodeTest, OpenAndCloseNoCache) { |
331 StringMap_t smap; | 346 StringMap_t smap; |
332 smap["cache_content"] = "false"; | 347 smap["cache_content"] = "false"; |
333 SetMountArgs(StringMap_t()); | 348 SetMountArgs(StringMap_t()); |
334 ExpectOpen("HEAD"); | 349 ExpectOpen("HEAD"); |
335 ExpectHeaders(""); | 350 ExpectHeaders(""); |
336 SetResponse(200, ""); | 351 SetResponse(200, ""); |
337 OpenNode(); | 352 OpenNode(); |
338 } | 353 } |
339 | 354 |
| 355 TEST_F(MountHttpNodeTest, OpenAndCloseNotFound) { |
| 356 StringMap_t smap; |
| 357 smap["cache_content"] = "false"; |
| 358 SetMountArgs(StringMap_t()); |
| 359 ExpectOpen("HEAD"); |
| 360 ExpectHeaders(""); |
| 361 SetResponseExpectFail(404, ""); |
| 362 ASSERT_EQ(ENOENT, mnt_->Open(Path(path_), O_RDONLY, &node_)); |
| 363 } |
| 364 |
| 365 TEST_F(MountHttpNodeTest, OpenAndCloseServerError) { |
| 366 StringMap_t smap; |
| 367 smap["cache_content"] = "false"; |
| 368 SetMountArgs(StringMap_t()); |
| 369 ExpectOpen("HEAD"); |
| 370 ExpectHeaders(""); |
| 371 SetResponseExpectFail(500, ""); |
| 372 ASSERT_EQ(EIO, mnt_->Open(Path(path_), O_RDONLY, &node_)); |
| 373 } |
| 374 |
| 375 TEST_F(MountHttpNodeTest, GetStat) { |
| 376 StringMap_t smap; |
| 377 smap["cache_content"] = "false"; |
| 378 SetMountArgs(StringMap_t()); |
| 379 ExpectOpen("HEAD"); |
| 380 ExpectHeaders(""); |
| 381 SetResponse(200, "Content-Length: 42\n"); |
| 382 OpenNode(); |
| 383 |
| 384 struct stat stat; |
| 385 EXPECT_EQ(0, node_->GetStat(&stat)); |
| 386 EXPECT_EQ(42, stat.st_size); |
| 387 } |
| 388 |
340 TEST_F(MountHttpNodeTest, ReadCached) { | 389 TEST_F(MountHttpNodeTest, ReadCached) { |
341 size_t result_size = 0; | 390 size_t result_size = 0; |
342 int result_bytes = 0; | 391 int result_bytes = 0; |
343 | 392 |
344 SetMountArgs(StringMap_t()); | 393 SetMountArgs(StringMap_t()); |
345 ExpectOpen("HEAD"); | 394 ExpectOpen("HEAD"); |
346 ExpectHeaders(""); | 395 ExpectHeaders(""); |
347 SetResponse(200, "Content-Length: 42\n"); | 396 SetResponse(200, "Content-Length: 42\n"); |
348 OpenNode(); | 397 OpenNode(); |
349 ResetMocks(); | 398 ResetMocks(); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 memset(&buf[0], 0, sizeof(buf)); | 569 memset(&buf[0], 0, sizeof(buf)); |
521 | 570 |
522 ExpectOpen("GET"); | 571 ExpectOpen("GET"); |
523 ExpectHeaders("Range: bytes=10-18\n"); | 572 ExpectHeaders("Range: bytes=10-18\n"); |
524 SetResponse(200, "Content-Length: 20\n"); | 573 SetResponse(200, "Content-Length: 20\n"); |
525 SetResponseBody("0123456789abcdefghij"); | 574 SetResponseBody("0123456789abcdefghij"); |
526 EXPECT_EQ(0, node_->Read(10, buf, sizeof(buf) - 1, &result_bytes)); | 575 EXPECT_EQ(0, node_->Read(10, buf, sizeof(buf) - 1, &result_bytes)); |
527 EXPECT_EQ(sizeof(buf) - 1, result_bytes); | 576 EXPECT_EQ(sizeof(buf) - 1, result_bytes); |
528 EXPECT_STREQ("abcdefghi", &buf[0]); | 577 EXPECT_STREQ("abcdefghi", &buf[0]); |
529 } | 578 } |
OLD | NEW |