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

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

Issue 7397008: Deprecate RegisterProtocolFactory/(Un)RegisterInterceptor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix CF tests Created 9 years, 5 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
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"
11 #include "content/common/test_url_constants.h" 11 #include "content/common/test_url_constants.h"
12 #include "content/common/url_constants.h" 12 #include "content/common/url_constants.h"
13 #include "net/url_request/url_request.h" 13 #include "net/url_request/url_request.h"
14 #include "net/url_request/url_request_test_job.h" 14 #include "net/url_request/url_request_test_job.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 class ChildProcessSecurityPolicyTest : public testing::Test { 17 class ChildProcessSecurityPolicyTest : public testing::Test {
18 protected: 18 protected:
19 // testing::Test 19 // testing::Test
20 virtual void SetUp() { 20 virtual void SetUp() {
21 // In the real world, "chrome:" is a handled scheme. 21 // In the real world, "chrome:" is a handled scheme.
22 net::URLRequest::RegisterProtocolFactory(chrome::kChromeUIScheme, 22 RegisterProtocolFactory(chrome::kChromeUIScheme,
23 &net::URLRequestTestJob::Factory); 23 &net::URLRequestTestJob::Factory);
24 } 24 }
25 virtual void TearDown() { 25 virtual void TearDown() {
26 net::URLRequest::RegisterProtocolFactory(chrome::kChromeUIScheme, NULL); 26 RegisterProtocolFactory(chrome::kChromeUIScheme, NULL);
27 }
28
29 static net::URLRequest::ProtocolFactory* RegisterProtocolFactory(
30 const std::string& scheme,
31 net::URLRequest::ProtocolFactory* factory) {
32 return net::URLRequest::Deprecated::RegisterProtocolFactory(
33 scheme, factory);
27 } 34 }
28 }; 35 };
29 36
30 static int kRendererID = 42; 37 static int kRendererID = 42;
31 static int kWorkerRendererID = kRendererID + 1; 38 static int kWorkerRendererID = kRendererID + 1;
32 39
33 TEST_F(ChildProcessSecurityPolicyTest, IsWebSafeSchemeTest) { 40 TEST_F(ChildProcessSecurityPolicyTest, IsWebSafeSchemeTest) {
34 ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance(); 41 ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance();
35 42
36 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kHttpScheme)); 43 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kHttpScheme));
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 170
164 TEST_F(ChildProcessSecurityPolicyTest, RegisterWebSafeSchemeTest) { 171 TEST_F(ChildProcessSecurityPolicyTest, RegisterWebSafeSchemeTest) {
165 ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance(); 172 ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance();
166 173
167 p->Add(kRendererID); 174 p->Add(kRendererID);
168 175
169 // Currently, "asdf" is destined for ShellExecute, so it is allowed. 176 // Currently, "asdf" is destined for ShellExecute, so it is allowed.
170 EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("asdf:rockers"))); 177 EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("asdf:rockers")));
171 178
172 // Once we register a ProtocolFactory for "asdf", we default to deny. 179 // Once we register a ProtocolFactory for "asdf", we default to deny.
173 net::URLRequest::RegisterProtocolFactory("asdf", 180 RegisterProtocolFactory("asdf",
174 &net::URLRequestTestJob::Factory); 181 &net::URLRequestTestJob::Factory);
eroman 2011/07/18 22:24:03 indentation.
175 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("asdf:rockers"))); 182 EXPECT_FALSE(p->CanRequestURL(kRendererID, GURL("asdf:rockers")));
176 183
177 // We can allow new schemes by adding them to the whitelist. 184 // We can allow new schemes by adding them to the whitelist.
178 p->RegisterWebSafeScheme("asdf"); 185 p->RegisterWebSafeScheme("asdf");
179 EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("asdf:rockers"))); 186 EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("asdf:rockers")));
180 187
181 // Cleanup. 188 // Cleanup.
182 net::URLRequest::RegisterProtocolFactory("asdf", NULL); 189 RegisterProtocolFactory("asdf", NULL);
183 EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("asdf:rockers"))); 190 EXPECT_TRUE(p->CanRequestURL(kRendererID, GURL("asdf:rockers")));
184 191
185 p->Remove(kRendererID); 192 p->Remove(kRendererID);
186 } 193 }
187 194
188 TEST_F(ChildProcessSecurityPolicyTest, CanServiceCommandsTest) { 195 TEST_F(ChildProcessSecurityPolicyTest, CanServiceCommandsTest) {
189 ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance(); 196 ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance();
190 197
191 p->Add(kRendererID); 198 p->Add(kRendererID);
192 199
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 433
427 // Renderers are added and removed on the UI thread, but the policy can be 434 // Renderers are added and removed on the UI thread, but the policy can be
428 // queried on the IO thread. The ChildProcessSecurityPolicy needs to be 435 // queried on the IO thread. The ChildProcessSecurityPolicy needs to be
429 // prepared to answer policy questions about renderers who no longer exist. 436 // prepared to answer policy questions about renderers who no longer exist.
430 437
431 // In this case, we default to secure behavior. 438 // In this case, we default to secure behavior.
432 EXPECT_FALSE(p->CanRequestURL(kRendererID, url)); 439 EXPECT_FALSE(p->CanRequestURL(kRendererID, url));
433 EXPECT_FALSE(p->CanReadFile(kRendererID, file)); 440 EXPECT_FALSE(p->CanReadFile(kRendererID, file));
434 EXPECT_FALSE(p->HasWebUIBindings(kRendererID)); 441 EXPECT_FALSE(p->HasWebUIBindings(kRendererID));
435 } 442 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698