| OLD | NEW |
| 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 <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 old_browser_client_ = SetBrowserClientForTesting(&test_browser_client_); | 62 old_browser_client_ = SetBrowserClientForTesting(&test_browser_client_); |
| 63 | 63 |
| 64 // Claim to always handle chrome:// URLs because the CPSP's notion of | 64 // Claim to always handle chrome:// URLs because the CPSP's notion of |
| 65 // allowing WebUI bindings is hard-wired to this particular scheme. | 65 // allowing WebUI bindings is hard-wired to this particular scheme. |
| 66 test_browser_client_.AddScheme(kChromeUIScheme); | 66 test_browser_client_.AddScheme(kChromeUIScheme); |
| 67 | 67 |
| 68 // Claim to always handle file:// URLs like the browser would. | 68 // Claim to always handle file:// URLs like the browser would. |
| 69 // net::URLRequest::IsHandledURL() no longer claims support for default | 69 // net::URLRequest::IsHandledURL() no longer claims support for default |
| 70 // protocols as this is the responsibility of the browser (which is | 70 // protocols as this is the responsibility of the browser (which is |
| 71 // responsible for adding the appropriate ProtocolHandler). | 71 // responsible for adding the appropriate ProtocolHandler). |
| 72 test_browser_client_.AddScheme(kFileScheme); | 72 test_browser_client_.AddScheme(url::kFileScheme); |
| 73 } | 73 } |
| 74 | 74 |
| 75 virtual void TearDown() { | 75 virtual void TearDown() { |
| 76 test_browser_client_.ClearSchemes(); | 76 test_browser_client_.ClearSchemes(); |
| 77 SetBrowserClientForTesting(old_browser_client_); | 77 SetBrowserClientForTesting(old_browser_client_); |
| 78 } | 78 } |
| 79 | 79 |
| 80 protected: | 80 protected: |
| 81 void RegisterTestScheme(const std::string& scheme) { | 81 void RegisterTestScheme(const std::string& scheme) { |
| 82 test_browser_client_.AddScheme(scheme); | 82 test_browser_client_.AddScheme(scheme); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 ContentBrowserClient* old_browser_client_; | 115 ContentBrowserClient* old_browser_client_; |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 | 118 |
| 119 TEST_F(ChildProcessSecurityPolicyTest, IsWebSafeSchemeTest) { | 119 TEST_F(ChildProcessSecurityPolicyTest, IsWebSafeSchemeTest) { |
| 120 ChildProcessSecurityPolicyImpl* p = | 120 ChildProcessSecurityPolicyImpl* p = |
| 121 ChildProcessSecurityPolicyImpl::GetInstance(); | 121 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 122 | 122 |
| 123 EXPECT_TRUE(p->IsWebSafeScheme(url::kHttpScheme)); | 123 EXPECT_TRUE(p->IsWebSafeScheme(url::kHttpScheme)); |
| 124 EXPECT_TRUE(p->IsWebSafeScheme(url::kHttpsScheme)); | 124 EXPECT_TRUE(p->IsWebSafeScheme(url::kHttpsScheme)); |
| 125 EXPECT_TRUE(p->IsWebSafeScheme(kFtpScheme)); | 125 EXPECT_TRUE(p->IsWebSafeScheme(url::kFtpScheme)); |
| 126 EXPECT_TRUE(p->IsWebSafeScheme(kDataScheme)); | 126 EXPECT_TRUE(p->IsWebSafeScheme(url::kDataScheme)); |
| 127 EXPECT_TRUE(p->IsWebSafeScheme("feed")); | 127 EXPECT_TRUE(p->IsWebSafeScheme("feed")); |
| 128 EXPECT_TRUE(p->IsWebSafeScheme(kBlobScheme)); | 128 EXPECT_TRUE(p->IsWebSafeScheme(url::kBlobScheme)); |
| 129 EXPECT_TRUE(p->IsWebSafeScheme(kFileSystemScheme)); | 129 EXPECT_TRUE(p->IsWebSafeScheme(url::kFileSystemScheme)); |
| 130 | 130 |
| 131 EXPECT_FALSE(p->IsWebSafeScheme("registered-web-safe-scheme")); | 131 EXPECT_FALSE(p->IsWebSafeScheme("registered-web-safe-scheme")); |
| 132 p->RegisterWebSafeScheme("registered-web-safe-scheme"); | 132 p->RegisterWebSafeScheme("registered-web-safe-scheme"); |
| 133 EXPECT_TRUE(p->IsWebSafeScheme("registered-web-safe-scheme")); | 133 EXPECT_TRUE(p->IsWebSafeScheme("registered-web-safe-scheme")); |
| 134 | 134 |
| 135 EXPECT_FALSE(p->IsWebSafeScheme(kChromeUIScheme)); | 135 EXPECT_FALSE(p->IsWebSafeScheme(kChromeUIScheme)); |
| 136 } | 136 } |
| 137 | 137 |
| 138 TEST_F(ChildProcessSecurityPolicyTest, IsPseudoSchemeTest) { | 138 TEST_F(ChildProcessSecurityPolicyTest, IsPseudoSchemeTest) { |
| 139 ChildProcessSecurityPolicyImpl* p = | 139 ChildProcessSecurityPolicyImpl* p = |
| 140 ChildProcessSecurityPolicyImpl::GetInstance(); | 140 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 141 | 141 |
| 142 EXPECT_TRUE(p->IsPseudoScheme(kAboutScheme)); | 142 EXPECT_TRUE(p->IsPseudoScheme(kAboutScheme)); |
| 143 EXPECT_TRUE(p->IsPseudoScheme(kJavaScriptScheme)); | 143 EXPECT_TRUE(p->IsPseudoScheme(url::kJavaScriptScheme)); |
| 144 EXPECT_TRUE(p->IsPseudoScheme(kViewSourceScheme)); | 144 EXPECT_TRUE(p->IsPseudoScheme(kViewSourceScheme)); |
| 145 | 145 |
| 146 EXPECT_FALSE(p->IsPseudoScheme("registered-pseudo-scheme")); | 146 EXPECT_FALSE(p->IsPseudoScheme("registered-pseudo-scheme")); |
| 147 p->RegisterPseudoScheme("registered-pseudo-scheme"); | 147 p->RegisterPseudoScheme("registered-pseudo-scheme"); |
| 148 EXPECT_TRUE(p->IsPseudoScheme("registered-pseudo-scheme")); | 148 EXPECT_TRUE(p->IsPseudoScheme("registered-pseudo-scheme")); |
| 149 | 149 |
| 150 EXPECT_FALSE(p->IsPseudoScheme(kChromeUIScheme)); | 150 EXPECT_FALSE(p->IsPseudoScheme(kChromeUIScheme)); |
| 151 } | 151 } |
| 152 | 152 |
| 153 TEST_F(ChildProcessSecurityPolicyTest, StandardSchemesTest) { | 153 TEST_F(ChildProcessSecurityPolicyTest, StandardSchemesTest) { |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 // queried on the IO thread. The ChildProcessSecurityPolicy needs to be | 634 // queried on the IO thread. The ChildProcessSecurityPolicy needs to be |
| 635 // prepared to answer policy questions about renderers who no longer exist. | 635 // prepared to answer policy questions about renderers who no longer exist. |
| 636 | 636 |
| 637 // In this case, we default to secure behavior. | 637 // In this case, we default to secure behavior. |
| 638 EXPECT_FALSE(p->CanRequestURL(kRendererID, url)); | 638 EXPECT_FALSE(p->CanRequestURL(kRendererID, url)); |
| 639 EXPECT_FALSE(p->CanReadFile(kRendererID, file)); | 639 EXPECT_FALSE(p->CanReadFile(kRendererID, file)); |
| 640 EXPECT_FALSE(p->HasWebUIBindings(kRendererID)); | 640 EXPECT_FALSE(p->HasWebUIBindings(kRendererID)); |
| 641 } | 641 } |
| 642 | 642 |
| 643 } // namespace content | 643 } // namespace content |
| OLD | NEW |