| 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/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/process/process.h" | 10 #include "base/process/process.h" |
| 11 #include "base/process/process_handle.h" | 11 #include "base/process/process_handle.h" |
| 12 #include "content/child/request_extra_data.h" | 12 #include "content/child/request_extra_data.h" |
| 13 #include "content/child/request_info.h" | 13 #include "content/child/request_info.h" |
| 14 #include "content/child/resource_dispatcher.h" | 14 #include "content/child/resource_dispatcher.h" |
| 15 #include "content/common/resource_messages.h" | 15 #include "content/common/resource_messages.h" |
| 16 #include "content/common/service_worker/service_worker_types.h" | 16 #include "content/common/service_worker/service_worker_types.h" |
| 17 #include "content/public/child/request_delegate_peer.h" |
| 17 #include "content/public/common/resource_response.h" | 18 #include "content/public/common/resource_response.h" |
| 18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 19 #include "net/http/http_response_headers.h" | 20 #include "net/http/http_response_headers.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "webkit/child/resource_loader_bridge.h" |
| 21 #include "webkit/common/appcache/appcache_interfaces.h" | 23 #include "webkit/common/appcache/appcache_interfaces.h" |
| 22 | 24 |
| 23 using webkit_glue::ResourceLoaderBridge; | 25 using webkit_glue::ResourceLoaderBridge; |
| 24 using webkit_glue::ResourceResponseInfo; | 26 using webkit_glue::ResourceResponseInfo; |
| 25 | 27 |
| 26 namespace content { | 28 namespace content { |
| 27 | 29 |
| 28 static const char test_page_url[] = "http://www.google.com/"; | 30 static const char test_page_url[] = "http://www.google.com/"; |
| 29 static const char test_page_headers[] = | 31 static const char test_page_headers[] = |
| 30 "HTTP/1.1 200 OK\nContent-Type:text/html\n\n"; | 32 "HTTP/1.1 200 OK\nContent-Type:text/html\n\n"; |
| 31 static const char test_page_mime_type[] = "text/html"; | 33 static const char test_page_mime_type[] = "text/html"; |
| 32 static const char test_page_charset[] = ""; | 34 static const char test_page_charset[] = ""; |
| 33 static const char test_page_contents[] = | 35 static const char test_page_contents[] = |
| 34 "<html><head><title>Google</title></head><body><h1>Google</h1></body></html>"; | 36 "<html><head><title>Google</title></head><body><h1>Google</h1></body></html>"; |
| 35 static const uint32 test_page_contents_len = arraysize(test_page_contents) - 1; | 37 static const uint32 test_page_contents_len = arraysize(test_page_contents) - 1; |
| 36 | 38 |
| 37 // Listens for request response data and stores it so that it can be compared | 39 // Listens for request response data and stores it so that it can be compared |
| 38 // to the reference data. | 40 // to the reference data. |
| 39 class TestRequestCallback : public ResourceLoaderBridge::Peer { | 41 class TestRequestCallback : public RequestDelegatePeer { |
| 40 public: | 42 public: |
| 41 TestRequestCallback() : complete_(false) { | 43 TestRequestCallback() : complete_(false) { |
| 42 } | 44 } |
| 43 | 45 |
| 44 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE { | 46 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE { |
| 45 } | 47 } |
| 46 | 48 |
| 47 virtual bool OnReceivedRedirect( | 49 virtual bool OnReceivedRedirect( |
| 48 const GURL& new_url, | 50 const GURL& new_url, |
| 49 const ResourceResponseInfo& info, | 51 const ResourceResponseInfo& info, |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 TEST_F(ResourceDispatcherTest, SerializedPostData) { | 224 TEST_F(ResourceDispatcherTest, SerializedPostData) { |
| 223 // FIXME | 225 // FIXME |
| 224 } | 226 } |
| 225 | 227 |
| 226 // This class provides functionality to validate whether the ResourceDispatcher | 228 // This class provides functionality to validate whether the ResourceDispatcher |
| 227 // object honors the deferred loading contract correctly, i.e. if deferred | 229 // object honors the deferred loading contract correctly, i.e. if deferred |
| 228 // loading is enabled it should queue up any responses received. If deferred | 230 // loading is enabled it should queue up any responses received. If deferred |
| 229 // loading is enabled/disabled in the context of a dispatched message, other | 231 // loading is enabled/disabled in the context of a dispatched message, other |
| 230 // queued messages should not be dispatched until deferred load is turned off. | 232 // queued messages should not be dispatched until deferred load is turned off. |
| 231 class DeferredResourceLoadingTest : public ResourceDispatcherTest, | 233 class DeferredResourceLoadingTest : public ResourceDispatcherTest, |
| 232 public ResourceLoaderBridge::Peer { | 234 public RequestDelegatePeer { |
| 233 public: | 235 public: |
| 234 DeferredResourceLoadingTest() | 236 DeferredResourceLoadingTest() |
| 235 : defer_loading_(false) { | 237 : defer_loading_(false) { |
| 236 } | 238 } |
| 237 | 239 |
| 238 virtual bool Send(IPC::Message* msg) OVERRIDE { | 240 virtual bool Send(IPC::Message* msg) OVERRIDE { |
| 239 delete msg; | 241 delete msg; |
| 240 return true; | 242 return true; |
| 241 } | 243 } |
| 242 | 244 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 255 EXPECT_TRUE(shared_handle_.ShareToProcess(base::GetCurrentProcessHandle(), | 257 EXPECT_TRUE(shared_handle_.ShareToProcess(base::GetCurrentProcessHandle(), |
| 256 &duplicated_handle)); | 258 &duplicated_handle)); |
| 257 | 259 |
| 258 dispatcher_->OnMessageReceived( | 260 dispatcher_->OnMessageReceived( |
| 259 ResourceMsg_SetDataBuffer(0, duplicated_handle, 100, 0)); | 261 ResourceMsg_SetDataBuffer(0, duplicated_handle, 100, 0)); |
| 260 dispatcher_->OnMessageReceived(ResourceMsg_DataReceived(0, 0, 100, 100)); | 262 dispatcher_->OnMessageReceived(ResourceMsg_DataReceived(0, 0, 100, 100)); |
| 261 | 263 |
| 262 set_defer_loading(false); | 264 set_defer_loading(false); |
| 263 } | 265 } |
| 264 | 266 |
| 265 // ResourceLoaderBridge::Peer methods. | 267 // RequestDelegatePeer methods. |
| 266 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE { | 268 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE { |
| 267 } | 269 } |
| 268 | 270 |
| 269 virtual bool OnReceivedRedirect( | 271 virtual bool OnReceivedRedirect( |
| 270 const GURL& new_url, | 272 const GURL& new_url, |
| 271 const ResourceResponseInfo& info, | 273 const ResourceResponseInfo& info, |
| 272 bool* has_new_first_party_for_cookies, | 274 bool* has_new_first_party_for_cookies, |
| 273 GURL* new_first_party_for_cookies) OVERRIDE { | 275 GURL* new_first_party_for_cookies) OVERRIDE { |
| 274 *has_new_first_party_for_cookies = false; | 276 *has_new_first_party_for_cookies = false; |
| 275 return true; | 277 return true; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 333 |
| 332 bridge->Start(this); | 334 bridge->Start(this); |
| 333 InitMessages(); | 335 InitMessages(); |
| 334 | 336 |
| 335 // Dispatch deferred messages. | 337 // Dispatch deferred messages. |
| 336 message_loop.RunUntilIdle(); | 338 message_loop.RunUntilIdle(); |
| 337 delete bridge; | 339 delete bridge; |
| 338 } | 340 } |
| 339 | 341 |
| 340 class TimeConversionTest : public ResourceDispatcherTest, | 342 class TimeConversionTest : public ResourceDispatcherTest, |
| 341 public ResourceLoaderBridge::Peer { | 343 public RequestDelegatePeer { |
| 342 public: | 344 public: |
| 343 virtual bool Send(IPC::Message* msg) OVERRIDE { | 345 virtual bool Send(IPC::Message* msg) OVERRIDE { |
| 344 delete msg; | 346 delete msg; |
| 345 return true; | 347 return true; |
| 346 } | 348 } |
| 347 | 349 |
| 348 void PerformTest(const ResourceResponseHead& response_head) { | 350 void PerformTest(const ResourceResponseHead& response_head) { |
| 349 scoped_ptr<ResourceLoaderBridge> bridge(CreateBridge()); | 351 scoped_ptr<ResourceLoaderBridge> bridge(CreateBridge()); |
| 350 bridge->Start(this); | 352 bridge->Start(this); |
| 351 | 353 |
| 352 dispatcher_->OnMessageReceived( | 354 dispatcher_->OnMessageReceived( |
| 353 ResourceMsg_ReceivedResponse(0, response_head)); | 355 ResourceMsg_ReceivedResponse(0, response_head)); |
| 354 } | 356 } |
| 355 | 357 |
| 356 // ResourceLoaderBridge::Peer methods. | 358 // RequestDelegatePeer methods. |
| 357 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE { | 359 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE { |
| 358 } | 360 } |
| 359 | 361 |
| 360 virtual bool OnReceivedRedirect( | 362 virtual bool OnReceivedRedirect( |
| 361 const GURL& new_url, | 363 const GURL& new_url, |
| 362 const ResourceResponseInfo& info, | 364 const ResourceResponseInfo& info, |
| 363 bool* has_new_first_party_for_cookies, | 365 bool* has_new_first_party_for_cookies, |
| 364 GURL* new_first_party_for_cookies) OVERRIDE { | 366 GURL* new_first_party_for_cookies) OVERRIDE { |
| 365 return true; | 367 return true; |
| 366 } | 368 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 response_head.error_code = net::OK; | 433 response_head.error_code = net::OK; |
| 432 | 434 |
| 433 PerformTest(response_head); | 435 PerformTest(response_head); |
| 434 | 436 |
| 435 EXPECT_EQ(base::TimeTicks(), response_info().load_timing.request_start); | 437 EXPECT_EQ(base::TimeTicks(), response_info().load_timing.request_start); |
| 436 EXPECT_EQ(base::TimeTicks(), | 438 EXPECT_EQ(base::TimeTicks(), |
| 437 response_info().load_timing.connect_timing.dns_start); | 439 response_info().load_timing.connect_timing.dns_start); |
| 438 } | 440 } |
| 439 | 441 |
| 440 } // namespace content | 442 } // namespace content |
| OLD | NEW |