Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / common / gpu / gpu_channel_manager_unittest.cc
blobe8770e313931e8c4dc3c47c2bb1f5c0a727174c8
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.
5 #include "content/common/gpu/gpu_channel.h"
6 #include "content/common/gpu/gpu_channel_manager.h"
7 #include "content/common/gpu/gpu_channel_test_common.h"
8 #include "content/common/gpu/gpu_messages.h"
9 #include "gpu/command_buffer/common/value_state.h"
10 #include "gpu/command_buffer/service/gl_utils.h"
11 #include "gpu/command_buffer/service/valuebuffer_manager.h"
12 #include "ipc/ipc_test_sink.h"
14 using gpu::gles2::ValuebufferManager;
15 using gpu::ValueState;
17 namespace content {
19 class GpuChannelManagerTest : public GpuChannelTestCommon {
20 public:
21 GpuChannelManagerTest() : GpuChannelTestCommon() {}
22 ~GpuChannelManagerTest() override {}
25 TEST_F(GpuChannelManagerTest, EstablishChannel) {
26 int32 kClientId = 1;
27 uint64 kClientTracingId = 1;
29 ASSERT_TRUE(channel_manager());
31 EXPECT_TRUE(channel_manager()->OnMessageReceived(GpuMsg_EstablishChannel(
32 kClientId, kClientTracingId, false, false, false)));
33 EXPECT_EQ((size_t)1, sink()->message_count());
34 const IPC::Message* msg =
35 sink()->GetUniqueMessageMatching(GpuHostMsg_ChannelEstablished::ID);
36 ASSERT_TRUE(msg);
37 base::Tuple<IPC::ChannelHandle> handle;
38 ASSERT_TRUE(GpuHostMsg_ChannelEstablished::Read(msg, &handle));
39 EXPECT_NE("", base::get<0>(handle).name);
40 sink()->ClearMessages();
42 GpuChannel* channel = channel_manager()->LookupChannel(kClientId);
43 ASSERT_TRUE(channel);
44 EXPECT_EQ(base::get<0>(handle).name, channel->channel_id());
47 TEST_F(GpuChannelManagerTest, SecureValueStateForwarding) {
48 int32 kClientId1 = 111;
49 uint64 kClientTracingId1 = 11111;
50 int32 kClientId2 = 222;
51 uint64 kClientTracingId2 = 22222;
52 ValueState value_state1;
53 value_state1.int_value[0] = 1111;
54 value_state1.int_value[1] = 0;
55 value_state1.int_value[2] = 0;
56 value_state1.int_value[3] = 0;
57 ValueState value_state2;
58 value_state2.int_value[0] = 3333;
59 value_state2.int_value[1] = 0;
60 value_state2.int_value[2] = 0;
61 value_state2.int_value[3] = 0;
63 ASSERT_TRUE(channel_manager());
65 // Initialize gpu channels
66 EXPECT_TRUE(channel_manager()->OnMessageReceived(GpuMsg_EstablishChannel(
67 kClientId1, kClientTracingId1, false, false, false)));
68 GpuChannel* channel1 = channel_manager()->LookupChannel(kClientId1);
69 ASSERT_TRUE(channel1);
71 EXPECT_TRUE(channel_manager()->OnMessageReceived(GpuMsg_EstablishChannel(
72 kClientId2, kClientTracingId2, false, false, false)));
73 GpuChannel* channel2 = channel_manager()->LookupChannel(kClientId2);
74 ASSERT_TRUE(channel2);
76 EXPECT_NE(channel1, channel2);
78 // Make sure value states are only accessible by proper channels
79 channel_manager()->OnMessageReceived(GpuMsg_UpdateValueState(
80 kClientId1, GL_MOUSE_POSITION_CHROMIUM, value_state1));
81 channel_manager()->OnMessageReceived(GpuMsg_UpdateValueState(
82 kClientId2, GL_MOUSE_POSITION_CHROMIUM, value_state2));
84 const gpu::ValueStateMap* pending_value_buffer_state1 =
85 channel1->pending_valuebuffer_state();
86 const gpu::ValueStateMap* pending_value_buffer_state2 =
87 channel2->pending_valuebuffer_state();
88 EXPECT_NE(pending_value_buffer_state1, pending_value_buffer_state2);
90 const ValueState* state1 =
91 pending_value_buffer_state1->GetState(GL_MOUSE_POSITION_CHROMIUM);
92 const ValueState* state2 =
93 pending_value_buffer_state2->GetState(GL_MOUSE_POSITION_CHROMIUM);
94 EXPECT_NE(state1, state2);
96 EXPECT_EQ(state1->int_value[0], value_state1.int_value[0]);
97 EXPECT_EQ(state2->int_value[0], value_state2.int_value[0]);
98 EXPECT_NE(state1->int_value[0], state2->int_value[0]);
101 } // namespace content