OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/test/test_simple_task_runner.h" |
| 6 #include "content/common/gpu/gpu_channel.h" |
| 7 #include "content/common/gpu/gpu_channel_manager.h" |
| 8 #include "content/common/gpu/gpu_messages.h" |
| 9 #include "content/common/message_router.h" |
| 10 #include "gpu/command_buffer/common/value_state.h" |
| 11 #include "gpu/command_buffer/service/gl_utils.h" |
| 12 #include "gpu/command_buffer/service/valuebuffer_manager.h" |
| 13 #include "ipc/ipc_sync_channel.h" |
| 14 |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 |
| 17 using gpu::gles2::ValuebufferManager; |
| 18 using gpu::ValueState; |
| 19 |
| 20 namespace content { |
| 21 |
| 22 class GpuChannelManagerTest : public testing::Test { |
| 23 public: |
| 24 GpuChannelManagerTest() {} |
| 25 |
| 26 void SetUp() override { |
| 27 task_runner_ = scoped_refptr<base::SingleThreadTaskRunner>( |
| 28 new base::TestSimpleTaskRunner()); |
| 29 channel_ = IPC::SyncChannel::Create( |
| 30 &router_, task_runner_, NULL); |
| 31 manager_.reset( |
| 32 new GpuChannelManager(&router_, |
| 33 NULL, |
| 34 base::MessageLoopProxy::current().get(), |
| 35 NULL, |
| 36 channel_.get())); |
| 37 } |
| 38 |
| 39 protected: |
| 40 scoped_ptr<GpuChannelManager> manager_; |
| 41 |
| 42 private: |
| 43 base::MessageLoop message_loop_; |
| 44 |
| 45 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 46 scoped_ptr<IPC::SyncChannel> channel_; |
| 47 MessageRouter router_; |
| 48 }; |
| 49 |
| 50 TEST_F(GpuChannelManagerTest, SecureValueStateForwarding) { |
| 51 const int kClientId1 = 111; |
| 52 const int kClientId2 = 222; |
| 53 ValueState kValueState1; |
| 54 kValueState1.int_value[0] = 1111; |
| 55 ValueState kValueState2; |
| 56 kValueState2.int_value[0] = 3333; |
| 57 |
| 58 // Initialize gpu channels |
| 59 manager_->OnMessageReceived( |
| 60 GpuMsg_EstablishChannel(kClientId1, false, false)); |
| 61 GpuChannel *channel1 = manager_->LookupChannel(kClientId1); |
| 62 manager_->OnMessageReceived( |
| 63 GpuMsg_EstablishChannel(kClientId2, false, false)); |
| 64 GpuChannel *channel2 = manager_->LookupChannel(kClientId2); |
| 65 ASSERT_TRUE(channel1 != NULL); |
| 66 ASSERT_TRUE(channel2 != NULL); |
| 67 ASSERT_NE(channel1, channel2); |
| 68 |
| 69 // Make sure value states are only accessible by proper channels |
| 70 manager_->OnMessageReceived(GpuMsg_UpdateValueState( |
| 71 kClientId1, GL_MOUSE_POSITION_CHROMIUM, kValueState1)); |
| 72 manager_->OnMessageReceived(GpuMsg_UpdateValueState( |
| 73 kClientId2, GL_MOUSE_POSITION_CHROMIUM, kValueState2)); |
| 74 |
| 75 const ValueState* stubValueState1 = |
| 76 channel1->valuebuffer_manager()->GetPendingState( |
| 77 GL_MOUSE_POSITION_CHROMIUM); |
| 78 const ValueState* stubValueState2 = |
| 79 channel2->valuebuffer_manager()->GetPendingState( |
| 80 GL_MOUSE_POSITION_CHROMIUM); |
| 81 ASSERT_EQ(stubValueState1->int_value[0], kValueState1.int_value[0]); |
| 82 ASSERT_EQ(stubValueState2->int_value[0], kValueState2.int_value[0]); |
| 83 ASSERT_NE(stubValueState1->int_value[0], stubValueState2->int_value[0]); |
| 84 } |
| 85 |
| 86 } // namespace content |
OLD | NEW |