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