Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: content/browser/gpu/gpu_data_manager_impl_private_unittest.cc

Issue 237903002: Clean up mac gpu switching code a little. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix linux test Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/gpu/gpu_data_manager_impl_private.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "content/browser/gpu/gpu_data_manager_impl_private.h" 9 #include "content/browser/gpu/gpu_data_manager_impl_private.h"
10 #include "content/public/browser/gpu_data_manager_observer.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 "gpu/command_buffer/service/gpu_switches.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" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 16
17 #define LONG_STRING_CONST(...) #__VA_ARGS__ 17 #define LONG_STRING_CONST(...) #__VA_ARGS__
18 18
19 namespace content { 19 namespace content {
20 namespace { 20 namespace {
21 21
22 class TestObserver : public GpuDataManagerObserver { 22 class TestObserver : public GpuDataManagerObserver {
23 public: 23 public:
(...skipping 10 matching lines...) Expand all
34 34
35 virtual void OnGpuInfoUpdate() OVERRIDE { 35 virtual void OnGpuInfoUpdate() OVERRIDE {
36 gpu_info_updated_ = true; 36 gpu_info_updated_ = true;
37 } 37 }
38 38
39 virtual void OnVideoMemoryUsageStatsUpdate( 39 virtual void OnVideoMemoryUsageStatsUpdate(
40 const GPUVideoMemoryUsageStats& stats) OVERRIDE { 40 const GPUVideoMemoryUsageStats& stats) OVERRIDE {
41 video_memory_usage_stats_updated_ = true; 41 video_memory_usage_stats_updated_ = true;
42 } 42 }
43 43
44 void Reset() {
45 gpu_info_updated_ = false;
46 video_memory_usage_stats_updated_ = false;
47 }
48
44 private: 49 private:
45 bool gpu_info_updated_; 50 bool gpu_info_updated_;
46 bool video_memory_usage_stats_updated_; 51 bool video_memory_usage_stats_updated_;
47 }; 52 };
48 53
49 static base::Time GetTimeForTesting() { 54 static base::Time GetTimeForTesting() {
50 return base::Time::FromDoubleT(1000); 55 return base::Time::FromDoubleT(1000);
51 } 56 }
52 57
53 static GURL GetDomain1ForTesting() { 58 static GURL GetDomain1ForTesting() {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 "value": "GeForce" 163 "value": "GeForce"
159 }, 164 },
160 "features": [ 165 "features": [
161 "accelerated_2d_canvas" 166 "accelerated_2d_canvas"
162 ] 167 ]
163 } 168 }
164 ] 169 ]
165 } 170 }
166 ); 171 );
167 172
168 GPUInfo gpu_info; 173 gpu::GPUInfo gpu_info;
169 gpu_info.gpu.vendor_id = 0x10de; 174 gpu_info.gpu.vendor_id = 0x10de;
170 gpu_info.gpu.device_id = 0x0640; 175 gpu_info.gpu.device_id = 0x0640;
171 manager->InitializeForTesting(blacklist_json, gpu_info); 176 manager->InitializeForTesting(blacklist_json, gpu_info);
172 177
173 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); 178 EXPECT_TRUE(manager->GpuAccessAllowed(&reason));
174 EXPECT_TRUE(reason.empty()); 179 EXPECT_TRUE(reason.empty());
175 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); 180 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
176 EXPECT_TRUE(manager->IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)); 181 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL));
177 182
178 gpu_info.gl_vendor = "NVIDIA"; 183 gpu_info.gl_vendor = "NVIDIA";
179 gpu_info.gl_renderer = "NVIDIA GeForce GT 120"; 184 gpu_info.gl_renderer = "NVIDIA GeForce GT 120";
180 manager->UpdateGpuInfo(gpu_info); 185 manager->UpdateGpuInfo(gpu_info);
181 EXPECT_FALSE(manager->GpuAccessAllowed(&reason)); 186 EXPECT_FALSE(manager->GpuAccessAllowed(&reason));
182 EXPECT_FALSE(reason.empty()); 187 EXPECT_FALSE(reason.empty());
183 EXPECT_EQ(2u, manager->GetBlacklistedFeatureCount()); 188 EXPECT_EQ(2u, manager->GetBlacklistedFeatureCount());
184 EXPECT_TRUE(manager->IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)); 189 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL));
185 EXPECT_TRUE(manager->IsFeatureBlacklisted( 190 EXPECT_TRUE(manager->IsFeatureBlacklisted(
186 GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); 191 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS));
187 } 192 }
188 193
189 TEST_F(GpuDataManagerImplPrivateTest, GpuSideExceptions) { 194 TEST_F(GpuDataManagerImplPrivateTest, GpuSideExceptions) {
190 ScopedGpuDataManagerImplPrivate manager; 195 ScopedGpuDataManagerImplPrivate manager;
191 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); 196 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
192 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); 197 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
193 198
194 const std::string blacklist_json = LONG_STRING_CONST( 199 const std::string blacklist_json = LONG_STRING_CONST(
195 { 200 {
196 "name": "gpu blacklist", 201 "name": "gpu blacklist",
197 "version": "0.1", 202 "version": "0.1",
198 "entries": [ 203 "entries": [
199 { 204 {
200 "id": 1, 205 "id": 1,
201 "exceptions": [ 206 "exceptions": [
202 { 207 {
203 "gl_renderer": { 208 "gl_renderer": {
204 "op": "contains", 209 "op": "contains",
205 "value": "GeForce" 210 "value": "GeForce"
206 } 211 }
207 } 212 }
208 ], 213 ],
209 "features": [ 214 "features": [
210 "webgl" 215 "webgl"
211 ] 216 ]
212 } 217 }
213 ] 218 ]
214 } 219 }
215 ); 220 );
216 GPUInfo gpu_info; 221 gpu::GPUInfo gpu_info;
217 gpu_info.gpu.vendor_id = 0x10de; 222 gpu_info.gpu.vendor_id = 0x10de;
218 gpu_info.gpu.device_id = 0x0640; 223 gpu_info.gpu.device_id = 0x0640;
219 manager->InitializeForTesting(blacklist_json, gpu_info); 224 manager->InitializeForTesting(blacklist_json, gpu_info);
220 225
221 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); 226 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
222 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); 227 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
223 228
224 // Now assume gpu process launches and full GPU info is collected. 229 // Now assume gpu process launches and full GPU info is collected.
225 gpu_info.gl_renderer = "NVIDIA GeForce GT 120"; 230 gpu_info.gl_renderer = "NVIDIA GeForce GT 120";
226 manager->UpdateGpuInfo(gpu_info); 231 manager->UpdateGpuInfo(gpu_info);
227 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); 232 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
228 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); 233 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
229 } 234 }
230 235
231 TEST_F(GpuDataManagerImplPrivateTest, DisableHardwareAcceleration) { 236 TEST_F(GpuDataManagerImplPrivateTest, DisableHardwareAcceleration) {
232 ScopedGpuDataManagerImplPrivate manager; 237 ScopedGpuDataManagerImplPrivate manager;
233 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); 238 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
234 std::string reason; 239 std::string reason;
235 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); 240 EXPECT_TRUE(manager->GpuAccessAllowed(&reason));
236 EXPECT_TRUE(reason.empty()); 241 EXPECT_TRUE(reason.empty());
237 242
238 manager->DisableHardwareAcceleration(); 243 manager->DisableHardwareAcceleration();
239 EXPECT_FALSE(manager->GpuAccessAllowed(&reason)); 244 EXPECT_FALSE(manager->GpuAccessAllowed(&reason));
240 EXPECT_FALSE(reason.empty()); 245 EXPECT_FALSE(reason.empty());
241 EXPECT_EQ(static_cast<size_t>(NUMBER_OF_GPU_FEATURE_TYPES), 246 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES),
242 manager->GetBlacklistedFeatureCount()); 247 manager->GetBlacklistedFeatureCount());
243 } 248 }
244 249
245 TEST_F(GpuDataManagerImplPrivateTest, SwiftShaderRendering) { 250 TEST_F(GpuDataManagerImplPrivateTest, SwiftShaderRendering) {
246 // Blacklist, then register SwiftShader. 251 // Blacklist, then register SwiftShader.
247 ScopedGpuDataManagerImplPrivate manager; 252 ScopedGpuDataManagerImplPrivate manager;
248 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); 253 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
249 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); 254 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
250 EXPECT_FALSE(manager->ShouldUseSwiftShader()); 255 EXPECT_FALSE(manager->ShouldUseSwiftShader());
251 256
252 manager->DisableHardwareAcceleration(); 257 manager->DisableHardwareAcceleration();
253 EXPECT_FALSE(manager->GpuAccessAllowed(NULL)); 258 EXPECT_FALSE(manager->GpuAccessAllowed(NULL));
254 EXPECT_FALSE(manager->ShouldUseSwiftShader()); 259 EXPECT_FALSE(manager->ShouldUseSwiftShader());
255 260
256 // If SwiftShader is enabled, even if we blacklist GPU, 261 // If SwiftShader is enabled, even if we blacklist GPU,
257 // GPU process is still allowed. 262 // GPU process is still allowed.
258 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath")); 263 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath"));
259 manager->RegisterSwiftShaderPath(test_path); 264 manager->RegisterSwiftShaderPath(test_path);
260 EXPECT_TRUE(manager->ShouldUseSwiftShader()); 265 EXPECT_TRUE(manager->ShouldUseSwiftShader());
261 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); 266 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
262 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); 267 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
263 EXPECT_TRUE( 268 EXPECT_TRUE(manager->IsFeatureBlacklisted(
264 manager->IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); 269 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS));
265 } 270 }
266 271
267 TEST_F(GpuDataManagerImplPrivateTest, SwiftShaderRendering2) { 272 TEST_F(GpuDataManagerImplPrivateTest, SwiftShaderRendering2) {
268 // Register SwiftShader, then blacklist. 273 // Register SwiftShader, then blacklist.
269 ScopedGpuDataManagerImplPrivate manager; 274 ScopedGpuDataManagerImplPrivate manager;
270 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); 275 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
271 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); 276 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
272 EXPECT_FALSE(manager->ShouldUseSwiftShader()); 277 EXPECT_FALSE(manager->ShouldUseSwiftShader());
273 278
274 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath")); 279 const base::FilePath test_path(FILE_PATH_LITERAL("AnyPath"));
275 manager->RegisterSwiftShaderPath(test_path); 280 manager->RegisterSwiftShaderPath(test_path);
276 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); 281 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
277 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); 282 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
278 EXPECT_FALSE(manager->ShouldUseSwiftShader()); 283 EXPECT_FALSE(manager->ShouldUseSwiftShader());
279 284
280 manager->DisableHardwareAcceleration(); 285 manager->DisableHardwareAcceleration();
281 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); 286 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
282 EXPECT_TRUE(manager->ShouldUseSwiftShader()); 287 EXPECT_TRUE(manager->ShouldUseSwiftShader());
283 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); 288 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
284 EXPECT_TRUE( 289 EXPECT_TRUE(manager->IsFeatureBlacklisted(
285 manager->IsFeatureBlacklisted(GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)); 290 gpu::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS));
286 } 291 }
287 292
288 TEST_F(GpuDataManagerImplPrivateTest, GpuInfoUpdate) { 293 TEST_F(GpuDataManagerImplPrivateTest, GpuInfoUpdate) {
289 ScopedGpuDataManagerImpl manager; 294 ScopedGpuDataManagerImpl manager;
290 295
291 TestObserver observer; 296 TestObserver observer;
292 manager->AddObserver(&observer); 297 manager->AddObserver(&observer);
293 298
294 { 299 {
295 base::RunLoop run_loop; 300 base::RunLoop run_loop;
296 run_loop.RunUntilIdle(); 301 run_loop.RunUntilIdle();
297 } 302 }
298 EXPECT_FALSE(observer.gpu_info_updated()); 303 EXPECT_FALSE(observer.gpu_info_updated());
299 304
300 GPUInfo gpu_info; 305 gpu::GPUInfo gpu_info;
301 manager->UpdateGpuInfo(gpu_info); 306 manager->UpdateGpuInfo(gpu_info);
302 { 307 {
303 base::RunLoop run_loop; 308 base::RunLoop run_loop;
304 run_loop.RunUntilIdle(); 309 run_loop.RunUntilIdle();
305 } 310 }
306 EXPECT_TRUE(observer.gpu_info_updated()); 311 EXPECT_TRUE(observer.gpu_info_updated());
307 } 312 }
308 313
309 TEST_F(GpuDataManagerImplPrivateTest, NoGpuInfoUpdateWithSwiftShader) { 314 TEST_F(GpuDataManagerImplPrivateTest, NoGpuInfoUpdateWithSwiftShader) {
310 ScopedGpuDataManagerImpl manager; 315 ScopedGpuDataManagerImpl manager;
(...skipping 10 matching lines...) Expand all
321 } 326 }
322 327
323 TestObserver observer; 328 TestObserver observer;
324 manager->AddObserver(&observer); 329 manager->AddObserver(&observer);
325 { 330 {
326 base::RunLoop run_loop; 331 base::RunLoop run_loop;
327 run_loop.RunUntilIdle(); 332 run_loop.RunUntilIdle();
328 } 333 }
329 EXPECT_FALSE(observer.gpu_info_updated()); 334 EXPECT_FALSE(observer.gpu_info_updated());
330 335
331 GPUInfo gpu_info; 336 gpu::GPUInfo gpu_info;
332 manager->UpdateGpuInfo(gpu_info); 337 manager->UpdateGpuInfo(gpu_info);
333 { 338 {
334 base::RunLoop run_loop; 339 base::RunLoop run_loop;
335 run_loop.RunUntilIdle(); 340 run_loop.RunUntilIdle();
336 } 341 }
337 EXPECT_FALSE(observer.gpu_info_updated()); 342 EXPECT_FALSE(observer.gpu_info_updated());
338 } 343 }
339 344
340 TEST_F(GpuDataManagerImplPrivateTest, GPUVideoMemoryUsageStatsUpdate) { 345 TEST_F(GpuDataManagerImplPrivateTest, GPUVideoMemoryUsageStatsUpdate) {
341 ScopedGpuDataManagerImpl manager; 346 ScopedGpuDataManagerImpl manager;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 "version": "0.1", 501 "version": "0.1",
497 "entries": [ 502 "entries": [
498 { 503 {
499 "id": 1, 504 "id": 1,
500 "vendor_id": "0x8086", 505 "vendor_id": "0x8086",
501 "exceptions": [ 506 "exceptions": [
502 { 507 {
503 "device_id": ["0x0042"], 508 "device_id": ["0x0042"],
504 "driver_version": { 509 "driver_version": {
505 "op": ">=", 510 "op": ">=",
506 "number": "8.0.2" 511 "value": "8.0.2"
507 } 512 }
508 } 513 }
509 ], 514 ],
510 "features": [ 515 "features": [
511 "webgl" 516 "webgl"
512 ] 517 ]
513 } 518 }
514 ] 519 ]
515 } 520 }
516 ); 521 );
517 GPUInfo gpu_info; 522 gpu::GPUInfo gpu_info;
518 gpu_info.gpu.vendor_id = 0x8086; 523 gpu_info.gpu.vendor_id = 0x8086;
519 gpu_info.gpu.device_id = 0x0042; 524 gpu_info.gpu.device_id = 0x0042;
520 manager->InitializeForTesting(blacklist_json, gpu_info); 525 manager->InitializeForTesting(blacklist_json, gpu_info);
521 526
522 // Not enough GPUInfo. 527 // Not enough GPUInfo.
523 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); 528 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
524 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); 529 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
525 530
526 // Now assume browser gets GL strings from local state. 531 // Now assume browser gets GL strings from local state.
527 // The entry applies, blacklist more features than from the preliminary step. 532 // The entry applies, blacklist more features than from the preliminary step.
528 // However, GPU process is not blocked because this is all browser side and 533 // However, GPU process is not blocked because this is all browser side and
529 // happens before renderer launching. 534 // happens before renderer launching.
530 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa801); 535 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa801);
531 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); 536 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
532 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); 537 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
533 EXPECT_TRUE(manager->IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)); 538 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL));
534 } 539 }
535 540
536 TEST_F(GpuDataManagerImplPrivateTest, SetGLStringsNoEffects) { 541 TEST_F(GpuDataManagerImplPrivateTest, SetGLStringsNoEffects) {
537 const char* kGLVendorMesa = "Tungsten Graphics, Inc"; 542 const char* kGLVendorMesa = "Tungsten Graphics, Inc";
538 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41"; 543 const char* kGLRendererMesa = "Mesa DRI Intel(R) G41";
539 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL"; 544 const char* kGLVersionMesa801 = "2.1 Mesa 8.0.1-DEVEL";
540 const char* kGLVersionMesa802 = "2.1 Mesa 8.0.2-DEVEL"; 545 const char* kGLVersionMesa802 = "2.1 Mesa 8.0.2-DEVEL";
541 546
542 ScopedGpuDataManagerImplPrivate manager; 547 ScopedGpuDataManagerImplPrivate manager;
543 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount()); 548 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
544 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); 549 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
545 550
546 const std::string blacklist_json = LONG_STRING_CONST( 551 const std::string blacklist_json = LONG_STRING_CONST(
547 { 552 {
548 "name": "gpu blacklist", 553 "name": "gpu blacklist",
549 "version": "0.1", 554 "version": "0.1",
550 "entries": [ 555 "entries": [
551 { 556 {
552 "id": 1, 557 "id": 1,
553 "vendor_id": "0x8086", 558 "vendor_id": "0x8086",
554 "exceptions": [ 559 "exceptions": [
555 { 560 {
556 "device_id": ["0x0042"], 561 "device_id": ["0x0042"],
557 "driver_version": { 562 "driver_version": {
558 "op": ">=", 563 "op": ">=",
559 "number": "8.0.2" 564 "value": "8.0.2"
560 } 565 }
561 } 566 }
562 ], 567 ],
563 "features": [ 568 "features": [
564 "webgl" 569 "webgl"
565 ] 570 ]
566 } 571 }
567 ] 572 ]
568 } 573 }
569 ); 574 );
570 GPUInfo gpu_info; 575 gpu::GPUInfo gpu_info;
571 gpu_info.gpu.vendor_id = 0x8086; 576 gpu_info.gpu.vendor_id = 0x8086;
572 gpu_info.gpu.device_id = 0x0042; 577 gpu_info.gpu.device_id = 0x0042;
573 gpu_info.gl_vendor = kGLVendorMesa; 578 gpu_info.gl_vendor = kGLVendorMesa;
574 gpu_info.gl_renderer = kGLRendererMesa; 579 gpu_info.gl_renderer = kGLRendererMesa;
575 gpu_info.gl_version = kGLVersionMesa801; 580 gpu_info.gl_version = kGLVersionMesa801;
576 gpu_info.driver_vendor = "Mesa"; 581 gpu_info.driver_vendor = "Mesa";
577 gpu_info.driver_version = "8.0.1"; 582 gpu_info.driver_version = "8.0.1";
578 manager->InitializeForTesting(blacklist_json, gpu_info); 583 manager->InitializeForTesting(blacklist_json, gpu_info);
579 584
580 // Full GPUInfo, the entry applies. 585 // Full GPUInfo, the entry applies.
581 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); 586 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
582 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); 587 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
583 EXPECT_TRUE(manager->IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)); 588 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL));
584 589
585 // Now assume browser gets GL strings from local state. 590 // Now assume browser gets GL strings from local state.
586 // SetGLStrings() has no effects because GPUInfo already got these strings. 591 // SetGLStrings() has no effects because GPUInfo already got these strings.
587 // (Otherwise the entry should not apply.) 592 // (Otherwise the entry should not apply.)
588 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa802); 593 manager->SetGLStrings(kGLVendorMesa, kGLRendererMesa, kGLVersionMesa802);
589 EXPECT_TRUE(manager->GpuAccessAllowed(NULL)); 594 EXPECT_TRUE(manager->GpuAccessAllowed(NULL));
590 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount()); 595 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
591 EXPECT_TRUE(manager->IsFeatureBlacklisted(GPU_FEATURE_TYPE_WEBGL)); 596 EXPECT_TRUE(manager->IsFeatureBlacklisted(gpu::GPU_FEATURE_TYPE_WEBGL));
592 } 597 }
593 #endif // OS_LINUX 598 #endif // OS_LINUX
594 599
595 TEST_F(GpuDataManagerImplPrivateTest, GpuDriverBugListSingle) { 600 TEST_F(GpuDataManagerImplPrivateTest, GpuDriverBugListSingle) {
596 ScopedGpuDataManagerImplPrivate manager; 601 ScopedGpuDataManagerImplPrivate manager;
597 manager->gpu_driver_bugs_.insert(5); 602 manager->gpu_driver_bugs_.insert(5);
598 603
599 CommandLine command_line(0, NULL); 604 CommandLine command_line(0, NULL);
600 manager->AppendGpuCommandLine(&command_line); 605 manager->AppendGpuCommandLine(&command_line);
601 606
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 { 639 {
635 "id": 1, 640 "id": 1,
636 "features": [ 641 "features": [
637 "all" 642 "all"
638 ] 643 ]
639 } 644 }
640 ] 645 ]
641 } 646 }
642 ); 647 );
643 648
644 GPUInfo gpu_info; 649 gpu::GPUInfo gpu_info;
645 gpu_info.gpu.vendor_id = 0x10de; 650 gpu_info.gpu.vendor_id = 0x10de;
646 gpu_info.gpu.device_id = 0x0640; 651 gpu_info.gpu.device_id = 0x0640;
647 manager->InitializeForTesting(blacklist_json, gpu_info); 652 manager->InitializeForTesting(blacklist_json, gpu_info);
648 653
649 EXPECT_EQ(static_cast<size_t>(NUMBER_OF_GPU_FEATURE_TYPES), 654 EXPECT_EQ(static_cast<size_t>(gpu::NUMBER_OF_GPU_FEATURE_TYPES),
650 manager->GetBlacklistedFeatureCount()); 655 manager->GetBlacklistedFeatureCount());
651 // TODO(zmo): remove the Linux specific behavior once we fix 656 // TODO(zmo): remove the Linux specific behavior once we fix
652 // crbug.com/238466. 657 // crbug.com/238466.
653 #if defined(OS_LINUX) 658 #if defined(OS_LINUX)
654 EXPECT_TRUE(manager->GpuAccessAllowed(&reason)); 659 EXPECT_TRUE(manager->GpuAccessAllowed(&reason));
655 EXPECT_TRUE(reason.empty()); 660 EXPECT_TRUE(reason.empty());
656 #else 661 #else
657 EXPECT_FALSE(manager->GpuAccessAllowed(&reason)); 662 EXPECT_FALSE(manager->GpuAccessAllowed(&reason));
658 EXPECT_FALSE(reason.empty()); 663 EXPECT_FALSE(reason.empty());
659 #endif 664 #endif
660 } 665 }
661 666
667 TEST_F(GpuDataManagerImplPrivateTest, UpdateActiveGpu) {
668 ScopedGpuDataManagerImpl manager;
669
670 const std::string blacklist_json = LONG_STRING_CONST(
671 {
672 "name": "gpu blacklist",
673 "version": "0.1",
674 "entries": [
675 {
676 "id": 1,
677 "vendor_id": "0x8086",
678 "multi_gpu_category": "active",
679 "features": [
680 "webgl"
681 ]
682 }
683 ]
684 }
685 );
686
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);
697
698 manager->InitializeForTesting(blacklist_json, gpu_info);
699 TestObserver observer;
700 manager->AddObserver(&observer);
701
702 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
703
704 // Update with the same Intel GPU active.
705 EXPECT_FALSE(manager->UpdateActiveGpu(0x8086, 0x04a1));
706 {
707 base::RunLoop run_loop;
708 run_loop.RunUntilIdle();
709 }
710 EXPECT_FALSE(observer.gpu_info_updated());
711 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
712
713 // Set NVIDIA GPU to be active.
714 EXPECT_TRUE(manager->UpdateActiveGpu(0x10de, 0x0640));
715 {
716 base::RunLoop run_loop;
717 run_loop.RunUntilIdle();
718 }
719 EXPECT_TRUE(observer.gpu_info_updated());
720 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
721
722 observer.Reset();
723 EXPECT_FALSE(observer.gpu_info_updated());
724
725 // Update with the same NVIDIA GPU active.
726 EXPECT_FALSE(manager->UpdateActiveGpu(0x10de, 0x0640));
727 {
728 base::RunLoop run_loop;
729 run_loop.RunUntilIdle();
730 }
731 EXPECT_FALSE(observer.gpu_info_updated());
732 EXPECT_EQ(0u, manager->GetBlacklistedFeatureCount());
733
734 // Set Intel GPU to be active.
735 EXPECT_TRUE(manager->UpdateActiveGpu(0x8086, 0x04a1));
736 {
737 base::RunLoop run_loop;
738 run_loop.RunUntilIdle();
739 }
740 EXPECT_TRUE(observer.gpu_info_updated());
741 EXPECT_EQ(1u, manager->GetBlacklistedFeatureCount());
742 }
743
662 } // namespace content 744 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/gpu/gpu_data_manager_impl_private.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698