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

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

Issue 6912001: Merge 83754 - blob_storage_controller.cc assert from this bug was caused by the fact that worker ... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/742/src/
Patch Set: Created 9 years, 7 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 "chrome/common/url_constants.h" 10 #include "chrome/common/url_constants.h"
11 #include "content/browser/child_process_security_policy.h" 11 #include "content/browser/child_process_security_policy.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 net::URLRequest::RegisterProtocolFactory(chrome::kChromeUIScheme, 21 net::URLRequest::RegisterProtocolFactory(chrome::kChromeUIScheme,
22 &net::URLRequestTestJob::Factory); 22 &net::URLRequestTestJob::Factory);
23 } 23 }
24 virtual void TearDown() { 24 virtual void TearDown() {
25 net::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 static int kWorkerRendererID = kRendererID + 1;
30 31
31 TEST_F(ChildProcessSecurityPolicyTest, IsWebSafeSchemeTest) { 32 TEST_F(ChildProcessSecurityPolicyTest, IsWebSafeSchemeTest) {
32 ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance(); 33 ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance();
33 34
34 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kHttpScheme)); 35 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kHttpScheme));
35 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kHttpsScheme)); 36 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kHttpsScheme));
36 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kFtpScheme)); 37 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kFtpScheme));
37 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kDataScheme)); 38 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kDataScheme));
38 EXPECT_TRUE(p->IsWebSafeScheme("feed")); 39 EXPECT_TRUE(p->IsWebSafeScheme("feed"));
39 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kExtensionScheme)); 40 EXPECT_TRUE(p->IsWebSafeScheme(chrome::kExtensionScheme));
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 343
343 // Revoke all permissions for the file (it should inherit its permissions 344 // Revoke all permissions for the file (it should inherit its permissions
344 // from the directory again). 345 // from the directory again).
345 p->RevokeAllPermissionsForFile(kRendererID, file); 346 p->RevokeAllPermissionsForFile(kRendererID, file);
346 EXPECT_TRUE(p->HasPermissionsForFile(kRendererID, file, 347 EXPECT_TRUE(p->HasPermissionsForFile(kRendererID, file,
347 base::PLATFORM_FILE_OPEN | 348 base::PLATFORM_FILE_OPEN |
348 base::PLATFORM_FILE_READ)); 349 base::PLATFORM_FILE_READ));
349 EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, file, 350 EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, file,
350 base::PLATFORM_FILE_TEMPORARY)); 351 base::PLATFORM_FILE_TEMPORARY));
351 p->Remove(kRendererID); 352 p->Remove(kRendererID);
353
354 // Grant file permissions for the file to main thread renderer process,
355 // make sure its worker thread renderer process inherits those.
356 p->Add(kRendererID);
357 p->GrantPermissionsForFile(kRendererID, file, base::PLATFORM_FILE_OPEN |
358 base::PLATFORM_FILE_READ);
359 EXPECT_TRUE(p->HasPermissionsForFile(kRendererID, file,
360 base::PLATFORM_FILE_OPEN |
361 base::PLATFORM_FILE_READ));
362 EXPECT_FALSE(p->HasPermissionsForFile(kRendererID, file,
363 base::PLATFORM_FILE_WRITE));
364 p->AddWorker(kWorkerRendererID, kRendererID);
365 EXPECT_TRUE(p->HasPermissionsForFile(kWorkerRendererID, file,
366 base::PLATFORM_FILE_OPEN |
367 base::PLATFORM_FILE_READ));
368 EXPECT_FALSE(p->HasPermissionsForFile(kWorkerRendererID, file,
369 base::PLATFORM_FILE_WRITE));
370 p->Remove(kRendererID);
371 EXPECT_FALSE(p->HasPermissionsForFile(kWorkerRendererID, file,
372 base::PLATFORM_FILE_OPEN |
373 base::PLATFORM_FILE_READ));
374 p->Remove(kWorkerRendererID);
352 } 375 }
353 376
354 TEST_F(ChildProcessSecurityPolicyTest, CanServiceWebUIBindings) { 377 TEST_F(ChildProcessSecurityPolicyTest, CanServiceWebUIBindings) {
355 ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance(); 378 ChildProcessSecurityPolicy* p = ChildProcessSecurityPolicy::GetInstance();
356 379
357 GURL url("chrome://thumb/http://www.google.com/"); 380 GURL url("chrome://thumb/http://www.google.com/");
358 381
359 p->Add(kRendererID); 382 p->Add(kRendererID);
360 383
361 EXPECT_FALSE(p->HasWebUIBindings(kRendererID)); 384 EXPECT_FALSE(p->HasWebUIBindings(kRendererID));
(...skipping 25 matching lines...) Expand all
387 410
388 // Renderers are added and removed on the UI thread, but the policy can be 411 // Renderers are added and removed on the UI thread, but the policy can be
389 // queried on the IO thread. The ChildProcessSecurityPolicy needs to be 412 // queried on the IO thread. The ChildProcessSecurityPolicy needs to be
390 // prepared to answer policy questions about renderers who no longer exist. 413 // prepared to answer policy questions about renderers who no longer exist.
391 414
392 // In this case, we default to secure behavior. 415 // In this case, we default to secure behavior.
393 EXPECT_FALSE(p->CanRequestURL(kRendererID, url)); 416 EXPECT_FALSE(p->CanRequestURL(kRendererID, url));
394 EXPECT_FALSE(p->CanReadFile(kRendererID, file)); 417 EXPECT_FALSE(p->CanReadFile(kRendererID, file));
395 EXPECT_FALSE(p->HasWebUIBindings(kRendererID)); 418 EXPECT_FALSE(p->HasWebUIBindings(kRendererID));
396 } 419 }
OLDNEW
« no previous file with comments | « content/browser/child_process_security_policy.cc ('k') | content/browser/worker_host/worker_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698