| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "sandbox/mac/bootstrap_sandbox.h" | 5 #include "sandbox/mac/bootstrap_sandbox.h" |
| 6 | 6 |
| 7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
| 8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
| 9 #include <mach/mach.h> | 9 #include <mach/mach.h> |
| 10 #include <servers/bootstrap.h> | 10 #include <servers/bootstrap.h> |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 sandbox_->PrepareToForkWithPolicy(policy_id); | 100 sandbox_->PrepareToForkWithPolicy(policy_id); |
| 101 base::LaunchOptions options; | 101 base::LaunchOptions options; |
| 102 options.replacement_bootstrap_name = sandbox_->server_bootstrap_name(); | 102 options.replacement_bootstrap_name = sandbox_->server_bootstrap_name(); |
| 103 base::Process process = SpawnChildWithOptions(child_name, options); | 103 base::Process process = SpawnChildWithOptions(child_name, options); |
| 104 ASSERT_TRUE(process.IsValid()); | 104 ASSERT_TRUE(process.IsValid()); |
| 105 sandbox_->FinishedFork(process.Handle()); | 105 sandbox_->FinishedFork(process.Handle()); |
| 106 int code = 0; | 106 int code = 0; |
| 107 EXPECT_TRUE(process.WaitForExit(&code)); | 107 EXPECT_TRUE(process.WaitForExit(&code)); |
| 108 EXPECT_EQ(0, code); | 108 EXPECT_EQ(0, code); |
| 109 if (out_pid) | 109 if (out_pid) |
| 110 *out_pid = process.pid(); | 110 *out_pid = process.Pid(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 protected: | 113 protected: |
| 114 scoped_ptr<BootstrapSandbox> sandbox_; | 114 scoped_ptr<BootstrapSandbox> sandbox_; |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 const char kNotificationTestMain[] = "PostNotification"; | 117 const char kNotificationTestMain[] = "PostNotification"; |
| 118 | 118 |
| 119 // Run the test without the sandbox. | 119 // Run the test without the sandbox. |
| 120 TEST_F(BootstrapSandboxTest, DistributedNotifications_Unsandboxed) { | 120 TEST_F(BootstrapSandboxTest, DistributedNotifications_Unsandboxed) { |
| 121 base::scoped_nsobject<DistributedNotificationObserver> observer( | 121 base::scoped_nsobject<DistributedNotificationObserver> observer( |
| 122 [[DistributedNotificationObserver alloc] init]); | 122 [[DistributedNotificationObserver alloc] init]); |
| 123 | 123 |
| 124 base::Process process = SpawnChild(kNotificationTestMain); | 124 base::Process process = SpawnChild(kNotificationTestMain); |
| 125 ASSERT_TRUE(process.IsValid()); | 125 ASSERT_TRUE(process.IsValid()); |
| 126 int code = 0; | 126 int code = 0; |
| 127 EXPECT_TRUE(process.WaitForExit(&code)); | 127 EXPECT_TRUE(process.WaitForExit(&code)); |
| 128 EXPECT_EQ(0, code); | 128 EXPECT_EQ(0, code); |
| 129 | 129 |
| 130 [observer waitForNotification]; | 130 [observer waitForNotification]; |
| 131 EXPECT_EQ(1, [observer receivedCount]); | 131 EXPECT_EQ(1, [observer receivedCount]); |
| 132 EXPECT_EQ(process.pid(), [[observer object] intValue]); | 132 EXPECT_EQ(process.Pid(), [[observer object] intValue]); |
| 133 } | 133 } |
| 134 | 134 |
| 135 // Run the test with the sandbox enabled without notifications on the policy | 135 // Run the test with the sandbox enabled without notifications on the policy |
| 136 // whitelist. | 136 // whitelist. |
| 137 TEST_F(BootstrapSandboxTest, DistributedNotifications_SandboxDeny) { | 137 TEST_F(BootstrapSandboxTest, DistributedNotifications_SandboxDeny) { |
| 138 base::scoped_nsobject<DistributedNotificationObserver> observer( | 138 base::scoped_nsobject<DistributedNotificationObserver> observer( |
| 139 [[DistributedNotificationObserver alloc] init]); | 139 [[DistributedNotificationObserver alloc] init]); |
| 140 | 140 |
| 141 sandbox_->RegisterSandboxPolicy(1, BaselinePolicy()); | 141 sandbox_->RegisterSandboxPolicy(1, BaselinePolicy()); |
| 142 RunChildWithPolicy(1, kNotificationTestMain, NULL); | 142 RunChildWithPolicy(1, kNotificationTestMain, NULL); |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 kr = mach_msg_receive(&rcv_msg.header); | 509 kr = mach_msg_receive(&rcv_msg.header); |
| 510 MACH_CHECK(kr == KERN_SUCCESS, kr) << "mach_msg_receive"; | 510 MACH_CHECK(kr == KERN_SUCCESS, kr) << "mach_msg_receive"; |
| 511 | 511 |
| 512 // Try to message the sandbox. | 512 // Try to message the sandbox. |
| 513 bootstrap_look_up(bootstrap_port, "test", &port); | 513 bootstrap_look_up(bootstrap_port, "test", &port); |
| 514 | 514 |
| 515 return 0; | 515 return 0; |
| 516 } | 516 } |
| 517 | 517 |
| 518 } // namespace sandbox | 518 } // namespace sandbox |
| OLD | NEW |