Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: content/child/resource_dispatcher_unittest.cc

Issue 267973002: Revert of Remove webkit's ResourceLoaderBridge interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/child/resource_dispatcher.cc ('k') | content/child/web_url_loader_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
22 #include "webkit/common/appcache/appcache_interfaces.h" 23 #include "webkit/common/appcache/appcache_interfaces.h"
23 24
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[] =
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 157
156 protected: 158 protected:
157 // testing::Test 159 // testing::Test
158 virtual void SetUp() OVERRIDE { 160 virtual void SetUp() OVERRIDE {
159 dispatcher_.reset(new ResourceDispatcher(this)); 161 dispatcher_.reset(new ResourceDispatcher(this));
160 } 162 }
161 virtual void TearDown() OVERRIDE { 163 virtual void TearDown() OVERRIDE {
162 dispatcher_.reset(); 164 dispatcher_.reset();
163 } 165 }
164 166
165 RequestInfo* CreateRequestInfo(RequestExtraData* extra_data) { 167 ResourceLoaderBridge* CreateBridge() {
166 RequestInfo* request_info = new RequestInfo(); 168 RequestInfo request_info;
167 request_info->method = "GET"; 169 request_info.method = "GET";
168 request_info->url = GURL(test_page_url); 170 request_info.url = GURL(test_page_url);
169 request_info->first_party_for_cookies = GURL(test_page_url); 171 request_info.first_party_for_cookies = GURL(test_page_url);
170 request_info->referrer = GURL(); 172 request_info.referrer = GURL();
171 request_info->headers = std::string(); 173 request_info.headers = std::string();
172 request_info->load_flags = 0; 174 request_info.load_flags = 0;
173 request_info->requestor_pid = 0; 175 request_info.requestor_pid = 0;
174 request_info->request_type = ResourceType::SUB_RESOURCE; 176 request_info.request_type = ResourceType::SUB_RESOURCE;
175 request_info->appcache_host_id = appcache::kNoHostId; 177 request_info.appcache_host_id = appcache::kNoHostId;
176 request_info->routing_id = 0; 178 request_info.routing_id = 0;
177 request_info->extra_data = extra_data; 179 RequestExtraData extra_data;
180 request_info.extra_data = &extra_data;
178 181
179 return request_info; 182 return dispatcher_->CreateBridge(request_info);
180 } 183 }
181 184
182 std::vector<IPC::Message> message_queue_; 185 std::vector<IPC::Message> message_queue_;
183 static scoped_ptr<ResourceDispatcher> dispatcher_; 186 static scoped_ptr<ResourceDispatcher> dispatcher_;
184 }; 187 };
185 188
186 // static 189 /*static*/
187 scoped_ptr<ResourceDispatcher> ResourceDispatcherTest::dispatcher_; 190 scoped_ptr<ResourceDispatcher> ResourceDispatcherTest::dispatcher_;
188 191
189 // Does a simple request and tests that the correct data is received. 192 // Does a simple request and tests that the correct data is received.
190 TEST_F(ResourceDispatcherTest, RoundTrip) { 193 TEST_F(ResourceDispatcherTest, RoundTrip) {
191 RequestExtraData extra_data;
192 scoped_ptr<RequestInfo> request_info(CreateRequestInfo(&extra_data));
193 TestRequestCallback callback; 194 TestRequestCallback callback;
195 ResourceLoaderBridge* bridge = CreateBridge();
194 196
195 dispatcher_->StartAsync(*request_info.get(), NULL, &callback); 197 bridge->Start(&callback);
196 198
197 ProcessMessages(); 199 ProcessMessages();
198 200
199 // FIXME(brettw) when the request complete messages are actually handledo 201 // FIXME(brettw) when the request complete messages are actually handledo
200 // and dispatched, uncomment this. 202 // and dispatched, uncomment this.
201 //EXPECT_TRUE(callback.complete()); 203 //EXPECT_TRUE(callback.complete());
202 //EXPECT_STREQ(test_page_contents, callback.data().c_str()); 204 //EXPECT_STREQ(test_page_contents, callback.data().c_str());
203 //EXPECT_EQ(test_page_contents_len, callback.total_encoded_data_length()); 205 //EXPECT_EQ(test_page_contents_len, callback.total_encoded_data_length());
206
207 delete bridge;
204 } 208 }
205 209
206 // Tests that the request IDs are straight when there are multiple requests. 210 // Tests that the request IDs are straight when there are multiple requests.
207 TEST_F(ResourceDispatcherTest, MultipleRequests) { 211 TEST_F(ResourceDispatcherTest, MultipleRequests) {
208 // FIXME 212 // FIXME
209 } 213 }
210 214
211 // Tests that the cancel method prevents other messages from being received 215 // Tests that the cancel method prevents other messages from being received
212 TEST_F(ResourceDispatcherTest, Cancel) { 216 TEST_F(ResourceDispatcherTest, Cancel) {
213 // FIXME 217 // FIXME
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 return defer_loading_; 322 return defer_loading_;
319 } 323 }
320 324
321 bool defer_loading_; 325 bool defer_loading_;
322 base::SharedMemory shared_handle_; 326 base::SharedMemory shared_handle_;
323 }; 327 };
324 328
325 TEST_F(DeferredResourceLoadingTest, DeferredLoadTest) { 329 TEST_F(DeferredResourceLoadingTest, DeferredLoadTest) {
326 base::MessageLoopForIO message_loop; 330 base::MessageLoopForIO message_loop;
327 331
328 RequestExtraData extra_data; 332 ResourceLoaderBridge* bridge = CreateBridge();
329 scoped_ptr<RequestInfo> request_info(CreateRequestInfo(&extra_data)); 333
330 dispatcher_->StartAsync(*request_info.get(), NULL, this); 334 bridge->Start(this);
331 InitMessages(); 335 InitMessages();
332 336
333 // Dispatch deferred messages. 337 // Dispatch deferred messages.
334 message_loop.RunUntilIdle(); 338 message_loop.RunUntilIdle();
339 delete bridge;
335 } 340 }
336 341
337 class TimeConversionTest : public ResourceDispatcherTest, 342 class TimeConversionTest : public ResourceDispatcherTest,
338 public RequestPeer { 343 public RequestPeer {
339 public: 344 public:
340 virtual bool Send(IPC::Message* msg) OVERRIDE { 345 virtual bool Send(IPC::Message* msg) OVERRIDE {
341 delete msg; 346 delete msg;
342 return true; 347 return true;
343 } 348 }
344 349
345 void PerformTest(const ResourceResponseHead& response_head) { 350 void PerformTest(const ResourceResponseHead& response_head) {
346 RequestExtraData extra_data; 351 scoped_ptr<ResourceLoaderBridge> bridge(CreateBridge());
347 scoped_ptr<RequestInfo> request_info(CreateRequestInfo(&extra_data)); 352 bridge->Start(this);
348 dispatcher_->StartAsync(*request_info.get(), NULL, this);
349 353
350 dispatcher_->OnMessageReceived( 354 dispatcher_->OnMessageReceived(
351 ResourceMsg_ReceivedResponse(0, response_head)); 355 ResourceMsg_ReceivedResponse(0, response_head));
352 } 356 }
353 357
354 // RequestPeer methods. 358 // RequestPeer methods.
355 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE { 359 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE {
356 } 360 }
357 361
358 virtual bool OnReceivedRedirect( 362 virtual bool OnReceivedRedirect(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 response_head.error_code = net::OK; 433 response_head.error_code = net::OK;
430 434
431 PerformTest(response_head); 435 PerformTest(response_head);
432 436
433 EXPECT_EQ(base::TimeTicks(), response_info().load_timing.request_start); 437 EXPECT_EQ(base::TimeTicks(), response_info().load_timing.request_start);
434 EXPECT_EQ(base::TimeTicks(), 438 EXPECT_EQ(base::TimeTicks(),
435 response_info().load_timing.connect_timing.dns_start); 439 response_info().load_timing.connect_timing.dns_start);
436 } 440 }
437 441
438 } // namespace content 442 } // namespace content
OLDNEW
« no previous file with comments | « content/child/resource_dispatcher.cc ('k') | content/child/web_url_loader_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698