summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gpu_blacklist_unittest.cc
blob: 0d44233d4e190469b5a64e1f6e84ccb55d611ca6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <vector>

#include "base/base_paths.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/path_service.h"
#include "base/version.h"
#include "chrome/browser/gpu_blacklist.h"
#include "content/public/browser/gpu_data_manager.h"
#include "content/public/common/gpu_info.h"
#include "testing/gtest/include/gtest/gtest.h"

using content::GpuFeatureType;

class GpuBlacklistTest : public testing::Test {
 public:
  GpuBlacklistTest() { }

  virtual ~GpuBlacklistTest() { }

  const content::GPUInfo& gpu_info() const {
    return gpu_info_;
  }

  GpuBlacklist* Create() {
    return new GpuBlacklist();
  }

 protected:
  void SetUp() {
    gpu_info_.gpu.vendor_id = 0x10de;
    gpu_info_.gpu.device_id = 0x0640;
    gpu_info_.driver_vendor = "NVIDIA";
    gpu_info_.driver_version = "1.6.18";
    gpu_info_.driver_date = "7-14-2009";
    gpu_info_.gl_vendor = "NVIDIA Corporation";
    gpu_info_.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine";
    gpu_info_.performance_stats.graphics = 5.0;
    gpu_info_.performance_stats.gaming = 5.0;
    gpu_info_.performance_stats.overall = 5.0;
  }

  void TearDown() {
  }

 private:
  content::GPUInfo gpu_info_;
};

TEST_F(GpuBlacklistTest, CurrentBlacklistValidation) {
  FilePath data_file;
  ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &data_file));
  data_file =
      data_file.Append(FILE_PATH_LITERAL("chrome"))
               .Append(FILE_PATH_LITERAL("browser"))
               .Append(FILE_PATH_LITERAL("resources"))
               .Append(FILE_PATH_LITERAL("software_rendering_list"))
               .Append(FILE_PATH_LITERAL("software_rendering_list.json"));
  ASSERT_TRUE(file_util::PathExists(data_file));
  int64 data_file_size64 = 0;
  ASSERT_TRUE(file_util::GetFileSize(data_file, &data_file_size64));
  int data_file_size = static_cast<int>(data_file_size64);
  scoped_array<char> data(new char[data_file_size]);
  ASSERT_EQ(file_util::ReadFile(data_file, data.get(), data_file_size),
            data_file_size);
  std::string json_string(data.get(), data_file_size);
  scoped_ptr<GpuBlacklist> blacklist(Create());
  EXPECT_TRUE(blacklist->LoadGpuBlacklist(
      json_string, GpuBlacklist::kAllOs));
  EXPECT_FALSE(blacklist->contains_unknown_fields());
}

TEST_F(GpuBlacklistTest, DefaultBlacklistSettings) {
  scoped_ptr<Version> os_version(Version::GetVersionFromString("10.6.4"));
  scoped_ptr<GpuBlacklist> blacklist(Create());
  // Default blacklist settings: all feature are allowed.
  GpuFeatureType type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsMacosx, os_version.get(), gpu_info());
  EXPECT_EQ(type, 0);
}

TEST_F(GpuBlacklistTest, EmptyBlacklist) {
  // Empty list: all features are allowed.
  const std::string empty_list_json =
      "{\n"
      "  \"name\": \"gpu blacklist\",\n"
      "  \"version\": \"2.5\",\n"
      "  \"entries\": [\n"
      "  ]\n"
      "}";
  scoped_ptr<Version> os_version(Version::GetVersionFromString("10.6.4"));
  scoped_ptr<GpuBlacklist> blacklist(Create());

  EXPECT_TRUE(blacklist->LoadGpuBlacklist(
      empty_list_json, GpuBlacklist::kAllOs));
  EXPECT_EQ(blacklist->GetVersion(), std::string("2.5"));
  GpuFeatureType type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsMacosx, os_version.get(), gpu_info());
  EXPECT_EQ(type, 0);
}

TEST_F(GpuBlacklistTest, DetailedEntryAndInvalidJson) {
  // Blacklist accelerated_compositing with exact setting.
  const std::string exact_list_json =
      "{\n"
      "  \"name\": \"gpu blacklist\",\n"
      "  \"version\": \"0.1\",\n"
      "  \"entries\": [\n"
      "    {\n"
      "      \"id\": 5,\n"
      "      \"os\": {\n"
      "        \"type\": \"macosx\",\n"
      "        \"version\": {\n"
      "          \"op\": \"=\",\n"
      "          \"number\": \"10.6.4\"\n"
      "        }\n"
      "      },\n"
      "      \"vendor_id\": \"0x10de\",\n"
      "      \"device_id\": [\"0x0640\"],\n"
      "      \"driver_version\": {\n"
      "        \"op\": \"=\",\n"
      "        \"number\": \"1.6.18\"\n"
      "      },\n"
      "      \"blacklist\": [\n"
      "        \"accelerated_compositing\"\n"
      "      ]\n"
      "    }\n"
      "  ]\n"
      "}";
  scoped_ptr<Version> os_version(Version::GetVersionFromString("10.6.4"));
  scoped_ptr<GpuBlacklist> blacklist(Create());

  EXPECT_TRUE(blacklist->LoadGpuBlacklist(
      exact_list_json, GpuBlacklist::kAllOs));
  GpuFeatureType type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsMacosx, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING);

  // Invalid json input should not change the current blacklist settings.
  const std::string invalid_json = "invalid";

  EXPECT_FALSE(blacklist->LoadGpuBlacklist(
      invalid_json, GpuBlacklist::kAllOs));
  type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsMacosx, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING);
  std::vector<uint32> entries;
  bool disabled = false;
  blacklist->GetGpuFeatureTypeEntries(
      content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING, entries, disabled);
  EXPECT_EQ(entries.size(), 1u);
  EXPECT_EQ(entries[0], 5u);
  blacklist->GetGpuFeatureTypeEntries(
      content::GPU_FEATURE_TYPE_ALL, entries, disabled);
  EXPECT_EQ(entries.size(), 1u);
  EXPECT_EQ(entries[0], 5u);
  EXPECT_EQ(blacklist->max_entry_id(), 5u);
}

TEST_F(GpuBlacklistTest, VendorOnAllOsEntry) {
  // Blacklist a vendor on all OS.
  const std::string vendor_json =
      "{\n"
      "  \"name\": \"gpu blacklist\",\n"
      "  \"version\": \"0.1\",\n"
      "  \"entries\": [\n"
      "    {\n"
      "      \"id\": 1,\n"
      "      \"vendor_id\": \"0x10de\",\n"
      "      \"blacklist\": [\n"
      "        \"webgl\"\n"
      "      ]\n"
      "    }\n"
      "  ]\n"
      "}";
  scoped_ptr<Version> os_version(Version::GetVersionFromString("10.6.4"));
  scoped_ptr<GpuBlacklist> blacklist(Create());

  // Blacklist entries won't be filtered to the current OS only upon loading.
  EXPECT_TRUE(blacklist->LoadGpuBlacklist(
      vendor_json, GpuBlacklist::kAllOs));
  GpuFeatureType type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsMacosx, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL);
  type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsWin, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL);
  type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsLinux, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL);
#if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) || \
    defined(OS_OPENBSD)
  // Blacklist entries will be filtered to the current OS only upon loading.
  EXPECT_TRUE(blacklist->LoadGpuBlacklist(
      vendor_json, GpuBlacklist::kCurrentOsOnly));
  type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsMacosx, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL);
  type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsWin, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL);
  type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsLinux, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL);
#endif
}

TEST_F(GpuBlacklistTest, VendorOnLinuxEntry) {
  // Blacklist a vendor on Linux only.
  const std::string vendor_linux_json =
      "{\n"
      "  \"name\": \"gpu blacklist\",\n"
      "  \"version\": \"0.1\",\n"
      "  \"entries\": [\n"
      "    {\n"
      "      \"id\": 1,\n"
      "      \"os\": {\n"
      "        \"type\": \"linux\"\n"
      "      },\n"
      "      \"vendor_id\": \"0x10de\",\n"
      "      \"blacklist\": [\n"
      "        \"accelerated_2d_canvas\"\n"
      "      ]\n"
      "    }\n"
      "  ]\n"
      "}";
  scoped_ptr<Version> os_version(Version::GetVersionFromString("10.6.4"));
  scoped_ptr<GpuBlacklist> blacklist(Create());

  EXPECT_TRUE(blacklist->LoadGpuBlacklist(
      vendor_linux_json, GpuBlacklist::kAllOs));
  GpuFeatureType type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsMacosx, os_version.get(), gpu_info());
  EXPECT_EQ(type, 0);
  type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsWin, os_version.get(), gpu_info());
  EXPECT_EQ(type, 0);
  type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsLinux, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS);
}

TEST_F(GpuBlacklistTest, AllExceptNVidiaOnLinuxEntry) {
  // Blacklist all cards in Linux except NVIDIA.
  const std::string linux_except_nvidia_json =
      "{\n"
      "  \"name\": \"gpu blacklist\",\n"
      "  \"version\": \"0.1\",\n"
      "  \"entries\": [\n"
      "    {\n"
      "      \"id\": 1,\n"
      "      \"os\": {\n"
      "        \"type\": \"linux\"\n"
      "      },\n"
      "      \"exceptions\": [\n"
      "        {\n"
      "          \"vendor_id\": \"0x10de\"\n"
      "        }\n"
      "      ],\n"
      "      \"blacklist\": [\n"
      "        \"accelerated_2d_canvas\"\n"
      "      ]\n"
      "    }\n"
      "  ]\n"
      "}";
  scoped_ptr<Version> os_version(Version::GetVersionFromString("10.6.4"));
  scoped_ptr<GpuBlacklist> blacklist(Create());

  EXPECT_TRUE(blacklist->LoadGpuBlacklist(
      linux_except_nvidia_json, GpuBlacklist::kAllOs));
  GpuFeatureType type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsMacosx, os_version.get(), gpu_info());
  EXPECT_EQ(type, 0);
  type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsWin, os_version.get(), gpu_info());
  EXPECT_EQ(type, 0);
  type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsLinux, os_version.get(), gpu_info());
  EXPECT_EQ(type, 0);
}

TEST_F(GpuBlacklistTest, AllExceptIntelOnLinuxEntry) {
  // Blacklist all cards in Linux except Intel.
  const std::string linux_except_intel_json =
      "{\n"
      "  \"name\": \"gpu blacklist\",\n"
      "  \"version\": \"0.1\",\n"
      "  \"entries\": [\n"
      "    {\n"
      "      \"id\": 1,\n"
      "      \"os\": {\n"
      "        \"type\": \"linux\"\n"
      "      },\n"
      "      \"exceptions\": [\n"
      "        {\n"
      "          \"vendor_id\": \"0x8086\"\n"
      "        }\n"
      "      ],\n"
      "      \"blacklist\": [\n"
      "        \"accelerated_2d_canvas\"\n"
      "      ]\n"
      "    }\n"
      "  ]\n"
      "}";
  scoped_ptr<Version> os_version(Version::GetVersionFromString("10.6.4"));
  scoped_ptr<GpuBlacklist> blacklist(Create());

  EXPECT_TRUE(blacklist->LoadGpuBlacklist(
      linux_except_intel_json, GpuBlacklist::kAllOs));
  GpuFeatureType type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsMacosx, os_version.get(), gpu_info());
  EXPECT_EQ(type, 0);
  type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsWin, os_version.get(), gpu_info());
  EXPECT_EQ(type, 0);
  type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsLinux, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS);
}

TEST_F(GpuBlacklistTest, DateOnWindowsEntry) {
  // Blacklist all drivers earlier than 2010-01 in Windows.
  const std::string date_windows_json =
      "{\n"
      "  \"name\": \"gpu blacklist\",\n"
      "  \"version\": \"0.1\",\n"
      "  \"entries\": [\n"
      "    {\n"
      "      \"id\": 1,\n"
      "      \"os\": {\n"
      "        \"type\": \"win\"\n"
      "      },\n"
      "      \"driver_date\": {\n"
      "        \"op\": \"<\",\n"
      "        \"number\": \"2010.1\"\n"
      "      },\n"
      "      \"blacklist\": [\n"
      "        \"accelerated_2d_canvas\"\n"
      "      ]\n"
      "    }\n"
      "  ]\n"
      "}";
  scoped_ptr<Version> os_version(Version::GetVersionFromString("10.6.4"));
  scoped_ptr<GpuBlacklist> blacklist(Create());

  EXPECT_TRUE(blacklist->LoadGpuBlacklist(
      date_windows_json, GpuBlacklist::kAllOs));
  GpuFeatureType type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsMacosx, os_version.get(), gpu_info());
  EXPECT_EQ(type, 0);
  type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsLinux, os_version.get(), gpu_info());
  EXPECT_EQ(type, 0);
  type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsWin, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS);
}

TEST_F(GpuBlacklistTest, MultipleDevicesEntry) {
  const std::string devices_json =
      "{\n"
      "  \"name\": \"gpu blacklist\",\n"
      "  \"version\": \"0.1\",\n"
      "  \"entries\": [\n"
      "    {\n"
      "      \"id\": 1,\n"
      "      \"vendor_id\": \"0x10de\",\n"
      "      \"device_id\": [\"0x1023\", \"0x0640\"],\n"
      "      \"blacklist\": [\n"
      "        \"multisampling\"\n"
      "      ]\n"
      "    }\n"
      "  ]\n"
      "}";
  scoped_ptr<Version> os_version(Version::GetVersionFromString("10.6.4"));
  scoped_ptr<GpuBlacklist> blacklist(Create());

  EXPECT_TRUE(blacklist->LoadGpuBlacklist(
      devices_json, GpuBlacklist::kAllOs));
  GpuFeatureType type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsMacosx, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_MULTISAMPLING);
  type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsWin, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_MULTISAMPLING);
  type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsLinux, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_MULTISAMPLING);
}

TEST_F(GpuBlacklistTest, ChromeOSEntry) {
  const std::string devices_json =
      "{\n"
      "  \"name\": \"gpu blacklist\",\n"
      "  \"version\": \"0.1\",\n"
      "  \"entries\": [\n"
      "    {\n"
      "      \"id\": 1,\n"
      "      \"os\": {\n"
      "        \"type\": \"chromeos\"\n"
      "      },\n"
      "      \"blacklist\": [\n"
      "        \"webgl\"\n"
      "      ]\n"
      "    }\n"
      "  ]\n"
      "}";
  scoped_ptr<Version> os_version(Version::GetVersionFromString("10.6.4"));
  scoped_ptr<GpuBlacklist> blacklist(Create());

  EXPECT_TRUE(blacklist->LoadGpuBlacklist(
      devices_json, GpuBlacklist::kAllOs));
  GpuFeatureType type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsChromeOS, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL);
  type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsLinux, os_version.get(), gpu_info());
  EXPECT_EQ(type, 0);
}

TEST_F(GpuBlacklistTest, ChromeVersionEntry) {
  const std::string browser_version_json =
      "{\n"
      "  \"name\": \"gpu blacklist\",\n"
      "  \"version\": \"0.1\",\n"
      "  \"entries\": [\n"
      "    {\n"
      "      \"id\": 1,\n"
      "      \"browser_version\": {\n"
      "        \"op\": \">=\",\n"
      "        \"number\": \"10\"\n"
      "      },\n"
      "      \"blacklist\": [\n"
      "        \"webgl\"\n"
      "      ]\n"
      "    }\n"
      "  ]\n"
      "}";
  scoped_ptr<Version> os_version(Version::GetVersionFromString("10.6.4"));

  scoped_ptr<GpuBlacklist> blacklist9(Create());
  EXPECT_TRUE(blacklist9->LoadGpuBlacklist(
      "9.0", browser_version_json, GpuBlacklist::kAllOs));
  GpuFeatureType type = blacklist9->DetermineGpuFeatureType(
      GpuBlacklist::kOsWin, os_version.get(), gpu_info());
  EXPECT_EQ(type, 0);

  scoped_ptr<GpuBlacklist> blacklist10(Create());
  EXPECT_TRUE(blacklist10->LoadGpuBlacklist(
      "10.0", browser_version_json, GpuBlacklist::kAllOs));
  type = blacklist10->DetermineGpuFeatureType(
      GpuBlacklist::kOsWin, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL);
}

TEST_F(GpuBlacklistTest, MalformedVendor) {
  // vendor_id is defined as list instead of string.
  const std::string malformed_vendor_json =
      "{\n"
      "  \"name\": \"gpu blacklist\",\n"
      "  \"version\": \"0.1\",\n"
      "  \"entries\": [\n"
      "    {\n"
      "      \"id\": 1,\n"
      "      \"vendor_id\": \"[0x10de]\",\n"
      "      \"blacklist\": [\n"
      "        \"accelerated_2d_canvas\"\n"
      "      ]\n"
      "    }\n"
      "  ]\n"
      "}";
  scoped_ptr<GpuBlacklist> blacklist(Create());

  EXPECT_FALSE(blacklist->LoadGpuBlacklist(
      malformed_vendor_json, GpuBlacklist::kAllOs));
}

TEST_F(GpuBlacklistTest, UnknownField) {
  const std::string unknown_field_json =
      "{\n"
      "  \"name\": \"gpu blacklist\",\n"
      "  \"version\": \"0.1\",\n"
      "  \"entries\": [\n"
      "    {\n"
      "      \"id\": 1,\n"
      "      \"unknown_field\": 0,\n"
      "      \"blacklist\": [\n"
      "        \"accelerated_2d_canvas\"\n"
      "      ]\n"
      "    },\n"
      "    {\n"
      "      \"id\": 2,\n"
      "      \"blacklist\": [\n"
      "        \"webgl\"\n"
      "      ]\n"
      "    }\n"
      "  ]\n"
      "}";
  scoped_ptr<Version> os_version(Version::GetVersionFromString("10.6.4"));
  scoped_ptr<GpuBlacklist> blacklist(Create());

  EXPECT_TRUE(blacklist->LoadGpuBlacklist(
      unknown_field_json, GpuBlacklist::kAllOs));
  EXPECT_EQ(1u, blacklist->num_entries());
  EXPECT_TRUE(blacklist->contains_unknown_fields());
  GpuFeatureType type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsWin, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL);
}

TEST_F(GpuBlacklistTest, UnknownExceptionField) {
  const std::string unknown_exception_field_json =
      "{\n"
      "  \"name\": \"gpu blacklist\",\n"
      "  \"version\": \"0.1\",\n"
      "  \"entries\": [\n"
      "    {\n"
      "      \"id\": 1,\n"
      "      \"unknown_field\": 0,\n"
      "      \"blacklist\": [\n"
      "        \"accelerated_compositing\"\n"
      "      ]\n"
      "    },\n"
      "    {\n"
      "      \"id\": 2,\n"
      "      \"exceptions\": [\n"
      "        {\n"
      "          \"unknown_field\": 0\n"
      "        }\n"
      "      ],\n"
      "      \"blacklist\": [\n"
      "        \"accelerated_2d_canvas\"\n"
      "      ]\n"
      "    },\n"
      "    {\n"
      "      \"id\": 3,\n"
      "      \"blacklist\": [\n"
      "        \"webgl\"\n"
      "      ]\n"
      "    }\n"
      "  ]\n"
      "}";
  scoped_ptr<Version> os_version(Version::GetVersionFromString("10.6.4"));
  scoped_ptr<GpuBlacklist> blacklist(Create());

  EXPECT_TRUE(blacklist->LoadGpuBlacklist(
      unknown_exception_field_json, GpuBlacklist::kAllOs));
  EXPECT_EQ(1u, blacklist->num_entries());
  EXPECT_TRUE(blacklist->contains_unknown_fields());
  GpuFeatureType type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsWin, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL);
}

TEST_F(GpuBlacklistTest, UnknownFeature) {
  const std::string unknown_feature_json =
      "{\n"
      "  \"name\": \"gpu blacklist\",\n"
      "  \"version\": \"0.1\",\n"
      "  \"entries\": [\n"
      "    {\n"
      "      \"id\": 1,\n"
      "      \"blacklist\": [\n"
      "        \"accelerated_something\",\n"
      "        \"webgl\"\n"
      "      ]\n"
      "    }\n"
      "  ]\n"
      "}";
  scoped_ptr<Version> os_version(Version::GetVersionFromString("10.6.4"));
  scoped_ptr<GpuBlacklist> blacklist(Create());

  EXPECT_TRUE(blacklist->LoadGpuBlacklist(
      unknown_feature_json, GpuBlacklist::kAllOs));
  EXPECT_EQ(1u, blacklist->num_entries());
  EXPECT_TRUE(blacklist->contains_unknown_fields());
  GpuFeatureType type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsWin, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL);
}

TEST_F(GpuBlacklistTest, GlVendor) {
  const std::string gl_vendor_json =
      "{\n"
      "  \"name\": \"gpu blacklist\",\n"
      "  \"version\": \"0.1\",\n"
      "  \"entries\": [\n"
      "    {\n"
      "      \"id\": 1,\n"
      "      \"gl_vendor\": {\n"
      "        \"op\": \"beginwith\",\n"
      "        \"value\": \"NVIDIA\"\n"
      "      },\n"
      "      \"blacklist\": [\n"
      "        \"webgl\"\n"
      "      ]\n"
      "    }\n"
      "  ]\n"
      "}";
  scoped_ptr<Version> os_version(Version::GetVersionFromString("10.6.4"));

  scoped_ptr<GpuBlacklist> blacklist(Create());
  EXPECT_TRUE(blacklist->LoadGpuBlacklist(
      gl_vendor_json, GpuBlacklist::kAllOs));
  GpuFeatureType type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsWin, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL);
}

TEST_F(GpuBlacklistTest, GlRenderer) {
  const std::string gl_renderer_json =
      "{\n"
      "  \"name\": \"gpu blacklist\",\n"
      "  \"version\": \"0.1\",\n"
      "  \"entries\": [\n"
      "    {\n"
      "      \"id\": 1,\n"
      "      \"gl_renderer\": {\n"
      "        \"op\": \"contains\",\n"
      "        \"value\": \"GeForce\"\n"
      "      },\n"
      "      \"blacklist\": [\n"
      "        \"webgl\"\n"
      "      ]\n"
      "    }\n"
      "  ]\n"
      "}";
  scoped_ptr<Version> os_version(Version::GetVersionFromString("10.6.4"));

  scoped_ptr<GpuBlacklist> blacklist(Create());
  EXPECT_TRUE(blacklist->LoadGpuBlacklist(
      gl_renderer_json, GpuBlacklist::kAllOs));
  GpuFeatureType type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsWin, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL);
}

TEST_F(GpuBlacklistTest, PerfGraphics) {
  const std::string json =
      "{\n"
      "  \"name\": \"gpu blacklist\",\n"
      "  \"version\": \"0.1\",\n"
      "  \"entries\": [\n"
      "    {\n"
      "      \"id\": 1,\n"
      "      \"perf_graphics\": {\n"
      "        \"op\": \"<\",\n"
      "        \"value\": \"6.0\"\n"
      "      },\n"
      "      \"blacklist\": [\n"
      "        \"webgl\"\n"
      "      ]\n"
      "    }\n"
      "  ]\n"
      "}";
  scoped_ptr<Version> os_version(Version::GetVersionFromString("10.6.4"));

  scoped_ptr<GpuBlacklist> blacklist(Create());
  EXPECT_TRUE(blacklist->LoadGpuBlacklist(json, GpuBlacklist::kAllOs));
  GpuFeatureType type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsWin, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL);
}

TEST_F(GpuBlacklistTest, PerfGaming) {
  const std::string json =
      "{\n"
      "  \"name\": \"gpu blacklist\",\n"
      "  \"version\": \"0.1\",\n"
      "  \"entries\": [\n"
      "    {\n"
      "      \"id\": 1,\n"
      "      \"perf_gaming\": {\n"
      "        \"op\": \"<=\",\n"
      "        \"value\": \"4.0\"\n"
      "      },\n"
      "      \"blacklist\": [\n"
      "        \"webgl\"\n"
      "      ]\n"
      "    }\n"
      "  ]\n"
      "}";
  scoped_ptr<Version> os_version(Version::GetVersionFromString("10.6.4"));

  scoped_ptr<GpuBlacklist> blacklist(Create());
  EXPECT_TRUE(blacklist->LoadGpuBlacklist(json, GpuBlacklist::kAllOs));
  GpuFeatureType type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsWin, os_version.get(), gpu_info());
  EXPECT_EQ(type, 0);
}

TEST_F(GpuBlacklistTest, PerfOverall) {
  const std::string json =
      "{\n"
      "  \"name\": \"gpu blacklist\",\n"
      "  \"version\": \"0.1\",\n"
      "  \"entries\": [\n"
      "    {\n"
      "      \"id\": 1,\n"
      "      \"perf_overall\": {\n"
      "        \"op\": \"between\",\n"
      "        \"value\": \"1.0\",\n"
      "        \"value2\": \"9.0\"\n"
      "      },\n"
      "      \"blacklist\": [\n"
      "        \"webgl\"\n"
      "      ]\n"
      "    }\n"
      "  ]\n"
      "}";
  scoped_ptr<Version> os_version(Version::GetVersionFromString("10.6.4"));

  scoped_ptr<GpuBlacklist> blacklist(Create());
  EXPECT_TRUE(blacklist->LoadGpuBlacklist(json, GpuBlacklist::kAllOs));
  GpuFeatureType type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsWin, os_version.get(), gpu_info());
  EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL);
}

TEST_F(GpuBlacklistTest, DisabledEntry) {
  const std::string disabled_json =
      "{\n"
      "  \"name\": \"gpu blacklist\",\n"
      "  \"version\": \"0.1\",\n"
      "  \"entries\": [\n"
      "    {\n"
      "      \"id\": 1,\n"
      "      \"disabled\": true,\n"
      "      \"blacklist\": [\n"
      "        \"webgl\"\n"
      "      ]\n"
      "    }\n"
      "  ]\n"
      "}";
  scoped_ptr<Version> os_version(Version::GetVersionFromString("10.6.4"));

  scoped_ptr<GpuBlacklist> blacklist(Create());
  EXPECT_TRUE(blacklist->LoadGpuBlacklist(
      disabled_json, GpuBlacklist::kAllOs));
  GpuFeatureType type = blacklist->DetermineGpuFeatureType(
      GpuBlacklist::kOsWin, os_version.get(), gpu_info());
  EXPECT_EQ(type, 0);
  std::vector<uint32> flag_entries;
  bool disabled = false;
  blacklist->GetGpuFeatureTypeEntries(
      content::GPU_FEATURE_TYPE_ALL, flag_entries, disabled);
  EXPECT_EQ(flag_entries.size(), 0u);
  disabled = true;
  blacklist->GetGpuFeatureTypeEntries(
      content::GPU_FEATURE_TYPE_ALL, flag_entries, disabled);
  EXPECT_EQ(flag_entries.size(), 1u);
}