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

Side by Side Diff: content/browser/renderer_host/resource_dispatcher_host_unittest.cc

Issue 10662005: Use IPC::Sender and IPC::Listener in content. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 "content/browser/renderer_host/resource_dispatcher_host_impl.h" 5 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 private: 154 private:
155 net::URLRequestContext* const request_context_; 155 net::URLRequestContext* const request_context_;
156 }; 156 };
157 157
158 // This class forwards the incoming messages to the ResourceDispatcherHostTest. 158 // This class forwards the incoming messages to the ResourceDispatcherHostTest.
159 // This is used to emulate different sub-processes, since this filter will 159 // This is used to emulate different sub-processes, since this filter will
160 // have a different ID than the original. For the test, we want all the incoming 160 // have a different ID than the original. For the test, we want all the incoming
161 // messages to go to the same place, which is why this forwards. 161 // messages to go to the same place, which is why this forwards.
162 class ForwardingFilter : public ResourceMessageFilter { 162 class ForwardingFilter : public ResourceMessageFilter {
163 public: 163 public:
164 explicit ForwardingFilter(IPC::Message::Sender* dest, 164 explicit ForwardingFilter(IPC::Sender* dest,
165 content::ResourceContext* resource_context) 165 content::ResourceContext* resource_context)
166 : ResourceMessageFilter( 166 : ResourceMessageFilter(
167 ChildProcessHostImpl::GenerateChildProcessUniqueId(), 167 ChildProcessHostImpl::GenerateChildProcessUniqueId(),
168 content::PROCESS_TYPE_RENDERER, 168 content::PROCESS_TYPE_RENDERER,
169 resource_context, 169 resource_context,
170 new MockURLRequestContextSelector( 170 new MockURLRequestContextSelector(
171 resource_context->GetRequestContext())), 171 resource_context->GetRequestContext())),
172 dest_(dest) { 172 dest_(dest) {
173 OnChannelConnected(base::GetCurrentProcId()); 173 OnChannelConnected(base::GetCurrentProcId());
174 } 174 }
175 175
176 // ResourceMessageFilter override 176 // ResourceMessageFilter override
177 virtual bool Send(IPC::Message* msg) { 177 virtual bool Send(IPC::Message* msg) {
178 if (!dest_) 178 if (!dest_)
179 return false; 179 return false;
180 return dest_->Send(msg); 180 return dest_->Send(msg);
181 } 181 }
182 182
183 protected: 183 protected:
184 virtual ~ForwardingFilter() {} 184 virtual ~ForwardingFilter() {}
185 185
186 private: 186 private:
187 IPC::Message::Sender* dest_; 187 IPC::Sender* dest_;
188 188
189 DISALLOW_COPY_AND_ASSIGN(ForwardingFilter); 189 DISALLOW_COPY_AND_ASSIGN(ForwardingFilter);
190 }; 190 };
191 191
192 // This class is a variation on URLRequestTestJob in that it does 192 // This class is a variation on URLRequestTestJob in that it does
193 // not complete start upon entry, only when specifically told to. 193 // not complete start upon entry, only when specifically told to.
194 class URLRequestTestDelayedStartJob : public net::URLRequestTestJob { 194 class URLRequestTestDelayedStartJob : public net::URLRequestTestJob {
195 public: 195 public:
196 URLRequestTestDelayedStartJob(net::URLRequest* request) 196 URLRequestTestDelayedStartJob(net::URLRequest* request)
197 : net::URLRequestTestJob(request) { 197 : net::URLRequestTestJob(request) {
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 if (defer_flags_ != DEFER_NONE) 364 if (defer_flags_ != DEFER_NONE)
365 throttles->push_back(new GenericResourceThrottle(defer_flags_)); 365 throttles->push_back(new GenericResourceThrottle(defer_flags_));
366 } 366 }
367 367
368 private: 368 private:
369 int defer_flags_; 369 int defer_flags_;
370 scoped_ptr<base::SupportsUserData::Data> user_data_; 370 scoped_ptr<base::SupportsUserData::Data> user_data_;
371 }; 371 };
372 372
373 class ResourceDispatcherHostTest : public testing::Test, 373 class ResourceDispatcherHostTest : public testing::Test,
374 public IPC::Message::Sender { 374 public IPC::Sender {
375 public: 375 public:
376 ResourceDispatcherHostTest() 376 ResourceDispatcherHostTest()
377 : ui_thread_(BrowserThread::UI, &message_loop_), 377 : ui_thread_(BrowserThread::UI, &message_loop_),
378 file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_), 378 file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_),
379 cache_thread_(BrowserThread::CACHE, &message_loop_), 379 cache_thread_(BrowserThread::CACHE, &message_loop_),
380 io_thread_(BrowserThread::IO, &message_loop_), 380 io_thread_(BrowserThread::IO, &message_loop_),
381 old_factory_(NULL), 381 old_factory_(NULL),
382 resource_type_(ResourceType::SUB_RESOURCE) { 382 resource_type_(ResourceType::SUB_RESOURCE) {
383 browser_context_.reset(new content::TestBrowserContext()); 383 browser_context_.reset(new content::TestBrowserContext());
384 BrowserContext::EnsureResourceContextInitialized(browser_context_.get()); 384 BrowserContext::EnsureResourceContextInitialized(browser_context_.get());
385 message_loop_.RunAllPending(); 385 message_loop_.RunAllPending();
386 filter_ = new ForwardingFilter( 386 filter_ = new ForwardingFilter(
387 this, browser_context_->GetResourceContext()); 387 this, browser_context_->GetResourceContext());
388 } 388 }
389 // IPC::Message::Sender implementation 389 // IPC::Sender implementation
390 virtual bool Send(IPC::Message* msg) { 390 virtual bool Send(IPC::Message* msg) {
391 accum_.AddMessage(*msg); 391 accum_.AddMessage(*msg);
392 delete msg; 392 delete msg;
393 return true; 393 return true;
394 } 394 }
395 395
396 protected: 396 protected:
397 // testing::Test 397 // testing::Test
398 virtual void SetUp() { 398 virtual void SetUp() {
399 DCHECK(!test_fixture_); 399 DCHECK(!test_fixture_);
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 PickleIterator iter(msgs[0][0]); 1428 PickleIterator iter(msgs[0][0]);
1429 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id)); 1429 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &request_id));
1430 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status)); 1430 EXPECT_TRUE(IPC::ReadParam(&msgs[0][0], &iter, &status));
1431 1431
1432 EXPECT_EQ(1, request_id); 1432 EXPECT_EQ(1, request_id);
1433 EXPECT_EQ(net::URLRequestStatus::FAILED, status.status()); 1433 EXPECT_EQ(net::URLRequestStatus::FAILED, status.status());
1434 EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME, status.error()); 1434 EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME, status.error());
1435 } 1435 }
1436 1436
1437 } // namespace content 1437 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.h ('k') | content/browser/resolve_proxy_msg_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698