OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "base/time.h" | 7 #include "base/time.h" |
8 #include "content/browser/gpu/gpu_data_manager_impl.h" | 8 #include "content/browser/gpu/gpu_data_manager_impl.h" |
9 #include "content/public/browser/gpu_data_manager_observer.h" | 9 #include "content/public/browser/gpu_data_manager_observer.h" |
10 #include "content/public/common/gpu_info.h" | 10 #include "content/public/common/gpu_info.h" |
11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
| 14 #define LONG_STRING_CONST(...) #__VA_ARGS__ |
| 15 |
14 namespace content { | 16 namespace content { |
15 namespace { | 17 namespace { |
16 | 18 |
17 class TestObserver : public GpuDataManagerObserver { | 19 class TestObserver : public GpuDataManagerObserver { |
18 public: | 20 public: |
19 TestObserver() | 21 TestObserver() |
20 : gpu_info_updated_(false), | 22 : gpu_info_updated_(false), |
21 video_memory_usage_stats_updated_(false) { | 23 video_memory_usage_stats_updated_(false) { |
22 } | 24 } |
23 virtual ~TestObserver() { } | 25 virtual ~TestObserver() { } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 TEST_F(GpuDataManagerImplTest, GpuSideBlacklisting) { | 105 TEST_F(GpuDataManagerImplTest, GpuSideBlacklisting) { |
104 // If a feature is allowed in preliminary step (browser side), but | 106 // If a feature is allowed in preliminary step (browser side), but |
105 // disabled when GPU process launches and collects full GPU info, | 107 // disabled when GPU process launches and collects full GPU info, |
106 // it's too late to let renderer know, so we basically block all GPU | 108 // it's too late to let renderer know, so we basically block all GPU |
107 // access, to be on the safe side. | 109 // access, to be on the safe side. |
108 ScopedGpuDataManagerImpl manager; | 110 ScopedGpuDataManagerImpl manager; |
109 ASSERT_TRUE(manager.get()); | 111 ASSERT_TRUE(manager.get()); |
110 EXPECT_EQ(0, manager->GetBlacklistedFeatures()); | 112 EXPECT_EQ(0, manager->GetBlacklistedFeatures()); |
111 EXPECT_TRUE(manager->GpuAccessAllowed()); | 113 EXPECT_TRUE(manager->GpuAccessAllowed()); |
112 | 114 |
113 const std::string blacklist_json = | 115 const std::string blacklist_json = LONG_STRING_CONST( |
114 "{\n" | 116 { |
115 " \"name\": \"gpu blacklist\",\n" | 117 "name": "gpu blacklist", |
116 " \"version\": \"0.1\",\n" | 118 "version": "0.1", |
117 " \"entries\": [\n" | 119 "entries": [ |
118 " {\n" | 120 { |
119 " \"id\": 1,\n" | 121 "id": 1, |
120 " \"blacklist\": [\n" | 122 "features": [ |
121 " \"webgl\"\n" | 123 "webgl" |
122 " ]\n" | 124 ] |
123 " },\n" | 125 }, |
124 " {\n" | 126 { |
125 " \"id\": 2,\n" | 127 "id": 2, |
126 " \"gl_renderer\": {\n" | 128 "gl_renderer": { |
127 " \"op\": \"contains\",\n" | 129 "op": "contains", |
128 " \"value\": \"GeForce\"\n" | 130 "value": "GeForce" |
129 " },\n" | 131 }, |
130 " \"blacklist\": [\n" | 132 "features": [ |
131 " \"accelerated_2d_canvas\"\n" | 133 "accelerated_2d_canvas" |
132 " ]\n" | 134 ] |
133 " }\n" | 135 } |
134 " ]\n" | 136 ] |
135 "}"; | 137 } |
| 138 ); |
136 | 139 |
137 GPUInfo gpu_info; | 140 GPUInfo gpu_info; |
138 gpu_info.gpu.vendor_id = 0x10de; | 141 gpu_info.gpu.vendor_id = 0x10de; |
139 gpu_info.gpu.device_id = 0x0640; | 142 gpu_info.gpu.device_id = 0x0640; |
140 manager->InitializeForTesting(blacklist_json, gpu_info); | 143 manager->InitializeForTesting(blacklist_json, gpu_info); |
141 | 144 |
142 EXPECT_TRUE(manager->GpuAccessAllowed()); | 145 EXPECT_TRUE(manager->GpuAccessAllowed()); |
143 EXPECT_EQ(GPU_FEATURE_TYPE_WEBGL, manager->GetBlacklistedFeatures()); | 146 EXPECT_EQ(GPU_FEATURE_TYPE_WEBGL, manager->GetBlacklistedFeatures()); |
144 | 147 |
145 gpu_info.gl_vendor = "NVIDIA"; | 148 gpu_info.gl_vendor = "NVIDIA"; |
146 gpu_info.gl_renderer = "NVIDIA GeForce GT 120"; | 149 gpu_info.gl_renderer = "NVIDIA GeForce GT 120"; |
147 manager->UpdateGpuInfo(gpu_info); | 150 manager->UpdateGpuInfo(gpu_info); |
148 EXPECT_FALSE(manager->GpuAccessAllowed()); | 151 EXPECT_FALSE(manager->GpuAccessAllowed()); |
149 EXPECT_EQ(GPU_FEATURE_TYPE_WEBGL | | 152 EXPECT_EQ(GPU_FEATURE_TYPE_WEBGL | |
150 GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS, | 153 GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS, |
151 manager->GetBlacklistedFeatures()); | 154 manager->GetBlacklistedFeatures()); |
152 } | 155 } |
153 | 156 |
154 TEST_F(GpuDataManagerImplTest, GpuSideExceptions) { | 157 TEST_F(GpuDataManagerImplTest, GpuSideExceptions) { |
155 ScopedGpuDataManagerImpl manager; | 158 ScopedGpuDataManagerImpl manager; |
156 ASSERT_TRUE(manager.get()); | 159 ASSERT_TRUE(manager.get()); |
157 EXPECT_EQ(0, manager->GetBlacklistedFeatures()); | 160 EXPECT_EQ(0, manager->GetBlacklistedFeatures()); |
158 EXPECT_TRUE(manager->GpuAccessAllowed()); | 161 EXPECT_TRUE(manager->GpuAccessAllowed()); |
159 | 162 |
160 const std::string blacklist_json = | 163 const std::string blacklist_json = LONG_STRING_CONST( |
161 "{\n" | 164 { |
162 " \"name\": \"gpu blacklist\",\n" | 165 "name": "gpu blacklist", |
163 " \"version\": \"0.1\",\n" | 166 "version": "0.1", |
164 " \"entries\": [\n" | 167 "entries": [ |
165 " {\n" | 168 { |
166 " \"id\": 1,\n" | 169 "id": 1, |
167 " \"exceptions\": [\n" | 170 "exceptions": [ |
168 " {\n" | 171 { |
169 " \"gl_renderer\": {\n" | 172 "gl_renderer": { |
170 " \"op\": \"contains\",\n" | 173 "op": "contains", |
171 " \"value\": \"GeForce\"\n" | 174 "value": "GeForce" |
172 " }\n" | 175 } |
173 " }\n" | 176 } |
174 " ],\n" | 177 ], |
175 " \"blacklist\": [\n" | 178 "features": [ |
176 " \"webgl\"\n" | 179 "webgl" |
177 " ]\n" | 180 ] |
178 " }\n" | 181 } |
179 " ]\n" | 182 ] |
180 "}"; | 183 } |
181 | 184 ); |
182 GPUInfo gpu_info; | 185 GPUInfo gpu_info; |
183 gpu_info.gpu.vendor_id = 0x10de; | 186 gpu_info.gpu.vendor_id = 0x10de; |
184 gpu_info.gpu.device_id = 0x0640; | 187 gpu_info.gpu.device_id = 0x0640; |
185 manager->InitializeForTesting(blacklist_json, gpu_info); | 188 manager->InitializeForTesting(blacklist_json, gpu_info); |
186 | 189 |
187 EXPECT_TRUE(manager->GpuAccessAllowed()); | 190 EXPECT_TRUE(manager->GpuAccessAllowed()); |
188 EXPECT_EQ(0, manager->GetBlacklistedFeatures()); | 191 EXPECT_EQ(0, manager->GetBlacklistedFeatures()); |
189 | 192 |
190 // Now assume gpu process launches and full GPU info is collected. | 193 // Now assume gpu process launches and full GPU info is collected. |
191 gpu_info.gl_renderer = "NVIDIA GeForce GT 120"; | 194 gpu_info.gl_renderer = "NVIDIA GeForce GT 120"; |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 TEST_F(GpuDataManagerImplTest, SetGLStrings) { | 458 TEST_F(GpuDataManagerImplTest, SetGLStrings) { |
456 const char* kGLVendorMesa = "Tungsten Graphics, Inc"; | 459 const char* kGLVendorMesa = "Tungsten Graphics, Inc"; |
457 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41"; | 460 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41"; |
458 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL"; | 461 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL"; |
459 | 462 |
460 ScopedGpuDataManagerImpl manager; | 463 ScopedGpuDataManagerImpl manager; |
461 ASSERT_TRUE(manager.get()); | 464 ASSERT_TRUE(manager.get()); |
462 EXPECT_EQ(0, manager->GetBlacklistedFeatures()); | 465 EXPECT_EQ(0, manager->GetBlacklistedFeatures()); |
463 EXPECT_TRUE(manager->GpuAccessAllowed()); | 466 EXPECT_TRUE(manager->GpuAccessAllowed()); |
464 | 467 |
465 const std::string blacklist_json = | 468 const std::string blacklist_json = LONG_STRING_CONST( |
466 "{\n" | 469 { |
467 " \"name\": \"gpu blacklist\",\n" | 470 "name": "gpu blacklist", |
468 " \"version\": \"0.1\",\n" | 471 "version": "0.1", |
469 " \"entries\": [\n" | 472 "entries": [ |
470 " {\n" | 473 { |
471 " \"id\": 1,\n" | 474 "id": 1, |
472 " \"vendor_id\": \"0x8086\",\n" | 475 "vendor_id": "0x8086", |
473 " \"exceptions\": [\n" | 476 "exceptions": [ |
474 " {\n" | 477 { |
475 " \"device_id\": [\"0x0042\"],\n" | 478 "device_id": ["0x0042"], |
476 " \"driver_version\": {\n" | 479 "driver_version": { |
477 " \"op\": \">=\",\n" | 480 "op": ">=", |
478 " \"number\": \"8.0.2\"\n" | 481 "number": "8.0.2" |
479 " }\n" | 482 } |
480 " }\n" | 483 } |
481 " ],\n" | 484 ], |
482 " \"blacklist\": [\n" | 485 "features": [ |
483 " \"webgl\"\n" | 486 "webgl" |
484 " ]\n" | 487 ] |
485 " }\n" | 488 } |
486 " ]\n" | 489 ] |
487 "}"; | 490 } |
488 | 491 ); |
489 GPUInfo gpu_info; | 492 GPUInfo gpu_info; |
490 gpu_info.gpu.vendor_id = 0x8086; | 493 gpu_info.gpu.vendor_id = 0x8086; |
491 gpu_info.gpu.device_id = 0x0042; | 494 gpu_info.gpu.device_id = 0x0042; |
492 manager->InitializeForTesting(blacklist_json, gpu_info); | 495 manager->InitializeForTesting(blacklist_json, gpu_info); |
493 | 496 |
494 // Not enough GPUInfo. | 497 // Not enough GPUInfo. |
495 EXPECT_TRUE(manager->GpuAccessAllowed()); | 498 EXPECT_TRUE(manager->GpuAccessAllowed()); |
496 EXPECT_EQ(0, manager->GetBlacklistedFeatures()); | 499 EXPECT_EQ(0, manager->GetBlacklistedFeatures()); |
497 | 500 |
498 // Now assume browser gets GL strings from local state. | 501 // Now assume browser gets GL strings from local state. |
499 // The entry applies, blacklist more features than from the preliminary step. | 502 // The entry applies, blacklist more features than from the preliminary step. |
500 // However, GPU process is not blocked because this is all browser side and | 503 // However, GPU process is not blocked because this is all browser side and |
501 // happens before renderer launching. | 504 // happens before renderer launching. |
502 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa801); | 505 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa801); |
503 EXPECT_TRUE(manager->GpuAccessAllowed()); | 506 EXPECT_TRUE(manager->GpuAccessAllowed()); |
504 EXPECT_EQ(GPU_FEATURE_TYPE_WEBGL, manager->GetBlacklistedFeatures()); | 507 EXPECT_EQ(GPU_FEATURE_TYPE_WEBGL, manager->GetBlacklistedFeatures()); |
505 } | 508 } |
506 | 509 |
507 TEST_F(GpuDataManagerImplTest, SetGLStringsNoEffects) { | 510 TEST_F(GpuDataManagerImplTest, SetGLStringsNoEffects) { |
508 const char* kGLVendorMesa = "Tungsten Graphics, Inc"; | 511 const char* kGLVendorMesa = "Tungsten Graphics, Inc"; |
509 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41"; | 512 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41"; |
510 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL"; | 513 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL"; |
511 const char* kGLVersionMesa802 = "2.1 Mesa 8.0.2-DEVEL"; | 514 const char* kGLVersionMesa802 = "2.1 Mesa 8.0.2-DEVEL"; |
512 | 515 |
513 ScopedGpuDataManagerImpl manager; | 516 ScopedGpuDataManagerImpl manager; |
514 ASSERT_TRUE(manager.get()); | 517 ASSERT_TRUE(manager.get()); |
515 EXPECT_EQ(0, manager->GetBlacklistedFeatures()); | 518 EXPECT_EQ(0, manager->GetBlacklistedFeatures()); |
516 EXPECT_TRUE(manager->GpuAccessAllowed()); | 519 EXPECT_TRUE(manager->GpuAccessAllowed()); |
517 | 520 |
518 const std::string blacklist_json = | 521 const std::string blacklist_json = LONG_STRING_CONST( |
519 "{\n" | 522 { |
520 " \"name\": \"gpu blacklist\",\n" | 523 "name": "gpu blacklist", |
521 " \"version\": \"0.1\",\n" | 524 "version": "0.1", |
522 " \"entries\": [\n" | 525 "entries": [ |
523 " {\n" | 526 { |
524 " \"id\": 1,\n" | 527 "id": 1, |
525 " \"vendor_id\": \"0x8086\",\n" | 528 "vendor_id": "0x8086", |
526 " \"exceptions\": [\n" | 529 "exceptions": [ |
527 " {\n" | 530 { |
528 " \"device_id\": [\"0x0042\"],\n" | 531 "device_id": ["0x0042"], |
529 " \"driver_version\": {\n" | 532 "driver_version": { |
530 " \"op\": \">=\",\n" | 533 "op": ">=", |
531 " \"number\": \"8.0.2\"\n" | 534 "number": "8.0.2" |
532 " }\n" | 535 } |
533 " }\n" | 536 } |
534 " ],\n" | 537 ], |
535 " \"blacklist\": [\n" | 538 "features": [ |
536 " \"webgl\"\n" | 539 "webgl" |
537 " ]\n" | 540 ] |
538 " }\n" | 541 } |
539 " ]\n" | 542 ] |
540 "}"; | 543 } |
541 | 544 ); |
542 GPUInfo gpu_info; | 545 GPUInfo gpu_info; |
543 gpu_info.gpu.vendor_id = 0x8086; | 546 gpu_info.gpu.vendor_id = 0x8086; |
544 gpu_info.gpu.device_id = 0x0042; | 547 gpu_info.gpu.device_id = 0x0042; |
545 gpu_info.gl_vendor = kGLVendorMesa; | 548 gpu_info.gl_vendor = kGLVendorMesa; |
546 gpu_info.gl_renderer = kGLRendererMesa; | 549 gpu_info.gl_renderer = kGLRendererMesa; |
547 gpu_info.gl_version = kGLVersionMesa801; | 550 gpu_info.gl_version = kGLVersionMesa801; |
548 gpu_info.driver_vendor = "Mesa"; | 551 gpu_info.driver_vendor = "Mesa"; |
549 gpu_info.driver_version = "8.0.1"; | 552 gpu_info.driver_version = "8.0.1"; |
550 manager->InitializeForTesting(blacklist_json, gpu_info); | 553 manager->InitializeForTesting(blacklist_json, gpu_info); |
551 | 554 |
552 // Full GPUInfo, the entry applies. | 555 // Full GPUInfo, the entry applies. |
553 EXPECT_TRUE(manager->GpuAccessAllowed()); | 556 EXPECT_TRUE(manager->GpuAccessAllowed()); |
554 EXPECT_EQ(GPU_FEATURE_TYPE_WEBGL, manager->GetBlacklistedFeatures()); | 557 EXPECT_EQ(GPU_FEATURE_TYPE_WEBGL, manager->GetBlacklistedFeatures()); |
555 | 558 |
556 // Now assume browser gets GL strings from local state. | 559 // Now assume browser gets GL strings from local state. |
557 // SetGLStrings() has no effects because GPUInfo already got these strings. | 560 // SetGLStrings() has no effects because GPUInfo already got these strings. |
558 // (Otherwise the entry should not apply.) | 561 // (Otherwise the entry should not apply.) |
559 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa802); | 562 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa802); |
560 EXPECT_TRUE(manager->GpuAccessAllowed()); | 563 EXPECT_TRUE(manager->GpuAccessAllowed()); |
561 EXPECT_EQ(GPU_FEATURE_TYPE_WEBGL, manager->GetBlacklistedFeatures()); | 564 EXPECT_EQ(GPU_FEATURE_TYPE_WEBGL, manager->GetBlacklistedFeatures()); |
562 } | 565 } |
563 #endif // OS_LINUX | 566 #endif // OS_LINUX |
564 | 567 |
565 } // namespace content | 568 } // namespace content |
OLD | NEW |