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

Side by Side Diff: chrome/browser/extensions/requirements_checker_browsertest.cc

Issue 2756793003: Move GPU blacklist and driver bug workaround list from json to data struct. (Closed)
Patch Set: pure rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/browser/extensions/chrome_requirements_checker.h" 14 #include "chrome/browser/extensions/chrome_requirements_checker.h"
15 #include "chrome/browser/extensions/extension_browsertest.h" 15 #include "chrome/browser/extensions/extension_browsertest.h"
16 #include "chrome/common/chrome_paths.h" 16 #include "chrome/common/chrome_paths.h"
17 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
18 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/gpu_data_manager.h" 19 #include "content/public/browser/gpu_data_manager.h"
20 #include "content/public/test/test_utils.h" 20 #include "content/public/test/test_utils.h"
21 #include "extensions/common/extension.h" 21 #include "extensions/common/extension.h"
22 #include "extensions/common/file_util.h" 22 #include "extensions/common/file_util.h"
23 #include "gpu/config/gpu_info.h"
24 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
25 24
26 namespace extensions { 25 namespace extensions {
27 26
28 class RequirementsCheckerBrowserTest : public ExtensionBrowserTest { 27 class RequirementsCheckerBrowserTest : public ExtensionBrowserTest {
29 public: 28 public:
30 RequirementsCheckerBrowserTest() 29 RequirementsCheckerBrowserTest()
31 : checker_(new ChromeRequirementsChecker()) {} 30 : checker_(new ChromeRequirementsChecker()) {}
32 31
33 scoped_refptr<const Extension> LoadExtensionFromDirName( 32 scoped_refptr<const Extension> LoadExtensionFromDirName(
34 const std::string& extension_dir_name) { 33 const std::string& extension_dir_name) {
35 base::FilePath extension_path; 34 base::FilePath extension_path;
36 std::string load_error; 35 std::string load_error;
37 PathService::Get(chrome::DIR_TEST_DATA, &extension_path); 36 PathService::Get(chrome::DIR_TEST_DATA, &extension_path);
38 extension_path = extension_path.AppendASCII("requirements_checker") 37 extension_path = extension_path.AppendASCII("requirements_checker")
39 .AppendASCII(extension_dir_name); 38 .AppendASCII(extension_dir_name);
40 scoped_refptr<const Extension> extension = file_util::LoadExtension( 39 scoped_refptr<const Extension> extension = file_util::LoadExtension(
41 extension_path, Manifest::UNPACKED, 0, &load_error); 40 extension_path, Manifest::UNPACKED, 0, &load_error);
42 CHECK_EQ(0U, load_error.length()); 41 CHECK_EQ(0U, load_error.length());
43 return extension; 42 return extension;
44 } 43 }
45 44
46 void ValidateRequirementErrors( 45 void ValidateRequirementErrors(
47 const std::vector<std::string>& expected_errors, 46 const std::vector<std::string>& expected_errors,
48 const std::vector<std::string>& actual_errors) { 47 const std::vector<std::string>& actual_errors) {
49 ASSERT_EQ(expected_errors, actual_errors); 48 ASSERT_EQ(expected_errors, actual_errors);
50 } 49 }
51 50
52 // This should only be called once per test instance. Calling more than once
53 // will result in stale information in the GPUDataManager which will throw off
54 // the RequirementsChecker.
55 void BlackListGPUFeatures(const std::vector<std::string>& features) {
56 #if !defined(NDEBUG)
57 static bool called = false;
58 DCHECK(!called);
59 called = true;
60 #endif
61
62 static const std::string json_blacklist =
63 "{\n"
64 " \"name\": \"gpu blacklist\",\n"
65 " \"version\": \"1.0\",\n"
66 " \"entries\": [\n"
67 " {\n"
68 " \"id\": 1,\n"
69 " \"features\": [\"" + base::JoinString(features, "\", \"") + "\"]\n"
70 " }\n"
71 " ]\n"
72 "}";
73 gpu::GPUInfo gpu_info;
74 content::GpuDataManager::GetInstance()->InitializeForTesting(
75 json_blacklist, gpu_info);
76 }
77
78 protected: 51 protected:
79 std::unique_ptr<RequirementsChecker> checker_; 52 std::unique_ptr<RequirementsChecker> checker_;
80 }; 53 };
81 54
82 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, CheckEmptyExtension) { 55 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, CheckEmptyExtension) {
83 scoped_refptr<const Extension> extension( 56 scoped_refptr<const Extension> extension(
84 LoadExtensionFromDirName("no_requirements")); 57 LoadExtensionFromDirName("no_requirements"));
85 ASSERT_TRUE(extension.get()); 58 ASSERT_TRUE(extension.get());
86 checker_->Check(extension, base::Bind( 59 checker_->Check(extension, base::Bind(
87 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, 60 &RequirementsCheckerBrowserTest::ValidateRequirementErrors,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, 95 &RequirementsCheckerBrowserTest::ValidateRequirementErrors,
123 base::Unretained(this), expected_errors)); 96 base::Unretained(this), expected_errors));
124 content::RunAllBlockingPoolTasksUntilIdle(); 97 content::RunAllBlockingPoolTasksUntilIdle();
125 } 98 }
126 99
127 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, DisallowWebGL) { 100 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, DisallowWebGL) {
128 scoped_refptr<const Extension> extension( 101 scoped_refptr<const Extension> extension(
129 LoadExtensionFromDirName("require_3d")); 102 LoadExtensionFromDirName("require_3d"));
130 ASSERT_TRUE(extension.get()); 103 ASSERT_TRUE(extension.get());
131 104
132 // Backlist webgl 105 content::GpuDataManager::GetInstance()->BlacklistWebGLForTesting();
133 std::vector<std::string> blacklisted_features;
134 blacklisted_features.push_back("accelerated_webgl");
135 BlackListGPUFeatures(blacklisted_features);
136 content::RunAllBlockingPoolTasksUntilIdle(); 106 content::RunAllBlockingPoolTasksUntilIdle();
137 107
138 std::vector<std::string> expected_errors; 108 std::vector<std::string> expected_errors;
139 expected_errors.push_back(l10n_util::GetStringUTF8( 109 expected_errors.push_back(l10n_util::GetStringUTF8(
140 IDS_EXTENSION_WEBGL_NOT_SUPPORTED)); 110 IDS_EXTENSION_WEBGL_NOT_SUPPORTED));
141 111
142 checker_->Check(extension, base::Bind( 112 checker_->Check(extension, base::Bind(
143 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, 113 &RequirementsCheckerBrowserTest::ValidateRequirementErrors,
144 base::Unretained(this), expected_errors)); 114 base::Unretained(this), expected_errors));
145 content::RunAllBlockingPoolTasksUntilIdle(); 115 content::RunAllBlockingPoolTasksUntilIdle();
(...skipping 11 matching lines...) Expand all
157 IDS_EXTENSION_WEBGL_NOT_SUPPORTED)); 127 IDS_EXTENSION_WEBGL_NOT_SUPPORTED));
158 } 128 }
159 129
160 checker_->Check(extension, base::Bind( 130 checker_->Check(extension, base::Bind(
161 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, 131 &RequirementsCheckerBrowserTest::ValidateRequirementErrors,
162 base::Unretained(this), expected_errors)); 132 base::Unretained(this), expected_errors));
163 content::RunAllBlockingPoolTasksUntilIdle(); 133 content::RunAllBlockingPoolTasksUntilIdle();
164 } 134 }
165 135
166 } // namespace extensions 136 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service_unittest.cc ('k') | content/browser/gpu/compositor_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698