OLD | NEW |
(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/browser/gpu_blacklist.h" |
| 18 #include "chrome/browser/gpu_util.h" |
| 19 #include "chrome/common/chrome_paths.h" |
| 20 #include "chrome/common/extensions/extension.h" |
| 21 #include "chrome/common/extensions/extension_file_util.h" |
| 22 #include "chrome/test/base/test_launcher_utils.h" |
| 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "grit/generated_resources.h" |
| 25 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "ui/gl/gl_switches.h" |
| 27 |
| 28 namespace extensions { |
| 29 |
| 30 class RequirementsCheckerBrowserTest : public ExtensionBrowserTest { |
| 31 public: |
| 32 void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 33 // In linux, we need to launch GPU process to decide if WebGL is allowed. |
| 34 // Run it on top of osmesa to avoid bot driver issues. |
| 35 #if defined(OS_LINUX) |
| 36 CHECK(test_launcher_utils::OverrideGLImplementation( |
| 37 command_line, gfx::kGLImplementationOSMesaName)) << |
| 38 "kUseGL must not be set multiple times!"; |
| 39 #endif |
| 40 } |
| 41 |
| 42 scoped_refptr<const Extension> LoadExtensionFromDirName( |
| 43 const std::string& extension_dir_name) { |
| 44 FilePath extension_path; |
| 45 std::string load_error; |
| 46 PathService::Get(chrome::DIR_TEST_DATA, &extension_path); |
| 47 extension_path = extension_path.AppendASCII("requirements_checker") |
| 48 .AppendASCII(extension_dir_name); |
| 49 scoped_refptr<const Extension> extension = |
| 50 extension_file_util::LoadExtension(extension_path, Extension::LOAD, |
| 51 0, &load_error); |
| 52 CHECK(load_error.length() == 0u); |
| 53 return extension; |
| 54 } |
| 55 |
| 56 void ValidateRequirementErrors(std::vector<std::string> expected_errors, |
| 57 std::vector<std::string> actual_errors) { |
| 58 ASSERT_EQ(expected_errors, actual_errors); |
| 59 requirement_errors_.swap(actual_errors); |
| 60 } |
| 61 |
| 62 // This should only be called once per test instance. Calling more than once |
| 63 // will result in stale information in the GPUDataManager which will throw off |
| 64 // the RequirementsChecker. |
| 65 void BlackListGPUFeatures(std::vector<content::GpuFeatureType> features) { |
| 66 std::vector<std::string> string_features; |
| 67 for (std::vector<content::GpuFeatureType>::iterator it = features.begin(); |
| 68 it != features.end(); |
| 69 ++it) { |
| 70 string_features.push_back( |
| 71 "\"" + gpu_util::GpuFeatureTypeToString(*it) + "\""); |
| 72 } |
| 73 |
| 74 static const std::string json_blacklist = |
| 75 "{\n" |
| 76 " \"name\": \"gpu blacklist\",\n" |
| 77 " \"version\": \"1.0\",\n" |
| 78 " \"entries\": [\n" |
| 79 " {\n" |
| 80 " \"id\": 1,\n" |
| 81 " \"blacklist\": [" + JoinString(string_features, ',') + "]\n" |
| 82 " }\n" |
| 83 " ]\n" |
| 84 "}"; |
| 85 GpuBlacklist* blacklist = GpuBlacklist::GetInstance(); |
| 86 ASSERT_TRUE(blacklist); |
| 87 ASSERT_TRUE(blacklist->LoadGpuBlacklist(json_blacklist, |
| 88 GpuBlacklist::kAllOs)); |
| 89 blacklist->UpdateGpuDataManager(); |
| 90 } |
| 91 |
| 92 protected: |
| 93 std::vector<std::string> requirement_errors_; |
| 94 RequirementsChecker checker_; |
| 95 }; |
| 96 |
| 97 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, CheckEmptyExtension) { |
| 98 scoped_refptr<const Extension> extension( |
| 99 LoadExtensionFromDirName("no_requirements")); |
| 100 ASSERT_TRUE(extension.get()); |
| 101 checker_.Check(extension, base::Bind( |
| 102 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, |
| 103 base::Unretained(this), std::vector<std::string>())); |
| 104 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 105 } |
| 106 |
| 107 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, CheckNpapiExtension) { |
| 108 scoped_refptr<const Extension> extension( |
| 109 LoadExtensionFromDirName("require_npapi")); |
| 110 ASSERT_TRUE(extension.get()); |
| 111 |
| 112 std::vector<std::string> expected_errors; |
| 113 // npapi plugins are dissalowd on CROMEOS. |
| 114 #if defined(OS_CHROMEOS) |
| 115 expected_errors.push_back(l10n_util::GetStringUTF8( |
| 116 IDS_EXTENSION_NPAPI_NOT_SUPPORTED)); |
| 117 #endif // defined(OS_CHROMEOS) |
| 118 |
| 119 checker_.Check(extension, base::Bind( |
| 120 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, |
| 121 base::Unretained(this), expected_errors)); |
| 122 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 123 } |
| 124 |
| 125 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, DisallowCSS3D) { |
| 126 scoped_refptr<const Extension> extension( |
| 127 LoadExtensionFromDirName("require_3d")); |
| 128 ASSERT_TRUE(extension.get()); |
| 129 |
| 130 |
| 131 // Blacklist css3d |
| 132 std::vector<content::GpuFeatureType> blacklisted_features; |
| 133 blacklisted_features.push_back( |
| 134 content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING); |
| 135 BlackListGPUFeatures(blacklisted_features); |
| 136 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 137 |
| 138 std::vector<std::string> expected_errors; |
| 139 expected_errors.push_back(l10n_util::GetStringUTF8( |
| 140 IDS_EXTENSION_CSS3D_NOT_SUPPORTED)); |
| 141 |
| 142 checker_.Check(extension, base::Bind( |
| 143 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, |
| 144 base::Unretained(this), expected_errors)); |
| 145 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 146 } |
| 147 |
| 148 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, DisallowWebGL) { |
| 149 scoped_refptr<const Extension> extension( |
| 150 LoadExtensionFromDirName("require_3d")); |
| 151 ASSERT_TRUE(extension.get()); |
| 152 |
| 153 // Backlist webgl |
| 154 std::vector<content::GpuFeatureType> blacklisted_features; |
| 155 blacklisted_features.push_back(content::GPU_FEATURE_TYPE_WEBGL); |
| 156 BlackListGPUFeatures(blacklisted_features); |
| 157 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 158 |
| 159 std::vector<std::string> expected_errors; |
| 160 expected_errors.push_back(l10n_util::GetStringUTF8( |
| 161 IDS_EXTENSION_WEBGL_NOT_SUPPORTED)); |
| 162 |
| 163 checker_.Check(extension, base::Bind( |
| 164 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, |
| 165 base::Unretained(this), expected_errors)); |
| 166 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 167 } |
| 168 |
| 169 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, DisallowGPUFeatures) { |
| 170 scoped_refptr<const Extension> extension( |
| 171 LoadExtensionFromDirName("require_3d")); |
| 172 ASSERT_TRUE(extension.get()); |
| 173 |
| 174 // Backlist both webgl and css3d |
| 175 std::vector<content::GpuFeatureType> blacklisted_features; |
| 176 blacklisted_features.push_back(content::GPU_FEATURE_TYPE_WEBGL); |
| 177 blacklisted_features.push_back( |
| 178 content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING); |
| 179 BlackListGPUFeatures(blacklisted_features); |
| 180 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 181 |
| 182 std::vector<std::string> expected_errors; |
| 183 expected_errors.push_back(l10n_util::GetStringUTF8( |
| 184 IDS_EXTENSION_WEBGL_NOT_SUPPORTED)); |
| 185 expected_errors.push_back(l10n_util::GetStringUTF8( |
| 186 IDS_EXTENSION_CSS3D_NOT_SUPPORTED)); |
| 187 |
| 188 checker_.Check(extension, base::Bind( |
| 189 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, |
| 190 base::Unretained(this), expected_errors)); |
| 191 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 192 } |
| 193 |
| 194 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, Check3DExtension) { |
| 195 scoped_refptr<const Extension> extension( |
| 196 LoadExtensionFromDirName("require_3d")); |
| 197 ASSERT_TRUE(extension.get()); |
| 198 |
| 199 checker_.Check(extension, base::Bind( |
| 200 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, |
| 201 base::Unretained(this), std::vector<std::string>())); |
| 202 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 203 } |
| 204 |
| 205 } // extensions |
OLD | NEW |