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

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

Issue 226273005: Remove webkit's ResourceLoaderBridge interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: REBASED 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"
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
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(RequestExtraData* extra_data) {
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 request_info->extra_data = extra_data;
180 request_info.extra_data = &extra_data;
181 178
182 return dispatcher_->CreateBridge(request_info); 179 return request_info;
183 } 180 }
184 181
185 std::vector<IPC::Message> message_queue_; 182 std::vector<IPC::Message> message_queue_;
186 static scoped_ptr<ResourceDispatcher> dispatcher_; 183 static scoped_ptr<ResourceDispatcher> dispatcher_;
187 }; 184 };
188 185
189 /*static*/ 186 // static
190 scoped_ptr<ResourceDispatcher> ResourceDispatcherTest::dispatcher_; 187 scoped_ptr<ResourceDispatcher> ResourceDispatcherTest::dispatcher_;
191 188
192 // Does a simple request and tests that the correct data is received. 189 // Does a simple request and tests that the correct data is received.
193 TEST_F(ResourceDispatcherTest, RoundTrip) { 190 TEST_F(ResourceDispatcherTest, RoundTrip) {
191 RequestExtraData extra_data;
192 scoped_ptr<RequestInfo> request_info(CreateRequestInfo(&extra_data));
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
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 RequestExtraData extra_data;
333 329 scoped_ptr<RequestInfo> request_info(CreateRequestInfo(&extra_data));
334 bridge->Start(this); 330 dispatcher_->StartAsync(*request_info.get(), NULL, this);
335 InitMessages(); 331 InitMessages();
336 332
337 // Dispatch deferred messages. 333 // Dispatch deferred messages.
338 message_loop.RunUntilIdle(); 334 message_loop.RunUntilIdle();
339 delete bridge;
340 } 335 }
341 336
342 class TimeConversionTest : public ResourceDispatcherTest, 337 class TimeConversionTest : public ResourceDispatcherTest,
343 public RequestPeer { 338 public RequestPeer {
344 public: 339 public:
345 virtual bool Send(IPC::Message* msg) OVERRIDE { 340 virtual bool Send(IPC::Message* msg) OVERRIDE {
346 delete msg; 341 delete msg;
347 return true; 342 return true;
348 } 343 }
349 344
350 void PerformTest(const ResourceResponseHead& response_head) { 345 void PerformTest(const ResourceResponseHead& response_head) {
351 scoped_ptr<ResourceLoaderBridge> bridge(CreateBridge()); 346 RequestExtraData extra_data;
352 bridge->Start(this); 347 scoped_ptr<RequestInfo> request_info(CreateRequestInfo(&extra_data));
348 dispatcher_->StartAsync(*request_info.get(), NULL, this);
353 349
354 dispatcher_->OnMessageReceived( 350 dispatcher_->OnMessageReceived(
355 ResourceMsg_ReceivedResponse(0, response_head)); 351 ResourceMsg_ReceivedResponse(0, response_head));
356 } 352 }
357 353
358 // RequestPeer methods. 354 // RequestPeer methods.
359 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE { 355 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE {
360 } 356 }
361 357
362 virtual bool OnReceivedRedirect( 358 virtual bool OnReceivedRedirect(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 response_head.error_code = net::OK; 429 response_head.error_code = net::OK;
434 430
435 PerformTest(response_head); 431 PerformTest(response_head);
436 432
437 EXPECT_EQ(base::TimeTicks(), response_info().load_timing.request_start); 433 EXPECT_EQ(base::TimeTicks(), response_info().load_timing.request_start);
438 EXPECT_EQ(base::TimeTicks(), 434 EXPECT_EQ(base::TimeTicks(),
439 response_info().load_timing.connect_timing.dns_start); 435 response_info().load_timing.connect_timing.dns_start);
440 } 436 }
441 437
442 } // namespace content 438 } // 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