Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "content/browser/gpu/gpu_data_manager_impl.h" | 9 #include "content/browser/gpu/gpu_data_manager_impl_private.h" |
| 10 #include "content/public/browser/gpu_data_manager_observer.h" | 10 #include "content/public/browser/gpu_data_manager_observer.h" |
| 11 #include "content/public/common/gpu_feature_type.h" | 11 #include "content/public/common/gpu_feature_type.h" |
| 12 #include "content/public/common/gpu_info.h" | 12 #include "content/public/common/gpu_info.h" |
| 13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 14 #include "gpu/command_buffer/service/gpu_switches.h" | 14 #include "gpu/command_buffer/service/gpu_switches.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 #define LONG_STRING_CONST(...) #__VA_ARGS__ | 17 #define LONG_STRING_CONST(...) #__VA_ARGS__ |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 static GURL GetDomain1ForTesting() { | 53 static GURL GetDomain1ForTesting() { |
| 54 return GURL("http://foo.com/"); | 54 return GURL("http://foo.com/"); |
| 55 } | 55 } |
| 56 | 56 |
| 57 static GURL GetDomain2ForTesting() { | 57 static GURL GetDomain2ForTesting() { |
| 58 return GURL("http://bar.com/"); | 58 return GURL("http://bar.com/"); |
| 59 } | 59 } |
| 60 | 60 |
| 61 } // namespace anonymous | 61 } // namespace anonymous |
| 62 | 62 |
| 63 class GpuDataManagerImplTest : public testing::Test { | 63 class GpuDataManagerImplTest : public testing::Test { |
|
Ken Russell (switch to Gerrit)
2013/05/09 20:21:16
This file should be renamed to gpu_data_manager_im
Zhenyao Mo
2013/05/09 23:35:12
Done.
| |
| 64 public: | 64 public: |
| 65 GpuDataManagerImplTest() { } | 65 GpuDataManagerImplTest() { } |
| 66 | 66 |
| 67 virtual ~GpuDataManagerImplTest() { } | 67 virtual ~GpuDataManagerImplTest() { } |
| 68 | 68 |
| 69 protected: | 69 protected: |
| 70 // scoped_ptr doesn't work with GpuDataManagerImpl because its | |
| 71 // destructor is private. GpuDataManagerImplTest is however a friend | |
| 72 // so we can make a little helper class here. | |
| 73 class ScopedGpuDataManagerImpl { | |
| 74 public: | |
| 75 ScopedGpuDataManagerImpl() : impl_(new GpuDataManagerImpl()) {} | |
| 76 ~ScopedGpuDataManagerImpl() { delete impl_; } | |
| 77 | |
| 78 GpuDataManagerImpl* get() const { return impl_; } | |
| 79 GpuDataManagerImpl* operator->() const { return impl_; } | |
| 80 // Small violation of C++ style guide to avoid polluting several | |
| 81 // tests with get() calls. | |
| 82 operator GpuDataManagerImpl*() { return impl_; } | |
| 83 | |
| 84 private: | |
| 85 GpuDataManagerImpl* impl_; | |
| 86 DISALLOW_COPY_AND_ASSIGN(ScopedGpuDataManagerImpl); | |
| 87 }; | |
| 88 | |
| 89 virtual void SetUp() { | 70 virtual void SetUp() { |
| 90 } | 71 } |
| 91 | 72 |
| 92 virtual void TearDown() { | 73 virtual void TearDown() { |
| 93 } | 74 } |
| 94 | 75 |
| 95 base::Time JustBeforeExpiration(GpuDataManagerImpl* manager); | 76 base::Time JustBeforeExpiration(const GpuDataManagerImplPrivate& manager); |
| 96 base::Time JustAfterExpiration(GpuDataManagerImpl* manager); | 77 base::Time JustAfterExpiration(const GpuDataManagerImplPrivate& manager); |
| 97 void TestBlockingDomainFrom3DAPIs( | 78 void TestBlockingDomainFrom3DAPIs( |
| 98 GpuDataManagerImpl::DomainGuilt guilt_level); | 79 GpuDataManagerImpl::DomainGuilt guilt_level); |
| 99 void TestUnblockingDomainFrom3DAPIs( | 80 void TestUnblockingDomainFrom3DAPIs( |
| 100 GpuDataManagerImpl::DomainGuilt guilt_level); | 81 GpuDataManagerImpl::DomainGuilt guilt_level); |
| 101 | 82 |
| 102 base::MessageLoop message_loop_; | 83 base::MessageLoop message_loop_; |
| 103 }; | 84 }; |
| 104 | 85 |
| 105 // We use new method instead of GetInstance() method because we want | 86 // We use new method instead of GetInstance() method because we want |
| 106 // each test to be independent of each other. | 87 // each test to be independent of each other. |
| 107 | 88 |
| 108 TEST_F(GpuDataManagerImplTest, GpuSideBlacklisting) { | 89 TEST_F(GpuDataManagerImplTest, GpuSideBlacklisting) { |
| 109 // If a feature is allowed in preliminary step (browser side), but | 90 // If a feature is allowed in preliminary step (browser side), but |
| 110 // disabled when GPU process launches and collects full GPU info, | 91 // disabled when GPU process launches and collects full GPU info, |
| 111 // it's too late to let renderer know, so we basically block all GPU | 92 // it's too late to let renderer know, so we basically block all GPU |
| 112 // access, to be on the safe side. | 93 // access, to be on the safe side. |
| 113 ScopedGpuDataManagerImpl manager; | 94 GpuDataManagerImplPrivate manager; |
| 114 ASSERT_TRUE(manager.get()); | 95 EXPECT_EQ(0u, manager.GetBlacklistedFeatureCount()); |
| 115 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | |
| 116 std::string reason; | 96 std::string reason; |
| 117 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); | 97 EXPECT_TRUE(manager.GpuAccessAllowed(&reason)); |
| 118 EXPECT_TRUE(reason.empty()); | 98 EXPECT_TRUE(reason.empty()); |
| 119 | 99 |
| 120 const std::string blacklist_json = LONG_STRING_CONST( | 100 const std::string blacklist_json = LONG_STRING_CONST( |
| 121 { | 101 { |
| 122 "name": "gpu blacklist", | 102 "name": "gpu blacklist", |
| 123 "version": "0.1", | 103 "version": "0.1", |
| 124 "entries": [ | 104 "entries": [ |
| 125 { | 105 { |
| 126 "id": 1, | 106 "id": 1, |
| 127 "features": [ | 107 "features": [ |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 138 "accelerated_2d_canvas" | 118 "accelerated_2d_canvas" |
| 139 ] | 119 ] |
| 140 } | 120 } |
| 141 ] | 121 ] |
| 142 } | 122 } |
| 143 ); | 123 ); |
| 144 | 124 |
| 145 GPUInfo gpu_info; | 125 GPUInfo gpu_info; |
| 146 gpu_info.gpu.vendor_id = 0x10de; | 126 gpu_info.gpu.vendor_id = 0x10de; |
| 147 gpu_info.gpu.device_id = 0x0640; | 127 gpu_info.gpu.device_id = 0x0640; |
| 148 manager->InitializeForTesting(blacklist_json, gpu_info); | 128 manager.InitializeForTesting(blacklist_json, gpu_info); |
| 149 | 129 |
| 150 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); | 130 EXPECT_TRUE(manager.GpuAccessAllowed(&reason)); |
| 151 EXPECT_TRUE(reason.empty()); | 131 EXPECT_TRUE(reason.empty()); |
| 152 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 132 EXPECT_EQ(1u, manager.GetBlacklistedFeatureCount()); |
| 153 EXPECT_TRUE(manager->IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)); | 133 EXPECT_TRUE(manager.IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)); |
| 154 | 134 |
| 155 gpu_info.gl_vendor = "NVIDIA"; | 135 gpu_info.gl_vendor = "NVIDIA"; |
| 156 gpu_info.gl_renderer = "NVIDIA GeForce GT 120"; | 136 gpu_info.gl_renderer = "NVIDIA GeForce GT 120"; |
| 157 manager->UpdateGpuInfo(gpu_info); | 137 manager.UpdateGpuInfo(gpu_info); |
| 158 EXPECT_FALSE(manager->GpuAccessAllowed(&reason)); | 138 EXPECT_FALSE(manager.GpuAccessAllowed(&reason)); |
| 159 EXPECT_FALSE(reason.empty()); | 139 EXPECT_FALSE(reason.empty()); |
| 160 EXPECT_EQ(2u, manager->GetBlacklistedFeatureCount()); | 140 EXPECT_EQ(2u, manager.GetBlacklistedFeatureCount()); |
| 161 EXPECT_TRUE(manager->IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)); | 141 EXPECT_TRUE(manager.IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)); |
| 162 EXPECT_TRUE(manager->IsFeatureBlacklisted( | 142 EXPECT_TRUE(manager.IsFeatureBlacklisted( |
| 163 GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); | 143 GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); |
| 164 } | 144 } |
| 165 | 145 |
| 166 TEST_F(GpuDataManagerImplTest, GpuSideExceptions) { | 146 TEST_F(GpuDataManagerImplTest, GpuSideExceptions) { |
| 167 ScopedGpuDataManagerImpl manager; | 147 GpuDataManagerImplPrivate manager; |
| 168 ASSERT_TRUE(manager.get()); | 148 EXPECT_EQ(0u, manager.GetBlacklistedFeatureCount()); |
| 169 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 149 EXPECT_TRUE(manager.GpuAccessAllowed(NULL)); |
| 170 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | |
| 171 | 150 |
| 172 const std::string blacklist_json = LONG_STRING_CONST( | 151 const std::string blacklist_json = LONG_STRING_CONST( |
| 173 { | 152 { |
| 174 "name": "gpu blacklist", | 153 "name": "gpu blacklist", |
| 175 "version": "0.1", | 154 "version": "0.1", |
| 176 "entries": [ | 155 "entries": [ |
| 177 { | 156 { |
| 178 "id": 1, | 157 "id": 1, |
| 179 "exceptions": [ | 158 "exceptions": [ |
| 180 { | 159 { |
| 181 "gl_renderer": { | 160 "gl_renderer": { |
| 182 "op": "contains", | 161 "op": "contains", |
| 183 "value": "GeForce" | 162 "value": "GeForce" |
| 184 } | 163 } |
| 185 } | 164 } |
| 186 ], | 165 ], |
| 187 "features": [ | 166 "features": [ |
| 188 "webgl" | 167 "webgl" |
| 189 ] | 168 ] |
| 190 } | 169 } |
| 191 ] | 170 ] |
| 192 } | 171 } |
| 193 ); | 172 ); |
| 194 GPUInfo gpu_info; | 173 GPUInfo gpu_info; |
| 195 gpu_info.gpu.vendor_id = 0x10de; | 174 gpu_info.gpu.vendor_id = 0x10de; |
| 196 gpu_info.gpu.device_id = 0x0640; | 175 gpu_info.gpu.device_id = 0x0640; |
| 197 manager->InitializeForTesting(blacklist_json, gpu_info); | 176 manager.InitializeForTesting(blacklist_json, gpu_info); |
| 198 | 177 |
| 199 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 178 EXPECT_TRUE(manager.GpuAccessAllowed(NULL)); |
| 200 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 179 EXPECT_EQ(0u, manager.GetBlacklistedFeatureCount()); |
| 201 | 180 |
| 202 // Now assume gpu process launches and full GPU info is collected. | 181 // Now assume gpu process launches and full GPU info is collected. |
| 203 gpu_info.gl_renderer = "NVIDIA GeForce GT 120"; | 182 gpu_info.gl_renderer = "NVIDIA GeForce GT 120"; |
| 204 manager->UpdateGpuInfo(gpu_info); | 183 manager.UpdateGpuInfo(gpu_info); |
| 205 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 184 EXPECT_TRUE(manager.GpuAccessAllowed(NULL)); |
| 206 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 185 EXPECT_EQ(0u, manager.GetBlacklistedFeatureCount()); |
| 207 } | 186 } |
| 208 | 187 |
| 209 TEST_F(GpuDataManagerImplTest, DisableHardwareAcceleration) { | 188 TEST_F(GpuDataManagerImplTest, DisableHardwareAcceleration) { |
| 210 ScopedGpuDataManagerImpl manager; | 189 GpuDataManagerImplPrivate manager; |
| 211 ASSERT_TRUE(manager.get()); | 190 EXPECT_EQ(0u, manager.GetBlacklistedFeatureCount()); |
| 212 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | |
| 213 std::string reason; | 191 std::string reason; |
| 214 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); | 192 EXPECT_TRUE(manager.GpuAccessAllowed(&reason)); |
| 215 EXPECT_TRUE(reason.empty()); | 193 EXPECT_TRUE(reason.empty()); |
| 216 | 194 |
| 217 manager->DisableHardwareAcceleration(); | 195 manager.DisableHardwareAcceleration(); |
| 218 EXPECT_FALSE(manager->GpuAccessAllowed(&reason)); | 196 EXPECT_FALSE(manager.GpuAccessAllowed(&reason)); |
| 219 EXPECT_FALSE(reason.empty()); | 197 EXPECT_FALSE(reason.empty()); |
| 220 EXPECT_EQ(static_cast<size_t>(NUMBER_OF_GPU_FEATURE_TYPES), | 198 EXPECT_EQ(static_cast<size_t>(NUMBER_OF_GPU_FEATURE_TYPES), |
| 221 manager->GetBlacklistedFeatureCount()); | 199 manager.GetBlacklistedFeatureCount()); |
| 222 } | 200 } |
| 223 | 201 |
| 224 TEST_F(GpuDataManagerImplTest, SwiftShaderRendering) { | 202 TEST_F(GpuDataManagerImplTest, SwiftShaderRendering) { |
| 225 // Blacklist, then register SwiftShader. | 203 // Blacklist, then register SwiftShader. |
| 226 ScopedGpuDataManagerImpl manager; | 204 GpuDataManagerImplPrivate manager; |
| 227 ASSERT_TRUE(manager.get()); | 205 EXPECT_EQ(0u, manager.GetBlacklistedFeatureCount()); |
| 228 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 206 EXPECT_TRUE(manager.GpuAccessAllowed(NULL)); |
| 229 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 207 EXPECT_FALSE(manager.ShouldUseSwiftShader()); |
| 230 EXPECT_FALSE(manager->ShouldUseSwiftShader()); | |
| 231 | 208 |
| 232 manager->DisableHardwareAcceleration(); | 209 manager.DisableHardwareAcceleration(); |
| 233 EXPECT_FALSE(manager->GpuAccessAllowed(NULL)); | 210 EXPECT_FALSE(manager.GpuAccessAllowed(NULL)); |
| 234 EXPECT_FALSE(manager->ShouldUseSwiftShader()); | 211 EXPECT_FALSE(manager.ShouldUseSwiftShader()); |
| 235 | 212 |
| 236 // If SwiftShader is enabled, even if we blacklist GPU, | 213 // If SwiftShader is enabled, even if we blacklist GPU, |
| 237 // GPU process is still allowed. | 214 // GPU process is still allowed. |
| 238 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath")); | 215 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath")); |
| 239 manager->RegisterSwiftShaderPath(test_path); | 216 manager.RegisterSwiftShaderPath(test_path); |
| 240 EXPECT_TRUE(manager->ShouldUseSwiftShader()); | 217 EXPECT_TRUE(manager.ShouldUseSwiftShader()); |
| 241 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 218 EXPECT_TRUE(manager.GpuAccessAllowed(NULL)); |
| 242 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 219 EXPECT_EQ(1u, manager.GetBlacklistedFeatureCount()); |
| 243 EXPECT_TRUE( | 220 EXPECT_TRUE( |
| 244 manager->IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); | 221 manager.IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); |
| 245 } | 222 } |
| 246 | 223 |
| 247 TEST_F(GpuDataManagerImplTest, SwiftShaderRendering2) { | 224 TEST_F(GpuDataManagerImplTest, SwiftShaderRendering2) { |
| 248 // Register SwiftShader, then blacklist. | 225 // Register SwiftShader, then blacklist. |
| 249 ScopedGpuDataManagerImpl manager; | 226 GpuDataManagerImplPrivate manager; |
| 250 ASSERT_TRUE(manager.get()); | 227 EXPECT_EQ(0u, manager.GetBlacklistedFeatureCount()); |
| 251 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 228 EXPECT_TRUE(manager.GpuAccessAllowed(NULL)); |
| 252 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 229 EXPECT_FALSE(manager.ShouldUseSwiftShader()); |
| 253 EXPECT_FALSE(manager->ShouldUseSwiftShader()); | |
| 254 | 230 |
| 255 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath")); | 231 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath")); |
| 256 manager->RegisterSwiftShaderPath(test_path); | 232 manager.RegisterSwiftShaderPath(test_path); |
| 257 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 233 EXPECT_EQ(0u, manager.GetBlacklistedFeatureCount()); |
| 258 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 234 EXPECT_TRUE(manager.GpuAccessAllowed(NULL)); |
| 259 EXPECT_FALSE(manager->ShouldUseSwiftShader()); | 235 EXPECT_FALSE(manager.ShouldUseSwiftShader()); |
| 260 | 236 |
| 261 manager->DisableHardwareAcceleration(); | 237 manager.DisableHardwareAcceleration(); |
| 262 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 238 EXPECT_TRUE(manager.GpuAccessAllowed(NULL)); |
| 263 EXPECT_TRUE(manager->ShouldUseSwiftShader()); | 239 EXPECT_TRUE(manager.ShouldUseSwiftShader()); |
| 264 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 240 EXPECT_EQ(1u, manager.GetBlacklistedFeatureCount()); |
| 265 EXPECT_TRUE( | 241 EXPECT_TRUE( |
| 266 manager->IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); | 242 manager.IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); |
| 267 } | 243 } |
| 268 | 244 |
| 269 TEST_F(GpuDataManagerImplTest, GpuInfoUpdate) { | 245 TEST_F(GpuDataManagerImplTest, GpuInfoUpdate) { |
| 270 ScopedGpuDataManagerImpl manager; | 246 GpuDataManagerImplPrivate manager; |
| 271 ASSERT_TRUE(manager.get()); | |
| 272 | 247 |
| 273 TestObserver observer; | 248 TestObserver observer; |
| 274 manager->AddObserver(&observer); | 249 manager.AddObserver(&observer); |
| 275 | 250 |
| 276 { | 251 { |
| 277 base::RunLoop run_loop; | 252 base::RunLoop run_loop; |
| 278 run_loop.RunUntilIdle(); | 253 run_loop.RunUntilIdle(); |
| 279 } | 254 } |
| 280 EXPECT_FALSE(observer.gpu_info_updated()); | 255 EXPECT_FALSE(observer.gpu_info_updated()); |
| 281 | 256 |
| 282 GPUInfo gpu_info; | 257 GPUInfo gpu_info; |
| 283 manager->UpdateGpuInfo(gpu_info); | 258 manager.UpdateGpuInfo(gpu_info); |
| 284 { | 259 { |
| 285 base::RunLoop run_loop; | 260 base::RunLoop run_loop; |
| 286 run_loop.RunUntilIdle(); | 261 run_loop.RunUntilIdle(); |
| 287 } | 262 } |
| 288 EXPECT_TRUE(observer.gpu_info_updated()); | 263 EXPECT_TRUE(observer.gpu_info_updated()); |
| 289 } | 264 } |
| 290 | 265 |
| 291 TEST_F(GpuDataManagerImplTest, NoGpuInfoUpdateWithSwiftShader) { | 266 TEST_F(GpuDataManagerImplTest, NoGpuInfoUpdateWithSwiftShader) { |
| 292 ScopedGpuDataManagerImpl manager; | 267 GpuDataManagerImplPrivate manager; |
| 293 ASSERT_TRUE(manager.get()); | |
| 294 | 268 |
| 295 manager->DisableHardwareAcceleration(); | 269 manager.DisableHardwareAcceleration(); |
| 296 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath")); | 270 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath")); |
| 297 manager->RegisterSwiftShaderPath(test_path); | 271 manager.RegisterSwiftShaderPath(test_path); |
| 298 EXPECT_TRUE(manager->ShouldUseSwiftShader()); | 272 EXPECT_TRUE(manager.ShouldUseSwiftShader()); |
| 299 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 273 EXPECT_TRUE(manager.GpuAccessAllowed(NULL)); |
| 300 | 274 |
| 301 { | 275 { |
| 302 base::RunLoop run_loop; | 276 base::RunLoop run_loop; |
| 303 run_loop.RunUntilIdle(); | 277 run_loop.RunUntilIdle(); |
| 304 } | 278 } |
| 305 | 279 |
| 306 TestObserver observer; | 280 TestObserver observer; |
| 307 manager->AddObserver(&observer); | 281 manager.AddObserver(&observer); |
| 308 { | 282 { |
| 309 base::RunLoop run_loop; | 283 base::RunLoop run_loop; |
| 310 run_loop.RunUntilIdle(); | 284 run_loop.RunUntilIdle(); |
| 311 } | 285 } |
| 312 EXPECT_FALSE(observer.gpu_info_updated()); | 286 EXPECT_FALSE(observer.gpu_info_updated()); |
| 313 | 287 |
| 314 GPUInfo gpu_info; | 288 GPUInfo gpu_info; |
| 315 manager->UpdateGpuInfo(gpu_info); | 289 manager.UpdateGpuInfo(gpu_info); |
| 316 { | 290 { |
| 317 base::RunLoop run_loop; | 291 base::RunLoop run_loop; |
| 318 run_loop.RunUntilIdle(); | 292 run_loop.RunUntilIdle(); |
| 319 } | 293 } |
| 320 EXPECT_FALSE(observer.gpu_info_updated()); | 294 EXPECT_FALSE(observer.gpu_info_updated()); |
| 321 } | 295 } |
| 322 | 296 |
| 323 TEST_F(GpuDataManagerImplTest, GPUVideoMemoryUsageStatsUpdate) { | 297 TEST_F(GpuDataManagerImplTest, GPUVideoMemoryUsageStatsUpdate) { |
| 324 ScopedGpuDataManagerImpl manager; | 298 GpuDataManagerImplPrivate manager; |
| 325 ASSERT_TRUE(manager.get()); | |
| 326 | 299 |
| 327 TestObserver observer; | 300 TestObserver observer; |
| 328 manager->AddObserver(&observer); | 301 manager.AddObserver(&observer); |
| 329 | 302 |
| 330 { | 303 { |
| 331 base::RunLoop run_loop; | 304 base::RunLoop run_loop; |
| 332 run_loop.RunUntilIdle(); | 305 run_loop.RunUntilIdle(); |
| 333 } | 306 } |
| 334 EXPECT_FALSE(observer.video_memory_usage_stats_updated()); | 307 EXPECT_FALSE(observer.video_memory_usage_stats_updated()); |
| 335 | 308 |
| 336 GPUVideoMemoryUsageStats vram_stats; | 309 GPUVideoMemoryUsageStats vram_stats; |
| 337 manager->UpdateVideoMemoryUsageStats(vram_stats); | 310 manager.UpdateVideoMemoryUsageStats(vram_stats); |
| 338 { | 311 { |
| 339 base::RunLoop run_loop; | 312 base::RunLoop run_loop; |
| 340 run_loop.RunUntilIdle(); | 313 run_loop.RunUntilIdle(); |
| 341 } | 314 } |
| 342 EXPECT_TRUE(observer.video_memory_usage_stats_updated()); | 315 EXPECT_TRUE(observer.video_memory_usage_stats_updated()); |
| 343 } | 316 } |
| 344 | 317 |
| 345 base::Time GpuDataManagerImplTest::JustBeforeExpiration( | 318 base::Time GpuDataManagerImplTest::JustBeforeExpiration( |
| 346 GpuDataManagerImpl* manager) { | 319 const GpuDataManagerImplPrivate& manager) { |
| 347 return GetTimeForTesting() + base::TimeDelta::FromMilliseconds( | 320 return GetTimeForTesting() + base::TimeDelta::FromMilliseconds( |
| 348 manager->GetBlockAllDomainsDurationInMs()) - | 321 manager.GetBlockAllDomainsDurationInMs()) - |
| 349 base::TimeDelta::FromMilliseconds(3); | 322 base::TimeDelta::FromMilliseconds(3); |
| 350 } | 323 } |
| 351 | 324 |
| 352 base::Time GpuDataManagerImplTest::JustAfterExpiration( | 325 base::Time GpuDataManagerImplTest::JustAfterExpiration( |
| 353 GpuDataManagerImpl* manager) { | 326 const GpuDataManagerImplPrivate& manager) { |
| 354 return GetTimeForTesting() + base::TimeDelta::FromMilliseconds( | 327 return GetTimeForTesting() + base::TimeDelta::FromMilliseconds( |
| 355 manager->GetBlockAllDomainsDurationInMs()) + | 328 manager.GetBlockAllDomainsDurationInMs()) + |
| 356 base::TimeDelta::FromMilliseconds(3); | 329 base::TimeDelta::FromMilliseconds(3); |
| 357 } | 330 } |
| 358 | 331 |
| 359 void GpuDataManagerImplTest::TestBlockingDomainFrom3DAPIs( | 332 void GpuDataManagerImplTest::TestBlockingDomainFrom3DAPIs( |
| 360 GpuDataManagerImpl::DomainGuilt guilt_level) { | 333 GpuDataManagerImpl::DomainGuilt guilt_level) { |
| 361 ScopedGpuDataManagerImpl manager; | 334 GpuDataManagerImplPrivate manager; |
| 362 ASSERT_TRUE(manager.get()); | |
| 363 | 335 |
| 364 manager->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(), | 336 manager.BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(), |
| 365 guilt_level, | 337 guilt_level, |
| 366 GetTimeForTesting()); | 338 GetTimeForTesting()); |
| 367 | 339 |
| 368 // This domain should be blocked no matter what. | 340 // This domain should be blocked no matter what. |
| 369 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED, | 341 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED, |
| 370 manager->Are3DAPIsBlockedAtTime(GetDomain1ForTesting(), | 342 manager.Are3DAPIsBlockedAtTime(GetDomain1ForTesting(), |
| 371 GetTimeForTesting())); | 343 GetTimeForTesting())); |
| 372 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED, | 344 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED, |
| 373 manager->Are3DAPIsBlockedAtTime(GetDomain1ForTesting(), | 345 manager.Are3DAPIsBlockedAtTime( |
| 374 JustBeforeExpiration(manager))); | 346 GetDomain1ForTesting(), JustBeforeExpiration(manager))); |
| 375 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED, | 347 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED, |
| 376 manager->Are3DAPIsBlockedAtTime(GetDomain1ForTesting(), | 348 manager.Are3DAPIsBlockedAtTime( |
| 377 JustAfterExpiration(manager))); | 349 GetDomain1ForTesting(), JustAfterExpiration(manager))); |
| 378 } | 350 } |
| 379 | 351 |
| 380 void GpuDataManagerImplTest::TestUnblockingDomainFrom3DAPIs( | 352 void GpuDataManagerImplTest::TestUnblockingDomainFrom3DAPIs( |
| 381 GpuDataManagerImpl::DomainGuilt guilt_level) { | 353 GpuDataManagerImpl::DomainGuilt guilt_level) { |
| 382 ScopedGpuDataManagerImpl manager; | 354 GpuDataManagerImplPrivate manager; |
| 383 ASSERT_TRUE(manager.get()); | |
| 384 | 355 |
| 385 manager->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(), | 356 manager.BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(), |
| 386 guilt_level, | 357 guilt_level, |
| 387 GetTimeForTesting()); | 358 GetTimeForTesting()); |
| 388 | 359 |
| 389 // Unblocking the domain should work. | 360 // Unblocking the domain should work. |
| 390 manager->UnblockDomainFrom3DAPIs(GetDomain1ForTesting()); | 361 manager.UnblockDomainFrom3DAPIs(GetDomain1ForTesting()); |
| 391 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED, | 362 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED, |
| 392 manager->Are3DAPIsBlockedAtTime(GetDomain1ForTesting(), | 363 manager.Are3DAPIsBlockedAtTime(GetDomain1ForTesting(), |
| 393 GetTimeForTesting())); | 364 GetTimeForTesting())); |
| 394 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED, | 365 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED, |
| 395 manager->Are3DAPIsBlockedAtTime(GetDomain1ForTesting(), | 366 manager.Are3DAPIsBlockedAtTime( |
| 396 JustBeforeExpiration(manager))); | 367 GetDomain1ForTesting(), JustBeforeExpiration(manager))); |
| 397 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED, | 368 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED, |
| 398 manager->Are3DAPIsBlockedAtTime(GetDomain1ForTesting(), | 369 manager.Are3DAPIsBlockedAtTime( |
| 399 JustAfterExpiration(manager))); | 370 GetDomain1ForTesting(), JustAfterExpiration(manager))); |
| 400 } | 371 } |
| 401 | 372 |
| 402 TEST_F(GpuDataManagerImplTest, BlockGuiltyDomainFrom3DAPIs) { | 373 TEST_F(GpuDataManagerImplTest, BlockGuiltyDomainFrom3DAPIs) { |
| 403 TestBlockingDomainFrom3DAPIs(GpuDataManagerImpl::DOMAIN_GUILT_KNOWN); | 374 TestBlockingDomainFrom3DAPIs(GpuDataManagerImpl::DOMAIN_GUILT_KNOWN); |
| 404 } | 375 } |
| 405 | 376 |
| 406 TEST_F(GpuDataManagerImplTest, BlockDomainOfUnknownGuiltFrom3DAPIs) { | 377 TEST_F(GpuDataManagerImplTest, BlockDomainOfUnknownGuiltFrom3DAPIs) { |
| 407 TestBlockingDomainFrom3DAPIs(GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN); | 378 TestBlockingDomainFrom3DAPIs(GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN); |
| 408 } | 379 } |
| 409 | 380 |
| 410 TEST_F(GpuDataManagerImplTest, BlockAllDomainsFrom3DAPIs) { | 381 TEST_F(GpuDataManagerImplTest, BlockAllDomainsFrom3DAPIs) { |
| 411 ScopedGpuDataManagerImpl manager; | 382 GpuDataManagerImplPrivate manager; |
| 412 ASSERT_TRUE(manager.get()); | |
| 413 | 383 |
| 414 manager->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(), | 384 manager.BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(), |
| 415 GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN, | 385 GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN, |
| 416 GetTimeForTesting()); | 386 GetTimeForTesting()); |
| 417 | 387 |
| 418 // Blocking of other domains should expire. | 388 // Blocking of other domains should expire. |
| 419 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_ALL_DOMAINS_BLOCKED, | 389 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_ALL_DOMAINS_BLOCKED, |
| 420 manager->Are3DAPIsBlockedAtTime(GetDomain2ForTesting(), | 390 manager.Are3DAPIsBlockedAtTime( |
| 421 JustBeforeExpiration(manager))); | 391 GetDomain2ForTesting(), JustBeforeExpiration(manager))); |
| 422 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED, | 392 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED, |
| 423 manager->Are3DAPIsBlockedAtTime(GetDomain2ForTesting(), | 393 manager.Are3DAPIsBlockedAtTime( |
| 424 JustAfterExpiration(manager))); | 394 GetDomain2ForTesting(), JustAfterExpiration(manager))); |
| 425 } | 395 } |
| 426 | 396 |
| 427 TEST_F(GpuDataManagerImplTest, UnblockGuiltyDomainFrom3DAPIs) { | 397 TEST_F(GpuDataManagerImplTest, UnblockGuiltyDomainFrom3DAPIs) { |
| 428 TestUnblockingDomainFrom3DAPIs(GpuDataManagerImpl::DOMAIN_GUILT_KNOWN); | 398 TestUnblockingDomainFrom3DAPIs(GpuDataManagerImpl::DOMAIN_GUILT_KNOWN); |
| 429 } | 399 } |
| 430 | 400 |
| 431 TEST_F(GpuDataManagerImplTest, UnblockDomainOfUnknownGuiltFrom3DAPIs) { | 401 TEST_F(GpuDataManagerImplTest, UnblockDomainOfUnknownGuiltFrom3DAPIs) { |
| 432 TestUnblockingDomainFrom3DAPIs(GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN); | 402 TestUnblockingDomainFrom3DAPIs(GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN); |
| 433 } | 403 } |
| 434 | 404 |
| 435 TEST_F(GpuDataManagerImplTest, UnblockOtherDomainFrom3DAPIs) { | 405 TEST_F(GpuDataManagerImplTest, UnblockOtherDomainFrom3DAPIs) { |
| 436 ScopedGpuDataManagerImpl manager; | 406 GpuDataManagerImplPrivate manager; |
| 437 ASSERT_TRUE(manager.get()); | |
| 438 | 407 |
| 439 manager->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(), | 408 manager.BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(), |
| 440 GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN, | 409 GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN, |
| 441 GetTimeForTesting()); | 410 GetTimeForTesting()); |
| 442 | 411 |
| 443 manager->UnblockDomainFrom3DAPIs(GetDomain2ForTesting()); | 412 manager.UnblockDomainFrom3DAPIs(GetDomain2ForTesting()); |
| 444 | 413 |
| 445 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED, | 414 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED, |
| 446 manager->Are3DAPIsBlockedAtTime(GetDomain2ForTesting(), | 415 manager.Are3DAPIsBlockedAtTime( |
| 447 JustBeforeExpiration(manager))); | 416 GetDomain2ForTesting(), JustBeforeExpiration(manager))); |
| 448 | 417 |
| 449 // The original domain should still be blocked. | 418 // The original domain should still be blocked. |
| 450 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED, | 419 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED, |
| 451 manager->Are3DAPIsBlockedAtTime(GetDomain1ForTesting(), | 420 manager.Are3DAPIsBlockedAtTime( |
| 452 JustBeforeExpiration(manager))); | 421 GetDomain1ForTesting(), JustBeforeExpiration(manager))); |
| 453 } | 422 } |
| 454 | 423 |
| 455 TEST_F(GpuDataManagerImplTest, UnblockThisDomainFrom3DAPIs) { | 424 TEST_F(GpuDataManagerImplTest, UnblockThisDomainFrom3DAPIs) { |
| 456 ScopedGpuDataManagerImpl manager; | 425 GpuDataManagerImplPrivate manager; |
| 457 ASSERT_TRUE(manager.get()); | |
| 458 | 426 |
| 459 manager->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(), | 427 manager.BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(), |
| 460 GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN, | 428 GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN, |
| 461 GetTimeForTesting()); | 429 GetTimeForTesting()); |
| 462 | 430 |
| 463 manager->UnblockDomainFrom3DAPIs(GetDomain1ForTesting()); | 431 manager.UnblockDomainFrom3DAPIs(GetDomain1ForTesting()); |
| 464 | 432 |
| 465 // This behavior is debatable. Perhaps the GPU reset caused by | 433 // This behavior is debatable. Perhaps the GPU reset caused by |
| 466 // domain 1 should still cause other domains to be blocked. | 434 // domain 1 should still cause other domains to be blocked. |
| 467 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED, | 435 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED, |
| 468 manager->Are3DAPIsBlockedAtTime(GetDomain2ForTesting(), | 436 manager.Are3DAPIsBlockedAtTime( |
| 469 JustBeforeExpiration(manager))); | 437 GetDomain2ForTesting(), JustBeforeExpiration(manager))); |
| 470 } | 438 } |
| 471 | 439 |
| 472 #if defined(OS_LINUX) | 440 #if defined(OS_LINUX) |
| 473 TEST_F(GpuDataManagerImplTest, SetGLStrings) { | 441 TEST_F(GpuDataManagerImplTest, SetGLStrings) { |
| 474 const char* kGLVendorMesa = "Tungsten Graphics, Inc"; | 442 const char* kGLVendorMesa = "Tungsten Graphics, Inc"; |
| 475 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41"; | 443 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41"; |
| 476 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL"; | 444 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL"; |
| 477 | 445 |
| 478 ScopedGpuDataManagerImpl manager; | 446 GpuDataManagerImplPrivate manager; |
| 479 ASSERT_TRUE(manager.get()); | 447 EXPECT_EQ(0u, manager.GetBlacklistedFeatureCount()); |
| 480 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 448 EXPECT_TRUE(manager.GpuAccessAllowed(NULL)); |
| 481 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | |
| 482 | 449 |
| 483 const std::string blacklist_json = LONG_STRING_CONST( | 450 const std::string blacklist_json = LONG_STRING_CONST( |
| 484 { | 451 { |
| 485 "name": "gpu blacklist", | 452 "name": "gpu blacklist", |
| 486 "version": "0.1", | 453 "version": "0.1", |
| 487 "entries": [ | 454 "entries": [ |
| 488 { | 455 { |
| 489 "id": 1, | 456 "id": 1, |
| 490 "vendor_id": "0x8086", | 457 "vendor_id": "0x8086", |
| 491 "exceptions": [ | 458 "exceptions": [ |
| 492 { | 459 { |
| 493 "device_id": ["0x0042"], | 460 "device_id": ["0x0042"], |
| 494 "driver_version": { | 461 "driver_version": { |
| 495 "op": ">=", | 462 "op": ">=", |
| 496 "number": "8.0.2" | 463 "number": "8.0.2" |
| 497 } | 464 } |
| 498 } | 465 } |
| 499 ], | 466 ], |
| 500 "features": [ | 467 "features": [ |
| 501 "webgl" | 468 "webgl" |
| 502 ] | 469 ] |
| 503 } | 470 } |
| 504 ] | 471 ] |
| 505 } | 472 } |
| 506 ); | 473 ); |
| 507 GPUInfo gpu_info; | 474 GPUInfo gpu_info; |
| 508 gpu_info.gpu.vendor_id = 0x8086; | 475 gpu_info.gpu.vendor_id = 0x8086; |
| 509 gpu_info.gpu.device_id = 0x0042; | 476 gpu_info.gpu.device_id = 0x0042; |
| 510 manager->InitializeForTesting(blacklist_json, gpu_info); | 477 manager.InitializeForTesting(blacklist_json, gpu_info); |
| 511 | 478 |
| 512 // Not enough GPUInfo. | 479 // Not enough GPUInfo. |
| 513 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 480 EXPECT_TRUE(manager.GpuAccessAllowed(NULL)); |
| 514 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 481 EXPECT_EQ(0u, manager.GetBlacklistedFeatureCount()); |
| 515 | 482 |
| 516 // Now assume browser gets GL strings from local state. | 483 // Now assume browser gets GL strings from local state. |
| 517 // The entry applies, blacklist more features than from the preliminary step. | 484 // The entry applies, blacklist more features than from the preliminary step. |
| 518 // However, GPU process is not blocked because this is all browser side and | 485 // However, GPU process is not blocked because this is all browser side and |
| 519 // happens before renderer launching. | 486 // happens before renderer launching. |
| 520 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa801); | 487 manager.SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa801); |
| 521 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 488 EXPECT_TRUE(manager.GpuAccessAllowed(NULL)); |
| 522 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 489 EXPECT_EQ(1u, manager.GetBlacklistedFeatureCount()); |
| 523 EXPECT_TRUE(manager->IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)); | 490 EXPECT_TRUE(manager.IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)); |
| 524 } | 491 } |
| 525 | 492 |
| 526 TEST_F(GpuDataManagerImplTest, SetGLStringsNoEffects) { | 493 TEST_F(GpuDataManagerImplTest, SetGLStringsNoEffects) { |
| 527 const char* kGLVendorMesa = "Tungsten Graphics, Inc"; | 494 const char* kGLVendorMesa = "Tungsten Graphics, Inc"; |
| 528 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41"; | 495 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41"; |
| 529 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL"; | 496 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL"; |
| 530 const char* kGLVersionMesa802 = "2.1 Mesa 8.0.2-DEVEL"; | 497 const char* kGLVersionMesa802 = "2.1 Mesa 8.0.2-DEVEL"; |
| 531 | 498 |
| 532 ScopedGpuDataManagerImpl manager; | 499 GpuDataManagerImplPrivate manager; |
| 533 ASSERT_TRUE(manager.get()); | 500 EXPECT_EQ(0u, manager.GetBlacklistedFeatureCount()); |
| 534 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | 501 EXPECT_TRUE(manager.GpuAccessAllowed(NULL)); |
| 535 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | |
| 536 | 502 |
| 537 const std::string blacklist_json = LONG_STRING_CONST( | 503 const std::string blacklist_json = LONG_STRING_CONST( |
| 538 { | 504 { |
| 539 "name": "gpu blacklist", | 505 "name": "gpu blacklist", |
| 540 "version": "0.1", | 506 "version": "0.1", |
| 541 "entries": [ | 507 "entries": [ |
| 542 { | 508 { |
| 543 "id": 1, | 509 "id": 1, |
| 544 "vendor_id": "0x8086", | 510 "vendor_id": "0x8086", |
| 545 "exceptions": [ | 511 "exceptions": [ |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 559 } | 525 } |
| 560 ); | 526 ); |
| 561 GPUInfo gpu_info; | 527 GPUInfo gpu_info; |
| 562 gpu_info.gpu.vendor_id = 0x8086; | 528 gpu_info.gpu.vendor_id = 0x8086; |
| 563 gpu_info.gpu.device_id = 0x0042; | 529 gpu_info.gpu.device_id = 0x0042; |
| 564 gpu_info.gl_vendor = kGLVendorMesa; | 530 gpu_info.gl_vendor = kGLVendorMesa; |
| 565 gpu_info.gl_renderer = kGLRendererMesa; | 531 gpu_info.gl_renderer = kGLRendererMesa; |
| 566 gpu_info.gl_version = kGLVersionMesa801; | 532 gpu_info.gl_version = kGLVersionMesa801; |
| 567 gpu_info.driver_vendor = "Mesa"; | 533 gpu_info.driver_vendor = "Mesa"; |
| 568 gpu_info.driver_version = "8.0.1"; | 534 gpu_info.driver_version = "8.0.1"; |
| 569 manager->InitializeForTesting(blacklist_json, gpu_info); | 535 manager.InitializeForTesting(blacklist_json, gpu_info); |
| 570 | 536 |
| 571 // Full GPUInfo, the entry applies. | 537 // Full GPUInfo, the entry applies. |
| 572 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 538 EXPECT_TRUE(manager.GpuAccessAllowed(NULL)); |
| 573 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 539 EXPECT_EQ(1u, manager.GetBlacklistedFeatureCount()); |
| 574 EXPECT_TRUE(manager->IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)); | 540 EXPECT_TRUE(manager.IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)); |
| 575 | 541 |
| 576 // Now assume browser gets GL strings from local state. | 542 // Now assume browser gets GL strings from local state. |
| 577 // SetGLStrings() has no effects because GPUInfo already got these strings. | 543 // SetGLStrings() has no effects because GPUInfo already got these strings. |
| 578 // (Otherwise the entry should not apply.) | 544 // (Otherwise the entry should not apply.) |
| 579 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa802); | 545 manager.SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa802); |
| 580 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); | 546 EXPECT_TRUE(manager.GpuAccessAllowed(NULL)); |
| 581 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); | 547 EXPECT_EQ(1u, manager.GetBlacklistedFeatureCount()); |
| 582 EXPECT_TRUE(manager->IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)); | 548 EXPECT_TRUE(manager.IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)); |
| 583 } | 549 } |
| 584 #endif // OS_LINUX | 550 #endif // OS_LINUX |
| 585 | 551 |
| 586 TEST_F(GpuDataManagerImplTest, GpuDriverBugListSingle) { | 552 TEST_F(GpuDataManagerImplTest, GpuDriverBugListSingle) { |
| 587 ScopedGpuDataManagerImpl manager; | 553 GpuDataManagerImplPrivate manager; |
| 588 ASSERT_TRUE(manager.get()); | 554 manager.gpu_driver_bugs_.insert(5); |
| 589 manager->gpu_driver_bugs_.insert(5); | |
| 590 | 555 |
| 591 CommandLine command_line(0, NULL); | 556 CommandLine command_line(0, NULL); |
| 592 manager->AppendGpuCommandLine(&command_line); | 557 manager.AppendGpuCommandLine(&command_line); |
| 593 | 558 |
| 594 EXPECT_TRUE(command_line.HasSwitch(switches::kGpuDriverBugWorkarounds)); | 559 EXPECT_TRUE(command_line.HasSwitch(switches::kGpuDriverBugWorkarounds)); |
| 595 std::string args = command_line.GetSwitchValueASCII( | 560 std::string args = command_line.GetSwitchValueASCII( |
| 596 switches::kGpuDriverBugWorkarounds); | 561 switches::kGpuDriverBugWorkarounds); |
| 597 EXPECT_STREQ("5", args.c_str()); | 562 EXPECT_STREQ("5", args.c_str()); |
| 598 } | 563 } |
| 599 | 564 |
| 600 TEST_F(GpuDataManagerImplTest, GpuDriverBugListMultiple) { | 565 TEST_F(GpuDataManagerImplTest, GpuDriverBugListMultiple) { |
| 601 ScopedGpuDataManagerImpl manager; | 566 GpuDataManagerImplPrivate manager; |
| 602 ASSERT_TRUE(manager.get()); | 567 manager.gpu_driver_bugs_.insert(5); |
| 603 manager->gpu_driver_bugs_.insert(5); | 568 manager.gpu_driver_bugs_.insert(7); |
| 604 manager->gpu_driver_bugs_.insert(7); | |
| 605 | 569 |
| 606 CommandLine command_line(0, NULL); | 570 CommandLine command_line(0, NULL); |
| 607 manager->AppendGpuCommandLine(&command_line); | 571 manager.AppendGpuCommandLine(&command_line); |
| 608 | 572 |
| 609 EXPECT_TRUE(command_line.HasSwitch(switches::kGpuDriverBugWorkarounds)); | 573 EXPECT_TRUE(command_line.HasSwitch(switches::kGpuDriverBugWorkarounds)); |
| 610 std::string args = command_line.GetSwitchValueASCII( | 574 std::string args = command_line.GetSwitchValueASCII( |
| 611 switches::kGpuDriverBugWorkarounds); | 575 switches::kGpuDriverBugWorkarounds); |
| 612 EXPECT_STREQ("5,7", args.c_str()); | 576 EXPECT_STREQ("5,7", args.c_str()); |
| 613 } | 577 } |
| 614 | 578 |
| 615 TEST_F(GpuDataManagerImplTest, BlacklistAllFeatures) { | 579 TEST_F(GpuDataManagerImplTest, BlacklistAllFeatures) { |
| 616 ScopedGpuDataManagerImpl manager; | 580 GpuDataManagerImplPrivate manager; |
| 617 ASSERT_TRUE(manager.get()); | 581 EXPECT_EQ(0u, manager.GetBlacklistedFeatureCount()); |
| 618 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); | |
| 619 std::string reason; | 582 std::string reason; |
| 620 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); | 583 EXPECT_TRUE(manager.GpuAccessAllowed(&reason)); |
| 621 EXPECT_TRUE(reason.empty()); | 584 EXPECT_TRUE(reason.empty()); |
| 622 | 585 |
| 623 const std::string blacklist_json = LONG_STRING_CONST( | 586 const std::string blacklist_json = LONG_STRING_CONST( |
| 624 { | 587 { |
| 625 "name": "gpu blacklist", | 588 "name": "gpu blacklist", |
| 626 "version": "0.1", | 589 "version": "0.1", |
| 627 "entries": [ | 590 "entries": [ |
| 628 { | 591 { |
| 629 "id": 1, | 592 "id": 1, |
| 630 "features": [ | 593 "features": [ |
| 631 "all" | 594 "all" |
| 632 ] | 595 ] |
| 633 } | 596 } |
| 634 ] | 597 ] |
| 635 } | 598 } |
| 636 ); | 599 ); |
| 637 | 600 |
| 638 GPUInfo gpu_info; | 601 GPUInfo gpu_info; |
| 639 gpu_info.gpu.vendor_id = 0x10de; | 602 gpu_info.gpu.vendor_id = 0x10de; |
| 640 gpu_info.gpu.device_id = 0x0640; | 603 gpu_info.gpu.device_id = 0x0640; |
| 641 manager->InitializeForTesting(blacklist_json, gpu_info); | 604 manager.InitializeForTesting(blacklist_json, gpu_info); |
| 642 | 605 |
| 643 EXPECT_EQ(static_cast<size_t>(NUMBER_OF_GPU_FEATURE_TYPES), | 606 EXPECT_EQ(static_cast<size_t>(NUMBER_OF_GPU_FEATURE_TYPES), |
| 644 manager->GetBlacklistedFeatureCount()); | 607 manager.GetBlacklistedFeatureCount()); |
| 645 // TODO(zmo): remove the Linux specific behavior once we fix | 608 // TODO(zmo): remove the Linux specific behavior once we fix |
| 646 // crbug.com/238466. | 609 // crbug.com/238466. |
| 647 #if defined(OS_LINUX) | 610 #if defined(OS_LINUX) |
| 648 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); | 611 EXPECT_TRUE(manager.GpuAccessAllowed(&reason)); |
| 649 EXPECT_TRUE(reason.empty()); | 612 EXPECT_TRUE(reason.empty()); |
| 650 #else | 613 #else |
| 651 EXPECT_FALSE(manager->GpuAccessAllowed(&reason)); | 614 EXPECT_FALSE(manager.GpuAccessAllowed(&reason)); |
| 652 EXPECT_FALSE(reason.empty()); | 615 EXPECT_FALSE(reason.empty()); |
| 653 #endif | 616 #endif |
| 654 } | 617 } |
| 655 | 618 |
| 656 } // namespace content | 619 } // namespace content |
| OLD | NEW |