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

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, 8 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
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; 24 using webkit_glue::ResourceLoaderBridge;
26 using webkit_glue::ResourceResponseInfo; 25 using webkit_glue::ResourceResponseInfo;
27 26
28 namespace content { 27 namespace content {
29 28
30 static const char test_page_url[] = "http://www.google.com/"; 29 static const char test_page_url[] = "http://www.google.com/";
31 static const char test_page_headers[] = 30 static const char test_page_headers[] =
32 "HTTP/1.1 200 OK\nContent-Type:text/html\n\n"; 31 "HTTP/1.1 200 OK\nContent-Type:text/html\n\n";
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 156
158 protected: 157 protected:
159 // testing::Test 158 // testing::Test
160 virtual void SetUp() OVERRIDE { 159 virtual void SetUp() OVERRIDE {
161 dispatcher_.reset(new ResourceDispatcher(this)); 160 dispatcher_.reset(new ResourceDispatcher(this));
162 } 161 }
163 virtual void TearDown() OVERRIDE { 162 virtual void TearDown() OVERRIDE {
164 dispatcher_.reset(); 163 dispatcher_.reset();
165 } 164 }
166 165
167 ResourceLoaderBridge* CreateBridge() { 166 void CreateBridge() {
168 RequestInfo request_info; 167 RequestInfo request_info;
169 request_info.method = "GET"; 168 request_info.method = "GET";
170 request_info.url = GURL(test_page_url); 169 request_info.url = GURL(test_page_url);
171 request_info.first_party_for_cookies = GURL(test_page_url); 170 request_info.first_party_for_cookies = GURL(test_page_url);
172 request_info.referrer = GURL(); 171 request_info.referrer = GURL();
173 request_info.headers = std::string(); 172 request_info.headers = std::string();
174 request_info.load_flags = 0; 173 request_info.load_flags = 0;
175 request_info.requestor_pid = 0; 174 request_info.requestor_pid = 0;
176 request_info.request_type = ResourceType::SUB_RESOURCE; 175 request_info.request_type = ResourceType::SUB_RESOURCE;
177 request_info.appcache_host_id = appcache::kNoHostId; 176 request_info.appcache_host_id = appcache::kNoHostId;
178 request_info.routing_id = 0; 177 request_info.routing_id = 0;
179 RequestExtraData extra_data; 178 RequestExtraData extra_data;
180 request_info.extra_data = &extra_data; 179 request_info.extra_data = &extra_data;
181 180
182 return dispatcher_->CreateBridge(request_info); 181 dispatcher_->CreateBridge(request_info);
183 } 182 }
184 183
185 std::vector<IPC::Message> message_queue_; 184 std::vector<IPC::Message> message_queue_;
186 static scoped_ptr<ResourceDispatcher> dispatcher_; 185 static scoped_ptr<ResourceDispatcher> dispatcher_;
187 }; 186 };
188 187
189 /*static*/ 188 // static
190 scoped_ptr<ResourceDispatcher> ResourceDispatcherTest::dispatcher_; 189 scoped_ptr<ResourceDispatcher> ResourceDispatcherTest::dispatcher_;
191 190
192 // Does a simple request and tests that the correct data is received. 191 // Does a simple request and tests that the correct data is received.
193 TEST_F(ResourceDispatcherTest, RoundTrip) { 192 TEST_F(ResourceDispatcherTest, RoundTrip) {
194 TestRequestCallback callback; 193 TestRequestCallback callback;
195 ResourceLoaderBridge* bridge = CreateBridge(); 194 CreateBridge();
196 195
197 bridge->Start(&callback); 196 dispatcher_->Start(&callback);
198 197
199 ProcessMessages(); 198 ProcessMessages();
200 199
201 // FIXME(brettw) when the request complete messages are actually handledo 200 // FIXME(brettw) when the request complete messages are actually handledo
202 // and dispatched, uncomment this. 201 // and dispatched, uncomment this.
203 //EXPECT_TRUE(callback.complete()); 202 //EXPECT_TRUE(callback.complete());
204 //EXPECT_STREQ(test_page_contents, callback.data().c_str()); 203 //EXPECT_STREQ(test_page_contents, callback.data().c_str());
205 //EXPECT_EQ(test_page_contents_len, callback.total_encoded_data_length()); 204 //EXPECT_EQ(test_page_contents_len, callback.total_encoded_data_length());
206
207 delete bridge;
208 } 205 }
209 206
210 // Tests that the request IDs are straight when there are multiple requests. 207 // Tests that the request IDs are straight when there are multiple requests.
211 TEST_F(ResourceDispatcherTest, MultipleRequests) { 208 TEST_F(ResourceDispatcherTest, MultipleRequests) {
212 // FIXME 209 // FIXME
213 } 210 }
214 211
215 // Tests that the cancel method prevents other messages from being received 212 // Tests that the cancel method prevents other messages from being received
216 TEST_F(ResourceDispatcherTest, Cancel) { 213 TEST_F(ResourceDispatcherTest, Cancel) {
217 // FIXME 214 // FIXME
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 return defer_loading_; 319 return defer_loading_;
323 } 320 }
324 321
325 bool defer_loading_; 322 bool defer_loading_;
326 base::SharedMemory shared_handle_; 323 base::SharedMemory shared_handle_;
327 }; 324 };
328 325
329 TEST_F(DeferredResourceLoadingTest, DeferredLoadTest) { 326 TEST_F(DeferredResourceLoadingTest, DeferredLoadTest) {
330 base::MessageLoopForIO message_loop; 327 base::MessageLoopForIO message_loop;
331 328
332 ResourceLoaderBridge* bridge = CreateBridge(); 329 CreateBridge();
330 dispatcher_->Start(this);
333 331
334 bridge->Start(this);
335 InitMessages(); 332 InitMessages();
336 333
337 // Dispatch deferred messages. 334 // Dispatch deferred messages.
338 message_loop.RunUntilIdle(); 335 message_loop.RunUntilIdle();
339 delete bridge;
340 } 336 }
341 337
342 class TimeConversionTest : public ResourceDispatcherTest, 338 class TimeConversionTest : public ResourceDispatcherTest,
343 public RequestPeer { 339 public RequestPeer {
344 public: 340 public:
345 virtual bool Send(IPC::Message* msg) OVERRIDE { 341 virtual bool Send(IPC::Message* msg) OVERRIDE {
346 delete msg; 342 delete msg;
347 return true; 343 return true;
348 } 344 }
349 345
350 void PerformTest(const ResourceResponseHead& response_head) { 346 void PerformTest(const ResourceResponseHead& response_head) {
351 scoped_ptr<ResourceLoaderBridge> bridge(CreateBridge()); 347 CreateBridge();
352 bridge->Start(this); 348 dispatcher_->Start(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

Powered by Google App Engine
This is Rietveld 408576698