| 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 <string> |    5 #include <string> | 
|    6  |    6  | 
|    7 #include "base/basictypes.h" |    7 #include "base/basictypes.h" | 
|    8 #include "base/file_path.h" |    8 #include "base/file_path.h" | 
|    9 #include "base/platform_file.h" |    9 #include "base/platform_file.h" | 
|   10 #include "chrome/browser/child_process_security_policy.h" |   10 #include "chrome/browser/child_process_security_policy.h" | 
|   11 #include "chrome/common/url_constants.h" |   11 #include "chrome/common/url_constants.h" | 
|   12 #include "net/url_request/url_request.h" |   12 #include "net/url_request/url_request.h" | 
|   13 #include "net/url_request/url_request_test_job.h" |   13 #include "net/url_request/url_request_test_job.h" | 
|   14 #include "testing/gtest/include/gtest/gtest.h" |   14 #include "testing/gtest/include/gtest/gtest.h" | 
|   15  |   15  | 
|   16 class ChildProcessSecurityPolicyTest : public testing::Test { |   16 class ChildProcessSecurityPolicyTest : public testing::Test { | 
|   17  protected: |   17  protected: | 
|   18   // testing::Test |   18   // testing::Test | 
|   19   virtual void SetUp() { |   19   virtual void SetUp() { | 
|   20     // In the real world, "chrome:" is a handled scheme. |   20     // In the real world, "chrome:" is a handled scheme. | 
|   21     URLRequest::RegisterProtocolFactory(chrome::kChromeUIScheme, |   21     net::URLRequest::RegisterProtocolFactory(chrome::kChromeUIScheme, | 
|   22                                         &URLRequestTestJob::Factory); |   22                                              &URLRequestTestJob::Factory); | 
|   23   } |   23   } | 
|   24   virtual void TearDown() { |   24   virtual void TearDown() { | 
|   25     URLRequest::RegisterProtocolFactory(chrome::kChromeUIScheme, NULL); |   25     net::URLRequest::RegisterProtocolFactory(chrome::kChromeUIScheme, NULL); | 
|   26   } |   26   } | 
|   27 }; |   27 }; | 
|   28  |   28  | 
|   29 static int kRendererID = 42; |   29 static int kRendererID = 42; | 
|   30  |   30  | 
|   31 TEST_F(ChildProcessSecurityPolicyTest, IsWebSafeSchemeTest) { |   31 TEST_F(ChildProcessSecurityPolicyTest, IsWebSafeSchemeTest) { | 
|   32   ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance(); |   32   ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance(); | 
|   33  |   33  | 
|   34   EXPECT_TRUE(p->IsWebSafeScheme(chrome::kHttpScheme)); |   34   EXPECT_TRUE(p->IsWebSafeScheme(chrome::kHttpScheme)); | 
|   35   EXPECT_TRUE(p->IsWebSafeScheme(chrome::kHttpsScheme)); |   35   EXPECT_TRUE(p->IsWebSafeScheme(chrome::kHttpsScheme)); | 
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  126  |  126  | 
|  127 TEST_F(ChildProcessSecurityPolicyTest, RegisterWebSafeSchemeTest) { |  127 TEST_F(ChildProcessSecurityPolicyTest, RegisterWebSafeSchemeTest) { | 
|  128   ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance(); |  128   ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance(); | 
|  129  |  129  | 
|  130   p->Add(kRendererID); |  130   p->Add(kRendererID); | 
|  131  |  131  | 
|  132   // Currently, "asdf" is destined for ShellExecute, so it is allowed. |  132   // Currently, "asdf" is destined for ShellExecute, so it is allowed. | 
|  133   EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("asdf:rockers"))); |  133   EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("asdf:rockers"))); | 
|  134  |  134  | 
|  135   // Once we register a ProtocolFactory for "asdf", we default to deny. |  135   // Once we register a ProtocolFactory for "asdf", we default to deny. | 
|  136   URLRequest::RegisterProtocolFactory("asdf", &URLRequestTestJob::Factory); |  136   net::URLRequest::RegisterProtocolFactory("asdf", &URLRequestTestJob::Factory); | 
|  137   EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("asdf:rockers"))); |  137   EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("asdf:rockers"))); | 
|  138  |  138  | 
|  139   // We can allow new schemes by adding them to the whitelist. |  139   // We can allow new schemes by adding them to the whitelist. | 
|  140   p->RegisterWebSafeScheme("asdf"); |  140   p->RegisterWebSafeScheme("asdf"); | 
|  141   EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("asdf:rockers"))); |  141   EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("asdf:rockers"))); | 
|  142  |  142  | 
|  143   // Cleanup. |  143   // Cleanup. | 
|  144   URLRequest::RegisterProtocolFactory("asdf", NULL); |  144   net::URLRequest::RegisterProtocolFactory("asdf", NULL); | 
|  145   EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("asdf:rockers"))); |  145   EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("asdf:rockers"))); | 
|  146  |  146  | 
|  147   p->Remove(kRendererID); |  147   p->Remove(kRendererID); | 
|  148 } |  148 } | 
|  149  |  149  | 
|  150 TEST_F(ChildProcessSecurityPolicyTest, CanServiceCommandsTest) { |  150 TEST_F(ChildProcessSecurityPolicyTest, CanServiceCommandsTest) { | 
|  151   ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance(); |  151   ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance(); | 
|  152  |  152  | 
|  153   p->Add(kRendererID); |  153   p->Add(kRendererID); | 
|  154  |  154  | 
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  323  |  323  | 
|  324   // Renderers are added and removed on the UI thread, but the policy can be |  324   // Renderers are added and removed on the UI thread, but the policy can be | 
|  325   // queried on the IO thread.  The ChildProcessSecurityPolicy needs to be |  325   // queried on the IO thread.  The ChildProcessSecurityPolicy needs to be | 
|  326   // prepared to answer policy questions about renderers who no longer exist. |  326   // prepared to answer policy questions about renderers who no longer exist. | 
|  327  |  327  | 
|  328   // In this case, we default to secure behavior. |  328   // In this case, we default to secure behavior. | 
|  329   EXPECT_FALSE(p->CanRequestURL(kRendererID, url)); |  329   EXPECT_FALSE(p->CanRequestURL(kRendererID, url)); | 
|  330   EXPECT_FALSE(p->CanReadFile(kRendererID, file)); |  330   EXPECT_FALSE(p->CanReadFile(kRendererID, file)); | 
|  331   EXPECT_FALSE(p->HasDOMUIBindings(kRendererID)); |  331   EXPECT_FALSE(p->HasDOMUIBindings(kRendererID)); | 
|  332 } |  332 } | 
| OLD | NEW |