| Index: content/browser/mach_broker_mac_unittest.cc
|
| diff --git a/content/browser/mach_broker_mac_unittest.cc b/content/browser/mach_broker_mac_unittest.cc
|
| index 9ba50c3109022be8757370123d8e38c2ba819fde..13f54edc50000c3d88ad1d0e052e73f7dab0e87d 100644
|
| --- a/content/browser/mach_broker_mac_unittest.cc
|
| +++ b/content/browser/mach_broker_mac_unittest.cc
|
| @@ -12,9 +12,11 @@ namespace content {
|
| class MachBrokerTest : public testing::Test {
|
| public:
|
| // Helper function to acquire/release locks and call |PlaceholderForPid()|.
|
| - void AddPlaceholderForPid(base::ProcessHandle pid, int child_process_id) {
|
| + void AddPlaceholderForPid(base::ProcessHandle pid,
|
| + int child_process_id,
|
| + bool is_gpu_process) {
|
| base::AutoLock lock(broker_.GetLock());
|
| - broker_.AddPlaceholderForPid(pid, child_process_id);
|
| + broker_.AddPlaceholderForPid(pid, child_process_id, is_gpu_process);
|
| }
|
|
|
| void InvalidateChildProcessId(int child_process_id) {
|
| @@ -32,6 +34,30 @@ class MachBrokerTest : public testing::Test {
|
| broker_.FinalizePid(pid, task_port);
|
| }
|
|
|
| + // Helper function to acquire/release locks and call |RegisterIOSurface()|.
|
| + bool RegisterIOSurface(base::ProcessHandle pid,
|
| + int io_surface_id,
|
| + int client_id,
|
| + mach_port_t io_surface_port) {
|
| + base::AutoLock lock(broker_.GetLock());
|
| + return broker_.RegisterIOSurface(pid, io_surface_id, client_id,
|
| + io_surface_port);
|
| + }
|
| +
|
| + // Helper function to acquire/release locks and call |UnregisterIOSurface()|.
|
| + void UnregisterIOSurface(base::ProcessHandle pid,
|
| + int io_surface_id,
|
| + int client_id) {
|
| + base::AutoLock lock(broker_.GetLock());
|
| + broker_.UnregisterIOSurface(pid, io_surface_id, client_id);
|
| + }
|
| +
|
| + // Helper function to acquire/release locks and call |AcquireIOSurface()|.
|
| + mach_port_t AcquireIOSurface(base::ProcessHandle pid, int io_surface_id) {
|
| + base::AutoLock lock(broker_.GetLock());
|
| + return broker_.AcquireIOSurface(pid, io_surface_id);
|
| + }
|
| +
|
| protected:
|
| MachBroker broker_;
|
| };
|
| @@ -43,7 +69,7 @@ TEST_F(MachBrokerTest, Locks) {
|
|
|
| TEST_F(MachBrokerTest, AddPlaceholderAndFinalize) {
|
| // Add a placeholder for PID 1.
|
| - AddPlaceholderForPid(1, 1);
|
| + AddPlaceholderForPid(1, 1, false);
|
| EXPECT_EQ(0u, broker_.TaskForPid(1));
|
|
|
| // Finalize PID 1.
|
| @@ -56,7 +82,7 @@ TEST_F(MachBrokerTest, AddPlaceholderAndFinalize) {
|
|
|
| TEST_F(MachBrokerTest, InvalidateChildProcessId) {
|
| // Add a placeholder for PID 1 and child process id 50.
|
| - AddPlaceholderForPid(1, 50);
|
| + AddPlaceholderForPid(1, 50, false);
|
| FinalizePid(1, 100u);
|
|
|
| EXPECT_EQ(100u, broker_.TaskForPid(1));
|
| @@ -66,7 +92,7 @@ TEST_F(MachBrokerTest, InvalidateChildProcessId) {
|
|
|
| TEST_F(MachBrokerTest, ValidateChildProcessIdMap) {
|
| // Add a placeholder for PID 1 and child process id 50.
|
| - AddPlaceholderForPid(1, 50);
|
| + AddPlaceholderForPid(1, 50, false);
|
| FinalizePid(1, 100u);
|
|
|
| EXPECT_EQ(1, GetChildProcessCount(50));
|
| @@ -80,4 +106,44 @@ TEST_F(MachBrokerTest, FinalizeUnknownPid) {
|
| EXPECT_EQ(0u, broker_.TaskForPid(1u));
|
| }
|
|
|
| +TEST_F(MachBrokerTest, IOSurfaces) {
|
| + const int kIOSurfaceId = 0;
|
| + // Add a placeholder and finalize PID 1 (GPU process).
|
| + AddPlaceholderForPid(1, 1, true);
|
| + FinalizePid(1, 100u);
|
| +
|
| + // Add a placeholder and finalize PID 2.
|
| + AddPlaceholderForPid(2, 2, false);
|
| + FinalizePid(2, 101u);
|
| +
|
| + // Add a placeholder and finalize PID 3.
|
| + AddPlaceholderForPid(3, 3, false);
|
| + FinalizePid(3, 103u);
|
| +
|
| + // Attempt to register an IOSurface using PID 2. Should fail as only GPU
|
| + // process is allowed to register IOSurfaces.
|
| + bool rv = RegisterIOSurface(2, kIOSurfaceId, 2, 200u);
|
| + EXPECT_FALSE(rv);
|
| + EXPECT_EQ(0u, AcquireIOSurface(2, kIOSurfaceId));
|
| +
|
| + // Register an IOSurface using PID 1 for usage by child process id 2.
|
| + rv = RegisterIOSurface(1, kIOSurfaceId, 2, 200u);
|
| + EXPECT_TRUE(rv);
|
| +
|
| + // PID 3 should not be able to acquire an IOSurface reference.
|
| + EXPECT_EQ(0u, AcquireIOSurface(3, kIOSurfaceId));
|
| +
|
| + // PID 2 should be able to acquire an IOSurface reference.
|
| + EXPECT_EQ(200u, AcquireIOSurface(2, kIOSurfaceId));
|
| +
|
| + // PID 2/3 should not be able to unregister IOSurface.
|
| + UnregisterIOSurface(2, kIOSurfaceId, 2);
|
| + UnregisterIOSurface(3, kIOSurfaceId, 2);
|
| + EXPECT_EQ(200u, AcquireIOSurface(2, kIOSurfaceId));
|
| +
|
| + // GPU process can unregister IOSurface.
|
| + UnregisterIOSurface(1, kIOSurfaceId, 2);
|
| + EXPECT_EQ(0u, AcquireIOSurface(2, kIOSurfaceId));
|
| +}
|
| +
|
| } // namespace content
|
|
|