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

Side by Side Diff: sandbox/mac/bootstrap_sandbox_unittest.mm

Issue 2733323002: Changing multiprocess test SpawnChild to return a struct. (Closed)
Patch Set: Fix Windows build. Created 3 years, 9 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
OLDNEW
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 void RunChildWithPolicy(int policy_id, 98 void RunChildWithPolicy(int policy_id,
99 const char* child_name, 99 const char* child_name,
100 base::ProcessHandle* out_pid) { 100 base::ProcessHandle* out_pid) {
101 std::unique_ptr<PreExecDelegate> pre_exec_delegate( 101 std::unique_ptr<PreExecDelegate> pre_exec_delegate(
102 sandbox_->NewClient(policy_id)); 102 sandbox_->NewClient(policy_id));
103 103
104 base::LaunchOptions options; 104 base::LaunchOptions options;
105 options.pre_exec_delegate = pre_exec_delegate.get(); 105 options.pre_exec_delegate = pre_exec_delegate.get();
106 106
107 base::Process process = SpawnChildWithOptions(child_name, options); 107 base::SpawnChildResult spawn_child =
108 ASSERT_TRUE(process.IsValid()); 108 SpawnChildWithOptions(child_name, options);
109 ASSERT_TRUE(spawn_child.process.IsValid());
109 int code = 0; 110 int code = 0;
110 EXPECT_TRUE(process.WaitForExit(&code)); 111 EXPECT_TRUE(spawn_child.process.WaitForExit(&code));
111 EXPECT_EQ(0, code); 112 EXPECT_EQ(0, code);
112 if (out_pid) 113 if (out_pid)
113 *out_pid = process.Pid(); 114 *out_pid = spawn_child.process.Pid();
114 } 115 }
115 116
116 protected: 117 protected:
117 std::unique_ptr<BootstrapSandbox> sandbox_; 118 std::unique_ptr<BootstrapSandbox> sandbox_;
118 }; 119 };
119 120
120 const char kNotificationTestMain[] = "PostNotification"; 121 const char kNotificationTestMain[] = "PostNotification";
121 122
122 // Run the test without the sandbox. 123 // Run the test without the sandbox.
123 TEST_F(BootstrapSandboxTest, DistributedNotifications_Unsandboxed) { 124 TEST_F(BootstrapSandboxTest, DistributedNotifications_Unsandboxed) {
124 base::scoped_nsobject<DistributedNotificationObserver> observer( 125 base::scoped_nsobject<DistributedNotificationObserver> observer(
125 [[DistributedNotificationObserver alloc] init]); 126 [[DistributedNotificationObserver alloc] init]);
126 127
127 base::Process process = SpawnChild(kNotificationTestMain); 128 base::SpawnChildResult spawn_child = SpawnChild(kNotificationTestMain);
128 ASSERT_TRUE(process.IsValid()); 129 ASSERT_TRUE(spawn_child.process.IsValid());
129 int code = 0; 130 int code = 0;
130 EXPECT_TRUE(process.WaitForExit(&code)); 131 EXPECT_TRUE(spawn_child.process.WaitForExit(&code));
131 EXPECT_EQ(0, code); 132 EXPECT_EQ(0, code);
132 133
133 [observer waitForNotification]; 134 [observer waitForNotification];
134 EXPECT_EQ(1, [observer receivedCount]); 135 EXPECT_EQ(1, [observer receivedCount]);
135 EXPECT_EQ(process.Pid(), [[observer object] intValue]); 136 EXPECT_EQ(spawn_child.process.Pid(), [[observer object] intValue]);
136 } 137 }
137 138
138 // Run the test with the sandbox enabled without notifications on the policy 139 // Run the test with the sandbox enabled without notifications on the policy
139 // whitelist. 140 // whitelist.
140 TEST_F(BootstrapSandboxTest, DistributedNotifications_SandboxDeny) { 141 TEST_F(BootstrapSandboxTest, DistributedNotifications_SandboxDeny) {
141 if (base::mac::IsAtLeastOS10_12()) { 142 if (base::mac::IsAtLeastOS10_12()) {
142 LOG(ERROR) << "BootstrapSandbox does not work on macOS Sierra or later."; 143 LOG(ERROR) << "BootstrapSandbox does not work on macOS Sierra or later.";
143 return; 144 return;
144 } 145 }
145 146
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 // Set up the policy and register the port. 465 // Set up the policy and register the port.
465 BootstrapSandboxPolicy policy(BaselinePolicy()); 466 BootstrapSandboxPolicy policy(BaselinePolicy());
466 policy.rules["sync"] = Rule(port); 467 policy.rules["sync"] = Rule(port);
467 sandbox_->RegisterSandboxPolicy(kTestPolicyId, policy); 468 sandbox_->RegisterSandboxPolicy(kTestPolicyId, policy);
468 469
469 // Launch the child. 470 // Launch the child.
470 std::unique_ptr<PreExecDelegate> pre_exec_delegate( 471 std::unique_ptr<PreExecDelegate> pre_exec_delegate(
471 sandbox_->NewClient(kTestPolicyId)); 472 sandbox_->NewClient(kTestPolicyId));
472 base::LaunchOptions options; 473 base::LaunchOptions options;
473 options.pre_exec_delegate = pre_exec_delegate.get(); 474 options.pre_exec_delegate = pre_exec_delegate.get();
474 base::Process process = SpawnChildWithOptions("ChildOutliveSandbox", options); 475 base::SpawnChildResult spawn_result =
476 SpawnChildWithOptions("ChildOutliveSandbox", options);
477 base::Process process = std::move(spawn_result.process);
475 ASSERT_TRUE(process.IsValid()); 478 ASSERT_TRUE(process.IsValid());
dcheng 2017/03/14 05:28:51 Ditto
Jay Civelli 2017/03/14 16:29:13 Done.
476 479
477 // Synchronize with the child. 480 // Synchronize with the child.
478 mach_msg_empty_rcv_t rcv_msg; 481 mach_msg_empty_rcv_t rcv_msg;
479 bzero(&rcv_msg, sizeof(rcv_msg)); 482 bzero(&rcv_msg, sizeof(rcv_msg));
480 kern_return_t kr = mach_msg(&rcv_msg.header, MACH_RCV_MSG, 0, 483 kern_return_t kr = mach_msg(&rcv_msg.header, MACH_RCV_MSG, 0,
481 sizeof(rcv_msg), port, 484 sizeof(rcv_msg), port,
482 TestTimeouts::tiny_timeout().InMilliseconds(), MACH_PORT_NULL); 485 TestTimeouts::tiny_timeout().InMilliseconds(), MACH_PORT_NULL);
483 ASSERT_EQ(KERN_SUCCESS, kr) << mach_error_string(kr); 486 ASSERT_EQ(KERN_SUCCESS, kr) << mach_error_string(kr);
484 487
485 // Destroy the sandbox. 488 // Destroy the sandbox.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 kr = mach_msg_receive(&rcv_msg.header); 543 kr = mach_msg_receive(&rcv_msg.header);
541 MACH_CHECK(kr == KERN_SUCCESS, kr) << "mach_msg_receive"; 544 MACH_CHECK(kr == KERN_SUCCESS, kr) << "mach_msg_receive";
542 545
543 // Try to message the sandbox. 546 // Try to message the sandbox.
544 bootstrap_look_up(bootstrap_port, "test", &port); 547 bootstrap_look_up(bootstrap_port, "test", &port);
545 548
546 return 0; 549 return 0;
547 } 550 }
548 551
549 } // namespace sandbox 552 } // namespace sandbox
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698