Allow only one bookmark to be added for multiple fast starring
[chromium-blink-merge.git] / gpu / config / gpu_info_collector_unittest.cc
blob25c22ea97eb8117f717f18005716c4acf7dd2931
1 // Copyright (c) 2012 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 "base/memory/scoped_ptr.h"
6 #include "gpu/config/gpu_info.h"
7 #include "gpu/config/gpu_info_collector.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/gl/gl_implementation.h"
11 #include "ui/gl/gl_mock.h"
12 #include "ui/gl/test/gl_surface_test_support.h"
14 using ::gfx::MockGLInterface;
15 using ::testing::Return;
16 using ::testing::SetArgPointee;
17 using ::testing::_;
19 namespace gpu {
21 class GPUInfoCollectorTest : public testing::Test {
22 public:
23 GPUInfoCollectorTest() {}
24 ~GPUInfoCollectorTest() override {}
26 void SetUp() override {
27 testing::Test::SetUp();
28 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress);
29 gfx::GLSurfaceTestSupport::InitializeOneOffWithMockBindings();
30 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>());
31 ::gfx::MockGLInterface::SetGLInterface(gl_.get());
32 #if defined(OS_WIN)
33 const uint32 vendor_id = 0x10de;
34 const uint32 device_id = 0x0658;
35 const char* driver_vendor = ""; // not implemented
36 const char* driver_version = "";
37 const char* shader_version = "1.40";
38 const char* gl_renderer = "Quadro FX 380/PCI/SSE2";
39 const char* gl_vendor = "NVIDIA Corporation";
40 const char* gl_version = "3.1.0";
41 const char* gl_shading_language_version = "1.40 NVIDIA via Cg compiler";
42 const char* gl_extensions =
43 "GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
44 "GL_EXT_read_format_bgra";
45 #elif defined(OS_MACOSX)
46 const uint32 vendor_id = 0x10de;
47 const uint32 device_id = 0x0640;
48 const char* driver_vendor = ""; // not implemented
49 const char* driver_version = "1.6.18";
50 const char* shader_version = "1.20";
51 const char* gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine";
52 const char* gl_vendor = "NVIDIA Corporation";
53 const char* gl_version = "2.1 NVIDIA-1.6.18";
54 const char* gl_shading_language_version = "1.20 ";
55 const char* gl_extensions =
56 "GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
57 "GL_EXT_read_format_bgra";
58 #elif defined(OS_ANDROID)
59 const uint32 vendor_id = 0; // not implemented
60 const uint32 device_id = 0; // not implemented
61 const char* driver_vendor = ""; // not implemented
62 const char* driver_version = "14.0";
63 const char* shader_version = "1.00";
64 const char* gl_renderer = "Adreno (TM) 320";
65 const char* gl_vendor = "Qualcomm";
66 const char* gl_version = "OpenGL ES 2.0 V@14.0 AU@04.02 (CL@3206)";
67 const char* gl_shading_language_version = "1.00";
68 const char* gl_extensions =
69 "GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
70 "GL_EXT_read_format_bgra";
71 #else // defined (OS_LINUX)
72 const uint32 vendor_id = 0x10de;
73 const uint32 device_id = 0x0658;
74 const char* driver_vendor = "NVIDIA";
75 const char* driver_version = "195.36.24";
76 const char* shader_version = "1.50";
77 const char* gl_renderer = "Quadro FX 380/PCI/SSE2";
78 const char* gl_vendor = "NVIDIA Corporation";
79 const char* gl_version = "3.2.0 NVIDIA 195.36.24";
80 const char* gl_shading_language_version = "1.50 NVIDIA via Cg compiler";
81 const char* gl_extensions =
82 "GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
83 "GL_EXT_read_format_bgra";
84 #endif
85 test_values_.gpu.vendor_id = vendor_id;
86 test_values_.gpu.device_id = device_id;
87 test_values_.driver_vendor = driver_vendor;
88 test_values_.driver_version =driver_version;
89 test_values_.pixel_shader_version = shader_version;
90 test_values_.vertex_shader_version = shader_version;
91 test_values_.gl_renderer = gl_renderer;
92 test_values_.gl_vendor = gl_vendor;
93 test_values_.gl_version = gl_version;
94 test_values_.gl_extensions = gl_extensions;
95 test_values_.can_lose_context = false;
97 EXPECT_CALL(*gl_, GetString(GL_EXTENSIONS))
98 .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
99 gl_extensions)));
100 EXPECT_CALL(*gl_, GetString(GL_SHADING_LANGUAGE_VERSION))
101 .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
102 gl_shading_language_version)));
103 EXPECT_CALL(*gl_, GetString(GL_VERSION))
104 .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
105 gl_version)));
106 EXPECT_CALL(*gl_, GetString(GL_VENDOR))
107 .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
108 gl_vendor)));
109 EXPECT_CALL(*gl_, GetString(GL_RENDERER))
110 .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
111 gl_renderer)));
112 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_SAMPLES, _))
113 .WillOnce(SetArgPointee<1>(8))
114 .RetiresOnSaturation();
117 void TearDown() override {
118 ::gfx::MockGLInterface::SetGLInterface(NULL);
119 gl_.reset();
120 gfx::ClearGLBindings();
122 testing::Test::TearDown();
125 public:
126 // Use StrictMock to make 100% sure we know how GL will be called.
127 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_;
128 GPUInfo test_values_;
131 // TODO(rlp): Test the vendor and device id collection if deemed necessary as
132 // it involves several complicated mocks for each platform.
134 TEST_F(GPUInfoCollectorTest, CollectGraphicsInfoGL) {
135 GPUInfo gpu_info;
136 CollectGraphicsInfoGL(&gpu_info);
137 EXPECT_EQ(test_values_.driver_vendor,
138 gpu_info.driver_vendor);
139 #if !defined(OS_WIN)
140 // Skip Windows because the driver version is obtained from bot registry.
141 EXPECT_EQ(test_values_.driver_version,
142 gpu_info.driver_version);
143 #endif
144 EXPECT_EQ(test_values_.pixel_shader_version,
145 gpu_info.pixel_shader_version);
146 EXPECT_EQ(test_values_.vertex_shader_version,
147 gpu_info.vertex_shader_version);
148 EXPECT_EQ(test_values_.gl_version, gpu_info.gl_version);
149 EXPECT_EQ(test_values_.gl_renderer, gpu_info.gl_renderer);
150 EXPECT_EQ(test_values_.gl_vendor, gpu_info.gl_vendor);
151 EXPECT_EQ(test_values_.gl_extensions, gpu_info.gl_extensions);
154 class CollectDriverInfoGLTest : public testing::Test {
155 public:
156 CollectDriverInfoGLTest() {}
157 ~CollectDriverInfoGLTest() override {}
159 void SetUp() override {}
160 void TearDown() override {}
163 TEST_F(CollectDriverInfoGLTest, CollectDriverInfoGL) {
164 const struct {
165 const char* gl_renderer;
166 const char* gl_vendor;
167 const char* gl_version;
168 const char* expected_driver_version;
169 } kTestStrings[] = {
170 #if defined(OS_ANDROID)
171 {"Adreno (TM) 320",
172 "Qualcomm",
173 "OpenGL ES 2.0 V@14.0 AU@04.02 (CL@3206)",
174 "14.0"},
175 {"Adreno (TM) 420", "Qualcomm", "OpenGL ES 3.0 V@84.0 AU@ (CL@)", "84.0"},
176 {"PowerVR Rogue G6430",
177 "Imagination Technologies",
178 "OpenGL ES 3.1 build 1.4@3283119",
179 "1.4"},
180 {"Mali-T604", "ARM", "OpenGL ES 3.1", "0"},
181 {"NVIDIA Tegra",
182 "NVIDIA Corporation",
183 "OpenGL ES 3.1 NVIDIA 343.00",
184 "343.00"},
185 {"NVIDIA Tegra 3",
186 "NVIDIA Corporation",
187 "OpenGL ES 2.0 14.01003",
188 "14.01003"},
189 {"random GPU",
190 "random vendor",
191 "OpenGL ES 2.0 with_long_version_string=1.2.3.4",
192 "1.2"},
193 {"random GPU",
194 "random vendor",
195 "OpenGL ES 2.0 with_short_version_string=1",
196 "0"},
197 {"random GPU",
198 "random vendor",
199 "OpenGL ES 2.0 with_no_version_string",
200 "0"},
201 #elif defined(OS_MACOSX)
202 {"Intel Iris Pro OpenGL Engine",
203 "Intel Inc.",
204 "2.1 INTEL-10.6.20",
205 "10.6.20"},
206 #elif defined(OS_LINUX)
207 {"Quadro K2000/PCIe/SSE2",
208 "NVIDIA Corporation",
209 "4.4.0 NVIDIA 331.79",
210 "331.79"},
211 #endif
212 {NULL, NULL, NULL, NULL}
215 GPUInfo gpu_info;
216 for (int i = 0; kTestStrings[i].gl_renderer != NULL; ++i) {
217 gpu_info.gl_renderer = kTestStrings[i].gl_renderer;
218 gpu_info.gl_vendor = kTestStrings[i].gl_vendor;
219 gpu_info.gl_version = kTestStrings[i].gl_version;
220 EXPECT_EQ(CollectDriverInfoGL(&gpu_info), kCollectInfoSuccess);
221 EXPECT_EQ(gpu_info.driver_version, kTestStrings[i].expected_driver_version);
225 } // namespace gpu