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); | |
Matt Giuca
2013/06/19 10:41:42
Note: I borrowed this code from my other CL https:
binji
2013/06/19 16:46:28
In the future, you can use "git cl upload <branch
Matt Giuca
2013/06/20 01:43:14
Yeah I wasn't sure whether to do that in this case
| |
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, Access) { | |
Matt Giuca
2013/06/19 10:41:42
Note: Access and AccessWrite suffer from the same
| |
356 StringMap_t smap; | |
357 smap["cache_content"] = "false"; | |
358 SetMountArgs(StringMap_t()); | |
359 ExpectOpen("HEAD"); | |
360 ExpectHeaders(""); | |
361 SetResponse(200, ""); | |
362 ASSERT_EQ(0, mnt_->Access(Path(path_), R_OK)); | |
363 } | |
364 | |
365 TEST_F(MountHttpNodeTest, AccessWrite) { | |
366 StringMap_t smap; | |
367 smap["cache_content"] = "false"; | |
368 SetMountArgs(StringMap_t()); | |
369 ExpectOpen("HEAD"); | |
370 ExpectHeaders(""); | |
371 SetResponse(200, ""); | |
372 ASSERT_EQ(EACCES, mnt_->Access(Path(path_), W_OK)); | |
373 } | |
374 | |
375 TEST_F(MountHttpNodeTest, AccessNotFound) { | |
376 StringMap_t smap; | |
377 smap["cache_content"] = "false"; | |
378 SetMountArgs(StringMap_t()); | |
379 ExpectOpen("HEAD"); | |
380 ExpectHeaders(""); | |
381 SetResponseExpectFail(404, ""); | |
382 // TODO(mgiuca): Expect ENOENT instead. http://crbug.com/251662. | |
383 ASSERT_EQ(EINVAL, mnt_->Access(Path(path_), R_OK)); | |
384 } | |
385 | |
340 TEST_F(MountHttpNodeTest, ReadCached) { | 386 TEST_F(MountHttpNodeTest, ReadCached) { |
341 size_t result_size = 0; | 387 size_t result_size = 0; |
342 int result_bytes = 0; | 388 int result_bytes = 0; |
343 | 389 |
344 SetMountArgs(StringMap_t()); | 390 SetMountArgs(StringMap_t()); |
345 ExpectOpen("HEAD"); | 391 ExpectOpen("HEAD"); |
346 ExpectHeaders(""); | 392 ExpectHeaders(""); |
347 SetResponse(200, "Content-Length: 42\n"); | 393 SetResponse(200, "Content-Length: 42\n"); |
348 OpenNode(); | 394 OpenNode(); |
349 ResetMocks(); | 395 ResetMocks(); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
520 memset(&buf[0], 0, sizeof(buf)); | 566 memset(&buf[0], 0, sizeof(buf)); |
521 | 567 |
522 ExpectOpen("GET"); | 568 ExpectOpen("GET"); |
523 ExpectHeaders("Range: bytes=10-18\n"); | 569 ExpectHeaders("Range: bytes=10-18\n"); |
524 SetResponse(200, "Content-Length: 20\n"); | 570 SetResponse(200, "Content-Length: 20\n"); |
525 SetResponseBody("0123456789abcdefghij"); | 571 SetResponseBody("0123456789abcdefghij"); |
526 EXPECT_EQ(0, node_->Read(10, buf, sizeof(buf) - 1, &result_bytes)); | 572 EXPECT_EQ(0, node_->Read(10, buf, sizeof(buf) - 1, &result_bytes)); |
527 EXPECT_EQ(sizeof(buf) - 1, result_bytes); | 573 EXPECT_EQ(sizeof(buf) - 1, result_bytes); |
528 EXPECT_STREQ("abcdefghi", &buf[0]); | 574 EXPECT_STREQ("abcdefghi", &buf[0]); |
529 } | 575 } |
OLD | NEW |