Enable Tab Dragging Tests with Linux and Ash
[chromium-blink-merge.git] / gpu / config / gpu_control_list_entry_unittest.cc
blob6ae866b7747d127a15a7d8b56be081e269055293
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/json/json_reader.h"
6 #include "gpu/config/gpu_control_list.h"
7 #include "gpu/config/gpu_info.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 #define LONG_STRING_CONST(...) #__VA_ARGS__
12 namespace gpu {
14 enum TestFeatureType {
15 TEST_FEATURE_0 = 0,
16 TEST_FEATURE_1,
17 TEST_FEATURE_2
20 class GpuControlListEntryTest : public testing::Test {
21 public:
22 GpuControlListEntryTest() { }
23 virtual ~GpuControlListEntryTest() { }
25 const GPUInfo& gpu_info() const {
26 return gpu_info_;
29 typedef GpuControlList::ScopedGpuControlListEntry ScopedEntry;
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 base::DictionaryValue* value = NULL;
36 if (root.get() == NULL || !root->GetAsDictionary(&value))
37 return NULL;
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;
44 return GpuControlList::GpuControlListEntry::GetEntryFromValue(
45 value, true, feature_map, supports_feature_type_all);
48 static ScopedEntry GetEntryFromString(const std::string& json) {
49 return GetEntryFromString(json, false);
52 virtual void SetUp() {
53 gpu_info_.gpu.vendor_id = 0x10de;
54 gpu_info_.gpu.device_id = 0x0640;
55 gpu_info_.gpu.active = true;
56 gpu_info_.driver_vendor = "NVIDIA";
57 gpu_info_.driver_version = "1.6.18";
58 gpu_info_.driver_date = "7-14-2009";
59 gpu_info_.gl_version = "2.1 NVIDIA-8.24.11 310.90.9b01";
60 gpu_info_.gl_vendor = "NVIDIA Corporation";
61 gpu_info_.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine";
62 gpu_info_.performance_stats.graphics = 5.0;
63 gpu_info_.performance_stats.gaming = 5.0;
64 gpu_info_.performance_stats.overall = 5.0;
67 protected:
68 GPUInfo gpu_info_;
71 TEST_F(GpuControlListEntryTest, DetailedEntry) {
72 const std::string json = LONG_STRING_CONST(
74 "id": 5,
75 "description": "test entry",
76 "cr_bugs": [1024, 678],
77 "webkit_bugs": [1950],
78 "os": {
79 "type": "macosx",
80 "version": {
81 "op": "=",
82 "value": "10.6.4"
85 "vendor_id": "0x10de",
86 "device_id": ["0x0640"],
87 "driver_version": {
88 "op": "=",
89 "value": "1.6.18"
91 "features": [
92 "test_feature_0"
97 ScopedEntry entry(GetEntryFromString(json));
98 EXPECT_TRUE(entry.get() != NULL);
99 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
100 EXPECT_FALSE(entry->disabled());
101 EXPECT_EQ(5u, entry->id());
102 EXPECT_STREQ("test entry", entry->description().c_str());
103 EXPECT_EQ(2u, entry->cr_bugs().size());
104 EXPECT_EQ(1024, entry->cr_bugs()[0]);
105 EXPECT_EQ(678, entry->cr_bugs()[1]);
106 EXPECT_EQ(1u, entry->webkit_bugs().size());
107 EXPECT_EQ(1950, entry->webkit_bugs()[0]);
108 EXPECT_EQ(1u, entry->features().size());
109 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_0));
110 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info()));
111 EXPECT_TRUE(entry->Contains(
112 GpuControlList::kOsMacosx, "10.6.4", gpu_info()));
115 TEST_F(GpuControlListEntryTest, VendorOnAllOsEntry) {
116 const std::string json = LONG_STRING_CONST(
118 "id": 1,
119 "vendor_id": "0x10de",
120 "features": [
121 "test_feature_0"
125 ScopedEntry entry(GetEntryFromString(json));
126 EXPECT_TRUE(entry.get() != NULL);
127 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType());
129 const GpuControlList::OsType os_type[] = {
130 GpuControlList::kOsMacosx,
131 GpuControlList::kOsWin,
132 GpuControlList::kOsLinux,
133 GpuControlList::kOsChromeOS,
134 GpuControlList::kOsAndroid
136 for (size_t i = 0; i < arraysize(os_type); ++i)
137 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info()));
140 TEST_F(GpuControlListEntryTest, VendorOnLinuxEntry) {
141 const std::string json = LONG_STRING_CONST(
143 "id": 1,
144 "os": {
145 "type": "linux"
147 "vendor_id": "0x10de",
148 "features": [
149 "test_feature_0"
153 ScopedEntry entry(GetEntryFromString(json));
154 EXPECT_TRUE(entry.get() != NULL);
155 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType());
157 const GpuControlList::OsType os_type[] = {
158 GpuControlList::kOsMacosx,
159 GpuControlList::kOsWin,
160 GpuControlList::kOsChromeOS,
161 GpuControlList::kOsAndroid
163 for (size_t i = 0; i < arraysize(os_type); ++i)
164 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info()));
165 EXPECT_TRUE(entry->Contains(
166 GpuControlList::kOsLinux, "10.6", gpu_info()));
169 TEST_F(GpuControlListEntryTest, AllExceptNVidiaOnLinuxEntry) {
170 const std::string json = LONG_STRING_CONST(
172 "id": 1,
173 "os": {
174 "type": "linux"
176 "exceptions": [
178 "vendor_id": "0x10de"
181 "features": [
182 "test_feature_0"
186 ScopedEntry entry(GetEntryFromString(json));
187 EXPECT_TRUE(entry.get() != NULL);
188 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType());
190 const GpuControlList::OsType os_type[] = {
191 GpuControlList::kOsMacosx,
192 GpuControlList::kOsWin,
193 GpuControlList::kOsLinux,
194 GpuControlList::kOsChromeOS,
195 GpuControlList::kOsAndroid
197 for (size_t i = 0; i < arraysize(os_type); ++i)
198 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info()));
201 TEST_F(GpuControlListEntryTest, AllExceptIntelOnLinuxEntry) {
202 const std::string json = LONG_STRING_CONST(
204 "id": 1,
205 "os": {
206 "type": "linux"
208 "exceptions": [
210 "vendor_id": "0x8086"
213 "features": [
214 "test_feature_0"
218 ScopedEntry entry(GetEntryFromString(json));
219 EXPECT_TRUE(entry.get() != NULL);
220 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType());
222 const GpuControlList::OsType os_type[] = {
223 GpuControlList::kOsMacosx,
224 GpuControlList::kOsWin,
225 GpuControlList::kOsChromeOS,
226 GpuControlList::kOsAndroid
228 for (size_t i = 0; i < arraysize(os_type); ++i)
229 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info()));
230 EXPECT_TRUE(entry->Contains(
231 GpuControlList::kOsLinux, "10.6", gpu_info()));
234 TEST_F(GpuControlListEntryTest, DateOnWindowsEntry) {
235 const std::string json = LONG_STRING_CONST(
237 "id": 1,
238 "os": {
239 "type": "win"
241 "driver_date": {
242 "op": "<",
243 "value": "2010.5.8"
245 "features": [
246 "test_feature_0"
250 ScopedEntry entry(GetEntryFromString(json));
251 EXPECT_TRUE(entry.get() != NULL);
252 EXPECT_EQ(GpuControlList::kOsWin, entry->GetOsType());
254 GPUInfo gpu_info;
255 gpu_info.driver_date = "4-12-2010";
256 EXPECT_TRUE(entry->Contains(
257 GpuControlList::kOsWin, "10.6", gpu_info));
258 gpu_info.driver_date = "5-8-2010";
259 EXPECT_FALSE(entry->Contains(
260 GpuControlList::kOsWin, "10.6", gpu_info));
261 gpu_info.driver_date = "5-9-2010";
262 EXPECT_FALSE(entry->Contains(
263 GpuControlList::kOsWin, "10.6", gpu_info));
266 TEST_F(GpuControlListEntryTest, MultipleDevicesEntry) {
267 const std::string json = LONG_STRING_CONST(
269 "id": 1,
270 "vendor_id": "0x10de",
271 "device_id": ["0x1023", "0x0640"],
272 "features": [
273 "test_feature_0"
277 ScopedEntry entry(GetEntryFromString(json));
278 EXPECT_TRUE(entry.get() != NULL);
279 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType());
281 const GpuControlList::OsType os_type[] = {
282 GpuControlList::kOsMacosx,
283 GpuControlList::kOsWin,
284 GpuControlList::kOsLinux,
285 GpuControlList::kOsChromeOS,
286 GpuControlList::kOsAndroid
288 for (size_t i = 0; i < arraysize(os_type); ++i)
289 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info()));
292 TEST_F(GpuControlListEntryTest, ChromeOSEntry) {
293 const std::string json = LONG_STRING_CONST(
295 "id": 1,
296 "os": {
297 "type": "chromeos"
299 "features": [
300 "test_feature_0"
304 ScopedEntry entry(GetEntryFromString(json));
305 EXPECT_TRUE(entry.get() != NULL);
306 EXPECT_EQ(GpuControlList::kOsChromeOS, entry->GetOsType());
308 const GpuControlList::OsType os_type[] = {
309 GpuControlList::kOsMacosx,
310 GpuControlList::kOsWin,
311 GpuControlList::kOsLinux,
312 GpuControlList::kOsAndroid
314 for (size_t i = 0; i < arraysize(os_type); ++i)
315 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info()));
316 EXPECT_TRUE(entry->Contains(
317 GpuControlList::kOsChromeOS, "10.6", gpu_info()));
320 TEST_F(GpuControlListEntryTest, MalformedVendor) {
321 const std::string json = LONG_STRING_CONST(
323 "id": 1,
324 "vendor_id": "[0x10de]",
325 "features": [
326 "test_feature_0"
330 ScopedEntry entry(GetEntryFromString(json));
331 EXPECT_TRUE(entry.get() == NULL);
334 TEST_F(GpuControlListEntryTest, UnknownFieldEntry) {
335 const std::string json = LONG_STRING_CONST(
337 "id": 1,
338 "unknown_field": 0,
339 "features": [
340 "test_feature_0"
344 ScopedEntry entry(GetEntryFromString(json));
345 EXPECT_TRUE(entry.get() == NULL);
348 TEST_F(GpuControlListEntryTest, UnknownExceptionFieldEntry) {
349 const std::string json = LONG_STRING_CONST(
351 "id": 2,
352 "exceptions": [
354 "unknown_field": 0
357 "features": [
358 "test_feature_0"
362 ScopedEntry entry(GetEntryFromString(json));
363 EXPECT_TRUE(entry.get() == NULL);
366 TEST_F(GpuControlListEntryTest, UnknownFeatureEntry) {
367 const std::string json = LONG_STRING_CONST(
369 "id": 1,
370 "features": [
371 "some_unknown_feature",
372 "test_feature_0"
376 ScopedEntry entry(GetEntryFromString(json));
377 EXPECT_TRUE(entry.get() == NULL);
380 TEST_F(GpuControlListEntryTest, GlVersionGLESEntry) {
381 const std::string json = LONG_STRING_CONST(
383 "id": 1,
384 "gl_type": "gles",
385 "gl_version": {
386 "op": "=",
387 "value": "3.0"
389 "features": [
390 "test_feature_0"
394 ScopedEntry entry(GetEntryFromString(json));
395 EXPECT_TRUE(entry.get() != NULL);
397 GPUInfo gpu_info;
398 gpu_info.gl_version = "OpenGL ES 3.0 V@66.0 AU@ (CL@)";
399 EXPECT_TRUE(entry->Contains(GpuControlList::kOsAndroid, "4.4.2", gpu_info));
401 gpu_info.gl_version = "OpenGL ES 3.1 V@66.0 AU@ (CL@)";
402 EXPECT_FALSE(entry->Contains(GpuControlList::kOsAndroid, "4.4.2", gpu_info));
404 gpu_info.gl_version = "3.0 NVIDIA-8.24.11 310.90.9b01";
405 EXPECT_FALSE(entry->Contains(GpuControlList::kOsMacosx, "10.9", gpu_info));
407 gpu_info.gl_version = "OpenGL ES 3.0 (ANGLE 1.2.0.2450)";
408 EXPECT_FALSE(entry->Contains(GpuControlList::kOsWin, "6.1", gpu_info));
411 TEST_F(GpuControlListEntryTest, GlVersionANGLEEntry) {
412 const std::string json = LONG_STRING_CONST(
414 "id": 1,
415 "gl_type": "angle",
416 "gl_version": {
417 "op": ">",
418 "value": "2.0"
420 "features": [
421 "test_feature_0"
425 ScopedEntry entry(GetEntryFromString(json));
426 EXPECT_TRUE(entry.get() != NULL);
428 GPUInfo gpu_info;
429 gpu_info.gl_version = "OpenGL ES 3.0 V@66.0 AU@ (CL@)";
430 EXPECT_FALSE(entry->Contains(GpuControlList::kOsAndroid, "4.4.2", gpu_info));
432 gpu_info.gl_version = "3.0 NVIDIA-8.24.11 310.90.9b01";
433 EXPECT_FALSE(entry->Contains(GpuControlList::kOsMacosx, "10.9", gpu_info));
435 gpu_info.gl_version = "OpenGL ES 3.0 (ANGLE 1.2.0.2450)";
436 EXPECT_TRUE(entry->Contains(GpuControlList::kOsWin, "6.1", gpu_info));
438 gpu_info.gl_version = "OpenGL ES 2.0 (ANGLE 1.2.0.2450)";
439 EXPECT_FALSE(entry->Contains(GpuControlList::kOsWin, "6.1", gpu_info));
442 TEST_F(GpuControlListEntryTest, GlVersionGLEntry) {
443 const std::string json = LONG_STRING_CONST(
445 "id": 1,
446 "gl_type": "gl",
447 "gl_version": {
448 "op": "<",
449 "value": "4.0"
451 "features": [
452 "test_feature_0"
456 ScopedEntry entry(GetEntryFromString(json));
457 EXPECT_TRUE(entry.get() != NULL);
459 GPUInfo gpu_info;
460 gpu_info.gl_version = "OpenGL ES 3.0 V@66.0 AU@ (CL@)";
461 EXPECT_FALSE(entry->Contains(GpuControlList::kOsAndroid, "4.4.2", gpu_info));
463 gpu_info.gl_version = "3.0 NVIDIA-8.24.11 310.90.9b01";
464 EXPECT_TRUE(entry->Contains(GpuControlList::kOsMacosx, "10.9", gpu_info));
466 gpu_info.gl_version = "4.0 NVIDIA-8.24.11 310.90.9b01";
467 EXPECT_FALSE(entry->Contains(GpuControlList::kOsMacosx, "10.9", gpu_info));
469 gpu_info.gl_version = "OpenGL ES 3.0 (ANGLE 1.2.0.2450)";
470 EXPECT_FALSE(entry->Contains(GpuControlList::kOsWin, "6.1", gpu_info));
473 TEST_F(GpuControlListEntryTest, GlVendorEntry) {
474 const std::string json = LONG_STRING_CONST(
476 "id": 1,
477 "gl_vendor": {
478 "op": "beginwith",
479 "value": "NVIDIA"
481 "features": [
482 "test_feature_0"
486 ScopedEntry entry(GetEntryFromString(json));
487 EXPECT_TRUE(entry.get() != NULL);
489 const GpuControlList::OsType os_type[] = {
490 GpuControlList::kOsMacosx,
491 GpuControlList::kOsWin,
492 GpuControlList::kOsLinux,
493 GpuControlList::kOsChromeOS,
494 GpuControlList::kOsAndroid
496 for (size_t i = 0; i < arraysize(os_type); ++i)
497 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info()));
500 TEST_F(GpuControlListEntryTest, GlRendererEntry) {
501 const std::string json = LONG_STRING_CONST(
503 "id": 1,
504 "gl_renderer": {
505 "op": "contains",
506 "value": "GeForce"
508 "features": [
509 "test_feature_0"
513 ScopedEntry entry(GetEntryFromString(json));
514 EXPECT_TRUE(entry.get() != NULL);
516 const GpuControlList::OsType os_type[] = {
517 GpuControlList::kOsMacosx,
518 GpuControlList::kOsWin,
519 GpuControlList::kOsLinux,
520 GpuControlList::kOsChromeOS,
521 GpuControlList::kOsAndroid
523 for (size_t i = 0; i < arraysize(os_type); ++i)
524 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info()));
527 TEST_F(GpuControlListEntryTest, PerfGraphicsEntry) {
528 const std::string json = LONG_STRING_CONST(
530 "id": 1,
531 "perf_graphics": {
532 "op": "<",
533 "value": "6.0"
535 "features": [
536 "test_feature_0"
540 ScopedEntry entry(GetEntryFromString(json));
541 EXPECT_TRUE(entry.get() != NULL);
542 EXPECT_TRUE(entry->Contains(GpuControlList::kOsWin, "10.6", gpu_info()));
545 TEST_F(GpuControlListEntryTest, PerfGamingEntry) {
546 const std::string json = LONG_STRING_CONST(
548 "id": 1,
549 "perf_graphics": {
550 "op": "<=",
551 "value": "4.0"
553 "features": [
554 "test_feature_0"
558 ScopedEntry entry(GetEntryFromString(json));
559 EXPECT_TRUE(entry.get() != NULL);
560 EXPECT_FALSE(entry->Contains(GpuControlList::kOsWin, "10.6", gpu_info()));
563 TEST_F(GpuControlListEntryTest, PerfOverallEntry) {
564 const std::string json = LONG_STRING_CONST(
566 "id": 1,
567 "perf_overall": {
568 "op": "between",
569 "value": "1.0",
570 "value2": "9.0"
572 "features": [
573 "test_feature_0"
577 ScopedEntry entry(GetEntryFromString(json));
578 EXPECT_TRUE(entry.get() != NULL);
579 EXPECT_TRUE(entry->Contains(GpuControlList::kOsWin, "10.6", gpu_info()));
582 TEST_F(GpuControlListEntryTest, DisabledEntry) {
583 const std::string json = LONG_STRING_CONST(
585 "id": 1,
586 "disabled": true,
587 "features": [
588 "test_feature_0"
592 ScopedEntry entry(GetEntryFromString(json));
593 EXPECT_TRUE(entry.get() != NULL);
594 EXPECT_TRUE(entry->disabled());
597 TEST_F(GpuControlListEntryTest, OptimusEntry) {
598 const std::string json = LONG_STRING_CONST(
600 "id": 1,
601 "os": {
602 "type": "linux"
604 "multi_gpu_style": "optimus",
605 "features": [
606 "test_feature_0"
610 GPUInfo gpu_info;
611 gpu_info.optimus = true;
613 ScopedEntry entry(GetEntryFromString(json));
614 EXPECT_TRUE(entry.get() != NULL);
615 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType());
616 EXPECT_TRUE(entry->Contains(
617 GpuControlList::kOsLinux, "10.6", gpu_info));
620 TEST_F(GpuControlListEntryTest, AMDSwitchableEntry) {
621 const std::string json = LONG_STRING_CONST(
623 "id": 1,
624 "os": {
625 "type": "macosx"
627 "multi_gpu_style": "amd_switchable",
628 "features": [
629 "test_feature_0"
633 GPUInfo gpu_info;
634 gpu_info.amd_switchable = true;
636 ScopedEntry entry(GetEntryFromString(json));
637 EXPECT_TRUE(entry.get() != NULL);
638 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
639 EXPECT_TRUE(entry->Contains(
640 GpuControlList::kOsMacosx, "10.6", gpu_info));
643 TEST_F(GpuControlListEntryTest, LexicalDriverVersionEntry) {
644 const std::string json = LONG_STRING_CONST(
646 "id": 1,
647 "os": {
648 "type": "linux"
650 "vendor_id": "0x1002",
651 "driver_version": {
652 "op": "=",
653 "style": "lexical",
654 "value": "8.76"
656 "features": [
657 "test_feature_0"
661 GPUInfo gpu_info;
662 gpu_info.gpu.vendor_id = 0x1002;
664 ScopedEntry entry(GetEntryFromString(json));
665 EXPECT_TRUE(entry.get() != NULL);
666 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType());
668 gpu_info.driver_version = "8.76";
669 EXPECT_TRUE(entry->Contains(
670 GpuControlList::kOsLinux, "10.6", gpu_info));
672 gpu_info.driver_version = "8.768";
673 EXPECT_TRUE(entry->Contains(
674 GpuControlList::kOsLinux, "10.6", gpu_info));
676 gpu_info.driver_version = "8.76.8";
677 EXPECT_TRUE(entry->Contains(
678 GpuControlList::kOsLinux, "10.6", gpu_info));
681 TEST_F(GpuControlListEntryTest, NeedsMoreInfoEntry) {
682 const std::string json = LONG_STRING_CONST(
684 "id": 1,
685 "vendor_id": "0x8086",
686 "driver_version": {
687 "op": "<",
688 "value": "10.7"
690 "features": [
691 "test_feature_1"
695 ScopedEntry entry(GetEntryFromString(json));
696 EXPECT_TRUE(entry.get() != NULL);
698 GPUInfo gpu_info;
699 gpu_info.gpu.vendor_id = 0x8086;
700 EXPECT_TRUE(entry->NeedsMoreInfo(gpu_info));
702 gpu_info.driver_version = "10.6";
703 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info));
706 TEST_F(GpuControlListEntryTest, NeedsMoreInfoForExceptionsEntry) {
707 const std::string json = LONG_STRING_CONST(
709 "id": 1,
710 "vendor_id": "0x8086",
711 "exceptions": [
713 "gl_renderer": {
714 "op": "contains",
715 "value": "mesa"
719 "features": [
720 "test_feature_1"
724 ScopedEntry entry(GetEntryFromString(json));
725 EXPECT_TRUE(entry.get() != NULL);
727 GPUInfo gpu_info;
728 gpu_info.gpu.vendor_id = 0x8086;
729 EXPECT_TRUE(entry->NeedsMoreInfo(gpu_info));
731 gpu_info.gl_renderer = "mesa";
732 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info));
735 TEST_F(GpuControlListEntryTest, FeatureTypeAllEntry) {
736 const std::string json = LONG_STRING_CONST(
738 "id": 1,
739 "features": [
740 "all"
744 ScopedEntry entry(GetEntryFromString(json, true));
745 EXPECT_TRUE(entry.get() != NULL);
746 EXPECT_EQ(3u, entry->features().size());
747 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_0));
748 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_1));
749 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_2));
752 TEST_F(GpuControlListEntryTest, InvalidVendorIdEntry) {
753 const std::string json = LONG_STRING_CONST(
755 "id": 1,
756 "vendor_id": "0x0000",
757 "features": [
758 "test_feature_1"
762 ScopedEntry entry(GetEntryFromString(json));
763 EXPECT_TRUE(entry.get() == NULL);
766 TEST_F(GpuControlListEntryTest, InvalidDeviceIdEntry) {
767 const std::string json = LONG_STRING_CONST(
769 "id": 1,
770 "vendor_id": "0x10de",
771 "device_id": ["0x1023", "0x0000"],
772 "features": [
773 "test_feature_1"
777 ScopedEntry entry(GetEntryFromString(json));
778 EXPECT_TRUE(entry.get() == NULL);
781 TEST_F(GpuControlListEntryTest, SingleActiveGPU) {
782 const std::string json = LONG_STRING_CONST(
784 "id": 1,
785 "os": {
786 "type": "macosx"
788 "vendor_id": "0x10de",
789 "device_id": ["0x0640"],
790 "multi_gpu_category": "active",
791 "features": [
792 "test_feature_0"
796 ScopedEntry entry(GetEntryFromString(json));
797 EXPECT_TRUE(entry.get() != NULL);
798 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
799 EXPECT_TRUE(entry->Contains(
800 GpuControlList::kOsMacosx, "10.6", gpu_info()));
803 TEST_F(GpuControlListEntryTest, MachineModelName) {
804 const std::string json = LONG_STRING_CONST(
806 "id": 1,
807 "os": {
808 "type": "android"
810 "machine_model_name": ["Nexus 4", "XT1032"],
811 "features": [
812 "test_feature_0"
816 ScopedEntry entry(GetEntryFromString(json));
817 EXPECT_TRUE(entry.get() != NULL);
818 EXPECT_EQ(GpuControlList::kOsAndroid, entry->GetOsType());
819 GPUInfo gpu_info;
821 gpu_info.machine_model_name = "Nexus 4";
822 EXPECT_TRUE(entry->Contains(
823 GpuControlList::kOsAndroid, "4.1", gpu_info));
825 gpu_info.machine_model_name = "XT1032";
826 EXPECT_TRUE(entry->Contains(
827 GpuControlList::kOsAndroid, "4.1", gpu_info));
829 gpu_info.machine_model_name = "XT1032i";
830 EXPECT_FALSE(entry->Contains(
831 GpuControlList::kOsAndroid, "4.1", gpu_info));
833 gpu_info.machine_model_name = "Nexus 5";
834 EXPECT_FALSE(entry->Contains(
835 GpuControlList::kOsAndroid, "4.1", gpu_info));
837 gpu_info.machine_model_name = "Nexus";
838 EXPECT_FALSE(entry->Contains(
839 GpuControlList::kOsAndroid, "4.1", gpu_info));
841 gpu_info.machine_model_name = "";
842 EXPECT_FALSE(entry->Contains(
843 GpuControlList::kOsAndroid, "4.1", gpu_info));
846 TEST_F(GpuControlListEntryTest, MachineModelNameException) {
847 const std::string json = LONG_STRING_CONST(
849 "id": 1,
850 "exceptions": [
852 "os": {
853 "type": "android"
855 "machine_model_name": ["Nexus 4"]
858 "features": [
859 "test_feature_0"
863 ScopedEntry entry(GetEntryFromString(json));
864 EXPECT_TRUE(entry.get() != NULL);
865 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType());
866 GPUInfo gpu_info;
868 gpu_info.machine_model_name = "Nexus 4";
869 EXPECT_FALSE(entry->Contains(
870 GpuControlList::kOsAndroid, "4.1", gpu_info));
871 EXPECT_TRUE(entry->Contains(
872 GpuControlList::kOsLinux, "4.1", gpu_info));
874 gpu_info.machine_model_name = "";
875 EXPECT_TRUE(entry->Contains(
876 GpuControlList::kOsAndroid, "4.1", gpu_info));
877 EXPECT_TRUE(entry->Contains(
878 GpuControlList::kOsLinux, "4.1", gpu_info));
881 TEST_F(GpuControlListEntryTest, MachineModelVersion) {
882 const std::string json = LONG_STRING_CONST(
884 "id": 1,
885 "os": {
886 "type": "macosx"
888 "machine_model_name": ["MacBookPro"],
889 "machine_model_version": {
890 "op": "=",
891 "value": "7.1"
893 "features": [
894 "test_feature_0"
898 ScopedEntry entry(GetEntryFromString(json));
899 EXPECT_TRUE(entry.get() != NULL);
900 GPUInfo gpu_info;
901 gpu_info.machine_model_name = "MacBookPro";
902 gpu_info.machine_model_version = "7.1";
903 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
904 EXPECT_TRUE(entry->Contains(
905 GpuControlList::kOsMacosx, "10.6", gpu_info));
908 TEST_F(GpuControlListEntryTest, MachineModelVersionException) {
909 const std::string json = LONG_STRING_CONST(
911 "id": 1,
912 "os": {
913 "type": "macosx"
915 "machine_model_name": ["MacBookPro"],
916 "exceptions": [
918 "machine_model_version": {
919 "op": ">",
920 "value": "7.1"
924 "features": [
925 "test_feature_0"
929 ScopedEntry entry(GetEntryFromString(json));
930 EXPECT_TRUE(entry.get() != NULL);
931 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
933 GPUInfo gpu_info;
934 gpu_info.machine_model_name = "MacBookPro";
935 gpu_info.machine_model_version = "7.0";
936 EXPECT_TRUE(entry->Contains(
937 GpuControlList::kOsMacosx, "10.6", gpu_info));
939 gpu_info.machine_model_version = "7.2";
940 EXPECT_FALSE(entry->Contains(
941 GpuControlList::kOsMacosx, "10.6", gpu_info));
943 gpu_info.machine_model_version = "";
944 EXPECT_TRUE(entry->Contains(
945 GpuControlList::kOsMacosx, "10.6", gpu_info));
948 class GpuControlListEntryDualGPUTest : public GpuControlListEntryTest {
949 public:
950 GpuControlListEntryDualGPUTest() { }
951 virtual ~GpuControlListEntryDualGPUTest() { }
953 virtual void SetUp() OVERRIDE {
954 // Set up a NVIDIA/Intel dual, with NVIDIA as primary and Intel as
955 // secondary, and initially Intel is active.
956 gpu_info_.gpu.vendor_id = 0x10de;
957 gpu_info_.gpu.device_id = 0x0640;
958 gpu_info_.gpu.active = false;
959 GPUInfo::GPUDevice second_gpu;
960 second_gpu.vendor_id = 0x8086;
961 second_gpu.device_id = 0x0166;
962 second_gpu.active = true;
963 gpu_info_.secondary_gpus.push_back(second_gpu);
966 void ActivatePrimaryGPU() {
967 gpu_info_.gpu.active = true;
968 gpu_info_.secondary_gpus[0].active = false;
971 void EntryShouldApply(const std::string& entry_json) const {
972 EXPECT_TRUE(EntryApplies(entry_json));
975 void EntryShouldNotApply(const std::string& entry_json) const {
976 EXPECT_FALSE(EntryApplies(entry_json));
979 private:
980 bool EntryApplies(const std::string& entry_json) const {
981 ScopedEntry entry(GetEntryFromString(entry_json));
982 EXPECT_TRUE(entry.get());
983 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
984 return entry->Contains(GpuControlList::kOsMacosx, "10.6", gpu_info());
988 TEST_F(GpuControlListEntryDualGPUTest, CategoryAny) {
989 const std::string json_intel = LONG_STRING_CONST(
991 "id": 1,
992 "os": {
993 "type": "macosx"
995 "vendor_id": "0x8086",
996 "device_id": ["0x0166"],
997 "multi_gpu_category": "any",
998 "features": [
999 "test_feature_0"
1003 EntryShouldApply(json_intel);
1005 const std::string json_nvidia = LONG_STRING_CONST(
1007 "id": 1,
1008 "os": {
1009 "type": "macosx"
1011 "vendor_id": "0x10de",
1012 "device_id": ["0x0640"],
1013 "multi_gpu_category": "any",
1014 "features": [
1015 "test_feature_0"
1019 EntryShouldApply(json_nvidia);
1022 TEST_F(GpuControlListEntryDualGPUTest, CategoryPrimarySecondary) {
1023 const std::string json_secondary = LONG_STRING_CONST(
1025 "id": 1,
1026 "os": {
1027 "type": "macosx"
1029 "vendor_id": "0x8086",
1030 "device_id": ["0x0166"],
1031 "multi_gpu_category": "secondary",
1032 "features": [
1033 "test_feature_0"
1037 EntryShouldApply(json_secondary);
1039 const std::string json_primary = LONG_STRING_CONST(
1041 "id": 1,
1042 "os": {
1043 "type": "macosx"
1045 "vendor_id": "0x8086",
1046 "device_id": ["0x0166"],
1047 "multi_gpu_category": "primary",
1048 "features": [
1049 "test_feature_0"
1053 EntryShouldNotApply(json_primary);
1055 const std::string json_default = LONG_STRING_CONST(
1057 "id": 1,
1058 "os": {
1059 "type": "macosx"
1061 "vendor_id": "0x8086",
1062 "device_id": ["0x0166"],
1063 "features": [
1064 "test_feature_0"
1068 // Default is primary.
1069 EntryShouldNotApply(json_default);
1072 TEST_F(GpuControlListEntryDualGPUTest, ActiveSecondaryGPU) {
1073 const std::string json = LONG_STRING_CONST(
1075 "id": 1,
1076 "os": {
1077 "type": "macosx"
1079 "vendor_id": "0x8086",
1080 "device_id": ["0x0166", "0x0168"],
1081 "multi_gpu_category": "active",
1082 "features": [
1083 "test_feature_0"
1087 // By default, secondary GPU is active.
1088 EntryShouldApply(json);
1090 ActivatePrimaryGPU();
1091 EntryShouldNotApply(json);
1094 TEST_F(GpuControlListEntryDualGPUTest, VendorOnlyActiveSecondaryGPU) {
1095 const std::string json = LONG_STRING_CONST(
1097 "id": 1,
1098 "os": {
1099 "type": "macosx"
1101 "vendor_id": "0x8086",
1102 "multi_gpu_category": "active",
1103 "features": [
1104 "test_feature_0"
1108 // By default, secondary GPU is active.
1109 EntryShouldApply(json);
1111 ActivatePrimaryGPU();
1112 EntryShouldNotApply(json);
1115 TEST_F(GpuControlListEntryDualGPUTest, ActivePrimaryGPU) {
1116 const std::string json = LONG_STRING_CONST(
1118 "id": 1,
1119 "os": {
1120 "type": "macosx"
1122 "vendor_id": "0x10de",
1123 "device_id": ["0x0640"],
1124 "multi_gpu_category": "active",
1125 "features": [
1126 "test_feature_0"
1130 // By default, secondary GPU is active.
1131 EntryShouldNotApply(json);
1133 ActivatePrimaryGPU();
1134 EntryShouldApply(json);
1137 TEST_F(GpuControlListEntryDualGPUTest, VendorOnlyActivePrimaryGPU) {
1138 const std::string json = LONG_STRING_CONST(
1140 "id": 1,
1141 "os": {
1142 "type": "macosx"
1144 "vendor_id": "0x10de",
1145 "multi_gpu_category": "active",
1146 "features": [
1147 "test_feature_0"
1151 // By default, secondary GPU is active.
1152 EntryShouldNotApply(json);
1154 ActivatePrimaryGPU();
1155 EntryShouldApply(json);
1158 } // namespace gpu