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/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
11 #include "content/browser/child_process_security_policy_impl.h" | 11 #include "content/browser/child_process_security_policy_impl.h" |
12 #include "content/browser/mock_content_browser_client.h" | |
13 #include "content/common/test_url_constants.h" | 12 #include "content/common/test_url_constants.h" |
14 #include "content/public/common/url_constants.h" | 13 #include "content/public/common/url_constants.h" |
| 14 #include "content/test/test_content_browser_client.h" |
15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 const int kRendererID = 42; | 20 const int kRendererID = 42; |
21 const int kWorkerRendererID = kRendererID + 1; | 21 const int kWorkerRendererID = kRendererID + 1; |
22 | 22 |
23 class ChildProcessSecurityPolicyTestBrowserClient | 23 class ChildProcessSecurityPolicyTestBrowserClient |
24 : public content::MockContentBrowserClient { | 24 : public content::TestContentBrowserClient { |
25 public: | 25 public: |
26 ChildProcessSecurityPolicyTestBrowserClient() {} | 26 ChildProcessSecurityPolicyTestBrowserClient() {} |
27 | 27 |
28 virtual bool IsHandledURL(const GURL& url) { | 28 virtual bool IsHandledURL(const GURL& url) { |
29 return schemes_.find(url.scheme()) != schemes_.end(); | 29 return schemes_.find(url.scheme()) != schemes_.end(); |
30 } | 30 } |
31 | 31 |
32 void ClearSchemes() { | 32 void ClearSchemes() { |
33 schemes_.clear(); | 33 schemes_.clear(); |
34 } | 34 } |
35 | 35 |
36 void AddScheme(const std::string& scheme) { | 36 void AddScheme(const std::string& scheme) { |
37 schemes_.insert(scheme); | 37 schemes_.insert(scheme); |
38 } | 38 } |
39 | 39 |
40 private: | 40 private: |
41 std::set<std::string> schemes_; | 41 std::set<std::string> schemes_; |
42 }; | 42 }; |
43 | 43 |
44 } // namespace | 44 } // namespace |
45 | 45 |
46 class ChildProcessSecurityPolicyTest : public testing::Test { | 46 class ChildProcessSecurityPolicyTest : public testing::Test { |
47 public: | 47 public: |
48 ChildProcessSecurityPolicyTest() : old_browser_client_(NULL) { | 48 ChildProcessSecurityPolicyTest() : old_browser_client_(NULL) { |
49 } | 49 } |
50 | 50 |
51 virtual void SetUp() { | 51 virtual void SetUp() { |
52 old_browser_client_ = content::GetContentClient()->browser(); | 52 old_browser_client_ = content::GetContentClient()->browser(); |
53 content::GetContentClient()->set_browser(&test_browser_client_); | 53 content::GetContentClient()->set_browser_for_testing(&test_browser_client_); |
54 | 54 |
55 // Claim to always handle chrome:// URLs because the CPSP's notion of | 55 // Claim to always handle chrome:// URLs because the CPSP's notion of |
56 // allowing WebUI bindings is hard-wired to this particular scheme. | 56 // allowing WebUI bindings is hard-wired to this particular scheme. |
57 test_browser_client_.AddScheme("chrome"); | 57 test_browser_client_.AddScheme("chrome"); |
58 } | 58 } |
59 | 59 |
60 virtual void TearDown() { | 60 virtual void TearDown() { |
61 test_browser_client_.ClearSchemes(); | 61 test_browser_client_.ClearSchemes(); |
62 content::GetContentClient()->set_browser(old_browser_client_); | 62 content::GetContentClient()->set_browser_for_testing(old_browser_client_); |
63 } | 63 } |
64 | 64 |
65 protected: | 65 protected: |
66 void RegisterTestScheme(const std::string& scheme) { | 66 void RegisterTestScheme(const std::string& scheme) { |
67 test_browser_client_.AddScheme(scheme); | 67 test_browser_client_.AddScheme(scheme); |
68 } | 68 } |
69 | 69 |
70 private: | 70 private: |
71 ChildProcessSecurityPolicyTestBrowserClient test_browser_client_; | 71 ChildProcessSecurityPolicyTestBrowserClient test_browser_client_; |
72 content::ContentBrowserClient* old_browser_client_; | 72 content::ContentBrowserClient* old_browser_client_; |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 | 467 |
468 // Renderers are added and removed on the UI thread, but the policy can be | 468 // Renderers are added and removed on the UI thread, but the policy can be |
469 // queried on the IO thread. The ChildProcessSecurityPolicy needs to be | 469 // queried on the IO thread. The ChildProcessSecurityPolicy needs to be |
470 // prepared to answer policy questions about renderers who no longer exist. | 470 // prepared to answer policy questions about renderers who no longer exist. |
471 | 471 |
472 // In this case, we default to secure behavior. | 472 // In this case, we default to secure behavior. |
473 EXPECT_FALSE(p->CanRequestURL(kRendererID, url)); | 473 EXPECT_FALSE(p->CanRequestURL(kRendererID, url)); |
474 EXPECT_FALSE(p->CanReadFile(kRendererID, file)); | 474 EXPECT_FALSE(p->CanReadFile(kRendererID, file)); |
475 EXPECT_FALSE(p->HasWebUIBindings(kRendererID)); | 475 EXPECT_FALSE(p->HasWebUIBindings(kRendererID)); |
476 } | 476 } |
OLD | NEW |