| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| 11 #include "gpu/config/gpu_info.h" | 11 #include "gpu/config/gpu_info.h" |
| 12 #include "gpu/config/gpu_info_collector.h" | 12 #include "gpu/config/gpu_info_collector.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/gl/gl_implementation.h" | 15 #include "ui/gl/gl_implementation.h" |
| 16 #include "ui/gl/gl_mock.h" | 16 #include "ui/gl/gl_mock.h" |
| 17 #include "ui/gl/test/gl_surface_test_support.h" | 17 #include "ui/gl/test/gl_surface_test_support.h" |
| 18 | 18 |
| 19 using ::gfx::MockGLInterface; | 19 using ::gl::MockGLInterface; |
| 20 using ::testing::Return; | 20 using ::testing::Return; |
| 21 using ::testing::SetArgPointee; | 21 using ::testing::SetArgPointee; |
| 22 using ::testing::_; | 22 using ::testing::_; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // Allows testing of all configurations on all operating systems. | 26 // Allows testing of all configurations on all operating systems. |
| 27 enum MockedOperatingSystemKind { | 27 enum MockedOperatingSystemKind { |
| 28 kMockedAndroid, | 28 kMockedAndroid, |
| 29 kMockedLinux, | 29 kMockedLinux, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 44 | 44 |
| 45 class GPUInfoCollectorTest | 45 class GPUInfoCollectorTest |
| 46 : public testing::Test, | 46 : public testing::Test, |
| 47 public ::testing::WithParamInterface<MockedOperatingSystemKind> { | 47 public ::testing::WithParamInterface<MockedOperatingSystemKind> { |
| 48 public: | 48 public: |
| 49 GPUInfoCollectorTest() {} | 49 GPUInfoCollectorTest() {} |
| 50 ~GPUInfoCollectorTest() override {} | 50 ~GPUInfoCollectorTest() override {} |
| 51 | 51 |
| 52 void SetUp() override { | 52 void SetUp() override { |
| 53 testing::Test::SetUp(); | 53 testing::Test::SetUp(); |
| 54 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress); | 54 gl::SetGLGetProcAddressProc(gl::MockGLInterface::GetGLProcAddress); |
| 55 gfx::GLSurfaceTestSupport::InitializeOneOffWithMockBindings(); | 55 gl::GLSurfaceTestSupport::InitializeOneOffWithMockBindings(); |
| 56 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); | 56 gl_.reset(new ::testing::StrictMock<::gl::MockGLInterface>()); |
| 57 ::gfx::MockGLInterface::SetGLInterface(gl_.get()); | 57 ::gl::MockGLInterface::SetGLInterface(gl_.get()); |
| 58 switch (GetParam()) { | 58 switch (GetParam()) { |
| 59 case kMockedAndroid: { | 59 case kMockedAndroid: { |
| 60 test_values_.gpu.vendor_id = 0; // not implemented | 60 test_values_.gpu.vendor_id = 0; // not implemented |
| 61 test_values_.gpu.device_id = 0; // not implemented | 61 test_values_.gpu.device_id = 0; // not implemented |
| 62 test_values_.driver_vendor = ""; // not implemented | 62 test_values_.driver_vendor = ""; // not implemented |
| 63 test_values_.driver_version = "14.0"; | 63 test_values_.driver_version = "14.0"; |
| 64 test_values_.pixel_shader_version = "1.00"; | 64 test_values_.pixel_shader_version = "1.00"; |
| 65 test_values_.vertex_shader_version = "1.00"; | 65 test_values_.vertex_shader_version = "1.00"; |
| 66 test_values_.gl_renderer = "Adreno (TM) 320"; | 66 test_values_.gl_renderer = "Adreno (TM) 320"; |
| 67 test_values_.gl_vendor = "Qualcomm"; | 67 test_values_.gl_vendor = "Qualcomm"; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 test_values_.can_lose_context = false; | 129 test_values_.can_lose_context = false; |
| 130 | 130 |
| 131 EXPECT_CALL(*gl_, GetString(GL_VERSION)) | 131 EXPECT_CALL(*gl_, GetString(GL_VERSION)) |
| 132 .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>( | 132 .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>( |
| 133 test_values_.gl_version.c_str()))); | 133 test_values_.gl_version.c_str()))); |
| 134 | 134 |
| 135 // Now that that expectation is set up, we can call this helper function. | 135 // Now that that expectation is set up, we can call this helper function. |
| 136 if (gfx::WillUseGLGetStringForExtensions()) { | 136 if (gl::WillUseGLGetStringForExtensions()) { |
| 137 EXPECT_CALL(*gl_, GetString(GL_EXTENSIONS)) | 137 EXPECT_CALL(*gl_, GetString(GL_EXTENSIONS)) |
| 138 .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>( | 138 .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>( |
| 139 test_values_.gl_extensions.c_str()))); | 139 test_values_.gl_extensions.c_str()))); |
| 140 } else { | 140 } else { |
| 141 split_extensions_.clear(); | 141 split_extensions_.clear(); |
| 142 split_extensions_ = base::SplitString( | 142 split_extensions_ = base::SplitString( |
| 143 test_values_.gl_extensions, " ", | 143 test_values_.gl_extensions, " ", |
| 144 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 144 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 145 EXPECT_CALL(*gl_, GetIntegerv(GL_NUM_EXTENSIONS, _)) | 145 EXPECT_CALL(*gl_, GetIntegerv(GL_NUM_EXTENSIONS, _)) |
| 146 .WillRepeatedly(SetArgPointee<1>(split_extensions_.size())); | 146 .WillRepeatedly(SetArgPointee<1>(split_extensions_.size())); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 158 test_values_.gl_vendor.c_str()))); | 158 test_values_.gl_vendor.c_str()))); |
| 159 EXPECT_CALL(*gl_, GetString(GL_RENDERER)) | 159 EXPECT_CALL(*gl_, GetString(GL_RENDERER)) |
| 160 .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>( | 160 .WillRepeatedly(Return(reinterpret_cast<const GLubyte*>( |
| 161 test_values_.gl_renderer.c_str()))); | 161 test_values_.gl_renderer.c_str()))); |
| 162 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_SAMPLES, _)) | 162 EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_SAMPLES, _)) |
| 163 .WillOnce(SetArgPointee<1>(8)) | 163 .WillOnce(SetArgPointee<1>(8)) |
| 164 .RetiresOnSaturation(); | 164 .RetiresOnSaturation(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void TearDown() override { | 167 void TearDown() override { |
| 168 ::gfx::MockGLInterface::SetGLInterface(NULL); | 168 ::gl::MockGLInterface::SetGLInterface(NULL); |
| 169 gl_.reset(); | 169 gl_.reset(); |
| 170 gfx::ClearGLBindings(); | 170 gl::ClearGLBindings(); |
| 171 | 171 |
| 172 testing::Test::TearDown(); | 172 testing::Test::TearDown(); |
| 173 } | 173 } |
| 174 | 174 |
| 175 public: | 175 public: |
| 176 // Use StrictMock to make 100% sure we know how GL will be called. | 176 // Use StrictMock to make 100% sure we know how GL will be called. |
| 177 std::unique_ptr<::testing::StrictMock<::gfx::MockGLInterface>> gl_; | 177 std::unique_ptr<::testing::StrictMock<::gl::MockGLInterface>> gl_; |
| 178 GPUInfo test_values_; | 178 GPUInfo test_values_; |
| 179 const char* gl_shading_language_version_ = nullptr; | 179 const char* gl_shading_language_version_ = nullptr; |
| 180 | 180 |
| 181 // Persistent storage is needed for the split extension string. | 181 // Persistent storage is needed for the split extension string. |
| 182 std::vector<std::string> split_extensions_; | 182 std::vector<std::string> split_extensions_; |
| 183 }; | 183 }; |
| 184 | 184 |
| 185 INSTANTIATE_TEST_CASE_P(GPUConfig, | 185 INSTANTIATE_TEST_CASE_P(GPUConfig, |
| 186 GPUInfoCollectorTest, | 186 GPUInfoCollectorTest, |
| 187 ::testing::ValuesIn(kMockedOperatingSystemKinds)); | 187 ::testing::ValuesIn(kMockedOperatingSystemKinds)); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 | 353 |
| 354 gpu_info.gl_vendor = "Google Corporation"; | 354 gpu_info.gl_vendor = "Google Corporation"; |
| 355 gpu_info.gl_renderer = "Chrome GPU Team"; | 355 gpu_info.gl_renderer = "Chrome GPU Team"; |
| 356 IdentifyActiveGPU(&gpu_info); | 356 IdentifyActiveGPU(&gpu_info); |
| 357 EXPECT_FALSE(gpu_info.gpu.active); | 357 EXPECT_FALSE(gpu_info.gpu.active); |
| 358 EXPECT_FALSE(gpu_info.secondary_gpus[0].active); | 358 EXPECT_FALSE(gpu_info.secondary_gpus[0].active); |
| 359 } | 359 } |
| 360 | 360 |
| 361 } // namespace gpu | 361 } // namespace gpu |
| 362 | 362 |
| OLD | NEW |