Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
[chromium-blink-merge.git] / content / browser / gpu / gpu_data_manager_impl_private_unittest.cc
blob8955ce1f88d751258b36fe54a3bceb797c6daaa3
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"
15 #include "url/gurl.h"
17 #define LONG_STRING_CONST(...) #__VA_ARGS__
19 namespace content {
20 namespace {
22 class TestObserver : public GpuDataManagerObserver {
23 public:
24 TestObserver()
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;
44 void Reset() {
45 gpu_info_updated_ = false;
46 video_memory_usage_stats_updated_ = false;
49 private:
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 {
69 public:
70 GpuDataManagerImplPrivateTest() { }
72 virtual ~GpuDataManagerImplPrivateTest() { }
74 protected:
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 {
79 public:
80 ScopedGpuDataManagerImpl() : impl_(new GpuDataManagerImpl()) {
81 EXPECT_TRUE(impl_);
82 EXPECT_TRUE(impl_->private_.get());
84 ~ScopedGpuDataManagerImpl() { delete impl_; }
86 GpuDataManagerImpl* get() const { return impl_; }
88 GpuDataManagerImpl* operator->() const { return impl_; }
90 private:
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 {
98 public:
99 ScopedGpuDataManagerImplPrivate() : impl_(new GpuDataManagerImpl()) {
100 EXPECT_TRUE(impl_);
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();
113 private:
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());
144 std::string reason;
145 EXPECT_TRUE(manager->GpuAccessAllowed(&reason));
146 EXPECT_TRUE(reason.empty());
148 const std::string blacklist_json = LONG_STRING_CONST(
150 "name": "gpu blacklist",
151 "version": "0.1",
152 "entries": [
154 "id": 1,
155 "features": [
156 "webgl"
160 "id": 2,
161 "gl_renderer": {
162 "op": "contains",
163 "value": "GeForce"
165 "features": [
166 "accelerated_2d_canvas"
173 gpu::GPUInfo gpu_info;
174 gpu_info.gpu.vendor_id = 0x10de;
175 gpu_info.gpu.device_id = 0x0640;
176 manager->InitializeForTesting(blacklist_json, gpu_info);
178 EXPECT_TRUE(manager->GpuAccessAllowed(&reason));
179 EXPECT_TRUE(reason.empty());
180 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
181 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL));
183 gpu_info.gl_vendor = "NVIDIA";
184 gpu_info.gl_renderer = "NVIDIA GeForce GT 120";
185 manager->UpdateGpuInfo(gpu_info);
186 EXPECT_FALSE(manager->GpuAccessAllowed(&reason));
187 EXPECT_FALSE(reason.empty());
188 EXPECT_EQ(2u, manager->GetBlacklistedFeatureCount());
189 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL));
190 EXPECT_TRUE(manager->IsFeatureBlacklisted(
191 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS));
194 TEST_F(GpuDataManagerImplPrivateTest, GpuSideExceptions) {
195 ScopedGpuDataManagerImplPrivate manager;
196 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
197 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
199 const std::string blacklist_json = LONG_STRING_CONST(
201 "name": "gpu blacklist",
202 "version": "0.1",
203 "entries": [
205 "id": 1,
206 "exceptions": [
208 "gl_renderer": {
209 "op": "contains",
210 "value": "GeForce"
214 "features": [
215 "webgl"
221 gpu::GPUInfo gpu_info;
222 gpu_info.gpu.vendor_id = 0x10de;
223 gpu_info.gpu.device_id = 0x0640;
224 manager->InitializeForTesting(blacklist_json, gpu_info);
226 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
227 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
229 // Now assume gpu process launches and full GPU info is collected.
230 gpu_info.gl_renderer = "NVIDIA GeForce GT 120";
231 manager->UpdateGpuInfo(gpu_info);
232 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
233 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
236 TEST_F(GpuDataManagerImplPrivateTest, DisableHardwareAcceleration) {
237 ScopedGpuDataManagerImplPrivate manager;
238 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
239 std::string reason;
240 EXPECT_TRUE(manager->GpuAccessAllowed(&reason));
241 EXPECT_TRUE(reason.empty());
243 manager->DisableHardwareAcceleration();
244 EXPECT_FALSE(manager->GpuAccessAllowed(&reason));
245 EXPECT_FALSE(reason.empty());
246 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES),
247 manager->GetBlacklistedFeatureCount());
250 TEST_F(GpuDataManagerImplPrivateTest, SwiftShaderRendering) {
251 // Blacklist, then register SwiftShader.
252 ScopedGpuDataManagerImplPrivate manager;
253 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
254 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
255 EXPECT_FALSE(manager->ShouldUseSwiftShader());
257 manager->DisableHardwareAcceleration();
258 EXPECT_FALSE(manager->GpuAccessAllowed(NULL));
259 EXPECT_FALSE(manager->ShouldUseSwiftShader());
261 // If SwiftShader is enabled, even if we blacklist GPU,
262 // GPU process is still allowed.
263 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath"));
264 manager->RegisterSwiftShaderPath(test_path);
265 EXPECT_TRUE(manager->ShouldUseSwiftShader());
266 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
267 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
268 EXPECT_TRUE(manager->IsFeatureBlacklisted(
269 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS));
272 TEST_F(GpuDataManagerImplPrivateTest, SwiftShaderRendering2) {
273 // Register SwiftShader, then blacklist.
274 ScopedGpuDataManagerImplPrivate manager;
275 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
276 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
277 EXPECT_FALSE(manager->ShouldUseSwiftShader());
279 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath"));
280 manager->RegisterSwiftShaderPath(test_path);
281 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
282 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
283 EXPECT_FALSE(manager->ShouldUseSwiftShader());
285 manager->DisableHardwareAcceleration();
286 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
287 EXPECT_TRUE(manager->ShouldUseSwiftShader());
288 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
289 EXPECT_TRUE(manager->IsFeatureBlacklisted(
290 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS));
293 TEST_F(GpuDataManagerImplPrivateTest, GpuInfoUpdate) {
294 ScopedGpuDataManagerImpl manager;
296 TestObserver observer;
297 manager->AddObserver(&observer);
300 base::RunLoop run_loop;
301 run_loop.RunUntilIdle();
303 EXPECT_FALSE(observer.gpu_info_updated());
305 gpu::GPUInfo gpu_info;
306 manager->UpdateGpuInfo(gpu_info);
308 base::RunLoop run_loop;
309 run_loop.RunUntilIdle();
311 EXPECT_TRUE(observer.gpu_info_updated());
314 TEST_F(GpuDataManagerImplPrivateTest, NoGpuInfoUpdateWithSwiftShader) {
315 ScopedGpuDataManagerImpl manager;
317 manager->DisableHardwareAcceleration();
318 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath"));
319 manager->RegisterSwiftShaderPath(test_path);
320 EXPECT_TRUE(manager->ShouldUseSwiftShader());
321 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
324 base::RunLoop run_loop;
325 run_loop.RunUntilIdle();
328 TestObserver observer;
329 manager->AddObserver(&observer);
331 base::RunLoop run_loop;
332 run_loop.RunUntilIdle();
334 EXPECT_FALSE(observer.gpu_info_updated());
336 gpu::GPUInfo gpu_info;
337 manager->UpdateGpuInfo(gpu_info);
339 base::RunLoop run_loop;
340 run_loop.RunUntilIdle();
342 EXPECT_FALSE(observer.gpu_info_updated());
345 TEST_F(GpuDataManagerImplPrivateTest, GPUVideoMemoryUsageStatsUpdate) {
346 ScopedGpuDataManagerImpl manager;
348 TestObserver observer;
349 manager->AddObserver(&observer);
352 base::RunLoop run_loop;
353 run_loop.RunUntilIdle();
355 EXPECT_FALSE(observer.video_memory_usage_stats_updated());
357 GPUVideoMemoryUsageStats vram_stats;
358 manager->UpdateVideoMemoryUsageStats(vram_stats);
360 base::RunLoop run_loop;
361 run_loop.RunUntilIdle();
363 EXPECT_TRUE(observer.video_memory_usage_stats_updated());
366 base::Time GpuDataManagerImplPrivateTest::JustBeforeExpiration(
367 const GpuDataManagerImplPrivate* manager) {
368 return GetTimeForTesting() + base::TimeDelta::FromMilliseconds(
369 manager->GetBlockAllDomainsDurationInMs()) -
370 base::TimeDelta::FromMilliseconds(3);
373 base::Time GpuDataManagerImplPrivateTest::JustAfterExpiration(
374 const GpuDataManagerImplPrivate* manager) {
375 return GetTimeForTesting() + base::TimeDelta::FromMilliseconds(
376 manager->GetBlockAllDomainsDurationInMs()) +
377 base::TimeDelta::FromMilliseconds(3);
380 void GpuDataManagerImplPrivateTest::TestBlockingDomainFrom3DAPIs(
381 GpuDataManagerImpl::DomainGuilt guilt_level) {
382 ScopedGpuDataManagerImplPrivate manager;
384 manager->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(),
385 guilt_level,
386 GetTimeForTesting());
388 // This domain should be blocked no matter what.
389 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED,
390 manager->Are3DAPIsBlockedAtTime(GetDomain1ForTesting(),
391 GetTimeForTesting()));
392 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED,
393 manager->Are3DAPIsBlockedAtTime(
394 GetDomain1ForTesting(), JustBeforeExpiration(manager.get())));
395 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED,
396 manager->Are3DAPIsBlockedAtTime(
397 GetDomain1ForTesting(), JustAfterExpiration(manager.get())));
400 void GpuDataManagerImplPrivateTest::TestUnblockingDomainFrom3DAPIs(
401 GpuDataManagerImpl::DomainGuilt guilt_level) {
402 ScopedGpuDataManagerImplPrivate manager;
404 manager->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(),
405 guilt_level,
406 GetTimeForTesting());
408 // Unblocking the domain should work.
409 manager->UnblockDomainFrom3DAPIs(GetDomain1ForTesting());
410 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED,
411 manager->Are3DAPIsBlockedAtTime(GetDomain1ForTesting(),
412 GetTimeForTesting()));
413 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED,
414 manager->Are3DAPIsBlockedAtTime(
415 GetDomain1ForTesting(), JustBeforeExpiration(manager.get())));
416 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED,
417 manager->Are3DAPIsBlockedAtTime(
418 GetDomain1ForTesting(), JustAfterExpiration(manager.get())));
421 TEST_F(GpuDataManagerImplPrivateTest, BlockGuiltyDomainFrom3DAPIs) {
422 TestBlockingDomainFrom3DAPIs(GpuDataManagerImpl::DOMAIN_GUILT_KNOWN);
425 TEST_F(GpuDataManagerImplPrivateTest, BlockDomainOfUnknownGuiltFrom3DAPIs) {
426 TestBlockingDomainFrom3DAPIs(GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN);
429 TEST_F(GpuDataManagerImplPrivateTest, BlockAllDomainsFrom3DAPIs) {
430 ScopedGpuDataManagerImplPrivate manager;
432 manager->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(),
433 GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN,
434 GetTimeForTesting());
436 // Blocking of other domains should expire.
437 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_ALL_DOMAINS_BLOCKED,
438 manager->Are3DAPIsBlockedAtTime(
439 GetDomain2ForTesting(), JustBeforeExpiration(manager.get())));
440 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED,
441 manager->Are3DAPIsBlockedAtTime(
442 GetDomain2ForTesting(), JustAfterExpiration(manager.get())));
445 TEST_F(GpuDataManagerImplPrivateTest, UnblockGuiltyDomainFrom3DAPIs) {
446 TestUnblockingDomainFrom3DAPIs(GpuDataManagerImpl::DOMAIN_GUILT_KNOWN);
449 TEST_F(GpuDataManagerImplPrivateTest, UnblockDomainOfUnknownGuiltFrom3DAPIs) {
450 TestUnblockingDomainFrom3DAPIs(GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN);
453 TEST_F(GpuDataManagerImplPrivateTest, UnblockOtherDomainFrom3DAPIs) {
454 ScopedGpuDataManagerImplPrivate manager;
456 manager->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(),
457 GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN,
458 GetTimeForTesting());
460 manager->UnblockDomainFrom3DAPIs(GetDomain2ForTesting());
462 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED,
463 manager->Are3DAPIsBlockedAtTime(
464 GetDomain2ForTesting(), JustBeforeExpiration(manager.get())));
466 // The original domain should still be blocked.
467 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED,
468 manager->Are3DAPIsBlockedAtTime(
469 GetDomain1ForTesting(), JustBeforeExpiration(manager.get())));
472 TEST_F(GpuDataManagerImplPrivateTest, UnblockThisDomainFrom3DAPIs) {
473 ScopedGpuDataManagerImplPrivate manager;
475 manager->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(),
476 GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN,
477 GetTimeForTesting());
479 manager->UnblockDomainFrom3DAPIs(GetDomain1ForTesting());
481 // This behavior is debatable. Perhaps the GPU reset caused by
482 // domain 1 should still cause other domains to be blocked.
483 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED,
484 manager->Are3DAPIsBlockedAtTime(
485 GetDomain2ForTesting(), JustBeforeExpiration(manager.get())));
488 #if defined(OS_LINUX)
489 TEST_F(GpuDataManagerImplPrivateTest, SetGLStrings) {
490 const char* kGLVendorMesa = "Tungsten Graphics, Inc";
491 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41";
492 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL";
494 ScopedGpuDataManagerImplPrivate manager;
495 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
496 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
498 const std::string blacklist_json = LONG_STRING_CONST(
500 "name": "gpu blacklist",
501 "version": "0.1",
502 "entries": [
504 "id": 1,
505 "vendor_id": "0x8086",
506 "exceptions": [
508 "device_id": ["0x0042"],
509 "driver_version": {
510 "op": ">=",
511 "value": "8.0.2"
515 "features": [
516 "webgl"
522 gpu::GPUInfo gpu_info;
523 gpu_info.gpu.vendor_id = 0x8086;
524 gpu_info.gpu.device_id = 0x0042;
525 manager->InitializeForTesting(blacklist_json, gpu_info);
527 // Not enough GPUInfo.
528 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
529 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
531 // Now assume browser gets GL strings from local state.
532 // The entry applies, blacklist more features than from the preliminary step.
533 // However, GPU process is not blocked because this is all browser side and
534 // happens before renderer launching.
535 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa801);
536 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
537 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
538 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL));
541 TEST_F(GpuDataManagerImplPrivateTest, SetGLStringsNoEffects) {
542 const char* kGLVendorMesa = "Tungsten Graphics, Inc";
543 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41";
544 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL";
545 const char* kGLVersionMesa802 = "2.1 Mesa 8.0.2-DEVEL";
547 ScopedGpuDataManagerImplPrivate manager;
548 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
549 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
551 const std::string blacklist_json = LONG_STRING_CONST(
553 "name": "gpu blacklist",
554 "version": "0.1",
555 "entries": [
557 "id": 1,
558 "vendor_id": "0x8086",
559 "exceptions": [
561 "device_id": ["0x0042"],
562 "driver_version": {
563 "op": ">=",
564 "value": "8.0.2"
568 "features": [
569 "webgl"
575 gpu::GPUInfo gpu_info;
576 gpu_info.gpu.vendor_id = 0x8086;
577 gpu_info.gpu.device_id = 0x0042;
578 gpu_info.gl_vendor = kGLVendorMesa;
579 gpu_info.gl_renderer = kGLRendererMesa;
580 gpu_info.gl_version = kGLVersionMesa801;
581 gpu_info.driver_vendor = "Mesa";
582 gpu_info.driver_version = "8.0.1";
583 manager->InitializeForTesting(blacklist_json, gpu_info);
585 // Full GPUInfo, the entry applies.
586 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
587 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
588 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL));
590 // Now assume browser gets GL strings from local state.
591 // SetGLStrings() has no effects because GPUInfo already got these strings.
592 // (Otherwise the entry should not apply.)
593 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa802);
594 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
595 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
596 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL));
598 #endif // OS_LINUX
600 TEST_F(GpuDataManagerImplPrivateTest, GpuDriverBugListSingle) {
601 ScopedGpuDataManagerImplPrivate manager;
602 manager->gpu_driver_bugs_.insert(5);
604 CommandLine command_line(0, NULL);
605 manager->AppendGpuCommandLine(&command_line);
607 EXPECT_TRUE(command_line.HasSwitch(switches::kGpuDriverBugWorkarounds));
608 std::string args = command_line.GetSwitchValueASCII(
609 switches::kGpuDriverBugWorkarounds);
610 EXPECT_STREQ("5", args.c_str());
613 TEST_F(GpuDataManagerImplPrivateTest, GpuDriverBugListMultiple) {
614 ScopedGpuDataManagerImplPrivate manager;
615 manager->gpu_driver_bugs_.insert(5);
616 manager->gpu_driver_bugs_.insert(7);
618 CommandLine command_line(0, NULL);
619 manager->AppendGpuCommandLine(&command_line);
621 EXPECT_TRUE(command_line.HasSwitch(switches::kGpuDriverBugWorkarounds));
622 std::string args = command_line.GetSwitchValueASCII(
623 switches::kGpuDriverBugWorkarounds);
624 EXPECT_STREQ("5,7", args.c_str());
627 TEST_F(GpuDataManagerImplPrivateTest, BlacklistAllFeatures) {
628 ScopedGpuDataManagerImplPrivate manager;
629 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
630 std::string reason;
631 EXPECT_TRUE(manager->GpuAccessAllowed(&reason));
632 EXPECT_TRUE(reason.empty());
634 const std::string blacklist_json = LONG_STRING_CONST(
636 "name": "gpu blacklist",
637 "version": "0.1",
638 "entries": [
640 "id": 1,
641 "features": [
642 "all"
649 gpu::GPUInfo gpu_info;
650 gpu_info.gpu.vendor_id = 0x10de;
651 gpu_info.gpu.device_id = 0x0640;
652 manager->InitializeForTesting(blacklist_json, gpu_info);
654 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES),
655 manager->GetBlacklistedFeatureCount());
656 // TODO(zmo): remove the Linux specific behavior once we fix
657 // crbug.com/238466.
658 #if defined(OS_LINUX)
659 EXPECT_TRUE(manager->GpuAccessAllowed(&reason));
660 EXPECT_TRUE(reason.empty());
661 #else
662 EXPECT_FALSE(manager->GpuAccessAllowed(&reason));
663 EXPECT_FALSE(reason.empty());
664 #endif
667 TEST_F(GpuDataManagerImplPrivateTest, UpdateActiveGpu) {
668 ScopedGpuDataManagerImpl manager;
670 const std::string blacklist_json = LONG_STRING_CONST(
672 "name": "gpu blacklist",
673 "version": "0.1",
674 "entries": [
676 "id": 1,
677 "vendor_id": "0x8086",
678 "multi_gpu_category": "active",
679 "features": [
680 "webgl"
687 // Two GPUs, the secondary Intel GPU is active.
688 gpu::GPUInfo gpu_info;
689 gpu_info.gpu.vendor_id = 0x10de;
690 gpu_info.gpu.device_id = 0x0640;
691 gpu_info.gpu.active = false;
692 gpu::GPUInfo::GPUDevice intel_gpu;
693 intel_gpu.vendor_id = 0x8086;
694 intel_gpu.device_id = 0x04a1;
695 intel_gpu.active = true;
696 gpu_info.secondary_gpus.push_back(intel_gpu);
698 manager->InitializeForTesting(blacklist_json, gpu_info);
699 TestObserver observer;
700 manager->AddObserver(&observer);
702 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
704 // Update with the same Intel GPU active.
705 EXPECT_FALSE(manager->UpdateActiveGpu(0x8086, 0x04a1));
707 base::RunLoop run_loop;
708 run_loop.RunUntilIdle();
710 EXPECT_FALSE(observer.gpu_info_updated());
711 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
713 // Set NVIDIA GPU to be active.
714 EXPECT_TRUE(manager->UpdateActiveGpu(0x10de, 0x0640));
716 base::RunLoop run_loop;
717 run_loop.RunUntilIdle();
719 EXPECT_TRUE(observer.gpu_info_updated());
720 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
722 observer.Reset();
723 EXPECT_FALSE(observer.gpu_info_updated());
725 // Update with the same NVIDIA GPU active.
726 EXPECT_FALSE(manager->UpdateActiveGpu(0x10de, 0x0640));
728 base::RunLoop run_loop;
729 run_loop.RunUntilIdle();
731 EXPECT_FALSE(observer.gpu_info_updated());
732 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
734 // Set Intel GPU to be active.
735 EXPECT_TRUE(manager->UpdateActiveGpu(0x8086, 0x04a1));
737 base::RunLoop run_loop;
738 run_loop.RunUntilIdle();
740 EXPECT_TRUE(observer.gpu_info_updated());
741 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
744 } // namespace content