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

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

Issue 7068007: Revise about: and chrome: url handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update special_tabs.py from Nirnimesh's codereview.chromium.org/6995057/. Created 9 years, 6 months 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
« no previous file with comments | « chrome/test/functional/special_tabs.py ('k') | content/browser/site_instance.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/browser/child_process_security_policy.h" 10 #include "content/browser/child_process_security_policy.h"
(...skipping 27 matching lines...) Expand all
38 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kFtpScheme)); 38 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kFtpScheme));
39 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kDataScheme)); 39 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kDataScheme));
40 EXPECT_TRUE(p->IsWebSafeScheme("feed")); 40 EXPECT_TRUE(p->IsWebSafeScheme("feed"));
41 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kExtensionScheme)); 41 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kExtensionScheme));
42 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kBlobScheme)); 42 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kBlobScheme));
43 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kFileSystemScheme)); 43 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kFileSystemScheme));
44 44
45 EXPECT_FALSE(p->IsWebSafeScheme("registered-web-safe-scheme")); 45 EXPECT_FALSE(p->IsWebSafeScheme("registered-web-safe-scheme"));
46 p->RegisterWebSafeScheme("registered-web-safe-scheme"); 46 p->RegisterWebSafeScheme("registered-web-safe-scheme");
47 EXPECT_TRUE(p->IsWebSafeScheme("registered-web-safe-scheme")); 47 EXPECT_TRUE(p->IsWebSafeScheme("registered-web-safe-scheme"));
48
49 EXPECT_FALSE(p->IsWebSafeScheme(chrome::kChromeUIScheme));
48 } 50 }
49 51
50 TEST_F(ChildProcessSecurityPolicyTest, IsPseudoSchemeTest) { 52 TEST_F(ChildProcessSecurityPolicyTest, IsPseudoSchemeTest) {
51 ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance(); 53 ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance();
52 54
53 EXPECT_TRUE(p->IsPseudoScheme(chrome::kAboutScheme)); 55 EXPECT_TRUE(p->IsPseudoScheme(chrome::kAboutScheme));
54 EXPECT_TRUE(p->IsPseudoScheme(chrome::kJavaScriptScheme)); 56 EXPECT_TRUE(p->IsPseudoScheme(chrome::kJavaScriptScheme));
55 EXPECT_TRUE(p->IsPseudoScheme(chrome::kViewSourceScheme)); 57 EXPECT_TRUE(p->IsPseudoScheme(chrome::kViewSourceScheme));
56 58
57 EXPECT_FALSE(p->IsPseudoScheme("registered-pseudo-scheme")); 59 EXPECT_FALSE(p->IsPseudoScheme("registered-pseudo-scheme"));
58 p->RegisterPseudoScheme("registered-pseudo-scheme"); 60 p->RegisterPseudoScheme("registered-pseudo-scheme");
59 EXPECT_TRUE(p->IsPseudoScheme("registered-pseudo-scheme")); 61 EXPECT_TRUE(p->IsPseudoScheme("registered-pseudo-scheme"));
62
63 EXPECT_FALSE(p->IsPseudoScheme(chrome::kChromeUIScheme));
60 } 64 }
61 65
62 TEST_F(ChildProcessSecurityPolicyTest, IsDisabledSchemeTest) { 66 TEST_F(ChildProcessSecurityPolicyTest, IsDisabledSchemeTest) {
63 ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance(); 67 ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance();
64 68
65 EXPECT_FALSE(p->IsDisabledScheme("evil-scheme")); 69 EXPECT_FALSE(p->IsDisabledScheme("evil-scheme"));
66 std::set<std::string> disabled_set; 70 std::set<std::string> disabled_set;
67 disabled_set.insert("evil-scheme"); 71 disabled_set.insert("evil-scheme");
68 p->RegisterDisabledSchemes(disabled_set); 72 p->RegisterDisabledSchemes(disabled_set);
69 EXPECT_TRUE(p->IsDisabledScheme("evil-scheme")); 73 EXPECT_TRUE(p->IsDisabledScheme("evil-scheme"));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 116
113 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("about:memory"))); 117 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("about:memory")));
114 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("about:crash"))); 118 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("about:crash")));
115 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("about:cache"))); 119 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("about:cache")));
116 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("about:hang"))); 120 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("about:hang")));
117 121
118 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("aBoUt:memory"))); 122 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("aBoUt:memory")));
119 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("about:CrASh"))); 123 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("about:CrASh")));
120 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("abOuT:cAChe"))); 124 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("abOuT:cAChe")));
121 125
126 // These requests for about: pages should be denied.
122 p->GrantRequestURL(kRendererID, GURL(chrome::kTestMemoryURL)); 127 p->GrantRequestURL(kRendererID, GURL(chrome::kTestMemoryURL));
123 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL(chrome::kTestMemoryURL))); 128 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL(chrome::kTestMemoryURL)));
124 129
125 p->GrantRequestURL(kRendererID, GURL(chrome::kAboutCrashURL)); 130 p->GrantRequestURL(kRendererID, GURL(chrome::kAboutCrashURL));
126 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL(chrome::kAboutCrashURL))); 131 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL(chrome::kAboutCrashURL)));
127 132
128 p->GrantRequestURL(kRendererID, GURL(chrome::kTestCacheURL)); 133 p->GrantRequestURL(kRendererID, GURL(chrome::kTestCacheURL));
129 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL(chrome::kTestCacheURL))); 134 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL(chrome::kTestCacheURL)));
130 135
131 p->GrantRequestURL(kRendererID, GURL(chrome::kTestHangURL)); 136 p->GrantRequestURL(kRendererID, GURL(chrome::kTestHangURL));
132 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL(chrome::kTestHangURL))); 137 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL(chrome::kTestHangURL)));
133 138
139 // These requests for chrome:// pages should be granted.
140 p->GrantRequestURL(kRendererID, GURL(chrome::kTestNewTabURL));
141 EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL(chrome::kTestNewTabURL)));
142
143 p->GrantRequestURL(kRendererID, GURL(chrome::kTestHistoryURL));
144 EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL(chrome::kTestHistoryURL)));
145
146 p->GrantRequestURL(kRendererID, GURL(chrome::kTestBookmarksURL));
147 EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL(chrome::kTestBookmarksURL)));
148
134 p->Remove(kRendererID); 149 p->Remove(kRendererID);
135 } 150 }
136 151
137 TEST_F(ChildProcessSecurityPolicyTest, JavaScriptTest) { 152 TEST_F(ChildProcessSecurityPolicyTest, JavaScriptTest) {
138 ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance(); 153 ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance();
139 154
140 p->Add(kRendererID); 155 p->Add(kRendererID);
141 156
142 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("javascript:alert('xss')"))); 157 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("javascript:alert('xss')")));
143 p->GrantRequestURL(kRendererID, GURL("javascript:alert('xss')")); 158 p->GrantRequestURL(kRendererID, GURL("javascript:alert('xss')"));
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 426
412 // Renderers are added and removed on the UI thread, but the policy can be 427 // Renderers are added and removed on the UI thread, but the policy can be
413 // queried on the IO thread. The ChildProcessSecurityPolicy needs to be 428 // queried on the IO thread. The ChildProcessSecurityPolicy needs to be
414 // prepared to answer policy questions about renderers who no longer exist. 429 // prepared to answer policy questions about renderers who no longer exist.
415 430
416 // In this case, we default to secure behavior. 431 // In this case, we default to secure behavior.
417 EXPECT_FALSE(p->CanRequestURL(kRendererID, url)); 432 EXPECT_FALSE(p->CanRequestURL(kRendererID, url));
418 EXPECT_FALSE(p->CanReadFile(kRendererID, file)); 433 EXPECT_FALSE(p->CanReadFile(kRendererID, file));
419 EXPECT_FALSE(p->HasWebUIBindings(kRendererID)); 434 EXPECT_FALSE(p->HasWebUIBindings(kRendererID));
420 } 435 }
OLDNEW
« no previous file with comments | « chrome/test/functional/special_tabs.py ('k') | content/browser/site_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698