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

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

Issue 10908184: Enforce the 'requirements' field in manifests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <vector>
6
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/file_path.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/message_loop.h"
12 #include "base/path_service.h"
13 #include "base/string_util.h"
14 #include "base/threading/sequenced_worker_pool.h"
15 #include "chrome/browser/extensions/extension_browsertest.h"
16 #include "chrome/browser/extensions/requirements_checker.h"
17 #include "chrome/common/chrome_paths.h"
18 #include "chrome/common/extensions/extension.h"
19 #include "chrome/common/extensions/extension_file_util.h"
20 #include "chrome/test/base/test_launcher_utils.h"
21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/gpu_data_manager.h"
23 #include "grit/generated_resources.h"
24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/gl/gl_switches.h"
26
27 namespace extensions {
28
29 class RequirementsCheckerBrowserTest : public ExtensionBrowserTest {
30 public:
31 void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
32 // In linux, we need to launch GPU process to decide if WebGL is allowed.
33 // Run it on top of osmesa to avoid bot driver issues.
34 #if defined(OS_LINUX)
35 CHECK(test_launcher_utils::OverrideGLImplementation(
36 command_line, gfx::kGLImplementationOSMesaName)) <<
37 "kUseGL must not be set multiple times!";
38 #endif
39 }
40
41 scoped_refptr<const Extension> LoadExtensionFromDirName(
42 const std::string& extension_dir_name) {
43 FilePath extension_path;
44 std::string load_error;
45 PathService::Get(chrome::DIR_TEST_DATA, &extension_path);
46 extension_path = extension_path.AppendASCII("requirements_checker")
47 .AppendASCII(extension_dir_name);
48 scoped_refptr<const Extension> extension =
49 extension_file_util::LoadExtension(extension_path, Extension::LOAD,
50 0, &load_error);
51 CHECK(load_error.length() == 0u);
52 return extension;
53 }
54
55 void ValidateRequirementErrors(std::vector<std::string> expected_errors,
56 std::vector<std::string> actual_errors) {
57 ASSERT_EQ(expected_errors, actual_errors);
58 requirement_errors_.swap(actual_errors);
59 }
60
61 // This should only be called once per test instance. Calling more than once
62 // will result in stale information in the GPUDataManager which will throw off
63 // the RequirementsChecker.
64 void BlackListGPUFeatures(const std::vector<std::string>& features) {
65 static const std::string json_blacklist =
66 "{\n"
67 " \"name\": \"gpu blacklist\",\n"
68 " \"version\": \"1.0\",\n"
69 " \"entries\": [\n"
70 " {\n"
71 " \"id\": 1,\n"
72 " \"blacklist\": [\"" + JoinString(features, "\", \"") + "\"]\n"
73 " }\n"
74 " ]\n"
75 "}";
76 content::GpuDataManager::GetInstance()->Initialize("0", json_blacklist);
77 }
78
79 protected:
80 std::vector<std::string> requirement_errors_;
81 RequirementsChecker checker_;
82 };
83
84 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, CheckEmptyExtension) {
85 scoped_refptr<const Extension> extension(
86 LoadExtensionFromDirName("no_requirements"));
87 ASSERT_TRUE(extension.get());
88 checker_.Check(extension, base::Bind(
89 &RequirementsCheckerBrowserTest::ValidateRequirementErrors,
90 base::Unretained(this), std::vector<std::string>()));
91 content::BrowserThread::GetBlockingPool()->FlushForTesting();
92 }
93
94 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, CheckNpapiExtension) {
95 scoped_refptr<const Extension> extension(
96 LoadExtensionFromDirName("require_npapi"));
97 ASSERT_TRUE(extension.get());
98
99 std::vector<std::string> expected_errors;
100 // npapi plugins are dissalowd on CROMEOS.
101 #if defined(OS_CHROMEOS)
102 expected_errors.push_back(l10n_util::GetStringUTF8(
103 IDS_EXTENSION_NPAPI_NOT_SUPPORTED));
104 #endif // defined(OS_CHROMEOS)
105
106 checker_.Check(extension, base::Bind(
107 &RequirementsCheckerBrowserTest::ValidateRequirementErrors,
108 base::Unretained(this), expected_errors));
109 content::BrowserThread::GetBlockingPool()->FlushForTesting();
110 }
111
112 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, DisallowCSS3D) {
113 scoped_refptr<const Extension> extension(
114 LoadExtensionFromDirName("require_3d"));
115 ASSERT_TRUE(extension.get());
116
117
118 // Blacklist css3d
119 std::vector<std::string> blacklisted_features;
120 blacklisted_features.push_back("accelerated_compositing");
121 BlackListGPUFeatures(blacklisted_features);
122 content::BrowserThread::GetBlockingPool()->FlushForTesting();
123
124 std::vector<std::string> expected_errors;
125 expected_errors.push_back(l10n_util::GetStringUTF8(
126 IDS_EXTENSION_CSS3D_NOT_SUPPORTED));
127
128 checker_.Check(extension, base::Bind(
129 &RequirementsCheckerBrowserTest::ValidateRequirementErrors,
130 base::Unretained(this), expected_errors));
131 content::BrowserThread::GetBlockingPool()->FlushForTesting();
132 }
133
134 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, DisallowWebGL) {
135 scoped_refptr<const Extension> extension(
136 LoadExtensionFromDirName("require_3d"));
137 ASSERT_TRUE(extension.get());
138
139 // Backlist webgl
140 std::vector<std::string> blacklisted_features;
141 blacklisted_features.push_back("webgl");
142 BlackListGPUFeatures(blacklisted_features);
143 content::BrowserThread::GetBlockingPool()->FlushForTesting();
144
145 std::vector<std::string> expected_errors;
146 expected_errors.push_back(l10n_util::GetStringUTF8(
147 IDS_EXTENSION_WEBGL_NOT_SUPPORTED));
148
149 checker_.Check(extension, base::Bind(
150 &RequirementsCheckerBrowserTest::ValidateRequirementErrors,
151 base::Unretained(this), expected_errors));
152 content::BrowserThread::GetBlockingPool()->FlushForTesting();
153 }
154
155 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, DisallowGPUFeatures) {
156 scoped_refptr<const Extension> extension(
157 LoadExtensionFromDirName("require_3d"));
158 ASSERT_TRUE(extension.get());
159
160 // Backlist both webgl and css3d
161 std::vector<std::string> blacklisted_features;
162 blacklisted_features.push_back("webgl");
163 blacklisted_features.push_back("accelerated_compositing");
164 BlackListGPUFeatures(blacklisted_features);
165 content::BrowserThread::GetBlockingPool()->FlushForTesting();
166
167 std::vector<std::string> expected_errors;
168 expected_errors.push_back(l10n_util::GetStringUTF8(
169 IDS_EXTENSION_WEBGL_NOT_SUPPORTED));
170 expected_errors.push_back(l10n_util::GetStringUTF8(
171 IDS_EXTENSION_CSS3D_NOT_SUPPORTED));
172
173 checker_.Check(extension, base::Bind(
174 &RequirementsCheckerBrowserTest::ValidateRequirementErrors,
175 base::Unretained(this), expected_errors));
176 content::BrowserThread::GetBlockingPool()->FlushForTesting();
177 }
178
179 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, Check3DExtension) {
180 scoped_refptr<const Extension> extension(
181 LoadExtensionFromDirName("require_3d"));
182 ASSERT_TRUE(extension.get());
183
184 checker_.Check(extension, base::Bind(
185 &RequirementsCheckerBrowserTest::ValidateRequirementErrors,
186 base::Unretained(this), std::vector<std::string>()));
187 content::BrowserThread::GetBlockingPool()->FlushForTesting();
188 }
189
190 } // extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/requirements_checker.cc ('k') | chrome/browser/extensions/unpacked_installer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698