OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "base/json/json_reader.h" | |
6 #include "content/browser/gpu/gpu_control_list.h" | |
7 #include "content/public/common/gpu_info.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 #define LONG_STRING_CONST(...) #__VA_ARGS__ | |
11 | |
12 namespace content { | |
13 | |
14 enum TestFeatureType { | |
15 TEST_FEATURE_0 = 0, | |
16 TEST_FEATURE_1, | |
17 TEST_FEATURE_2 | |
18 }; | |
19 | |
20 class GpuControlListEntryTest : public testing::Test { | |
21 public: | |
22 GpuControlListEntryTest() { } | |
23 virtual ~GpuControlListEntryTest() { } | |
24 | |
25 const GPUInfo& gpu_info() const { | |
26 return gpu_info_; | |
27 } | |
28 | |
29 typedef GpuControlList::ScopedGpuControlListEntry ScopedEntry; | |
30 | |
31 static ScopedEntry GetEntryFromString( | |
32 const std::string& json, bool supports_feature_type_all) { | |
33 scoped_ptr<base::Value> root; | |
34 root.reset(base::JSONReader::Read(json)); | |
35 DictionaryValue* value = NULL; | |
36 if (root.get() == NULL || !root->GetAsDictionary(&value)) | |
37 return NULL; | |
38 | |
39 GpuControlList::FeatureMap feature_map; | |
40 feature_map["test_feature_0"] = TEST_FEATURE_0; | |
41 feature_map["test_feature_1"] = TEST_FEATURE_1; | |
42 feature_map["test_feature_2"] = TEST_FEATURE_2; | |
43 | |
44 return GpuControlList::GpuControlListEntry::GetEntryFromValue( | |
45 value, true, feature_map, supports_feature_type_all); | |
46 } | |
47 | |
48 static ScopedEntry GetEntryFromString(const std::string& json) { | |
49 return GetEntryFromString(json, false); | |
50 } | |
51 | |
52 virtual void SetUp() { | |
53 gpu_info_.gpu.vendor_id = 0x10de; | |
54 gpu_info_.gpu.device_id = 0x0640; | |
55 gpu_info_.driver_vendor = "NVIDIA"; | |
56 gpu_info_.driver_version = "1.6.18"; | |
57 gpu_info_.driver_date = "7-14-2009"; | |
58 gpu_info_.machine_model = "MacBookPro 7.1"; | |
59 gpu_info_.gl_vendor = "NVIDIA Corporation"; | |
60 gpu_info_.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine"; | |
61 gpu_info_.performance_stats.graphics = 5.0; | |
62 gpu_info_.performance_stats.gaming = 5.0; | |
63 gpu_info_.performance_stats.overall = 5.0; | |
64 } | |
65 | |
66 private: | |
67 GPUInfo gpu_info_; | |
68 }; | |
69 | |
70 TEST_F(GpuControlListEntryTest, DetailedEntry) { | |
71 const std::string json = LONG_STRING_CONST( | |
72 { | |
73 "id": 5, | |
74 "description": "test entry", | |
75 "cr_bugs": [1024, 678], | |
76 "webkit_bugs": [1950], | |
77 "os": { | |
78 "type": "macosx", | |
79 "version": { | |
80 "op": "=", | |
81 "number": "10.6.4" | |
82 } | |
83 }, | |
84 "vendor_id": "0x10de", | |
85 "device_id": ["0x0640"], | |
86 "driver_version": { | |
87 "op": "=", | |
88 "number": "1.6.18" | |
89 }, | |
90 "features": [ | |
91 "test_feature_0" | |
92 ] | |
93 } | |
94 ); | |
95 | |
96 ScopedEntry entry(GetEntryFromString(json)); | |
97 EXPECT_TRUE(entry != NULL); | |
98 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType()); | |
99 EXPECT_FALSE(entry->disabled()); | |
100 EXPECT_EQ(5u, entry->id()); | |
101 EXPECT_STREQ("test entry", entry->description().c_str()); | |
102 EXPECT_EQ(2u, entry->cr_bugs().size()); | |
103 EXPECT_EQ(1024, entry->cr_bugs()[0]); | |
104 EXPECT_EQ(678, entry->cr_bugs()[1]); | |
105 EXPECT_EQ(1u, entry->webkit_bugs().size()); | |
106 EXPECT_EQ(1950, entry->webkit_bugs()[0]); | |
107 EXPECT_EQ(1u, entry->features().size()); | |
108 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_0)); | |
109 EXPECT_FALSE(entry->contains_unknown_fields()); | |
110 EXPECT_FALSE(entry->contains_unknown_features()); | |
111 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info())); | |
112 EXPECT_TRUE(entry->Contains( | |
113 GpuControlList::kOsMacosx, "10.6.4", gpu_info())); | |
114 } | |
115 | |
116 TEST_F(GpuControlListEntryTest, VendorOnAllOsEntry) { | |
117 const std::string json = LONG_STRING_CONST( | |
118 { | |
119 "id": 1, | |
120 "vendor_id": "0x10de", | |
121 "features": [ | |
122 "test_feature_0" | |
123 ] | |
124 } | |
125 ); | |
126 ScopedEntry entry(GetEntryFromString(json)); | |
127 EXPECT_TRUE(entry != NULL); | |
128 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType()); | |
129 | |
130 const GpuControlList::OsType os_type[] = { | |
131 GpuControlList::kOsMacosx, | |
132 GpuControlList::kOsWin, | |
133 GpuControlList::kOsLinux, | |
134 GpuControlList::kOsChromeOS, | |
135 GpuControlList::kOsAndroid | |
136 }; | |
137 for (size_t i = 0; i < arraysize(os_type); ++i) | |
138 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info())); | |
139 } | |
140 | |
141 TEST_F(GpuControlListEntryTest, VendorOnLinuxEntry) { | |
142 const std::string json = LONG_STRING_CONST( | |
143 { | |
144 "id": 1, | |
145 "os": { | |
146 "type": "linux" | |
147 }, | |
148 "vendor_id": "0x10de", | |
149 "features": [ | |
150 "test_feature_0" | |
151 ] | |
152 } | |
153 ); | |
154 ScopedEntry entry(GetEntryFromString(json)); | |
155 EXPECT_TRUE(entry != NULL); | |
156 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType()); | |
157 | |
158 const GpuControlList::OsType os_type[] = { | |
159 GpuControlList::kOsMacosx, | |
160 GpuControlList::kOsWin, | |
161 GpuControlList::kOsChromeOS, | |
162 GpuControlList::kOsAndroid | |
163 }; | |
164 for (size_t i = 0; i < arraysize(os_type); ++i) | |
165 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info())); | |
166 EXPECT_TRUE(entry->Contains( | |
167 GpuControlList::kOsLinux, "10.6", gpu_info())); | |
168 } | |
169 | |
170 TEST_F(GpuControlListEntryTest, AllExceptNVidiaOnLinuxEntry) { | |
171 const std::string json = LONG_STRING_CONST( | |
172 { | |
173 "id": 1, | |
174 "os": { | |
175 "type": "linux" | |
176 }, | |
177 "exceptions": [ | |
178 { | |
179 "vendor_id": "0x10de" | |
180 } | |
181 ], | |
182 "features": [ | |
183 "test_feature_0" | |
184 ] | |
185 } | |
186 ); | |
187 ScopedEntry entry(GetEntryFromString(json)); | |
188 EXPECT_TRUE(entry != NULL); | |
189 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType()); | |
190 | |
191 const GpuControlList::OsType os_type[] = { | |
192 GpuControlList::kOsMacosx, | |
193 GpuControlList::kOsWin, | |
194 GpuControlList::kOsLinux, | |
195 GpuControlList::kOsChromeOS, | |
196 GpuControlList::kOsAndroid | |
197 }; | |
198 for (size_t i = 0; i < arraysize(os_type); ++i) | |
199 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info())); | |
200 } | |
201 | |
202 TEST_F(GpuControlListEntryTest, AllExceptIntelOnLinuxEntry) { | |
203 const std::string json = LONG_STRING_CONST( | |
204 { | |
205 "id": 1, | |
206 "os": { | |
207 "type": "linux" | |
208 }, | |
209 "exceptions": [ | |
210 { | |
211 "vendor_id": "0x8086" | |
212 } | |
213 ], | |
214 "features": [ | |
215 "test_feature_0" | |
216 ] | |
217 } | |
218 ); | |
219 ScopedEntry entry(GetEntryFromString(json)); | |
220 EXPECT_TRUE(entry != NULL); | |
221 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType()); | |
222 | |
223 const GpuControlList::OsType os_type[] = { | |
224 GpuControlList::kOsMacosx, | |
225 GpuControlList::kOsWin, | |
226 GpuControlList::kOsChromeOS, | |
227 GpuControlList::kOsAndroid | |
228 }; | |
229 for (size_t i = 0; i < arraysize(os_type); ++i) | |
230 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info())); | |
231 EXPECT_TRUE(entry->Contains( | |
232 GpuControlList::kOsLinux, "10.6", gpu_info())); | |
233 } | |
234 | |
235 TEST_F(GpuControlListEntryTest, DateOnWindowsEntry) { | |
236 const std::string json = LONG_STRING_CONST( | |
237 { | |
238 "id": 1, | |
239 "os": { | |
240 "type": "win" | |
241 }, | |
242 "driver_date": { | |
243 "op": "<", | |
244 "number": "2010.5.8" | |
245 }, | |
246 "features": [ | |
247 "test_feature_0" | |
248 ] | |
249 } | |
250 ); | |
251 ScopedEntry entry(GetEntryFromString(json)); | |
252 EXPECT_TRUE(entry != NULL); | |
253 EXPECT_EQ(GpuControlList::kOsWin, entry->GetOsType()); | |
254 | |
255 GPUInfo gpu_info; | |
256 gpu_info.driver_date = "4-12-2010"; | |
257 EXPECT_TRUE(entry->Contains( | |
258 GpuControlList::kOsWin, "10.6", gpu_info)); | |
259 gpu_info.driver_date = "5-8-2010"; | |
260 EXPECT_FALSE(entry->Contains( | |
261 GpuControlList::kOsWin, "10.6", gpu_info)); | |
262 gpu_info.driver_date = "5-9-2010"; | |
263 EXPECT_FALSE(entry->Contains( | |
264 GpuControlList::kOsWin, "10.6", gpu_info)); | |
265 } | |
266 | |
267 TEST_F(GpuControlListEntryTest, MultipleDevicesEntry) { | |
268 const std::string json = LONG_STRING_CONST( | |
269 { | |
270 "id": 1, | |
271 "vendor_id": "0x10de", | |
272 "device_id": ["0x1023", "0x0640"], | |
273 "features": [ | |
274 "test_feature_0" | |
275 ] | |
276 } | |
277 ); | |
278 ScopedEntry entry(GetEntryFromString(json)); | |
279 EXPECT_TRUE(entry != NULL); | |
280 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType()); | |
281 | |
282 const GpuControlList::OsType os_type[] = { | |
283 GpuControlList::kOsMacosx, | |
284 GpuControlList::kOsWin, | |
285 GpuControlList::kOsLinux, | |
286 GpuControlList::kOsChromeOS, | |
287 GpuControlList::kOsAndroid | |
288 }; | |
289 for (size_t i = 0; i < arraysize(os_type); ++i) | |
290 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info())); | |
291 } | |
292 | |
293 TEST_F(GpuControlListEntryTest, ChromeOSEntry) { | |
294 const std::string json = LONG_STRING_CONST( | |
295 { | |
296 "id": 1, | |
297 "os": { | |
298 "type": "chromeos" | |
299 }, | |
300 "features": [ | |
301 "test_feature_0" | |
302 ] | |
303 } | |
304 ); | |
305 ScopedEntry entry(GetEntryFromString(json)); | |
306 EXPECT_TRUE(entry != NULL); | |
307 EXPECT_EQ(GpuControlList::kOsChromeOS, entry->GetOsType()); | |
308 | |
309 const GpuControlList::OsType os_type[] = { | |
310 GpuControlList::kOsMacosx, | |
311 GpuControlList::kOsWin, | |
312 GpuControlList::kOsLinux, | |
313 GpuControlList::kOsAndroid | |
314 }; | |
315 for (size_t i = 0; i < arraysize(os_type); ++i) | |
316 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info())); | |
317 EXPECT_TRUE(entry->Contains( | |
318 GpuControlList::kOsChromeOS, "10.6", gpu_info())); | |
319 } | |
320 | |
321 TEST_F(GpuControlListEntryTest, MalformedVendor) { | |
322 const std::string json = LONG_STRING_CONST( | |
323 { | |
324 "id": 1, | |
325 "vendor_id": "[0x10de]", | |
326 "features": [ | |
327 "test_feature_0" | |
328 ] | |
329 } | |
330 ); | |
331 ScopedEntry entry(GetEntryFromString(json)); | |
332 EXPECT_TRUE(entry == NULL); | |
333 } | |
334 | |
335 TEST_F(GpuControlListEntryTest, UnknownFieldEntry) { | |
336 const std::string json = LONG_STRING_CONST( | |
337 { | |
338 "id": 1, | |
339 "unknown_field": 0, | |
340 "features": [ | |
341 "test_feature_0" | |
342 ] | |
343 } | |
344 ); | |
345 ScopedEntry entry(GetEntryFromString(json)); | |
346 EXPECT_TRUE(entry != NULL); | |
347 EXPECT_TRUE(entry->contains_unknown_fields()); | |
348 EXPECT_FALSE(entry->contains_unknown_features()); | |
349 } | |
350 | |
351 TEST_F(GpuControlListEntryTest, UnknownExceptionFieldEntry) { | |
352 const std::string json = LONG_STRING_CONST( | |
353 { | |
354 "id": 2, | |
355 "exceptions": [ | |
356 { | |
357 "unknown_field": 0 | |
358 } | |
359 ], | |
360 "features": [ | |
361 "test_feature_0" | |
362 ] | |
363 } | |
364 ); | |
365 ScopedEntry entry(GetEntryFromString(json)); | |
366 EXPECT_TRUE(entry != NULL); | |
367 EXPECT_TRUE(entry->contains_unknown_fields()); | |
368 EXPECT_FALSE(entry->contains_unknown_features()); | |
369 } | |
370 | |
371 TEST_F(GpuControlListEntryTest, UnknownFeatureEntry) { | |
372 const std::string json = LONG_STRING_CONST( | |
373 { | |
374 "id": 1, | |
375 "features": [ | |
376 "some_unknown_feature", | |
377 "test_feature_0" | |
378 ] | |
379 } | |
380 ); | |
381 ScopedEntry entry(GetEntryFromString(json)); | |
382 EXPECT_TRUE(entry != NULL); | |
383 EXPECT_FALSE(entry->contains_unknown_fields()); | |
384 EXPECT_TRUE(entry->contains_unknown_features()); | |
385 EXPECT_EQ(1u, entry->features().size()); | |
386 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_0)); | |
387 | |
388 const GpuControlList::OsType os_type[] = { | |
389 GpuControlList::kOsMacosx, | |
390 GpuControlList::kOsWin, | |
391 GpuControlList::kOsLinux, | |
392 GpuControlList::kOsChromeOS, | |
393 GpuControlList::kOsAndroid | |
394 }; | |
395 for (size_t i = 0; i < arraysize(os_type); ++i) | |
396 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info())); | |
397 } | |
398 | |
399 TEST_F(GpuControlListEntryTest, GlVendorEntry) { | |
400 const std::string json = LONG_STRING_CONST( | |
401 { | |
402 "id": 1, | |
403 "gl_vendor": { | |
404 "op": "beginwith", | |
405 "value": "NVIDIA" | |
406 }, | |
407 "features": [ | |
408 "test_feature_0" | |
409 ] | |
410 } | |
411 ); | |
412 ScopedEntry entry(GetEntryFromString(json)); | |
413 EXPECT_TRUE(entry != NULL); | |
414 | |
415 const GpuControlList::OsType os_type[] = { | |
416 GpuControlList::kOsMacosx, | |
417 GpuControlList::kOsWin, | |
418 GpuControlList::kOsLinux, | |
419 GpuControlList::kOsChromeOS, | |
420 GpuControlList::kOsAndroid | |
421 }; | |
422 for (size_t i = 0; i < arraysize(os_type); ++i) | |
423 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info())); | |
424 } | |
425 | |
426 TEST_F(GpuControlListEntryTest, GlRendererEntry) { | |
427 const std::string json = LONG_STRING_CONST( | |
428 { | |
429 "id": 1, | |
430 "gl_renderer": { | |
431 "op": "contains", | |
432 "value": "GeForce" | |
433 }, | |
434 "features": [ | |
435 "test_feature_0" | |
436 ] | |
437 } | |
438 ); | |
439 ScopedEntry entry(GetEntryFromString(json)); | |
440 EXPECT_TRUE(entry != NULL); | |
441 | |
442 const GpuControlList::OsType os_type[] = { | |
443 GpuControlList::kOsMacosx, | |
444 GpuControlList::kOsWin, | |
445 GpuControlList::kOsLinux, | |
446 GpuControlList::kOsChromeOS, | |
447 GpuControlList::kOsAndroid | |
448 }; | |
449 for (size_t i = 0; i < arraysize(os_type); ++i) | |
450 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info())); | |
451 } | |
452 | |
453 TEST_F(GpuControlListEntryTest, PerfGraphicsEntry) { | |
454 const std::string json = LONG_STRING_CONST( | |
455 { | |
456 "id": 1, | |
457 "perf_graphics": { | |
458 "op": "<", | |
459 "value": "6.0" | |
460 }, | |
461 "features": [ | |
462 "test_feature_0" | |
463 ] | |
464 } | |
465 ); | |
466 ScopedEntry entry(GetEntryFromString(json)); | |
467 EXPECT_TRUE(entry != NULL); | |
468 EXPECT_TRUE(entry->Contains( | |
469 GpuControlList::kOsWin, "10.6", gpu_info())); | |
470 } | |
471 | |
472 TEST_F(GpuControlListEntryTest, PerfGamingEntry) { | |
473 const std::string json = LONG_STRING_CONST( | |
474 { | |
475 "id": 1, | |
476 "perf_graphics": { | |
477 "op": "<=", | |
478 "value": "4.0" | |
479 }, | |
480 "features": [ | |
481 "test_feature_0" | |
482 ] | |
483 } | |
484 ); | |
485 ScopedEntry entry(GetEntryFromString(json)); | |
486 EXPECT_TRUE(entry != NULL); | |
487 EXPECT_FALSE(entry->Contains( | |
488 GpuControlList::kOsWin, "10.6", gpu_info())); | |
489 } | |
490 | |
491 TEST_F(GpuControlListEntryTest, PerfOverallEntry) { | |
492 const std::string json = LONG_STRING_CONST( | |
493 { | |
494 "id": 1, | |
495 "perf_overall": { | |
496 "op": "between", | |
497 "value": "1.0", | |
498 "value2": "9.0" | |
499 }, | |
500 "features": [ | |
501 "test_feature_0" | |
502 ] | |
503 } | |
504 ); | |
505 ScopedEntry entry(GetEntryFromString(json)); | |
506 EXPECT_TRUE(entry != NULL); | |
507 EXPECT_TRUE(entry->Contains( | |
508 GpuControlList::kOsWin, "10.6", gpu_info())); | |
509 } | |
510 | |
511 TEST_F(GpuControlListEntryTest, DisabledEntry) { | |
512 const std::string json = LONG_STRING_CONST( | |
513 { | |
514 "id": 1, | |
515 "disabled": true, | |
516 "features": [ | |
517 "test_feature_0" | |
518 ] | |
519 } | |
520 ); | |
521 ScopedEntry entry(GetEntryFromString(json)); | |
522 EXPECT_TRUE(entry != NULL); | |
523 EXPECT_TRUE(entry->disabled()); | |
524 } | |
525 | |
526 TEST_F(GpuControlListEntryTest, OptimusEntry) { | |
527 const std::string json = LONG_STRING_CONST( | |
528 { | |
529 "id": 1, | |
530 "os": { | |
531 "type": "linux" | |
532 }, | |
533 "multi_gpu_style": "optimus", | |
534 "features": [ | |
535 "test_feature_0" | |
536 ] | |
537 } | |
538 ); | |
539 GPUInfo gpu_info; | |
540 gpu_info.optimus = true; | |
541 | |
542 ScopedEntry entry(GetEntryFromString(json)); | |
543 EXPECT_TRUE(entry != NULL); | |
544 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType()); | |
545 EXPECT_TRUE(entry->Contains( | |
546 GpuControlList::kOsLinux, "10.6", gpu_info)); | |
547 } | |
548 | |
549 TEST_F(GpuControlListEntryTest, AMDSwitchableEntry) { | |
550 const std::string json = LONG_STRING_CONST( | |
551 { | |
552 "id": 1, | |
553 "os": { | |
554 "type": "macosx" | |
555 }, | |
556 "multi_gpu_style": "amd_switchable", | |
557 "features": [ | |
558 "test_feature_0" | |
559 ] | |
560 } | |
561 ); | |
562 GPUInfo gpu_info; | |
563 gpu_info.amd_switchable = true; | |
564 | |
565 ScopedEntry entry(GetEntryFromString(json)); | |
566 EXPECT_TRUE(entry != NULL); | |
567 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType()); | |
568 EXPECT_TRUE(entry->Contains( | |
569 GpuControlList::kOsMacosx, "10.6", gpu_info)); | |
570 } | |
571 | |
572 TEST_F(GpuControlListEntryTest, LexicalDriverVersionEntry) { | |
573 const std::string json = LONG_STRING_CONST( | |
574 { | |
575 "id": 1, | |
576 "os": { | |
577 "type": "linux" | |
578 }, | |
579 "vendor_id": "0x1002", | |
580 "driver_version": { | |
581 "op": "=", | |
582 "style": "lexical", | |
583 "number": "8.76" | |
584 }, | |
585 "features": [ | |
586 "test_feature_0" | |
587 ] | |
588 } | |
589 ); | |
590 GPUInfo gpu_info; | |
591 gpu_info.gpu.vendor_id = 0x1002; | |
592 | |
593 ScopedEntry entry(GetEntryFromString(json)); | |
594 EXPECT_TRUE(entry != NULL); | |
595 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType()); | |
596 | |
597 gpu_info.driver_version = "8.76"; | |
598 EXPECT_TRUE(entry->Contains( | |
599 GpuControlList::kOsLinux, "10.6", gpu_info)); | |
600 | |
601 gpu_info.driver_version = "8.768"; | |
602 EXPECT_TRUE(entry->Contains( | |
603 GpuControlList::kOsLinux, "10.6", gpu_info)); | |
604 | |
605 gpu_info.driver_version = "8.76.8"; | |
606 EXPECT_TRUE(entry->Contains( | |
607 GpuControlList::kOsLinux, "10.6", gpu_info)); | |
608 } | |
609 | |
610 TEST_F(GpuControlListEntryTest, MultipleGPUsAnyEntry) { | |
611 const std::string json = LONG_STRING_CONST( | |
612 { | |
613 "id": 1, | |
614 "os": { | |
615 "type": "macosx" | |
616 }, | |
617 "vendor_id": "0x8086", | |
618 "device_id": ["0x0166"], | |
619 "multi_gpu_category": "any", | |
620 "features": [ | |
621 "test_feature_0" | |
622 ] | |
623 } | |
624 ); | |
625 ScopedEntry entry(GetEntryFromString(json)); | |
626 EXPECT_TRUE(entry != NULL); | |
627 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType()); | |
628 | |
629 GPUInfo gpu_info; | |
630 gpu_info.gpu.vendor_id = 0x10de; | |
631 gpu_info.gpu.device_id = 0x1976; | |
632 EXPECT_FALSE(entry->Contains( | |
633 GpuControlList::kOsMacosx, "10.6", gpu_info)); | |
634 | |
635 GPUInfo::GPUDevice gpu_device; | |
636 gpu_device.vendor_id = 0x8086; | |
637 gpu_device.device_id = 0x0166; | |
638 gpu_info.secondary_gpus.push_back(gpu_device); | |
639 EXPECT_TRUE(entry->Contains( | |
640 GpuControlList::kOsMacosx, "10.6", gpu_info)); | |
641 } | |
642 | |
643 TEST_F(GpuControlListEntryTest, MultipleGPUsSecondaryEntry) { | |
644 const std::string json = LONG_STRING_CONST( | |
645 { | |
646 "id": 1, | |
647 "os": { | |
648 "type": "macosx" | |
649 }, | |
650 "vendor_id": "0x8086", | |
651 "device_id": ["0x0166"], | |
652 "multi_gpu_category": "secondary", | |
653 "features": [ | |
654 "test_feature_0" | |
655 ] | |
656 } | |
657 ); | |
658 ScopedEntry entry(GetEntryFromString(json)); | |
659 EXPECT_TRUE(entry != NULL); | |
660 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType()); | |
661 | |
662 GPUInfo gpu_info; | |
663 gpu_info.gpu.vendor_id = 0x10de; | |
664 gpu_info.gpu.device_id = 0x1976; | |
665 EXPECT_FALSE(entry->Contains( | |
666 GpuControlList::kOsMacosx, "10.6", gpu_info)); | |
667 | |
668 GPUInfo::GPUDevice gpu_device; | |
669 gpu_device.vendor_id = 0x8086; | |
670 gpu_device.device_id = 0x0166; | |
671 gpu_info.secondary_gpus.push_back(gpu_device); | |
672 EXPECT_TRUE(entry->Contains( | |
673 GpuControlList::kOsMacosx, "10.6", gpu_info)); | |
674 } | |
675 | |
676 TEST_F(GpuControlListEntryTest, NeedsMoreInfoEntry) { | |
677 const std::string json = LONG_STRING_CONST( | |
678 { | |
679 "id": 1, | |
680 "vendor_id": "0x8086", | |
681 "driver_version": { | |
682 "op": "<", | |
683 "number": "10.7" | |
684 }, | |
685 "features": [ | |
686 "test_feature_1" | |
687 ] | |
688 } | |
689 ); | |
690 ScopedEntry entry(GetEntryFromString(json)); | |
691 EXPECT_TRUE(entry != NULL); | |
692 | |
693 GPUInfo gpu_info; | |
694 gpu_info.gpu.vendor_id = 0x8086; | |
695 EXPECT_TRUE(entry->NeedsMoreInfo(gpu_info)); | |
696 | |
697 gpu_info.driver_version = "10.6"; | |
698 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info)); | |
699 } | |
700 | |
701 TEST_F(GpuControlListEntryTest, NeedsMoreInfoForExceptionsEntry) { | |
702 const std::string json = LONG_STRING_CONST( | |
703 { | |
704 "id": 1, | |
705 "vendor_id": "0x8086", | |
706 "exceptions": [ | |
707 { | |
708 "gl_renderer": { | |
709 "op": "contains", | |
710 "value": "mesa" | |
711 } | |
712 } | |
713 ], | |
714 "features": [ | |
715 "test_feature_1" | |
716 ] | |
717 } | |
718 ); | |
719 ScopedEntry entry(GetEntryFromString(json)); | |
720 EXPECT_TRUE(entry != NULL); | |
721 | |
722 GPUInfo gpu_info; | |
723 gpu_info.gpu.vendor_id = 0x8086; | |
724 EXPECT_TRUE(entry->NeedsMoreInfo(gpu_info)); | |
725 | |
726 gpu_info.gl_renderer = "mesa"; | |
727 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info)); | |
728 } | |
729 | |
730 TEST_F(GpuControlListEntryTest, FeatureTypeAllEntry) { | |
731 const std::string json = LONG_STRING_CONST( | |
732 { | |
733 "id": 1, | |
734 "features": [ | |
735 "all" | |
736 ] | |
737 } | |
738 ); | |
739 ScopedEntry entry(GetEntryFromString(json, true)); | |
740 EXPECT_TRUE(entry != NULL); | |
741 EXPECT_EQ(3u, entry->features().size()); | |
742 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_0)); | |
743 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_1)); | |
744 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_2)); | |
745 } | |
746 | |
747 } // namespace content | |
748 | |
OLD | NEW |