| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/process_util.h" | 8 #include "base/process_util.h" |
| 9 #include "chrome/browser/renderer_host/renderer_security_policy.h" | 9 #include "chrome/browser/renderer_host/renderer_security_policy.h" |
| 10 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 10 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 80 } |
| 81 messages_.erase(messages_.begin()); | 81 messages_.erase(messages_.begin()); |
| 82 msgs->push_back(cur_requests); | 82 msgs->push_back(cur_requests); |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 class ResourceDispatcherHostTest : public testing::Test, | 86 class ResourceDispatcherHostTest : public testing::Test, |
| 87 public ResourceDispatcherHost::Receiver { | 87 public ResourceDispatcherHost::Receiver { |
| 88 public: | 88 public: |
| 89 ResourceDispatcherHostTest() | 89 ResourceDispatcherHostTest() |
| 90 : Receiver(ChildProcessInfo::RENDER_PROCESS), host_(NULL) { | 90 : Receiver(ChildProcessInfo::RENDER_PROCESS), host_(NULL), pid_(-1) { |
| 91 set_handle(base::GetCurrentProcessHandle()); | 91 set_handle(base::GetCurrentProcessHandle()); |
| 92 } | 92 } |
| 93 // ResourceDispatcherHost::Receiver implementation | 93 // ResourceDispatcherHost::Receiver implementation |
| 94 virtual bool Send(IPC::Message* msg) { | 94 virtual bool Send(IPC::Message* msg) { |
| 95 accum_.AddMessage(*msg); | 95 accum_.AddMessage(*msg); |
| 96 delete msg; | 96 delete msg; |
| 97 return true; | 97 return true; |
| 98 } | 98 } |
| 99 | 99 |
| 100 URLRequestContext* GetRequestContext( | 100 URLRequestContext* GetRequestContext( |
| 101 uint32 request_id, | 101 uint32 request_id, |
| 102 const ViewHostMsg_Resource_Request& request_data) { | 102 const ViewHostMsg_Resource_Request& request_data) { |
| 103 return NULL; | 103 return NULL; |
| 104 } | 104 } |
| 105 | 105 |
| 106 virtual int GetProcessId() const { return pid_; } |
| 107 |
| 106 protected: | 108 protected: |
| 107 // testing::Test | 109 // testing::Test |
| 108 virtual void SetUp() { | 110 virtual void SetUp() { |
| 109 RendererSecurityPolicy::GetInstance()->Add(0); | 111 RendererSecurityPolicy::GetInstance()->Add(0); |
| 110 URLRequest::RegisterProtocolFactory("test", &URLRequestTestJob::Factory); | 112 URLRequest::RegisterProtocolFactory("test", &URLRequestTestJob::Factory); |
| 111 EnsureTestSchemeIsAllowed(); | 113 EnsureTestSchemeIsAllowed(); |
| 112 } | 114 } |
| 113 virtual void TearDown() { | 115 virtual void TearDown() { |
| 114 URLRequest::RegisterProtocolFactory("test", NULL); | 116 URLRequest::RegisterProtocolFactory("test", NULL); |
| 115 RendererSecurityPolicy::GetInstance()->Remove(0); | 117 RendererSecurityPolicy::GetInstance()->Remove(0); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 138 | 140 |
| 139 if (!have_white_listed_test_scheme) { | 141 if (!have_white_listed_test_scheme) { |
| 140 RendererSecurityPolicy::GetInstance()->RegisterWebSafeScheme("test"); | 142 RendererSecurityPolicy::GetInstance()->RegisterWebSafeScheme("test"); |
| 141 have_white_listed_test_scheme = true; | 143 have_white_listed_test_scheme = true; |
| 142 } | 144 } |
| 143 } | 145 } |
| 144 | 146 |
| 145 MessageLoopForIO message_loop_; | 147 MessageLoopForIO message_loop_; |
| 146 ResourceDispatcherHost host_; | 148 ResourceDispatcherHost host_; |
| 147 ResourceIPCAccumulator accum_; | 149 ResourceIPCAccumulator accum_; |
| 150 int pid_; |
| 148 }; | 151 }; |
| 149 | 152 |
| 150 // Spin up the message loop to kick off the request. | 153 // Spin up the message loop to kick off the request. |
| 151 static void KickOffRequest() { | 154 static void KickOffRequest() { |
| 152 MessageLoop::current()->RunAllPending(); | 155 MessageLoop::current()->RunAllPending(); |
| 153 } | 156 } |
| 154 | 157 |
| 155 void ResourceDispatcherHostTest::MakeTestRequest(int render_process_id, | 158 void ResourceDispatcherHostTest::MakeTestRequest(int render_process_id, |
| 156 int render_view_id, | 159 int render_view_id, |
| 157 int request_id, | 160 int request_id, |
| 158 const GURL& url) { | 161 const GURL& url) { |
| 159 MakeTestRequest(this, render_process_id, render_view_id, request_id, url); | 162 MakeTestRequest(this, render_process_id, render_view_id, request_id, url); |
| 160 } | 163 } |
| 161 | 164 |
| 162 void ResourceDispatcherHostTest::MakeTestRequest( | 165 void ResourceDispatcherHostTest::MakeTestRequest( |
| 163 ResourceDispatcherHost::Receiver* receiver, | 166 ResourceDispatcherHost::Receiver* receiver, |
| 164 int render_process_id, | 167 int render_process_id, |
| 165 int render_view_id, | 168 int render_view_id, |
| 166 int request_id, | 169 int request_id, |
| 167 const GURL& url) { | 170 const GURL& url) { |
| 168 int old_pid = pid(); | |
| 169 pid_ = render_process_id; | 171 pid_ = render_process_id; |
| 170 ViewHostMsg_Resource_Request request = CreateResourceRequest("GET", url); | 172 ViewHostMsg_Resource_Request request = CreateResourceRequest("GET", url); |
| 171 ViewHostMsg_RequestResource msg(render_view_id, request_id, request); | 173 ViewHostMsg_RequestResource msg(render_view_id, request_id, request); |
| 172 bool msg_was_ok; | 174 bool msg_was_ok; |
| 173 host_.OnMessageReceived(msg, receiver, &msg_was_ok); | 175 host_.OnMessageReceived(msg, receiver, &msg_was_ok); |
| 174 KickOffRequest(); | 176 KickOffRequest(); |
| 175 pid_ = old_pid; | 177 pid_ = -1; |
| 176 } | 178 } |
| 177 | 179 |
| 178 void ResourceDispatcherHostTest::MakeCancelRequest(int request_id) { | 180 void ResourceDispatcherHostTest::MakeCancelRequest(int request_id) { |
| 179 host_.CancelRequest(0, request_id, false); | 181 host_.CancelRequest(0, request_id, false); |
| 180 } | 182 } |
| 181 | 183 |
| 182 void CheckSuccessfulRequest(const std::vector<IPC::Message>& messages, | 184 void CheckSuccessfulRequest(const std::vector<IPC::Message>& messages, |
| 183 const std::string& reference_data) { | 185 const std::string& reference_data) { |
| 184 // A successful request will have received 4 messages: | 186 // A successful request will have received 4 messages: |
| 185 // ReceivedResponse (indicates headers received) | 187 // ReceivedResponse (indicates headers received) |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 EXPECT_EQ(URLRequestStatus::CANCELED, status.status()); | 641 EXPECT_EQ(URLRequestStatus::CANCELED, status.status()); |
| 640 EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES, status.os_error()); | 642 EXPECT_EQ(net::ERR_INSUFFICIENT_RESOURCES, status.os_error()); |
| 641 } | 643 } |
| 642 | 644 |
| 643 // The final 2 requests should have succeeded. | 645 // The final 2 requests should have succeeded. |
| 644 CheckSuccessfulRequest(msgs[kMaxRequests + 2], | 646 CheckSuccessfulRequest(msgs[kMaxRequests + 2], |
| 645 URLRequestTestJob::test_data_2()); | 647 URLRequestTestJob::test_data_2()); |
| 646 CheckSuccessfulRequest(msgs[kMaxRequests + 3], | 648 CheckSuccessfulRequest(msgs[kMaxRequests + 3], |
| 647 URLRequestTestJob::test_data_2()); | 649 URLRequestTestJob::test_data_2()); |
| 648 } | 650 } |
| OLD | NEW |