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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/process.h" | 10 #include "base/process.h" |
11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
12 #include "content/common/request_extra_data.h" | 12 #include "content/common/request_extra_data.h" |
13 #include "content/common/resource_dispatcher.h" | 13 #include "content/common/resource_dispatcher.h" |
14 #include "content/common/resource_messages.h" | 14 #include "content/common/resource_messages.h" |
15 #include "content/public/common/resource_response.h" | 15 #include "content/public/common/resource_response.h" |
| 16 #include "net/base/net_errors.h" |
16 #include "net/base/upload_data.h" | 17 #include "net/base/upload_data.h" |
17 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "webkit/appcache/appcache_interfaces.h" | 20 #include "webkit/appcache/appcache_interfaces.h" |
20 | 21 |
21 using webkit_glue::ResourceLoaderBridge; | 22 using webkit_glue::ResourceLoaderBridge; |
22 using webkit_glue::ResourceResponseInfo; | 23 using webkit_glue::ResourceResponseInfo; |
23 | 24 |
24 namespace content { | 25 namespace content { |
25 | 26 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 62 |
62 virtual void OnReceivedData(const char* data, | 63 virtual void OnReceivedData(const char* data, |
63 int data_length, | 64 int data_length, |
64 int encoded_data_length) OVERRIDE { | 65 int encoded_data_length) OVERRIDE { |
65 EXPECT_FALSE(complete_); | 66 EXPECT_FALSE(complete_); |
66 data_.append(data, data_length); | 67 data_.append(data, data_length); |
67 total_encoded_data_length_ += encoded_data_length; | 68 total_encoded_data_length_ += encoded_data_length; |
68 } | 69 } |
69 | 70 |
70 virtual void OnCompletedRequest( | 71 virtual void OnCompletedRequest( |
71 const net::URLRequestStatus& status, | 72 int error_code, |
| 73 bool was_ignored_by_handler, |
72 const std::string& security_info, | 74 const std::string& security_info, |
73 const base::TimeTicks& completion_time) OVERRIDE { | 75 const base::TimeTicks& completion_time) { |
74 EXPECT_FALSE(complete_); | 76 EXPECT_FALSE(complete_); |
75 complete_ = true; | 77 complete_ = true; |
76 } | 78 } |
77 | 79 |
78 bool complete() const { | 80 bool complete() const { |
79 return complete_; | 81 return complete_; |
80 } | 82 } |
81 const std::string& data() const { | 83 const std::string& data() const { |
82 return data_; | 84 return data_; |
83 } | 85 } |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 241 |
240 virtual bool Send(IPC::Message* msg) OVERRIDE { | 242 virtual bool Send(IPC::Message* msg) OVERRIDE { |
241 delete msg; | 243 delete msg; |
242 return true; | 244 return true; |
243 } | 245 } |
244 | 246 |
245 void InitMessages() { | 247 void InitMessages() { |
246 set_defer_loading(true); | 248 set_defer_loading(true); |
247 | 249 |
248 ResourceResponseHead response_head; | 250 ResourceResponseHead response_head; |
249 response_head.status.set_status(net::URLRequestStatus::SUCCESS); | 251 response_head.error_code = net::OK; |
250 | 252 |
251 dispatcher_->OnMessageReceived( | 253 dispatcher_->OnMessageReceived( |
252 ResourceMsg_ReceivedResponse(0, 0, response_head)); | 254 ResourceMsg_ReceivedResponse(0, 0, response_head)); |
253 | 255 |
254 // Duplicate the shared memory handle so both the test and the callee can | 256 // Duplicate the shared memory handle so both the test and the callee can |
255 // close their copy. | 257 // close their copy. |
256 base::SharedMemoryHandle duplicated_handle; | 258 base::SharedMemoryHandle duplicated_handle; |
257 EXPECT_TRUE(shared_handle_.ShareToProcess(base::GetCurrentProcessHandle(), | 259 EXPECT_TRUE(shared_handle_.ShareToProcess(base::GetCurrentProcessHandle(), |
258 &duplicated_handle)); | 260 &duplicated_handle)); |
259 | 261 |
(...skipping 25 matching lines...) Expand all Loading... |
285 } | 287 } |
286 | 288 |
287 virtual void OnReceivedData(const char* data, | 289 virtual void OnReceivedData(const char* data, |
288 int data_length, | 290 int data_length, |
289 int encoded_data_length) OVERRIDE { | 291 int encoded_data_length) OVERRIDE { |
290 EXPECT_EQ(defer_loading_, false); | 292 EXPECT_EQ(defer_loading_, false); |
291 set_defer_loading(false); | 293 set_defer_loading(false); |
292 } | 294 } |
293 | 295 |
294 virtual void OnCompletedRequest( | 296 virtual void OnCompletedRequest( |
295 const net::URLRequestStatus& status, | 297 int error_code, |
| 298 bool was_ignored_by_handler, |
296 const std::string& security_info, | 299 const std::string& security_info, |
297 const base::TimeTicks& completion_time) OVERRIDE { | 300 const base::TimeTicks& completion_time) { |
298 } | 301 } |
299 | 302 |
300 protected: | 303 protected: |
301 virtual void SetUp() OVERRIDE { | 304 virtual void SetUp() OVERRIDE { |
302 ResourceDispatcherTest::SetUp(); | 305 ResourceDispatcherTest::SetUp(); |
303 shared_handle_.Delete(kShmemSegmentName); | 306 shared_handle_.Delete(kShmemSegmentName); |
304 EXPECT_TRUE(shared_handle_.CreateNamed(kShmemSegmentName, false, 100)); | 307 EXPECT_TRUE(shared_handle_.CreateNamed(kShmemSegmentName, false, 100)); |
305 } | 308 } |
306 | 309 |
307 virtual void TearDown() OVERRIDE { | 310 virtual void TearDown() OVERRIDE { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 | 374 |
372 virtual void OnDownloadedData(int len) OVERRIDE { | 375 virtual void OnDownloadedData(int len) OVERRIDE { |
373 } | 376 } |
374 | 377 |
375 virtual void OnReceivedData(const char* data, | 378 virtual void OnReceivedData(const char* data, |
376 int data_length, | 379 int data_length, |
377 int encoded_data_length) OVERRIDE { | 380 int encoded_data_length) OVERRIDE { |
378 } | 381 } |
379 | 382 |
380 virtual void OnCompletedRequest( | 383 virtual void OnCompletedRequest( |
381 const net::URLRequestStatus& status, | 384 int error_code, |
| 385 bool was_ignored_by_handler, |
382 const std::string& security_info, | 386 const std::string& security_info, |
383 const base::TimeTicks& completion_time) OVERRIDE { | 387 const base::TimeTicks& completion_time) OVERRIDE { |
384 } | 388 } |
385 | 389 |
386 const ResourceResponseInfo& response_info() const { return response_info_; } | 390 const ResourceResponseInfo& response_info() const { return response_info_; } |
387 | 391 |
388 private: | 392 private: |
389 ResourceResponseInfo response_info_; | 393 ResourceResponseInfo response_info_; |
390 }; | 394 }; |
391 | 395 |
392 // TODO(simonjam): Enable this when 10829031 lands. | 396 // TODO(simonjam): Enable this when 10829031 lands. |
393 TEST_F(TimeConversionTest, DISABLED_ProperlyInitialized) { | 397 TEST_F(TimeConversionTest, DISABLED_ProperlyInitialized) { |
394 ResourceResponseHead response_head; | 398 ResourceResponseHead response_head; |
395 response_head.status.set_status(net::URLRequestStatus::SUCCESS); | 399 response_head.error_code = net::OK; |
396 response_head.request_start = base::TimeTicks::FromInternalValue(5); | 400 response_head.request_start = base::TimeTicks::FromInternalValue(5); |
397 response_head.response_start = base::TimeTicks::FromInternalValue(15); | 401 response_head.response_start = base::TimeTicks::FromInternalValue(15); |
398 response_head.load_timing.base_time = base::Time::Now(); | 402 response_head.load_timing.base_time = base::Time::Now(); |
399 response_head.load_timing.base_ticks = base::TimeTicks::FromInternalValue(10); | 403 response_head.load_timing.base_ticks = base::TimeTicks::FromInternalValue(10); |
400 response_head.load_timing.dns_start = -1; | 404 response_head.load_timing.dns_start = -1; |
401 response_head.load_timing.connect_start = 3; | 405 response_head.load_timing.connect_start = 3; |
402 | 406 |
403 PerformTest(response_head); | 407 PerformTest(response_head); |
404 | 408 |
405 EXPECT_LT(0, response_info().load_timing.base_ticks.ToInternalValue()); | 409 EXPECT_LT(0, response_info().load_timing.base_ticks.ToInternalValue()); |
406 EXPECT_EQ(-1, response_info().load_timing.dns_start); | 410 EXPECT_EQ(-1, response_info().load_timing.dns_start); |
407 EXPECT_LE(0, response_info().load_timing.connect_start); | 411 EXPECT_LE(0, response_info().load_timing.connect_start); |
408 } | 412 } |
409 | 413 |
410 TEST_F(TimeConversionTest, PartiallyInitialized) { | 414 TEST_F(TimeConversionTest, PartiallyInitialized) { |
411 ResourceResponseHead response_head; | 415 ResourceResponseHead response_head; |
412 response_head.status.set_status(net::URLRequestStatus::SUCCESS); | 416 response_head.error_code = net::OK; |
413 response_head.request_start = base::TimeTicks::FromInternalValue(5); | 417 response_head.request_start = base::TimeTicks::FromInternalValue(5); |
414 response_head.response_start = base::TimeTicks::FromInternalValue(15); | 418 response_head.response_start = base::TimeTicks::FromInternalValue(15); |
415 | 419 |
416 PerformTest(response_head); | 420 PerformTest(response_head); |
417 | 421 |
418 EXPECT_EQ(0, response_info().load_timing.base_ticks.ToInternalValue()); | 422 EXPECT_EQ(0, response_info().load_timing.base_ticks.ToInternalValue()); |
419 EXPECT_EQ(-1, response_info().load_timing.dns_start); | 423 EXPECT_EQ(-1, response_info().load_timing.dns_start); |
420 } | 424 } |
421 | 425 |
422 TEST_F(TimeConversionTest, NotInitialized) { | 426 TEST_F(TimeConversionTest, NotInitialized) { |
423 ResourceResponseHead response_head; | 427 ResourceResponseHead response_head; |
424 response_head.status.set_status(net::URLRequestStatus::SUCCESS); | 428 response_head.error_code = net::OK; |
425 | 429 |
426 PerformTest(response_head); | 430 PerformTest(response_head); |
427 | 431 |
428 EXPECT_EQ(0, response_info().load_timing.base_ticks.ToInternalValue()); | 432 EXPECT_EQ(0, response_info().load_timing.base_ticks.ToInternalValue()); |
429 EXPECT_EQ(-1, response_info().load_timing.dns_start); | 433 EXPECT_EQ(-1, response_info().load_timing.dns_start); |
430 } | 434 } |
431 | 435 |
432 } // namespace content | 436 } // namespace content |
OLD | NEW |