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
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h"
8 #include "base/time/time.h"
9 #include "content/browser/gpu/gpu_data_manager_impl_private.h"
10 #include "content/public/browser/gpu_data_manager_observer.h"
11 #include "gpu/command_buffer/service/gpu_switches.h"
12 #include "gpu/config/gpu_feature_type.h"
13 #include "gpu/config/gpu_info.h"
14 #include "testing/gtest/include/gtest/gtest.h"
17 #define LONG_STRING_CONST(...) #__VA_ARGS__
22 class TestObserver
: public GpuDataManagerObserver
{
25 : gpu_info_updated_(false),
26 video_memory_usage_stats_updated_(false) {
28 virtual ~TestObserver() { }
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_
;
35 virtual void OnGpuInfoUpdate() OVERRIDE
{
36 gpu_info_updated_
= true;
39 virtual void OnVideoMemoryUsageStatsUpdate(
40 const GPUVideoMemoryUsageStats
& stats
) OVERRIDE
{
41 video_memory_usage_stats_updated_
= true;
45 gpu_info_updated_
= false;
46 video_memory_usage_stats_updated_
= false;
50 bool gpu_info_updated_
;
51 bool video_memory_usage_stats_updated_
;
54 static base::Time
GetTimeForTesting() {
55 return base::Time::FromDoubleT(1000);
58 static GURL
GetDomain1ForTesting() {
59 return GURL("http://foo.com/");
62 static GURL
GetDomain2ForTesting() {
63 return GURL("http://bar.com/");
66 } // namespace anonymous
68 class GpuDataManagerImplPrivateTest
: public testing::Test
{
70 GpuDataManagerImplPrivateTest() { }
72 virtual ~GpuDataManagerImplPrivateTest() { }
75 // scoped_ptr doesn't work with GpuDataManagerImpl because its
76 // destructor is private. GpuDataManagerImplPrivateTest is however a friend
77 // so we can make a little helper class here.
78 class ScopedGpuDataManagerImpl
{
80 ScopedGpuDataManagerImpl() : impl_(new GpuDataManagerImpl()) {
82 EXPECT_TRUE(impl_
->private_
.get());
84 ~ScopedGpuDataManagerImpl() { delete impl_
; }
86 GpuDataManagerImpl
* get() const { return impl_
; }
88 GpuDataManagerImpl
* operator->() const { return impl_
; }
91 GpuDataManagerImpl
* impl_
;
92 DISALLOW_COPY_AND_ASSIGN(ScopedGpuDataManagerImpl
);
95 // We want to test the code path where GpuDataManagerImplPrivate is created
96 // in the GpuDataManagerImpl constructor.
97 class ScopedGpuDataManagerImplPrivate
{
99 ScopedGpuDataManagerImplPrivate() : impl_(new GpuDataManagerImpl()) {
101 EXPECT_TRUE(impl_
->private_
.get());
103 ~ScopedGpuDataManagerImplPrivate() { delete impl_
; }
105 GpuDataManagerImplPrivate
* get() const {
106 return impl_
->private_
.get();
109 GpuDataManagerImplPrivate
* operator->() const {
110 return impl_
->private_
.get();
114 GpuDataManagerImpl
* impl_
;
115 DISALLOW_COPY_AND_ASSIGN(ScopedGpuDataManagerImplPrivate
);
118 virtual void SetUp() {
121 virtual void TearDown() {
124 base::Time
JustBeforeExpiration(const GpuDataManagerImplPrivate
* manager
);
125 base::Time
JustAfterExpiration(const GpuDataManagerImplPrivate
* manager
);
126 void TestBlockingDomainFrom3DAPIs(
127 GpuDataManagerImpl::DomainGuilt guilt_level
);
128 void TestUnblockingDomainFrom3DAPIs(
129 GpuDataManagerImpl::DomainGuilt guilt_level
);
131 base::MessageLoop message_loop_
;
134 // We use new method instead of GetInstance() method because we want
135 // each test to be independent of each other.
137 TEST_F(GpuDataManagerImplPrivateTest
, GpuSideBlacklisting
) {
138 // If a feature is allowed in preliminary step (browser side), but
139 // disabled when GPU process launches and collects full GPU info,
140 // it's too late to let renderer know, so we basically block all GPU
141 // access, to be on the safe side.
142 ScopedGpuDataManagerImplPrivate manager
;
143 EXPECT_EQ(0u, manager
->GetBlacklistedFeatureCount());
145 EXPECT_TRUE(manager
->GpuAccessAllowed(&reason
));
146 EXPECT_TRUE(reason
.empty());
148 const std::string blacklist_json
= LONG_STRING_CONST(
150 "name": "gpu blacklist",
161 "gl_renderer": ".*GeForce.*",
163 "accelerated_2d_canvas"
170 gpu::GPUInfo gpu_info
;
171 gpu_info
.gpu
.vendor_id
= 0x10de;
172 gpu_info
.gpu
.device_id
= 0x0640;
173 manager
->InitializeForTesting(blacklist_json
, gpu_info
);
175 EXPECT_TRUE(manager
->GpuAccessAllowed(&reason
));
176 EXPECT_TRUE(reason
.empty());
177 EXPECT_EQ(1u, manager
->GetBlacklistedFeatureCount());
178 EXPECT_TRUE(manager
->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL
));
180 gpu_info
.gl_vendor
= "NVIDIA";
181 gpu_info
.gl_renderer
= "NVIDIA GeForce GT 120";
182 manager
->UpdateGpuInfo(gpu_info
);
183 EXPECT_FALSE(manager
->GpuAccessAllowed(&reason
));
184 EXPECT_FALSE(reason
.empty());
185 EXPECT_EQ(2u, manager
->GetBlacklistedFeatureCount());
186 EXPECT_TRUE(manager
->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL
));
187 EXPECT_TRUE(manager
->IsFeatureBlacklisted(
188 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS
));
191 TEST_F(GpuDataManagerImplPrivateTest
, GpuSideExceptions
) {
192 ScopedGpuDataManagerImplPrivate manager
;
193 EXPECT_EQ(0u, manager
->GetBlacklistedFeatureCount());
194 EXPECT_TRUE(manager
->GpuAccessAllowed(NULL
));
196 const std::string blacklist_json
= LONG_STRING_CONST(
198 "name": "gpu blacklist",
205 "gl_renderer": ".*GeForce.*"
215 gpu::GPUInfo gpu_info
;
216 gpu_info
.gpu
.vendor_id
= 0x10de;
217 gpu_info
.gpu
.device_id
= 0x0640;
218 manager
->InitializeForTesting(blacklist_json
, gpu_info
);
220 EXPECT_TRUE(manager
->GpuAccessAllowed(NULL
));
221 EXPECT_EQ(0u, manager
->GetBlacklistedFeatureCount());
223 // Now assume gpu process launches and full GPU info is collected.
224 gpu_info
.gl_renderer
= "NVIDIA GeForce GT 120";
225 manager
->UpdateGpuInfo(gpu_info
);
226 EXPECT_TRUE(manager
->GpuAccessAllowed(NULL
));
227 EXPECT_EQ(0u, manager
->GetBlacklistedFeatureCount());
230 TEST_F(GpuDataManagerImplPrivateTest
, DisableHardwareAcceleration
) {
231 ScopedGpuDataManagerImplPrivate manager
;
232 EXPECT_EQ(0u, manager
->GetBlacklistedFeatureCount());
234 EXPECT_TRUE(manager
->GpuAccessAllowed(&reason
));
235 EXPECT_TRUE(reason
.empty());
237 manager
->DisableHardwareAcceleration();
238 EXPECT_FALSE(manager
->GpuAccessAllowed(&reason
));
239 EXPECT_FALSE(reason
.empty());
240 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES
),
241 manager
->GetBlacklistedFeatureCount());
244 TEST_F(GpuDataManagerImplPrivateTest
, SwiftShaderRendering
) {
245 // Blacklist, then register SwiftShader.
246 ScopedGpuDataManagerImplPrivate manager
;
247 EXPECT_EQ(0u, manager
->GetBlacklistedFeatureCount());
248 EXPECT_TRUE(manager
->GpuAccessAllowed(NULL
));
249 EXPECT_FALSE(manager
->ShouldUseSwiftShader());
251 manager
->DisableHardwareAcceleration();
252 EXPECT_FALSE(manager
->GpuAccessAllowed(NULL
));
253 EXPECT_FALSE(manager
->ShouldUseSwiftShader());
255 // If SwiftShader is enabled, even if we blacklist GPU,
256 // GPU process is still allowed.
257 const base::FilePath
test_path(FILE_PATH_LITERAL("AnyPath"));
258 manager
->RegisterSwiftShaderPath(test_path
);
259 EXPECT_TRUE(manager
->ShouldUseSwiftShader());
260 EXPECT_TRUE(manager
->GpuAccessAllowed(NULL
));
261 EXPECT_EQ(1u, manager
->GetBlacklistedFeatureCount());
262 EXPECT_TRUE(manager
->IsFeatureBlacklisted(
263 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS
));
266 TEST_F(GpuDataManagerImplPrivateTest
, SwiftShaderRendering2
) {
267 // Register SwiftShader, then blacklist.
268 ScopedGpuDataManagerImplPrivate manager
;
269 EXPECT_EQ(0u, manager
->GetBlacklistedFeatureCount());
270 EXPECT_TRUE(manager
->GpuAccessAllowed(NULL
));
271 EXPECT_FALSE(manager
->ShouldUseSwiftShader());
273 const base::FilePath
test_path(FILE_PATH_LITERAL("AnyPath"));
274 manager
->RegisterSwiftShaderPath(test_path
);
275 EXPECT_EQ(0u, manager
->GetBlacklistedFeatureCount());
276 EXPECT_TRUE(manager
->GpuAccessAllowed(NULL
));
277 EXPECT_FALSE(manager
->ShouldUseSwiftShader());
279 manager
->DisableHardwareAcceleration();
280 EXPECT_TRUE(manager
->GpuAccessAllowed(NULL
));
281 EXPECT_TRUE(manager
->ShouldUseSwiftShader());
282 EXPECT_EQ(1u, manager
->GetBlacklistedFeatureCount());
283 EXPECT_TRUE(manager
->IsFeatureBlacklisted(
284 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS
));
287 TEST_F(GpuDataManagerImplPrivateTest
, GpuInfoUpdate
) {
288 ScopedGpuDataManagerImpl manager
;
290 TestObserver observer
;
291 manager
->AddObserver(&observer
);
294 base::RunLoop run_loop
;
295 run_loop
.RunUntilIdle();
297 EXPECT_FALSE(observer
.gpu_info_updated());
299 gpu::GPUInfo gpu_info
;
300 manager
->UpdateGpuInfo(gpu_info
);
302 base::RunLoop run_loop
;
303 run_loop
.RunUntilIdle();
305 EXPECT_TRUE(observer
.gpu_info_updated());
308 TEST_F(GpuDataManagerImplPrivateTest
, NoGpuInfoUpdateWithSwiftShader
) {
309 ScopedGpuDataManagerImpl manager
;
311 manager
->DisableHardwareAcceleration();
312 const base::FilePath
test_path(FILE_PATH_LITERAL("AnyPath"));
313 manager
->RegisterSwiftShaderPath(test_path
);
314 EXPECT_TRUE(manager
->ShouldUseSwiftShader());
315 EXPECT_TRUE(manager
->GpuAccessAllowed(NULL
));
318 base::RunLoop run_loop
;
319 run_loop
.RunUntilIdle();
322 TestObserver observer
;
323 manager
->AddObserver(&observer
);
325 base::RunLoop run_loop
;
326 run_loop
.RunUntilIdle();
328 EXPECT_FALSE(observer
.gpu_info_updated());
330 gpu::GPUInfo gpu_info
;
331 manager
->UpdateGpuInfo(gpu_info
);
333 base::RunLoop run_loop
;
334 run_loop
.RunUntilIdle();
336 EXPECT_FALSE(observer
.gpu_info_updated());
339 TEST_F(GpuDataManagerImplPrivateTest
, GPUVideoMemoryUsageStatsUpdate
) {
340 ScopedGpuDataManagerImpl manager
;
342 TestObserver observer
;
343 manager
->AddObserver(&observer
);
346 base::RunLoop run_loop
;
347 run_loop
.RunUntilIdle();
349 EXPECT_FALSE(observer
.video_memory_usage_stats_updated());
351 GPUVideoMemoryUsageStats vram_stats
;
352 manager
->UpdateVideoMemoryUsageStats(vram_stats
);
354 base::RunLoop run_loop
;
355 run_loop
.RunUntilIdle();
357 EXPECT_TRUE(observer
.video_memory_usage_stats_updated());
360 base::Time
GpuDataManagerImplPrivateTest::JustBeforeExpiration(
361 const GpuDataManagerImplPrivate
* manager
) {
362 return GetTimeForTesting() + base::TimeDelta::FromMilliseconds(
363 manager
->GetBlockAllDomainsDurationInMs()) -
364 base::TimeDelta::FromMilliseconds(3);
367 base::Time
GpuDataManagerImplPrivateTest::JustAfterExpiration(
368 const GpuDataManagerImplPrivate
* manager
) {
369 return GetTimeForTesting() + base::TimeDelta::FromMilliseconds(
370 manager
->GetBlockAllDomainsDurationInMs()) +
371 base::TimeDelta::FromMilliseconds(3);
374 void GpuDataManagerImplPrivateTest::TestBlockingDomainFrom3DAPIs(
375 GpuDataManagerImpl::DomainGuilt guilt_level
) {
376 ScopedGpuDataManagerImplPrivate manager
;
378 manager
->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(),
380 GetTimeForTesting());
382 // This domain should be blocked no matter what.
383 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED
,
384 manager
->Are3DAPIsBlockedAtTime(GetDomain1ForTesting(),
385 GetTimeForTesting()));
386 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED
,
387 manager
->Are3DAPIsBlockedAtTime(
388 GetDomain1ForTesting(), JustBeforeExpiration(manager
.get())));
389 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED
,
390 manager
->Are3DAPIsBlockedAtTime(
391 GetDomain1ForTesting(), JustAfterExpiration(manager
.get())));
394 void GpuDataManagerImplPrivateTest::TestUnblockingDomainFrom3DAPIs(
395 GpuDataManagerImpl::DomainGuilt guilt_level
) {
396 ScopedGpuDataManagerImplPrivate manager
;
398 manager
->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(),
400 GetTimeForTesting());
402 // Unblocking the domain should work.
403 manager
->UnblockDomainFrom3DAPIs(GetDomain1ForTesting());
404 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED
,
405 manager
->Are3DAPIsBlockedAtTime(GetDomain1ForTesting(),
406 GetTimeForTesting()));
407 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED
,
408 manager
->Are3DAPIsBlockedAtTime(
409 GetDomain1ForTesting(), JustBeforeExpiration(manager
.get())));
410 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED
,
411 manager
->Are3DAPIsBlockedAtTime(
412 GetDomain1ForTesting(), JustAfterExpiration(manager
.get())));
415 TEST_F(GpuDataManagerImplPrivateTest
, BlockGuiltyDomainFrom3DAPIs
) {
416 TestBlockingDomainFrom3DAPIs(GpuDataManagerImpl::DOMAIN_GUILT_KNOWN
);
419 TEST_F(GpuDataManagerImplPrivateTest
, BlockDomainOfUnknownGuiltFrom3DAPIs
) {
420 TestBlockingDomainFrom3DAPIs(GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN
);
423 TEST_F(GpuDataManagerImplPrivateTest
, BlockAllDomainsFrom3DAPIs
) {
424 ScopedGpuDataManagerImplPrivate manager
;
426 manager
->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(),
427 GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN
,
428 GetTimeForTesting());
430 // Blocking of other domains should expire.
431 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_ALL_DOMAINS_BLOCKED
,
432 manager
->Are3DAPIsBlockedAtTime(
433 GetDomain2ForTesting(), JustBeforeExpiration(manager
.get())));
434 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED
,
435 manager
->Are3DAPIsBlockedAtTime(
436 GetDomain2ForTesting(), JustAfterExpiration(manager
.get())));
439 TEST_F(GpuDataManagerImplPrivateTest
, UnblockGuiltyDomainFrom3DAPIs
) {
440 TestUnblockingDomainFrom3DAPIs(GpuDataManagerImpl::DOMAIN_GUILT_KNOWN
);
443 TEST_F(GpuDataManagerImplPrivateTest
, UnblockDomainOfUnknownGuiltFrom3DAPIs
) {
444 TestUnblockingDomainFrom3DAPIs(GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN
);
447 TEST_F(GpuDataManagerImplPrivateTest
, UnblockOtherDomainFrom3DAPIs
) {
448 ScopedGpuDataManagerImplPrivate manager
;
450 manager
->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(),
451 GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN
,
452 GetTimeForTesting());
454 manager
->UnblockDomainFrom3DAPIs(GetDomain2ForTesting());
456 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED
,
457 manager
->Are3DAPIsBlockedAtTime(
458 GetDomain2ForTesting(), JustBeforeExpiration(manager
.get())));
460 // The original domain should still be blocked.
461 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED
,
462 manager
->Are3DAPIsBlockedAtTime(
463 GetDomain1ForTesting(), JustBeforeExpiration(manager
.get())));
466 TEST_F(GpuDataManagerImplPrivateTest
, UnblockThisDomainFrom3DAPIs
) {
467 ScopedGpuDataManagerImplPrivate manager
;
469 manager
->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(),
470 GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN
,
471 GetTimeForTesting());
473 manager
->UnblockDomainFrom3DAPIs(GetDomain1ForTesting());
475 // This behavior is debatable. Perhaps the GPU reset caused by
476 // domain 1 should still cause other domains to be blocked.
477 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED
,
478 manager
->Are3DAPIsBlockedAtTime(
479 GetDomain2ForTesting(), JustBeforeExpiration(manager
.get())));
482 #if defined(OS_LINUX)
483 TEST_F(GpuDataManagerImplPrivateTest
, SetGLStrings
) {
484 const char* kGLVendorMesa
= "Tungsten Graphics, Inc";
485 const char* kGLRendererMesa
= "Mesa DRI Intel(R) G41";
486 const char* kGLVersionMesa801
= "2.1 Mesa 8.0.1-DEVEL";
488 ScopedGpuDataManagerImplPrivate manager
;
489 EXPECT_EQ(0u, manager
->GetBlacklistedFeatureCount());
490 EXPECT_TRUE(manager
->GpuAccessAllowed(NULL
));
492 const std::string blacklist_json
= LONG_STRING_CONST(
494 "name": "gpu blacklist",
499 "vendor_id": "0x8086",
502 "device_id": ["0x0042"],
516 gpu::GPUInfo gpu_info
;
517 gpu_info
.gpu
.vendor_id
= 0x8086;
518 gpu_info
.gpu
.device_id
= 0x0042;
519 manager
->InitializeForTesting(blacklist_json
, gpu_info
);
521 // Not enough GPUInfo.
522 EXPECT_TRUE(manager
->GpuAccessAllowed(NULL
));
523 EXPECT_EQ(0u, manager
->GetBlacklistedFeatureCount());
525 // Now assume browser gets GL strings from local state.
526 // The entry applies, blacklist more features than from the preliminary step.
527 // However, GPU process is not blocked because this is all browser side and
528 // happens before renderer launching.
529 manager
->SetGLStrings(kGLVendorMesa
, kGLRendererMesa
, kGLVersionMesa801
);
530 EXPECT_TRUE(manager
->GpuAccessAllowed(NULL
));
531 EXPECT_EQ(1u, manager
->GetBlacklistedFeatureCount());
532 EXPECT_TRUE(manager
->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL
));
535 TEST_F(GpuDataManagerImplPrivateTest
, SetGLStringsNoEffects
) {
536 const char* kGLVendorMesa
= "Tungsten Graphics, Inc";
537 const char* kGLRendererMesa
= "Mesa DRI Intel(R) G41";
538 const char* kGLVersionMesa801
= "2.1 Mesa 8.0.1-DEVEL";
539 const char* kGLVersionMesa802
= "2.1 Mesa 8.0.2-DEVEL";
541 ScopedGpuDataManagerImplPrivate manager
;
542 EXPECT_EQ(0u, manager
->GetBlacklistedFeatureCount());
543 EXPECT_TRUE(manager
->GpuAccessAllowed(NULL
));
545 const std::string blacklist_json
= LONG_STRING_CONST(
547 "name": "gpu blacklist",
552 "vendor_id": "0x8086",
555 "device_id": ["0x0042"],
569 gpu::GPUInfo gpu_info
;
570 gpu_info
.gpu
.vendor_id
= 0x8086;
571 gpu_info
.gpu
.device_id
= 0x0042;
572 gpu_info
.gl_vendor
= kGLVendorMesa
;
573 gpu_info
.gl_renderer
= kGLRendererMesa
;
574 gpu_info
.gl_version
= kGLVersionMesa801
;
575 gpu_info
.driver_vendor
= "Mesa";
576 gpu_info
.driver_version
= "8.0.1";
577 manager
->InitializeForTesting(blacklist_json
, gpu_info
);
579 // Full GPUInfo, the entry applies.
580 EXPECT_TRUE(manager
->GpuAccessAllowed(NULL
));
581 EXPECT_EQ(1u, manager
->GetBlacklistedFeatureCount());
582 EXPECT_TRUE(manager
->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL
));
584 // Now assume browser gets GL strings from local state.
585 // SetGLStrings() has no effects because GPUInfo already got these strings.
586 // (Otherwise the entry should not apply.)
587 manager
->SetGLStrings(kGLVendorMesa
, kGLRendererMesa
, kGLVersionMesa802
);
588 EXPECT_TRUE(manager
->GpuAccessAllowed(NULL
));
589 EXPECT_EQ(1u, manager
->GetBlacklistedFeatureCount());
590 EXPECT_TRUE(manager
->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL
));
594 TEST_F(GpuDataManagerImplPrivateTest
, GpuDriverBugListSingle
) {
595 ScopedGpuDataManagerImplPrivate manager
;
596 manager
->gpu_driver_bugs_
.insert(5);
598 base::CommandLine
command_line(0, NULL
);
599 manager
->AppendGpuCommandLine(&command_line
);
601 EXPECT_TRUE(command_line
.HasSwitch(switches::kGpuDriverBugWorkarounds
));
602 std::string args
= command_line
.GetSwitchValueASCII(
603 switches::kGpuDriverBugWorkarounds
);
604 EXPECT_STREQ("5", args
.c_str());
607 TEST_F(GpuDataManagerImplPrivateTest
, GpuDriverBugListMultiple
) {
608 ScopedGpuDataManagerImplPrivate manager
;
609 manager
->gpu_driver_bugs_
.insert(5);
610 manager
->gpu_driver_bugs_
.insert(7);
612 base::CommandLine
command_line(0, NULL
);
613 manager
->AppendGpuCommandLine(&command_line
);
615 EXPECT_TRUE(command_line
.HasSwitch(switches::kGpuDriverBugWorkarounds
));
616 std::string args
= command_line
.GetSwitchValueASCII(
617 switches::kGpuDriverBugWorkarounds
);
618 EXPECT_STREQ("5,7", args
.c_str());
621 TEST_F(GpuDataManagerImplPrivateTest
, BlacklistAllFeatures
) {
622 ScopedGpuDataManagerImplPrivate manager
;
623 EXPECT_EQ(0u, manager
->GetBlacklistedFeatureCount());
625 EXPECT_TRUE(manager
->GpuAccessAllowed(&reason
));
626 EXPECT_TRUE(reason
.empty());
628 const std::string blacklist_json
= LONG_STRING_CONST(
630 "name": "gpu blacklist",
643 gpu::GPUInfo gpu_info
;
644 gpu_info
.gpu
.vendor_id
= 0x10de;
645 gpu_info
.gpu
.device_id
= 0x0640;
646 manager
->InitializeForTesting(blacklist_json
, gpu_info
);
648 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES
),
649 manager
->GetBlacklistedFeatureCount());
650 // TODO(zmo): remove the Linux specific behavior once we fix
652 #if defined(OS_LINUX)
653 EXPECT_TRUE(manager
->GpuAccessAllowed(&reason
));
654 EXPECT_TRUE(reason
.empty());
656 EXPECT_FALSE(manager
->GpuAccessAllowed(&reason
));
657 EXPECT_FALSE(reason
.empty());
661 TEST_F(GpuDataManagerImplPrivateTest
, UpdateActiveGpu
) {
662 ScopedGpuDataManagerImpl manager
;
664 const std::string blacklist_json
= LONG_STRING_CONST(
666 "name": "gpu blacklist",
671 "vendor_id": "0x8086",
672 "multi_gpu_category": "active",
681 // Two GPUs, the secondary Intel GPU is active.
682 gpu::GPUInfo gpu_info
;
683 gpu_info
.gpu
.vendor_id
= 0x10de;
684 gpu_info
.gpu
.device_id
= 0x0640;
685 gpu_info
.gpu
.active
= false;
686 gpu::GPUInfo::GPUDevice intel_gpu
;
687 intel_gpu
.vendor_id
= 0x8086;
688 intel_gpu
.device_id
= 0x04a1;
689 intel_gpu
.active
= true;
690 gpu_info
.secondary_gpus
.push_back(intel_gpu
);
692 manager
->InitializeForTesting(blacklist_json
, gpu_info
);
693 TestObserver observer
;
694 manager
->AddObserver(&observer
);
696 EXPECT_EQ(1u, manager
->GetBlacklistedFeatureCount());
698 // Update with the same Intel GPU active.
699 EXPECT_FALSE(manager
->UpdateActiveGpu(0x8086, 0x04a1));
701 base::RunLoop run_loop
;
702 run_loop
.RunUntilIdle();
704 EXPECT_FALSE(observer
.gpu_info_updated());
705 EXPECT_EQ(1u, manager
->GetBlacklistedFeatureCount());
707 // Set NVIDIA GPU to be active.
708 EXPECT_TRUE(manager
->UpdateActiveGpu(0x10de, 0x0640));
710 base::RunLoop run_loop
;
711 run_loop
.RunUntilIdle();
713 EXPECT_TRUE(observer
.gpu_info_updated());
714 EXPECT_EQ(0u, manager
->GetBlacklistedFeatureCount());
717 EXPECT_FALSE(observer
.gpu_info_updated());
719 // Update with the same NVIDIA GPU active.
720 EXPECT_FALSE(manager
->UpdateActiveGpu(0x10de, 0x0640));
722 base::RunLoop run_loop
;
723 run_loop
.RunUntilIdle();
725 EXPECT_FALSE(observer
.gpu_info_updated());
726 EXPECT_EQ(0u, manager
->GetBlacklistedFeatureCount());
728 // Set Intel GPU to be active.
729 EXPECT_TRUE(manager
->UpdateActiveGpu(0x8086, 0x04a1));
731 base::RunLoop run_loop
;
732 run_loop
.RunUntilIdle();
734 EXPECT_TRUE(observer
.gpu_info_updated());
735 EXPECT_EQ(1u, manager
->GetBlacklistedFeatureCount());
738 } // namespace content