Remove invocation of WebSettings::setFontRenderingNormal, which is a no-op.
[chromium-blink-merge.git] / gpu / config / gpu_control_list_entry_unittest.cc
blob8991334f17c7e31dc4cfb9dc01dec1f1e5570f80
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 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_.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;
66 private:
67 GPUInfo gpu_info_;
70 TEST_F(GpuControlListEntryTest, DetailedEntry) {
71 const std::string json = LONG_STRING_CONST(
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"
84 "vendor_id": "0x10de",
85 "device_id": ["0x0640"],
86 "driver_version": {
87 "op": "=",
88 "number": "1.6.18"
90 "features": [
91 "test_feature_0"
96 ScopedEntry entry(GetEntryFromString(json));
97 EXPECT_TRUE(entry.get() != 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()));
116 TEST_F(GpuControlListEntryTest, VendorOnAllOsEntry) {
117 const std::string json = LONG_STRING_CONST(
119 "id": 1,
120 "vendor_id": "0x10de",
121 "features": [
122 "test_feature_0"
126 ScopedEntry entry(GetEntryFromString(json));
127 EXPECT_TRUE(entry.get() != NULL);
128 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType());
130 const GpuControlList::OsType os_type[] = {
131 GpuControlList::kOsMacosx,
132 GpuControlList::kOsWin,
133 GpuControlList::kOsLinux,
134 GpuControlList::kOsChromeOS,
135 GpuControlList::kOsAndroid
137 for (size_t i = 0; i < arraysize(os_type); ++i)
138 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info()));
141 TEST_F(GpuControlListEntryTest, VendorOnLinuxEntry) {
142 const std::string json = LONG_STRING_CONST(
144 "id": 1,
145 "os": {
146 "type": "linux"
148 "vendor_id": "0x10de",
149 "features": [
150 "test_feature_0"
154 ScopedEntry entry(GetEntryFromString(json));
155 EXPECT_TRUE(entry.get() != NULL);
156 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType());
158 const GpuControlList::OsType os_type[] = {
159 GpuControlList::kOsMacosx,
160 GpuControlList::kOsWin,
161 GpuControlList::kOsChromeOS,
162 GpuControlList::kOsAndroid
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()));
170 TEST_F(GpuControlListEntryTest, AllExceptNVidiaOnLinuxEntry) {
171 const std::string json = LONG_STRING_CONST(
173 "id": 1,
174 "os": {
175 "type": "linux"
177 "exceptions": [
179 "vendor_id": "0x10de"
182 "features": [
183 "test_feature_0"
187 ScopedEntry entry(GetEntryFromString(json));
188 EXPECT_TRUE(entry.get() != NULL);
189 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType());
191 const GpuControlList::OsType os_type[] = {
192 GpuControlList::kOsMacosx,
193 GpuControlList::kOsWin,
194 GpuControlList::kOsLinux,
195 GpuControlList::kOsChromeOS,
196 GpuControlList::kOsAndroid
198 for (size_t i = 0; i < arraysize(os_type); ++i)
199 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info()));
202 TEST_F(GpuControlListEntryTest, AllExceptIntelOnLinuxEntry) {
203 const std::string json = LONG_STRING_CONST(
205 "id": 1,
206 "os": {
207 "type": "linux"
209 "exceptions": [
211 "vendor_id": "0x8086"
214 "features": [
215 "test_feature_0"
219 ScopedEntry entry(GetEntryFromString(json));
220 EXPECT_TRUE(entry.get() != NULL);
221 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType());
223 const GpuControlList::OsType os_type[] = {
224 GpuControlList::kOsMacosx,
225 GpuControlList::kOsWin,
226 GpuControlList::kOsChromeOS,
227 GpuControlList::kOsAndroid
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()));
235 TEST_F(GpuControlListEntryTest, DateOnWindowsEntry) {
236 const std::string json = LONG_STRING_CONST(
238 "id": 1,
239 "os": {
240 "type": "win"
242 "driver_date": {
243 "op": "<",
244 "number": "2010.5.8"
246 "features": [
247 "test_feature_0"
251 ScopedEntry entry(GetEntryFromString(json));
252 EXPECT_TRUE(entry.get() != NULL);
253 EXPECT_EQ(GpuControlList::kOsWin, entry->GetOsType());
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));
267 TEST_F(GpuControlListEntryTest, MultipleDevicesEntry) {
268 const std::string json = LONG_STRING_CONST(
270 "id": 1,
271 "vendor_id": "0x10de",
272 "device_id": ["0x1023", "0x0640"],
273 "features": [
274 "test_feature_0"
278 ScopedEntry entry(GetEntryFromString(json));
279 EXPECT_TRUE(entry.get() != NULL);
280 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType());
282 const GpuControlList::OsType os_type[] = {
283 GpuControlList::kOsMacosx,
284 GpuControlList::kOsWin,
285 GpuControlList::kOsLinux,
286 GpuControlList::kOsChromeOS,
287 GpuControlList::kOsAndroid
289 for (size_t i = 0; i < arraysize(os_type); ++i)
290 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info()));
293 TEST_F(GpuControlListEntryTest, ChromeOSEntry) {
294 const std::string json = LONG_STRING_CONST(
296 "id": 1,
297 "os": {
298 "type": "chromeos"
300 "features": [
301 "test_feature_0"
305 ScopedEntry entry(GetEntryFromString(json));
306 EXPECT_TRUE(entry.get() != NULL);
307 EXPECT_EQ(GpuControlList::kOsChromeOS, entry->GetOsType());
309 const GpuControlList::OsType os_type[] = {
310 GpuControlList::kOsMacosx,
311 GpuControlList::kOsWin,
312 GpuControlList::kOsLinux,
313 GpuControlList::kOsAndroid
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()));
321 TEST_F(GpuControlListEntryTest, MalformedVendor) {
322 const std::string json = LONG_STRING_CONST(
324 "id": 1,
325 "vendor_id": "[0x10de]",
326 "features": [
327 "test_feature_0"
331 ScopedEntry entry(GetEntryFromString(json));
332 EXPECT_TRUE(entry.get() == NULL);
335 TEST_F(GpuControlListEntryTest, UnknownFieldEntry) {
336 const std::string json = LONG_STRING_CONST(
338 "id": 1,
339 "unknown_field": 0,
340 "features": [
341 "test_feature_0"
345 ScopedEntry entry(GetEntryFromString(json));
346 EXPECT_TRUE(entry.get() != NULL);
347 EXPECT_TRUE(entry->contains_unknown_fields());
348 EXPECT_FALSE(entry->contains_unknown_features());
351 TEST_F(GpuControlListEntryTest, UnknownExceptionFieldEntry) {
352 const std::string json = LONG_STRING_CONST(
354 "id": 2,
355 "exceptions": [
357 "unknown_field": 0
360 "features": [
361 "test_feature_0"
365 ScopedEntry entry(GetEntryFromString(json));
366 EXPECT_TRUE(entry.get() != NULL);
367 EXPECT_TRUE(entry->contains_unknown_fields());
368 EXPECT_FALSE(entry->contains_unknown_features());
371 TEST_F(GpuControlListEntryTest, UnknownFeatureEntry) {
372 const std::string json = LONG_STRING_CONST(
374 "id": 1,
375 "features": [
376 "some_unknown_feature",
377 "test_feature_0"
381 ScopedEntry entry(GetEntryFromString(json));
382 EXPECT_TRUE(entry.get() != 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));
388 const GpuControlList::OsType os_type[] = {
389 GpuControlList::kOsMacosx,
390 GpuControlList::kOsWin,
391 GpuControlList::kOsLinux,
392 GpuControlList::kOsChromeOS,
393 GpuControlList::kOsAndroid
395 for (size_t i = 0; i < arraysize(os_type); ++i)
396 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info()));
399 TEST_F(GpuControlListEntryTest, GlVendorEntry) {
400 const std::string json = LONG_STRING_CONST(
402 "id": 1,
403 "gl_vendor": {
404 "op": "beginwith",
405 "value": "NVIDIA"
407 "features": [
408 "test_feature_0"
412 ScopedEntry entry(GetEntryFromString(json));
413 EXPECT_TRUE(entry.get() != NULL);
415 const GpuControlList::OsType os_type[] = {
416 GpuControlList::kOsMacosx,
417 GpuControlList::kOsWin,
418 GpuControlList::kOsLinux,
419 GpuControlList::kOsChromeOS,
420 GpuControlList::kOsAndroid
422 for (size_t i = 0; i < arraysize(os_type); ++i)
423 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info()));
426 TEST_F(GpuControlListEntryTest, GlRendererEntry) {
427 const std::string json = LONG_STRING_CONST(
429 "id": 1,
430 "gl_renderer": {
431 "op": "contains",
432 "value": "GeForce"
434 "features": [
435 "test_feature_0"
439 ScopedEntry entry(GetEntryFromString(json));
440 EXPECT_TRUE(entry.get() != NULL);
442 const GpuControlList::OsType os_type[] = {
443 GpuControlList::kOsMacosx,
444 GpuControlList::kOsWin,
445 GpuControlList::kOsLinux,
446 GpuControlList::kOsChromeOS,
447 GpuControlList::kOsAndroid
449 for (size_t i = 0; i < arraysize(os_type); ++i)
450 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info()));
453 TEST_F(GpuControlListEntryTest, PerfGraphicsEntry) {
454 const std::string json = LONG_STRING_CONST(
456 "id": 1,
457 "perf_graphics": {
458 "op": "<",
459 "value": "6.0"
461 "features": [
462 "test_feature_0"
466 ScopedEntry entry(GetEntryFromString(json));
467 EXPECT_TRUE(entry.get() != NULL);
468 EXPECT_TRUE(entry->Contains(GpuControlList::kOsWin, "10.6", gpu_info()));
471 TEST_F(GpuControlListEntryTest, PerfGamingEntry) {
472 const std::string json = LONG_STRING_CONST(
474 "id": 1,
475 "perf_graphics": {
476 "op": "<=",
477 "value": "4.0"
479 "features": [
480 "test_feature_0"
484 ScopedEntry entry(GetEntryFromString(json));
485 EXPECT_TRUE(entry.get() != NULL);
486 EXPECT_FALSE(entry->Contains(GpuControlList::kOsWin, "10.6", gpu_info()));
489 TEST_F(GpuControlListEntryTest, PerfOverallEntry) {
490 const std::string json = LONG_STRING_CONST(
492 "id": 1,
493 "perf_overall": {
494 "op": "between",
495 "value": "1.0",
496 "value2": "9.0"
498 "features": [
499 "test_feature_0"
503 ScopedEntry entry(GetEntryFromString(json));
504 EXPECT_TRUE(entry.get() != NULL);
505 EXPECT_TRUE(entry->Contains(GpuControlList::kOsWin, "10.6", gpu_info()));
508 TEST_F(GpuControlListEntryTest, DisabledEntry) {
509 const std::string json = LONG_STRING_CONST(
511 "id": 1,
512 "disabled": true,
513 "features": [
514 "test_feature_0"
518 ScopedEntry entry(GetEntryFromString(json));
519 EXPECT_TRUE(entry.get() != NULL);
520 EXPECT_TRUE(entry->disabled());
523 TEST_F(GpuControlListEntryTest, OptimusEntry) {
524 const std::string json = LONG_STRING_CONST(
526 "id": 1,
527 "os": {
528 "type": "linux"
530 "multi_gpu_style": "optimus",
531 "features": [
532 "test_feature_0"
536 GPUInfo gpu_info;
537 gpu_info.optimus = true;
539 ScopedEntry entry(GetEntryFromString(json));
540 EXPECT_TRUE(entry.get() != NULL);
541 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType());
542 EXPECT_TRUE(entry->Contains(
543 GpuControlList::kOsLinux, "10.6", gpu_info));
546 TEST_F(GpuControlListEntryTest, AMDSwitchableEntry) {
547 const std::string json = LONG_STRING_CONST(
549 "id": 1,
550 "os": {
551 "type": "macosx"
553 "multi_gpu_style": "amd_switchable",
554 "features": [
555 "test_feature_0"
559 GPUInfo gpu_info;
560 gpu_info.amd_switchable = true;
562 ScopedEntry entry(GetEntryFromString(json));
563 EXPECT_TRUE(entry.get() != NULL);
564 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
565 EXPECT_TRUE(entry->Contains(
566 GpuControlList::kOsMacosx, "10.6", gpu_info));
569 TEST_F(GpuControlListEntryTest, LexicalDriverVersionEntry) {
570 const std::string json = LONG_STRING_CONST(
572 "id": 1,
573 "os": {
574 "type": "linux"
576 "vendor_id": "0x1002",
577 "driver_version": {
578 "op": "=",
579 "style": "lexical",
580 "number": "8.76"
582 "features": [
583 "test_feature_0"
587 GPUInfo gpu_info;
588 gpu_info.gpu.vendor_id = 0x1002;
590 ScopedEntry entry(GetEntryFromString(json));
591 EXPECT_TRUE(entry.get() != NULL);
592 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType());
594 gpu_info.driver_version = "8.76";
595 EXPECT_TRUE(entry->Contains(
596 GpuControlList::kOsLinux, "10.6", gpu_info));
598 gpu_info.driver_version = "8.768";
599 EXPECT_TRUE(entry->Contains(
600 GpuControlList::kOsLinux, "10.6", gpu_info));
602 gpu_info.driver_version = "8.76.8";
603 EXPECT_TRUE(entry->Contains(
604 GpuControlList::kOsLinux, "10.6", gpu_info));
607 TEST_F(GpuControlListEntryTest, MultipleGPUsAnyEntry) {
608 const std::string json = LONG_STRING_CONST(
610 "id": 1,
611 "os": {
612 "type": "macosx"
614 "vendor_id": "0x8086",
615 "device_id": ["0x0166"],
616 "multi_gpu_category": "any",
617 "features": [
618 "test_feature_0"
622 ScopedEntry entry(GetEntryFromString(json));
623 EXPECT_TRUE(entry.get() != NULL);
624 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
626 GPUInfo gpu_info;
627 gpu_info.gpu.vendor_id = 0x10de;
628 gpu_info.gpu.device_id = 0x1976;
629 EXPECT_FALSE(entry->Contains(
630 GpuControlList::kOsMacosx, "10.6", gpu_info));
632 GPUInfo::GPUDevice gpu_device;
633 gpu_device.vendor_id = 0x8086;
634 gpu_device.device_id = 0x0166;
635 gpu_info.secondary_gpus.push_back(gpu_device);
636 EXPECT_TRUE(entry->Contains(
637 GpuControlList::kOsMacosx, "10.6", gpu_info));
640 TEST_F(GpuControlListEntryTest, MultipleGPUsSecondaryEntry) {
641 const std::string json = LONG_STRING_CONST(
643 "id": 1,
644 "os": {
645 "type": "macosx"
647 "vendor_id": "0x8086",
648 "device_id": ["0x0166"],
649 "multi_gpu_category": "secondary",
650 "features": [
651 "test_feature_0"
655 ScopedEntry entry(GetEntryFromString(json));
656 EXPECT_TRUE(entry.get() != NULL);
657 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
659 GPUInfo gpu_info;
660 gpu_info.gpu.vendor_id = 0x10de;
661 gpu_info.gpu.device_id = 0x1976;
662 EXPECT_FALSE(entry->Contains(
663 GpuControlList::kOsMacosx, "10.6", gpu_info));
665 GPUInfo::GPUDevice gpu_device;
666 gpu_device.vendor_id = 0x8086;
667 gpu_device.device_id = 0x0166;
668 gpu_info.secondary_gpus.push_back(gpu_device);
669 EXPECT_TRUE(entry->Contains(
670 GpuControlList::kOsMacosx, "10.6", gpu_info));
673 TEST_F(GpuControlListEntryTest, NeedsMoreInfoEntry) {
674 const std::string json = LONG_STRING_CONST(
676 "id": 1,
677 "vendor_id": "0x8086",
678 "driver_version": {
679 "op": "<",
680 "number": "10.7"
682 "features": [
683 "test_feature_1"
687 ScopedEntry entry(GetEntryFromString(json));
688 EXPECT_TRUE(entry.get() != NULL);
690 GPUInfo gpu_info;
691 gpu_info.gpu.vendor_id = 0x8086;
692 EXPECT_TRUE(entry->NeedsMoreInfo(gpu_info));
694 gpu_info.driver_version = "10.6";
695 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info));
698 TEST_F(GpuControlListEntryTest, NeedsMoreInfoForExceptionsEntry) {
699 const std::string json = LONG_STRING_CONST(
701 "id": 1,
702 "vendor_id": "0x8086",
703 "exceptions": [
705 "gl_renderer": {
706 "op": "contains",
707 "value": "mesa"
711 "features": [
712 "test_feature_1"
716 ScopedEntry entry(GetEntryFromString(json));
717 EXPECT_TRUE(entry.get() != NULL);
719 GPUInfo gpu_info;
720 gpu_info.gpu.vendor_id = 0x8086;
721 EXPECT_TRUE(entry->NeedsMoreInfo(gpu_info));
723 gpu_info.gl_renderer = "mesa";
724 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info));
727 TEST_F(GpuControlListEntryTest, FeatureTypeAllEntry) {
728 const std::string json = LONG_STRING_CONST(
730 "id": 1,
731 "features": [
732 "all"
736 ScopedEntry entry(GetEntryFromString(json, true));
737 EXPECT_TRUE(entry.get() != NULL);
738 EXPECT_EQ(3u, entry->features().size());
739 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_0));
740 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_1));
741 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_2));
744 } // namespace gpu