Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / content / browser / gpu / gpu_data_manager_impl_private_unittest.cc
blob8bcb01052e723fd1d3b61c2813a552840af2ad10
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 #if defined(OS_WIN)
18 #include "base/win/windows_version.h"
19 #endif
21 #define LONG_STRING_CONST(...) #__VA_ARGS__
23 namespace content {
24 namespace {
26 class TestObserver : public GpuDataManagerObserver {
27 public:
28 TestObserver()
29 : gpu_info_updated_(false),
30 video_memory_usage_stats_updated_(false) {
32 ~TestObserver() override {}
34 bool gpu_info_updated() const { return gpu_info_updated_; }
35 bool video_memory_usage_stats_updated() const {
36 return video_memory_usage_stats_updated_;
39 void OnGpuInfoUpdate() override { gpu_info_updated_ = true; }
41 void OnVideoMemoryUsageStatsUpdate(
42 const GPUVideoMemoryUsageStats& stats) override {
43 video_memory_usage_stats_updated_ = true;
46 void Reset() {
47 gpu_info_updated_ = false;
48 video_memory_usage_stats_updated_ = false;
51 private:
52 bool gpu_info_updated_;
53 bool video_memory_usage_stats_updated_;
56 static base::Time GetTimeForTesting() {
57 return base::Time::FromDoubleT(1000);
60 static GURL GetDomain1ForTesting() {
61 return GURL("http://foo.com/");
64 static GURL GetDomain2ForTesting() {
65 return GURL("http://bar.com/");
68 } // namespace anonymous
70 class GpuDataManagerImplPrivateTest : public testing::Test {
71 public:
72 GpuDataManagerImplPrivateTest() { }
74 ~GpuDataManagerImplPrivateTest() override {}
76 protected:
77 // scoped_ptr doesn't work with GpuDataManagerImpl because its
78 // destructor is private. GpuDataManagerImplPrivateTest is however a friend
79 // so we can make a little helper class here.
80 class ScopedGpuDataManagerImpl {
81 public:
82 ScopedGpuDataManagerImpl() : impl_(new GpuDataManagerImpl()) {
83 EXPECT_TRUE(impl_);
84 EXPECT_TRUE(impl_->private_.get());
86 ~ScopedGpuDataManagerImpl() { delete impl_; }
88 GpuDataManagerImpl* get() const { return impl_; }
90 GpuDataManagerImpl* operator->() const { return impl_; }
92 private:
93 GpuDataManagerImpl* impl_;
94 DISALLOW_COPY_AND_ASSIGN(ScopedGpuDataManagerImpl);
97 // We want to test the code path where GpuDataManagerImplPrivate is created
98 // in the GpuDataManagerImpl constructor.
99 class ScopedGpuDataManagerImplPrivate {
100 public:
101 ScopedGpuDataManagerImplPrivate() : impl_(new GpuDataManagerImpl()) {
102 EXPECT_TRUE(impl_);
103 EXPECT_TRUE(impl_->private_.get());
105 ~ScopedGpuDataManagerImplPrivate() { delete impl_; }
107 GpuDataManagerImplPrivate* get() const {
108 return impl_->private_.get();
111 GpuDataManagerImplPrivate* operator->() const {
112 return impl_->private_.get();
115 private:
116 GpuDataManagerImpl* impl_;
117 DISALLOW_COPY_AND_ASSIGN(ScopedGpuDataManagerImplPrivate);
120 void SetUp() override {}
122 void TearDown() override {}
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": ".*GeForce.*",
162 "features": [
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",
199 "version": "0.1",
200 "entries": [
202 "id": 1,
203 "exceptions": [
205 "gl_renderer": ".*GeForce.*"
208 "features": [
209 "webgl"
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());
233 std::string reason;
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, WarpEnabledOverridesSwiftShader) {
288 // If WARP fallback is enabled on Windows 8 it should not allow SwiftShader
289 // to be enabled.
290 #if defined(OS_WIN)
291 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
292 ScopedGpuDataManagerImplPrivate manager;
293 manager->ForceWarpModeForTesting();
294 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath"));
295 manager->RegisterSwiftShaderPath(test_path);
296 manager->DisableHardwareAcceleration();
297 EXPECT_TRUE(manager->ShouldUseWarp());
298 EXPECT_FALSE(manager->ShouldUseSwiftShader());
300 #endif
303 TEST_F(GpuDataManagerImplPrivateTest, GpuInfoUpdate) {
304 ScopedGpuDataManagerImpl manager;
306 TestObserver observer;
307 manager->AddObserver(&observer);
310 base::RunLoop run_loop;
311 run_loop.RunUntilIdle();
313 EXPECT_FALSE(observer.gpu_info_updated());
315 gpu::GPUInfo gpu_info;
316 manager->UpdateGpuInfo(gpu_info);
318 base::RunLoop run_loop;
319 run_loop.RunUntilIdle();
321 EXPECT_TRUE(observer.gpu_info_updated());
324 TEST_F(GpuDataManagerImplPrivateTest, NoGpuInfoUpdateWithSwiftShader) {
325 ScopedGpuDataManagerImpl manager;
327 manager->DisableHardwareAcceleration();
328 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath"));
329 manager->RegisterSwiftShaderPath(test_path);
330 EXPECT_TRUE(manager->ShouldUseSwiftShader());
331 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
334 base::RunLoop run_loop;
335 run_loop.RunUntilIdle();
338 TestObserver observer;
339 manager->AddObserver(&observer);
341 base::RunLoop run_loop;
342 run_loop.RunUntilIdle();
344 EXPECT_FALSE(observer.gpu_info_updated());
346 gpu::GPUInfo gpu_info;
347 manager->UpdateGpuInfo(gpu_info);
349 base::RunLoop run_loop;
350 run_loop.RunUntilIdle();
352 EXPECT_FALSE(observer.gpu_info_updated());
355 TEST_F(GpuDataManagerImplPrivateTest, GPUVideoMemoryUsageStatsUpdate) {
356 ScopedGpuDataManagerImpl manager;
358 TestObserver observer;
359 manager->AddObserver(&observer);
362 base::RunLoop run_loop;
363 run_loop.RunUntilIdle();
365 EXPECT_FALSE(observer.video_memory_usage_stats_updated());
367 GPUVideoMemoryUsageStats vram_stats;
368 manager->UpdateVideoMemoryUsageStats(vram_stats);
370 base::RunLoop run_loop;
371 run_loop.RunUntilIdle();
373 EXPECT_TRUE(observer.video_memory_usage_stats_updated());
376 base::Time GpuDataManagerImplPrivateTest::JustBeforeExpiration(
377 const GpuDataManagerImplPrivate* manager) {
378 return GetTimeForTesting() + base::TimeDelta::FromMilliseconds(
379 manager->GetBlockAllDomainsDurationInMs()) -
380 base::TimeDelta::FromMilliseconds(3);
383 base::Time GpuDataManagerImplPrivateTest::JustAfterExpiration(
384 const GpuDataManagerImplPrivate* manager) {
385 return GetTimeForTesting() + base::TimeDelta::FromMilliseconds(
386 manager->GetBlockAllDomainsDurationInMs()) +
387 base::TimeDelta::FromMilliseconds(3);
390 void GpuDataManagerImplPrivateTest::TestBlockingDomainFrom3DAPIs(
391 GpuDataManagerImpl::DomainGuilt guilt_level) {
392 ScopedGpuDataManagerImplPrivate manager;
394 manager->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(),
395 guilt_level,
396 GetTimeForTesting());
398 // This domain should be blocked no matter what.
399 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED,
400 manager->Are3DAPIsBlockedAtTime(GetDomain1ForTesting(),
401 GetTimeForTesting()));
402 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED,
403 manager->Are3DAPIsBlockedAtTime(
404 GetDomain1ForTesting(), JustBeforeExpiration(manager.get())));
405 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED,
406 manager->Are3DAPIsBlockedAtTime(
407 GetDomain1ForTesting(), JustAfterExpiration(manager.get())));
410 void GpuDataManagerImplPrivateTest::TestUnblockingDomainFrom3DAPIs(
411 GpuDataManagerImpl::DomainGuilt guilt_level) {
412 ScopedGpuDataManagerImplPrivate manager;
414 manager->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(),
415 guilt_level,
416 GetTimeForTesting());
418 // Unblocking the domain should work.
419 manager->UnblockDomainFrom3DAPIs(GetDomain1ForTesting());
420 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED,
421 manager->Are3DAPIsBlockedAtTime(GetDomain1ForTesting(),
422 GetTimeForTesting()));
423 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED,
424 manager->Are3DAPIsBlockedAtTime(
425 GetDomain1ForTesting(), JustBeforeExpiration(manager.get())));
426 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED,
427 manager->Are3DAPIsBlockedAtTime(
428 GetDomain1ForTesting(), JustAfterExpiration(manager.get())));
431 TEST_F(GpuDataManagerImplPrivateTest, BlockGuiltyDomainFrom3DAPIs) {
432 TestBlockingDomainFrom3DAPIs(GpuDataManagerImpl::DOMAIN_GUILT_KNOWN);
435 TEST_F(GpuDataManagerImplPrivateTest, BlockDomainOfUnknownGuiltFrom3DAPIs) {
436 TestBlockingDomainFrom3DAPIs(GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN);
439 TEST_F(GpuDataManagerImplPrivateTest, BlockAllDomainsFrom3DAPIs) {
440 ScopedGpuDataManagerImplPrivate manager;
442 manager->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(),
443 GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN,
444 GetTimeForTesting());
446 // Blocking of other domains should expire.
447 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_ALL_DOMAINS_BLOCKED,
448 manager->Are3DAPIsBlockedAtTime(
449 GetDomain2ForTesting(), JustBeforeExpiration(manager.get())));
450 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED,
451 manager->Are3DAPIsBlockedAtTime(
452 GetDomain2ForTesting(), JustAfterExpiration(manager.get())));
455 TEST_F(GpuDataManagerImplPrivateTest, UnblockGuiltyDomainFrom3DAPIs) {
456 TestUnblockingDomainFrom3DAPIs(GpuDataManagerImpl::DOMAIN_GUILT_KNOWN);
459 TEST_F(GpuDataManagerImplPrivateTest, UnblockDomainOfUnknownGuiltFrom3DAPIs) {
460 TestUnblockingDomainFrom3DAPIs(GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN);
463 TEST_F(GpuDataManagerImplPrivateTest, UnblockOtherDomainFrom3DAPIs) {
464 ScopedGpuDataManagerImplPrivate manager;
466 manager->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(),
467 GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN,
468 GetTimeForTesting());
470 manager->UnblockDomainFrom3DAPIs(GetDomain2ForTesting());
472 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED,
473 manager->Are3DAPIsBlockedAtTime(
474 GetDomain2ForTesting(), JustBeforeExpiration(manager.get())));
476 // The original domain should still be blocked.
477 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_BLOCKED,
478 manager->Are3DAPIsBlockedAtTime(
479 GetDomain1ForTesting(), JustBeforeExpiration(manager.get())));
482 TEST_F(GpuDataManagerImplPrivateTest, UnblockThisDomainFrom3DAPIs) {
483 ScopedGpuDataManagerImplPrivate manager;
485 manager->BlockDomainFrom3DAPIsAtTime(GetDomain1ForTesting(),
486 GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN,
487 GetTimeForTesting());
489 manager->UnblockDomainFrom3DAPIs(GetDomain1ForTesting());
491 // This behavior is debatable. Perhaps the GPU reset caused by
492 // domain 1 should still cause other domains to be blocked.
493 EXPECT_EQ(GpuDataManagerImpl::DOMAIN_BLOCK_STATUS_NOT_BLOCKED,
494 manager->Are3DAPIsBlockedAtTime(
495 GetDomain2ForTesting(), JustBeforeExpiration(manager.get())));
498 #if defined(OS_LINUX)
499 TEST_F(GpuDataManagerImplPrivateTest, SetGLStrings) {
500 const char* kGLVendorMesa = "Tungsten Graphics, Inc";
501 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41";
502 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL";
504 ScopedGpuDataManagerImplPrivate manager;
505 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
506 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
508 const std::string blacklist_json = LONG_STRING_CONST(
510 "name": "gpu blacklist",
511 "version": "0.1",
512 "entries": [
514 "id": 1,
515 "vendor_id": "0x8086",
516 "exceptions": [
518 "device_id": ["0x0042"],
519 "driver_version": {
520 "op": ">=",
521 "value": "8.0.2"
525 "features": [
526 "webgl"
532 gpu::GPUInfo gpu_info;
533 gpu_info.gpu.vendor_id = 0x8086;
534 gpu_info.gpu.device_id = 0x0042;
535 manager->InitializeForTesting(blacklist_json, gpu_info);
537 // Not enough GPUInfo.
538 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
539 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
541 // Now assume browser gets GL strings from local state.
542 // The entry applies, blacklist more features than from the preliminary step.
543 // However, GPU process is not blocked because this is all browser side and
544 // happens before renderer launching.
545 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa801);
546 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
547 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
548 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL));
551 TEST_F(GpuDataManagerImplPrivateTest, SetGLStringsNoEffects) {
552 const char* kGLVendorMesa = "Tungsten Graphics, Inc";
553 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41";
554 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL";
555 const char* kGLVersionMesa802 = "2.1 Mesa 8.0.2-DEVEL";
557 ScopedGpuDataManagerImplPrivate manager;
558 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
559 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
561 const std::string blacklist_json = LONG_STRING_CONST(
563 "name": "gpu blacklist",
564 "version": "0.1",
565 "entries": [
567 "id": 1,
568 "vendor_id": "0x8086",
569 "exceptions": [
571 "device_id": ["0x0042"],
572 "driver_version": {
573 "op": ">=",
574 "value": "8.0.2"
578 "features": [
579 "webgl"
585 gpu::GPUInfo gpu_info;
586 gpu_info.gpu.vendor_id = 0x8086;
587 gpu_info.gpu.device_id = 0x0042;
588 gpu_info.gl_vendor = kGLVendorMesa;
589 gpu_info.gl_renderer = kGLRendererMesa;
590 gpu_info.gl_version = kGLVersionMesa801;
591 gpu_info.driver_vendor = "Mesa";
592 gpu_info.driver_version = "8.0.1";
593 manager->InitializeForTesting(blacklist_json, gpu_info);
595 // Full GPUInfo, the entry applies.
596 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
597 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
598 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL));
600 // Now assume browser gets GL strings from local state.
601 // SetGLStrings() has no effects because GPUInfo already got these strings.
602 // (Otherwise the entry should not apply.)
603 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa802);
604 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
605 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
606 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL));
608 #endif // OS_LINUX
610 TEST_F(GpuDataManagerImplPrivateTest, GpuDriverBugListSingle) {
611 ScopedGpuDataManagerImplPrivate manager;
612 manager->gpu_driver_bugs_.insert(5);
614 base::CommandLine command_line(0, NULL);
615 manager->AppendGpuCommandLine(&command_line);
617 EXPECT_TRUE(command_line.HasSwitch(switches::kGpuDriverBugWorkarounds));
618 std::string args = command_line.GetSwitchValueASCII(
619 switches::kGpuDriverBugWorkarounds);
620 EXPECT_STREQ("5", args.c_str());
623 TEST_F(GpuDataManagerImplPrivateTest, GpuDriverBugListMultiple) {
624 ScopedGpuDataManagerImplPrivate manager;
625 manager->gpu_driver_bugs_.insert(5);
626 manager->gpu_driver_bugs_.insert(7);
628 base::CommandLine command_line(0, NULL);
629 manager->AppendGpuCommandLine(&command_line);
631 EXPECT_TRUE(command_line.HasSwitch(switches::kGpuDriverBugWorkarounds));
632 std::string args = command_line.GetSwitchValueASCII(
633 switches::kGpuDriverBugWorkarounds);
634 EXPECT_STREQ("5,7", args.c_str());
637 TEST_F(GpuDataManagerImplPrivateTest, BlacklistAllFeatures) {
638 ScopedGpuDataManagerImplPrivate manager;
639 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
640 std::string reason;
641 EXPECT_TRUE(manager->GpuAccessAllowed(&reason));
642 EXPECT_TRUE(reason.empty());
644 const std::string blacklist_json = LONG_STRING_CONST(
646 "name": "gpu blacklist",
647 "version": "0.1",
648 "entries": [
650 "id": 1,
651 "features": [
652 "all"
659 gpu::GPUInfo gpu_info;
660 gpu_info.gpu.vendor_id = 0x10de;
661 gpu_info.gpu.device_id = 0x0640;
662 manager->InitializeForTesting(blacklist_json, gpu_info);
664 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES),
665 manager->GetBlacklistedFeatureCount());
666 // TODO(zmo): remove the Linux specific behavior once we fix
667 // crbug.com/238466.
668 #if defined(OS_LINUX)
669 EXPECT_TRUE(manager->GpuAccessAllowed(&reason));
670 EXPECT_TRUE(reason.empty());
671 #else
672 EXPECT_FALSE(manager->GpuAccessAllowed(&reason));
673 EXPECT_FALSE(reason.empty());
674 #endif
677 TEST_F(GpuDataManagerImplPrivateTest, UpdateActiveGpu) {
678 ScopedGpuDataManagerImpl manager;
680 const std::string blacklist_json = LONG_STRING_CONST(
682 "name": "gpu blacklist",
683 "version": "0.1",
684 "entries": [
686 "id": 1,
687 "vendor_id": "0x8086",
688 "multi_gpu_category": "active",
689 "features": [
690 "webgl"
697 // Two GPUs, the secondary Intel GPU is active.
698 gpu::GPUInfo gpu_info;
699 gpu_info.gpu.vendor_id = 0x10de;
700 gpu_info.gpu.device_id = 0x0640;
701 gpu_info.gpu.active = false;
702 gpu::GPUInfo::GPUDevice intel_gpu;
703 intel_gpu.vendor_id = 0x8086;
704 intel_gpu.device_id = 0x04a1;
705 intel_gpu.active = true;
706 gpu_info.secondary_gpus.push_back(intel_gpu);
708 manager->InitializeForTesting(blacklist_json, gpu_info);
709 TestObserver observer;
710 manager->AddObserver(&observer);
712 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
714 // Update with the same Intel GPU active.
715 EXPECT_FALSE(manager->UpdateActiveGpu(0x8086, 0x04a1));
717 base::RunLoop run_loop;
718 run_loop.RunUntilIdle();
720 EXPECT_FALSE(observer.gpu_info_updated());
721 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
723 // Set NVIDIA GPU to be active.
724 EXPECT_TRUE(manager->UpdateActiveGpu(0x10de, 0x0640));
726 base::RunLoop run_loop;
727 run_loop.RunUntilIdle();
729 EXPECT_TRUE(observer.gpu_info_updated());
730 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
732 observer.Reset();
733 EXPECT_FALSE(observer.gpu_info_updated());
735 // Update with the same NVIDIA GPU active.
736 EXPECT_FALSE(manager->UpdateActiveGpu(0x10de, 0x0640));
738 base::RunLoop run_loop;
739 run_loop.RunUntilIdle();
741 EXPECT_FALSE(observer.gpu_info_updated());
742 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
744 // Set Intel GPU to be active.
745 EXPECT_TRUE(manager->UpdateActiveGpu(0x8086, 0x04a1));
747 base::RunLoop run_loop;
748 run_loop.RunUntilIdle();
750 EXPECT_TRUE(observer.gpu_info_updated());
751 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
754 } // namespace content