| 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_peer.h" | 17 #include "content/public/child/request_peer.h" |
| 18 #include "content/public/common/resource_response.h" | 18 #include "content/public/common/resource_response.h" |
| 19 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 20 #include "net/http/http_response_headers.h" | 20 #include "net/http/http_response_headers.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "webkit/child/resource_loader_bridge.h" | |
| 23 #include "webkit/common/appcache/appcache_interfaces.h" | 22 #include "webkit/common/appcache/appcache_interfaces.h" |
| 24 | 23 |
| 25 using webkit_glue::ResourceLoaderBridge; | |
| 26 using webkit_glue::ResourceResponseInfo; | 24 using webkit_glue::ResourceResponseInfo; |
| 27 | 25 |
| 28 namespace content { | 26 namespace content { |
| 29 | 27 |
| 30 static const char test_page_url[] = "http://www.google.com/"; | 28 static const char test_page_url[] = "http://www.google.com/"; |
| 31 static const char test_page_headers[] = | 29 static const char test_page_headers[] = |
| 32 "HTTP/1.1 200 OK\nContent-Type:text/html\n\n"; | 30 "HTTP/1.1 200 OK\nContent-Type:text/html\n\n"; |
| 33 static const char test_page_mime_type[] = "text/html"; | 31 static const char test_page_mime_type[] = "text/html"; |
| 34 static const char test_page_charset[] = ""; | 32 static const char test_page_charset[] = ""; |
| 35 static const char test_page_contents[] = | 33 static const char test_page_contents[] = |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 | 155 |
| 158 protected: | 156 protected: |
| 159 // testing::Test | 157 // testing::Test |
| 160 virtual void SetUp() OVERRIDE { | 158 virtual void SetUp() OVERRIDE { |
| 161 dispatcher_.reset(new ResourceDispatcher(this)); | 159 dispatcher_.reset(new ResourceDispatcher(this)); |
| 162 } | 160 } |
| 163 virtual void TearDown() OVERRIDE { | 161 virtual void TearDown() OVERRIDE { |
| 164 dispatcher_.reset(); | 162 dispatcher_.reset(); |
| 165 } | 163 } |
| 166 | 164 |
| 167 ResourceLoaderBridge* CreateBridge() { | 165 RequestInfo* CreateRequestInfo() { |
| 168 RequestInfo request_info; | 166 RequestInfo* request_info = new RequestInfo(); |
| 169 request_info.method = "GET"; | 167 request_info->method = "GET"; |
| 170 request_info.url = GURL(test_page_url); | 168 request_info->url = GURL(test_page_url); |
| 171 request_info.first_party_for_cookies = GURL(test_page_url); | 169 request_info->first_party_for_cookies = GURL(test_page_url); |
| 172 request_info.referrer = GURL(); | 170 request_info->referrer = GURL(); |
| 173 request_info.headers = std::string(); | 171 request_info->headers = std::string(); |
| 174 request_info.load_flags = 0; | 172 request_info->load_flags = 0; |
| 175 request_info.requestor_pid = 0; | 173 request_info->requestor_pid = 0; |
| 176 request_info.request_type = ResourceType::SUB_RESOURCE; | 174 request_info->request_type = ResourceType::SUB_RESOURCE; |
| 177 request_info.appcache_host_id = appcache::kNoHostId; | 175 request_info->appcache_host_id = appcache::kNoHostId; |
| 178 request_info.routing_id = 0; | 176 request_info->routing_id = 0; |
| 179 RequestExtraData extra_data; | 177 RequestExtraData extra_data; |
| 180 request_info.extra_data = &extra_data; | 178 request_info->extra_data = &extra_data; |
| 181 | 179 |
| 182 return dispatcher_->CreateBridge(request_info); | 180 return request_info; |
| 183 } | 181 } |
| 184 | 182 |
| 185 std::vector<IPC::Message> message_queue_; | 183 std::vector<IPC::Message> message_queue_; |
| 186 static scoped_ptr<ResourceDispatcher> dispatcher_; | 184 static scoped_ptr<ResourceDispatcher> dispatcher_; |
| 187 }; | 185 }; |
| 188 | 186 |
| 189 /*static*/ | 187 // static |
| 190 scoped_ptr<ResourceDispatcher> ResourceDispatcherTest::dispatcher_; | 188 scoped_ptr<ResourceDispatcher> ResourceDispatcherTest::dispatcher_; |
| 191 | 189 |
| 192 // Does a simple request and tests that the correct data is received. | 190 // Does a simple request and tests that the correct data is received. |
| 193 TEST_F(ResourceDispatcherTest, RoundTrip) { | 191 TEST_F(ResourceDispatcherTest, RoundTrip) { |
| 192 scoped_ptr<RequestInfo> request_info(CreateRequestInfo()); |
| 194 TestRequestCallback callback; | 193 TestRequestCallback callback; |
| 195 ResourceLoaderBridge* bridge = CreateBridge(); | |
| 196 | 194 |
| 197 bridge->Start(&callback); | 195 dispatcher_->StartAsync(*request_info.get(), NULL, &callback); |
| 198 | 196 |
| 199 ProcessMessages(); | 197 ProcessMessages(); |
| 200 | 198 |
| 201 // FIXME(brettw) when the request complete messages are actually handledo | 199 // FIXME(brettw) when the request complete messages are actually handledo |
| 202 // and dispatched, uncomment this. | 200 // and dispatched, uncomment this. |
| 203 //EXPECT_TRUE(callback.complete()); | 201 //EXPECT_TRUE(callback.complete()); |
| 204 //EXPECT_STREQ(test_page_contents, callback.data().c_str()); | 202 //EXPECT_STREQ(test_page_contents, callback.data().c_str()); |
| 205 //EXPECT_EQ(test_page_contents_len, callback.total_encoded_data_length()); | 203 //EXPECT_EQ(test_page_contents_len, callback.total_encoded_data_length()); |
| 206 | |
| 207 delete bridge; | |
| 208 } | 204 } |
| 209 | 205 |
| 210 // Tests that the request IDs are straight when there are multiple requests. | 206 // Tests that the request IDs are straight when there are multiple requests. |
| 211 TEST_F(ResourceDispatcherTest, MultipleRequests) { | 207 TEST_F(ResourceDispatcherTest, MultipleRequests) { |
| 212 // FIXME | 208 // FIXME |
| 213 } | 209 } |
| 214 | 210 |
| 215 // Tests that the cancel method prevents other messages from being received | 211 // Tests that the cancel method prevents other messages from being received |
| 216 TEST_F(ResourceDispatcherTest, Cancel) { | 212 TEST_F(ResourceDispatcherTest, Cancel) { |
| 217 // FIXME | 213 // FIXME |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 return defer_loading_; | 318 return defer_loading_; |
| 323 } | 319 } |
| 324 | 320 |
| 325 bool defer_loading_; | 321 bool defer_loading_; |
| 326 base::SharedMemory shared_handle_; | 322 base::SharedMemory shared_handle_; |
| 327 }; | 323 }; |
| 328 | 324 |
| 329 TEST_F(DeferredResourceLoadingTest, DeferredLoadTest) { | 325 TEST_F(DeferredResourceLoadingTest, DeferredLoadTest) { |
| 330 base::MessageLoopForIO message_loop; | 326 base::MessageLoopForIO message_loop; |
| 331 | 327 |
| 332 ResourceLoaderBridge* bridge = CreateBridge(); | 328 scoped_ptr<RequestInfo> request_info(CreateRequestInfo()); |
| 333 | 329 dispatcher_->StartAsync(*request_info.get(), NULL, this); |
| 334 bridge->Start(this); | |
| 335 InitMessages(); | 330 InitMessages(); |
| 336 | 331 |
| 337 // Dispatch deferred messages. | 332 // Dispatch deferred messages. |
| 338 message_loop.RunUntilIdle(); | 333 message_loop.RunUntilIdle(); |
| 339 delete bridge; | |
| 340 } | 334 } |
| 341 | 335 |
| 342 class TimeConversionTest : public ResourceDispatcherTest, | 336 class TimeConversionTest : public ResourceDispatcherTest, |
| 343 public RequestPeer { | 337 public RequestPeer { |
| 344 public: | 338 public: |
| 345 virtual bool Send(IPC::Message* msg) OVERRIDE { | 339 virtual bool Send(IPC::Message* msg) OVERRIDE { |
| 346 delete msg; | 340 delete msg; |
| 347 return true; | 341 return true; |
| 348 } | 342 } |
| 349 | 343 |
| 350 void PerformTest(const ResourceResponseHead& response_head) { | 344 void PerformTest(const ResourceResponseHead& response_head) { |
| 351 scoped_ptr<ResourceLoaderBridge> bridge(CreateBridge()); | 345 scoped_ptr<RequestInfo> request_info(CreateRequestInfo()); |
| 352 bridge->Start(this); | 346 dispatcher_->StartAsync(*request_info.get(), NULL, this); |
| 353 | 347 |
| 354 dispatcher_->OnMessageReceived( | 348 dispatcher_->OnMessageReceived( |
| 355 ResourceMsg_ReceivedResponse(0, response_head)); | 349 ResourceMsg_ReceivedResponse(0, response_head)); |
| 356 } | 350 } |
| 357 | 351 |
| 358 // RequestPeer methods. | 352 // RequestPeer methods. |
| 359 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE { | 353 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE { |
| 360 } | 354 } |
| 361 | 355 |
| 362 virtual bool OnReceivedRedirect( | 356 virtual bool OnReceivedRedirect( |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 response_head.error_code = net::OK; | 427 response_head.error_code = net::OK; |
| 434 | 428 |
| 435 PerformTest(response_head); | 429 PerformTest(response_head); |
| 436 | 430 |
| 437 EXPECT_EQ(base::TimeTicks(), response_info().load_timing.request_start); | 431 EXPECT_EQ(base::TimeTicks(), response_info().load_timing.request_start); |
| 438 EXPECT_EQ(base::TimeTicks(), | 432 EXPECT_EQ(base::TimeTicks(), |
| 439 response_info().load_timing.connect_timing.dns_start); | 433 response_info().load_timing.connect_timing.dns_start); |
| 440 } | 434 } |
| 441 | 435 |
| 442 } // namespace content | 436 } // namespace content |
| OLD | NEW |