Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: content/browser/child_process_security_policy_unittest.cc

Issue 11274038: content/browser: Move more files into the content namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win - part2 Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/public/common/url_constants.h" 12 #include "content/public/common/url_constants.h"
13 #include "content/test/test_content_browser_client.h" 13 #include "content/test/test_content_browser_client.h"
14 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace content {
18
17 namespace { 19 namespace {
18 20
19 const int kRendererID = 42; 21 const int kRendererID = 42;
20 const int kWorkerRendererID = kRendererID + 1; 22 const int kWorkerRendererID = kRendererID + 1;
21 23
22 class ChildProcessSecurityPolicyTestBrowserClient 24 class ChildProcessSecurityPolicyTestBrowserClient
23 : public content::TestContentBrowserClient { 25 : public TestContentBrowserClient {
24 public: 26 public:
25 ChildProcessSecurityPolicyTestBrowserClient() {} 27 ChildProcessSecurityPolicyTestBrowserClient() {}
26 28
27 virtual bool IsHandledURL(const GURL& url) { 29 virtual bool IsHandledURL(const GURL& url) {
28 return schemes_.find(url.scheme()) != schemes_.end(); 30 return schemes_.find(url.scheme()) != schemes_.end();
29 } 31 }
30 32
31 void ClearSchemes() { 33 void ClearSchemes() {
32 schemes_.clear(); 34 schemes_.clear();
33 } 35 }
34 36
35 void AddScheme(const std::string& scheme) { 37 void AddScheme(const std::string& scheme) {
36 schemes_.insert(scheme); 38 schemes_.insert(scheme);
37 } 39 }
38 40
39 private: 41 private:
40 std::set<std::string> schemes_; 42 std::set<std::string> schemes_;
41 }; 43 };
42 44
43 } // namespace 45 } // namespace
44 46
45 class ChildProcessSecurityPolicyTest : public testing::Test { 47 class ChildProcessSecurityPolicyTest : public testing::Test {
46 public: 48 public:
47 ChildProcessSecurityPolicyTest() : old_browser_client_(NULL) { 49 ChildProcessSecurityPolicyTest() : old_browser_client_(NULL) {
48 } 50 }
49 51
50 virtual void SetUp() { 52 virtual void SetUp() {
51 old_browser_client_ = content::GetContentClient()->browser(); 53 old_browser_client_ = GetContentClient()->browser();
52 content::GetContentClient()->set_browser_for_testing(&test_browser_client_); 54 GetContentClient()->set_browser_for_testing(&test_browser_client_);
53 55
54 // Claim to always handle chrome:// URLs because the CPSP's notion of 56 // Claim to always handle chrome:// URLs because the CPSP's notion of
55 // allowing WebUI bindings is hard-wired to this particular scheme. 57 // allowing WebUI bindings is hard-wired to this particular scheme.
56 test_browser_client_.AddScheme("chrome"); 58 test_browser_client_.AddScheme("chrome");
57 } 59 }
58 60
59 virtual void TearDown() { 61 virtual void TearDown() {
60 test_browser_client_.ClearSchemes(); 62 test_browser_client_.ClearSchemes();
61 content::GetContentClient()->set_browser_for_testing(old_browser_client_); 63 GetContentClient()->set_browser_for_testing(old_browser_client_);
62 } 64 }
63 65
64 protected: 66 protected:
65 void RegisterTestScheme(const std::string& scheme) { 67 void RegisterTestScheme(const std::string& scheme) {
66 test_browser_client_.AddScheme(scheme); 68 test_browser_client_.AddScheme(scheme);
67 } 69 }
68 70
69 private: 71 private:
70 ChildProcessSecurityPolicyTestBrowserClient test_browser_client_; 72 ChildProcessSecurityPolicyTestBrowserClient test_browser_client_;
71 content::ContentBrowserClient* old_browser_client_; 73 ContentBrowserClient* old_browser_client_;
72 }; 74 };
73 75
74 TEST_F(ChildProcessSecurityPolicyTest, IsWebSafeSchemeTest) { 76 TEST_F(ChildProcessSecurityPolicyTest, IsWebSafeSchemeTest) {
75 ChildProcessSecurityPolicyImpl* p = 77 ChildProcessSecurityPolicyImpl* p =
76 ChildProcessSecurityPolicyImpl::GetInstance(); 78 ChildProcessSecurityPolicyImpl::GetInstance();
77 79
78 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kHttpScheme)); 80 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kHttpScheme));
79 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kHttpsScheme)); 81 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kHttpsScheme));
80 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kFtpScheme)); 82 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kFtpScheme));
81 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kDataScheme)); 83 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kDataScheme));
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 485
484 // Renderers are added and removed on the UI thread, but the policy can be 486 // Renderers are added and removed on the UI thread, but the policy can be
485 // queried on the IO thread. The ChildProcessSecurityPolicy needs to be 487 // queried on the IO thread. The ChildProcessSecurityPolicy needs to be
486 // prepared to answer policy questions about renderers who no longer exist. 488 // prepared to answer policy questions about renderers who no longer exist.
487 489
488 // In this case, we default to secure behavior. 490 // In this case, we default to secure behavior.
489 EXPECT_FALSE(p->CanRequestURL(kRendererID, url)); 491 EXPECT_FALSE(p->CanRequestURL(kRendererID, url));
490 EXPECT_FALSE(p->CanReadFile(kRendererID, file)); 492 EXPECT_FALSE(p->CanReadFile(kRendererID, file));
491 EXPECT_FALSE(p->HasWebUIBindings(kRendererID)); 493 EXPECT_FALSE(p->HasWebUIBindings(kRendererID));
492 } 494 }
495
496 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/child_process_security_policy_impl.cc ('k') | content/browser/cross_site_request_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698