| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/browser_thread.h" | 10 #include "chrome/browser/browser_thread.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 const ViewHostMsg_Resource_Request& request_data) { | 177 const ViewHostMsg_Resource_Request& request_data) { |
| 178 return NULL; | 178 return NULL; |
| 179 } | 179 } |
| 180 | 180 |
| 181 protected: | 181 protected: |
| 182 // testing::Test | 182 // testing::Test |
| 183 virtual void SetUp() { | 183 virtual void SetUp() { |
| 184 DCHECK(!test_fixture_); | 184 DCHECK(!test_fixture_); |
| 185 test_fixture_ = this; | 185 test_fixture_ = this; |
| 186 ChildProcessSecurityPolicy::GetInstance()->Add(0); | 186 ChildProcessSecurityPolicy::GetInstance()->Add(0); |
| 187 URLRequest::RegisterProtocolFactory("test", | 187 net::URLRequest::RegisterProtocolFactory( |
| 188 &ResourceDispatcherHostTest::Factory); | 188 "test", |
| 189 &ResourceDispatcherHostTest::Factory); |
| 189 EnsureTestSchemeIsAllowed(); | 190 EnsureTestSchemeIsAllowed(); |
| 190 } | 191 } |
| 191 | 192 |
| 192 virtual void TearDown() { | 193 virtual void TearDown() { |
| 193 URLRequest::RegisterProtocolFactory("test", NULL); | 194 net::URLRequest::RegisterProtocolFactory("test", NULL); |
| 194 if (!scheme_.empty()) | 195 if (!scheme_.empty()) |
| 195 URLRequest::RegisterProtocolFactory(scheme_, old_factory_); | 196 net::URLRequest::RegisterProtocolFactory(scheme_, old_factory_); |
| 196 | 197 |
| 197 DCHECK(test_fixture_ == this); | 198 DCHECK(test_fixture_ == this); |
| 198 test_fixture_ = NULL; | 199 test_fixture_ = NULL; |
| 199 | 200 |
| 200 host_.Shutdown(); | 201 host_.Shutdown(); |
| 201 | 202 |
| 202 ChildProcessSecurityPolicy::GetInstance()->Remove(0); | 203 ChildProcessSecurityPolicy::GetInstance()->Remove(0); |
| 203 | 204 |
| 204 // The plugin lib is automatically loaded during these test | 205 // The plugin lib is automatically loaded during these test |
| 205 // and we want a clean environment for other tests. | 206 // and we want a clean environment for other tests. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 // Sets a particular resource type for any request from now on. | 244 // Sets a particular resource type for any request from now on. |
| 244 void SetResourceType(ResourceType::Type type) { | 245 void SetResourceType(ResourceType::Type type) { |
| 245 resource_type_ = type; | 246 resource_type_ = type; |
| 246 } | 247 } |
| 247 | 248 |
| 248 // Intercepts requests for the given protocol. | 249 // Intercepts requests for the given protocol. |
| 249 void HandleScheme(const std::string& scheme) { | 250 void HandleScheme(const std::string& scheme) { |
| 250 DCHECK(scheme_.empty()); | 251 DCHECK(scheme_.empty()); |
| 251 DCHECK(!old_factory_); | 252 DCHECK(!old_factory_); |
| 252 scheme_ = scheme; | 253 scheme_ = scheme; |
| 253 old_factory_ = URLRequest::RegisterProtocolFactory( | 254 old_factory_ = net::URLRequest::RegisterProtocolFactory( |
| 254 scheme_, &ResourceDispatcherHostTest::Factory); | 255 scheme_, &ResourceDispatcherHostTest::Factory); |
| 255 } | 256 } |
| 256 | 257 |
| 257 // Our own URLRequestJob factory. | 258 // Our own URLRequestJob factory. |
| 258 static URLRequestJob* Factory(URLRequest* request, | 259 static URLRequestJob* Factory(net::URLRequest* request, |
| 259 const std::string& scheme) { | 260 const std::string& scheme) { |
| 260 if (test_fixture_->response_headers_.empty()) { | 261 if (test_fixture_->response_headers_.empty()) { |
| 261 return new URLRequestTestJob(request); | 262 return new URLRequestTestJob(request); |
| 262 } else { | 263 } else { |
| 263 return new URLRequestTestJob(request, test_fixture_->response_headers_, | 264 return new URLRequestTestJob(request, test_fixture_->response_headers_, |
| 264 test_fixture_->response_data_, false); | 265 test_fixture_->response_data_, false); |
| 265 } | 266 } |
| 266 } | 267 } |
| 267 | 268 |
| 268 MessageLoopForIO message_loop_; | 269 MessageLoopForIO message_loop_; |
| 269 BrowserThread ui_thread_; | 270 BrowserThread ui_thread_; |
| 270 BrowserThread io_thread_; | 271 BrowserThread io_thread_; |
| 271 ResourceDispatcherHost host_; | 272 ResourceDispatcherHost host_; |
| 272 ResourceIPCAccumulator accum_; | 273 ResourceIPCAccumulator accum_; |
| 273 std::string response_headers_; | 274 std::string response_headers_; |
| 274 std::string response_data_; | 275 std::string response_data_; |
| 275 std::string scheme_; | 276 std::string scheme_; |
| 276 URLRequest::ProtocolFactory* old_factory_; | 277 net::URLRequest::ProtocolFactory* old_factory_; |
| 277 ResourceType::Type resource_type_; | 278 ResourceType::Type resource_type_; |
| 278 static ResourceDispatcherHostTest* test_fixture_; | 279 static ResourceDispatcherHostTest* test_fixture_; |
| 279 }; | 280 }; |
| 280 // Static. | 281 // Static. |
| 281 ResourceDispatcherHostTest* ResourceDispatcherHostTest::test_fixture_ = NULL; | 282 ResourceDispatcherHostTest* ResourceDispatcherHostTest::test_fixture_ = NULL; |
| 282 | 283 |
| 283 void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id, | 284 void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id, |
| 284 int request_id, | 285 int request_id, |
| 285 const GURL& url) { | 286 const GURL& url) { |
| 286 MakeTestRequest(this, render_view_id, request_id, url); | 287 MakeTestRequest(this, render_view_id, request_id, url); |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 MakeTestRequest(&second_receiver, 1, 4, URLRequestTestJob::test_url_1()); | 645 MakeTestRequest(&second_receiver, 1, 4, URLRequestTestJob::test_url_1()); |
| 645 MakeTestRequest(this, 2, 5, URLRequestTestJob::test_url_2()); | 646 MakeTestRequest(this, 2, 5, URLRequestTestJob::test_url_2()); |
| 646 MakeTestRequest(this, 2, 6, URLRequestTestJob::test_url_3()); | 647 MakeTestRequest(this, 2, 6, URLRequestTestJob::test_url_3()); |
| 647 | 648 |
| 648 // Flush all the pending requests. | 649 // Flush all the pending requests. |
| 649 while (URLRequestTestJob::ProcessOnePendingMessage()) {} | 650 while (URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 650 } | 651 } |
| 651 | 652 |
| 652 // Test the private helper method "CalculateApproximateMemoryCost()". | 653 // Test the private helper method "CalculateApproximateMemoryCost()". |
| 653 TEST_F(ResourceDispatcherHostTest, CalculateApproximateMemoryCost) { | 654 TEST_F(ResourceDispatcherHostTest, CalculateApproximateMemoryCost) { |
| 654 URLRequest req(GURL("http://www.google.com"), NULL); | 655 net::URLRequest req(GURL("http://www.google.com"), NULL); |
| 655 EXPECT_EQ(4427, ResourceDispatcherHost::CalculateApproximateMemoryCost(&req)); | 656 EXPECT_EQ(4427, ResourceDispatcherHost::CalculateApproximateMemoryCost(&req)); |
| 656 | 657 |
| 657 // Add 9 bytes of referrer. | 658 // Add 9 bytes of referrer. |
| 658 req.set_referrer("123456789"); | 659 req.set_referrer("123456789"); |
| 659 EXPECT_EQ(4436, ResourceDispatcherHost::CalculateApproximateMemoryCost(&req)); | 660 EXPECT_EQ(4436, ResourceDispatcherHost::CalculateApproximateMemoryCost(&req)); |
| 660 | 661 |
| 661 // Add 33 bytes of upload content. | 662 // Add 33 bytes of upload content. |
| 662 std::string upload_content; | 663 std::string upload_content; |
| 663 upload_content.resize(33); | 664 upload_content.resize(33); |
| 664 std::fill(upload_content.begin(), upload_content.end(), 'x'); | 665 std::fill(upload_content.begin(), upload_content.end(), 'x'); |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1026 EXPECT_TRUE(request_info_->replace_extension_localization_templates()); | 1027 EXPECT_TRUE(request_info_->replace_extension_localization_templates()); |
| 1027 } | 1028 } |
| 1028 | 1029 |
| 1029 TEST_F(ApplyExtensionLocalizationFilterTest, GoodSchemeWrongResourceType) { | 1030 TEST_F(ApplyExtensionLocalizationFilterTest, GoodSchemeWrongResourceType) { |
| 1030 resource_type_ = ResourceType::MAIN_FRAME; | 1031 resource_type_ = ResourceType::MAIN_FRAME; |
| 1031 ResourceDispatcherHost::ApplyExtensionLocalizationFilter(*url_, | 1032 ResourceDispatcherHost::ApplyExtensionLocalizationFilter(*url_, |
| 1032 resource_type_, request_info_.get()); | 1033 resource_type_, request_info_.get()); |
| 1033 | 1034 |
| 1034 EXPECT_FALSE(request_info_->replace_extension_localization_templates()); | 1035 EXPECT_FALSE(request_info_->replace_extension_localization_templates()); |
| 1035 } | 1036 } |
| OLD | NEW |