| 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/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
| 10 #include "chrome/browser/child_process_security_policy.h" | 10 #include "chrome/browser/child_process_security_policy.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 ResourceDispatcherHost::Receiver* dest_; | 141 ResourceDispatcherHost::Receiver* dest_; |
| 142 | 142 |
| 143 DISALLOW_COPY_AND_ASSIGN(ForwardingReceiver); | 143 DISALLOW_COPY_AND_ASSIGN(ForwardingReceiver); |
| 144 }; | 144 }; |
| 145 | 145 |
| 146 class ResourceDispatcherHostTest : public testing::Test, | 146 class ResourceDispatcherHostTest : public testing::Test, |
| 147 public ResourceDispatcherHost::Receiver { | 147 public ResourceDispatcherHost::Receiver { |
| 148 public: | 148 public: |
| 149 ResourceDispatcherHostTest() | 149 ResourceDispatcherHostTest() |
| 150 : Receiver(ChildProcessInfo::RENDER_PROCESS, -1), | 150 : Receiver(ChildProcessInfo::RENDER_PROCESS, -1), |
| 151 ui_thread_(ChromeThread::UI, &message_loop_), |
| 151 io_thread_(ChromeThread::IO, &message_loop_), | 152 io_thread_(ChromeThread::IO, &message_loop_), |
| 152 old_factory_(NULL) { | 153 old_factory_(NULL) { |
| 153 set_handle(base::GetCurrentProcessHandle()); | 154 set_handle(base::GetCurrentProcessHandle()); |
| 154 } | 155 } |
| 155 // ResourceDispatcherHost::Receiver implementation | 156 // ResourceDispatcherHost::Receiver implementation |
| 156 virtual bool Send(IPC::Message* msg) { | 157 virtual bool Send(IPC::Message* msg) { |
| 157 accum_.AddMessage(*msg); | 158 accum_.AddMessage(*msg); |
| 158 delete msg; | 159 delete msg; |
| 159 return true; | 160 return true; |
| 160 } | 161 } |
| 161 | 162 |
| 162 URLRequestContext* GetRequestContext( | 163 URLRequestContext* GetRequestContext( |
| 163 uint32 request_id, | 164 uint32 request_id, |
| 164 const ViewHostMsg_Resource_Request& request_data) { | 165 const ViewHostMsg_Resource_Request& request_data) { |
| 165 return NULL; | 166 return NULL; |
| 166 } | 167 } |
| 167 | 168 |
| 168 protected: | 169 protected: |
| 169 // testing::Test | 170 // testing::Test |
| 170 virtual void SetUp() { | 171 virtual void SetUp() { |
| 171 DCHECK(!test_fixture_); | 172 DCHECK(!test_fixture_); |
| 172 test_fixture_ = this; | 173 test_fixture_ = this; |
| 173 ChildProcessSecurityPolicy::GetInstance()->Add(0); | 174 ChildProcessSecurityPolicy::GetInstance()->Add(0); |
| 174 URLRequest::RegisterProtocolFactory("test", | 175 URLRequest::RegisterProtocolFactory("test", |
| 175 &ResourceDispatcherHostTest::Factory); | 176 &ResourceDispatcherHostTest::Factory); |
| 176 EnsureTestSchemeIsAllowed(); | 177 EnsureTestSchemeIsAllowed(); |
| 177 } | 178 } |
| 179 |
| 178 virtual void TearDown() { | 180 virtual void TearDown() { |
| 179 URLRequest::RegisterProtocolFactory("test", NULL); | 181 URLRequest::RegisterProtocolFactory("test", NULL); |
| 180 if (!scheme_.empty()) | 182 if (!scheme_.empty()) |
| 181 URLRequest::RegisterProtocolFactory(scheme_, old_factory_); | 183 URLRequest::RegisterProtocolFactory(scheme_, old_factory_); |
| 182 | 184 |
| 183 DCHECK(test_fixture_ == this); | 185 DCHECK(test_fixture_ == this); |
| 184 test_fixture_ = NULL; | 186 test_fixture_ = NULL; |
| 185 | 187 |
| 186 ChildProcessSecurityPolicy::GetInstance()->Remove(0); | 188 ChildProcessSecurityPolicy::GetInstance()->Remove(0); |
| 187 | 189 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 const std::string& scheme) { | 240 const std::string& scheme) { |
| 239 if (test_fixture_->response_headers_.empty()) { | 241 if (test_fixture_->response_headers_.empty()) { |
| 240 return new URLRequestTestJob(request); | 242 return new URLRequestTestJob(request); |
| 241 } else { | 243 } else { |
| 242 return new URLRequestTestJob(request, test_fixture_->response_headers_, | 244 return new URLRequestTestJob(request, test_fixture_->response_headers_, |
| 243 test_fixture_->response_data_, false); | 245 test_fixture_->response_data_, false); |
| 244 } | 246 } |
| 245 } | 247 } |
| 246 | 248 |
| 247 MessageLoopForIO message_loop_; | 249 MessageLoopForIO message_loop_; |
| 250 ChromeThread ui_thread_; |
| 248 ChromeThread io_thread_; | 251 ChromeThread io_thread_; |
| 249 ResourceDispatcherHost host_; | 252 ResourceDispatcherHost host_; |
| 250 ResourceIPCAccumulator accum_; | 253 ResourceIPCAccumulator accum_; |
| 251 std::string response_headers_; | 254 std::string response_headers_; |
| 252 std::string response_data_; | 255 std::string response_data_; |
| 253 std::string scheme_; | 256 std::string scheme_; |
| 254 URLRequest::ProtocolFactory* old_factory_; | 257 URLRequest::ProtocolFactory* old_factory_; |
| 255 static ResourceDispatcherHostTest* test_fixture_; | 258 static ResourceDispatcherHostTest* test_fixture_; |
| 256 }; | 259 }; |
| 257 // Static. | 260 // Static. |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 | 874 |
| 872 // Sorts out all the messages we saw by request. | 875 // Sorts out all the messages we saw by request. |
| 873 ResourceIPCAccumulator::ClassifiedMessages msgs; | 876 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 874 accum_.GetClassifiedMessages(&msgs); | 877 accum_.GetClassifiedMessages(&msgs); |
| 875 ASSERT_EQ(1U, msgs.size()); | 878 ASSERT_EQ(1U, msgs.size()); |
| 876 | 879 |
| 877 ResourceResponseHead response_head; | 880 ResourceResponseHead response_head; |
| 878 GetResponseHead(msgs[0], &response_head); | 881 GetResponseHead(msgs[0], &response_head); |
| 879 ASSERT_EQ("text/plain", response_head.mime_type); | 882 ASSERT_EQ("text/plain", response_head.mime_type); |
| 880 } | 883 } |
| OLD | NEW |