| Index: content/browser/renderer_host/resource_dispatcher_host_unittest.cc
|
| ===================================================================
|
| --- content/browser/renderer_host/resource_dispatcher_host_unittest.cc (revision 122771)
|
| +++ content/browser/renderer_host/resource_dispatcher_host_unittest.cc (working copy)
|
| @@ -26,6 +26,7 @@
|
| #include "content/public/browser/resource_dispatcher_host_delegate.h"
|
| #include "content/public/browser/resource_throttle.h"
|
| #include "content/public/common/resource_response.h"
|
| +#include "content/test/test_browser_context.h"
|
| #include "net/base/net_errors.h"
|
| #include "net/base/upload_data.h"
|
| #include "net/http/http_util.h"
|
| @@ -35,14 +36,10 @@
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "webkit/appcache/appcache_interfaces.h"
|
|
|
| -namespace content {
|
| -class DownloadManager;
|
| -} // namespace content
|
| -
|
| +using content::BrowserContext;
|
| using content::BrowserThread;
|
| using content::BrowserThreadImpl;
|
| using content::ChildProcessHostImpl;
|
| -using content::DownloadManager;
|
| using content::GlobalRequestID;
|
|
|
| // TODO(eroman): Write unit tests for SafeBrowsing that exercise
|
| @@ -169,11 +166,12 @@
|
| // messages to go to the same place, which is why this forwards.
|
| class ForwardingFilter : public ResourceMessageFilter {
|
| public:
|
| - explicit ForwardingFilter(IPC::Message::Sender* dest)
|
| + explicit ForwardingFilter(IPC::Message::Sender* dest,
|
| + content::ResourceContext* resource_context)
|
| : ResourceMessageFilter(
|
| ChildProcessHostImpl::GenerateChildProcessUniqueId(),
|
| content::PROCESS_TYPE_RENDERER,
|
| - content::MockResourceContext::GetInstance(),
|
| + resource_context,
|
| new MockURLRequestContextSelector(
|
| content::MockResourceContext::GetInstance()->GetRequestContext())),
|
| dest_(dest) {
|
| @@ -334,10 +332,13 @@
|
| public:
|
| ResourceDispatcherHostTest()
|
| : ui_thread_(BrowserThread::UI, &message_loop_),
|
| + file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_),
|
| + cache_thread_(BrowserThread::CACHE, &message_loop_),
|
| io_thread_(BrowserThread::IO, &message_loop_),
|
| - ALLOW_THIS_IN_INITIALIZER_LIST(filter_(new ForwardingFilter(this))),
|
| old_factory_(NULL),
|
| resource_type_(ResourceType::SUB_RESOURCE) {
|
| + BrowserContext::EnsureResourceContextInitialized(&browser_context_);
|
| + filter_ = new ForwardingFilter(this, browser_context_.GetResourceContext());
|
| }
|
| // IPC::Message::Sender implementation
|
| virtual bool Send(IPC::Message* msg) {
|
| @@ -457,7 +458,10 @@
|
|
|
| MessageLoopForIO message_loop_;
|
| BrowserThreadImpl ui_thread_;
|
| + BrowserThreadImpl file_thread_;
|
| + BrowserThreadImpl cache_thread_;
|
| BrowserThreadImpl io_thread_;
|
| + TestBrowserContext browser_context_;
|
| scoped_refptr<ForwardingFilter> filter_;
|
| ResourceDispatcherHost host_;
|
| ResourceIPCAccumulator accum_;
|
| @@ -698,8 +702,8 @@
|
| // pending and some canceled.
|
| class TestFilter : public ForwardingFilter {
|
| public:
|
| - TestFilter()
|
| - : ForwardingFilter(NULL),
|
| + explicit TestFilter(content::ResourceContext* resource_context)
|
| + : ForwardingFilter(NULL, resource_context),
|
| has_canceled_(false),
|
| received_after_canceled_(0) {
|
| }
|
| @@ -718,7 +722,8 @@
|
|
|
| // Tests CancelRequestsForProcess
|
| TEST_F(ResourceDispatcherHostTest, TestProcessCancel) {
|
| - scoped_refptr<TestFilter> test_filter = new TestFilter();
|
| + scoped_refptr<TestFilter> test_filter = new TestFilter(
|
| + browser_context_.GetResourceContext());
|
|
|
| // request 1 goes to the test delegate
|
| ResourceHostMsg_Request request = CreateResourceRequest(
|
| @@ -871,7 +876,8 @@
|
| // Tests that blocked requests are canceled if their associated process dies.
|
| TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies) {
|
| // This second filter is used to emulate a second process.
|
| - scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter(this);
|
| + scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter(
|
| + this, browser_context_.GetResourceContext());
|
|
|
| EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(filter_->child_id()));
|
| EXPECT_EQ(0,
|
| @@ -915,7 +921,8 @@
|
| // destructor to make sure the blocked requests are deleted.
|
| TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsDontLeak) {
|
| // This second filter is used to emulate a second process.
|
| - scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter(this);
|
| + scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter(
|
| + this, browser_context_.GetResourceContext());
|
|
|
| host_.BlockRequestsForRoute(filter_->child_id(), 1);
|
| host_.BlockRequestsForRoute(filter_->child_id(), 2);
|
| @@ -1006,7 +1013,8 @@
|
| size_t kMaxRequests = kMaxCostPerProcess / kMemoryCostOfTest2Req;
|
|
|
| // This second filter is used to emulate a second process.
|
| - scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter(this);
|
| + scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter(
|
| + this, browser_context_.GetResourceContext());
|
|
|
| // Saturate the number of outstanding requests for our process.
|
| for (size_t i = 0; i < kMaxRequests; ++i) {
|
|
|