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

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

Issue 2783813002: Move ChromeRequirementsChecker to //extensions as a PreloadCheck (Closed)
Patch Set: minor test cleanup 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
(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/files/file_path.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/path_service.h"
12 #include "base/strings/string_util.h"
13 #include "build/build_config.h"
14 #include "chrome/browser/extensions/chrome_requirements_checker.h"
15 #include "chrome/browser/extensions/extension_browsertest.h"
16 #include "chrome/common/chrome_paths.h"
17 #include "chrome/grit/generated_resources.h"
18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/gpu_data_manager.h"
20 #include "content/public/test/test_utils.h"
21 #include "extensions/common/extension.h"
22 #include "extensions/common/file_util.h"
23 #include "gpu/config/gpu_info.h"
24 #include "ui/base/l10n/l10n_util.h"
25
26 namespace extensions {
27
28 class RequirementsCheckerBrowserTest : public ExtensionBrowserTest {
29 public:
30 RequirementsCheckerBrowserTest()
31 : checker_(new ChromeRequirementsChecker()) {}
32
33 scoped_refptr<const Extension> LoadExtensionFromDirName(
34 const std::string& extension_dir_name) {
35 base::FilePath extension_path;
36 std::string load_error;
37 PathService::Get(chrome::DIR_TEST_DATA, &extension_path);
38 extension_path = extension_path.AppendASCII("requirements_checker")
39 .AppendASCII(extension_dir_name);
40 scoped_refptr<const Extension> extension = file_util::LoadExtension(
41 extension_path, Manifest::UNPACKED, 0, &load_error);
42 CHECK_EQ(0U, load_error.length());
43 return extension;
44 }
45
46 void ValidateRequirementErrors(
47 const std::vector<std::string>& expected_errors,
48 const std::vector<std::string>& actual_errors) {
49 ASSERT_EQ(expected_errors, actual_errors);
50 }
51
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:
79 std::unique_ptr<RequirementsChecker> checker_;
80 };
81
82 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, CheckEmptyExtension) {
83 scoped_refptr<const Extension> extension(
84 LoadExtensionFromDirName("no_requirements"));
85 ASSERT_TRUE(extension.get());
86 checker_->Check(extension, base::Bind(
87 &RequirementsCheckerBrowserTest::ValidateRequirementErrors,
88 base::Unretained(this), std::vector<std::string>()));
89 content::RunAllBlockingPoolTasksUntilIdle();
90 }
91
92 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, CheckNpapiExtension) {
93 scoped_refptr<const Extension> extension(
94 LoadExtensionFromDirName("require_npapi"));
95 ASSERT_TRUE(extension.get());
96
97 std::vector<std::string> expected_errors;
98 #if defined(OS_POSIX) && !defined(OS_MACOSX)
99 expected_errors.push_back(l10n_util::GetStringUTF8(
100 IDS_EXTENSION_NPAPI_NOT_SUPPORTED));
101 #endif
102
103 checker_->Check(extension, base::Bind(
104 &RequirementsCheckerBrowserTest::ValidateRequirementErrors,
105 base::Unretained(this), expected_errors));
106 content::RunAllBlockingPoolTasksUntilIdle();
107 }
108
109 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest,
110 CheckWindowShapeExtension) {
111 scoped_refptr<const Extension> extension(
112 LoadExtensionFromDirName("require_window_shape"));
113 ASSERT_TRUE(extension.get());
114
115 std::vector<std::string> expected_errors;
116 #if !defined(USE_AURA)
117 expected_errors.push_back(l10n_util::GetStringUTF8(
118 IDS_EXTENSION_WINDOW_SHAPE_NOT_SUPPORTED));
119 #endif // !defined(USE_AURA)
120
121 checker_->Check(extension, base::Bind(
122 &RequirementsCheckerBrowserTest::ValidateRequirementErrors,
123 base::Unretained(this), expected_errors));
124 content::RunAllBlockingPoolTasksUntilIdle();
125 }
126
127 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, DisallowWebGL) {
128 scoped_refptr<const Extension> extension(
129 LoadExtensionFromDirName("require_3d"));
130 ASSERT_TRUE(extension.get());
131
132 // Backlist webgl
133 std::vector<std::string> blacklisted_features;
134 blacklisted_features.push_back("accelerated_webgl");
135 BlackListGPUFeatures(blacklisted_features);
136 content::RunAllBlockingPoolTasksUntilIdle();
137
138 std::vector<std::string> expected_errors;
139 expected_errors.push_back(l10n_util::GetStringUTF8(
140 IDS_EXTENSION_WEBGL_NOT_SUPPORTED));
141
142 checker_->Check(extension, base::Bind(
143 &RequirementsCheckerBrowserTest::ValidateRequirementErrors,
144 base::Unretained(this), expected_errors));
145 content::RunAllBlockingPoolTasksUntilIdle();
146 }
147
148 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, Check3DExtension) {
149 scoped_refptr<const Extension> extension(
150 LoadExtensionFromDirName("require_3d"));
151 ASSERT_TRUE(extension.get());
152
153 std::vector<std::string> expected_errors;
154
155 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL)) {
156 expected_errors.push_back(l10n_util::GetStringUTF8(
157 IDS_EXTENSION_WEBGL_NOT_SUPPORTED));
158 }
159
160 checker_->Check(extension, base::Bind(
161 &RequirementsCheckerBrowserTest::ValidateRequirementErrors,
162 base::Unretained(this), expected_errors));
163 content::RunAllBlockingPoolTasksUntilIdle();
164 }
165
166 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698