| OLD | NEW |
| 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/ptr_util.h" |
| 9 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 11 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 14 #include "chrome/browser/extensions/chrome_requirements_checker.h" | 15 #include "extensions/browser/requirements_checker.h" |
| 15 #include "chrome/browser/extensions/extension_browsertest.h" | 16 #include "chrome/browser/extensions/extension_browsertest.h" |
| 16 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
| 17 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/gpu_data_manager.h" | 20 #include "content/public/browser/gpu_data_manager.h" |
| 20 #include "content/public/test/test_utils.h" | 21 #include "content/public/test/test_utils.h" |
| 21 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
| 22 #include "extensions/common/file_util.h" | 23 #include "extensions/common/file_util.h" |
| 23 #include "gpu/config/gpu_info.h" | 24 #include "gpu/config/gpu_info.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 25 | 26 |
| 26 namespace extensions { | 27 namespace extensions { |
| 27 | 28 |
| 29 // TODO(michaelpg): Move test to //extensions. |
| 28 class RequirementsCheckerBrowserTest : public ExtensionBrowserTest { | 30 class RequirementsCheckerBrowserTest : public ExtensionBrowserTest { |
| 29 public: | 31 public: |
| 30 RequirementsCheckerBrowserTest() | 32 RequirementsCheckerBrowserTest() {} |
| 31 : checker_(new ChromeRequirementsChecker()) {} | |
| 32 | 33 |
| 33 scoped_refptr<const Extension> LoadExtensionFromDirName( | 34 scoped_refptr<const Extension> LoadExtensionFromDirName( |
| 34 const std::string& extension_dir_name) { | 35 const std::string& extension_dir_name) { |
| 35 base::FilePath extension_path; | 36 base::FilePath extension_path; |
| 36 std::string load_error; | 37 std::string load_error; |
| 37 PathService::Get(chrome::DIR_TEST_DATA, &extension_path); | 38 PathService::Get(chrome::DIR_TEST_DATA, &extension_path); |
| 38 extension_path = extension_path.AppendASCII("requirements_checker") | 39 extension_path = extension_path.AppendASCII("requirements_checker") |
| 39 .AppendASCII(extension_dir_name); | 40 .AppendASCII(extension_dir_name); |
| 40 scoped_refptr<const Extension> extension = file_util::LoadExtension( | 41 scoped_refptr<const Extension> extension = file_util::LoadExtension( |
| 41 extension_path, Manifest::UNPACKED, 0, &load_error); | 42 extension_path, Manifest::UNPACKED, 0, &load_error); |
| 42 CHECK_EQ(0U, load_error.length()); | 43 CHECK_EQ(0U, load_error.length()); |
| 43 return extension; | 44 return extension; |
| 44 } | 45 } |
| 45 | 46 |
| 46 void ValidateRequirementErrors( | 47 void ValidateRequirementErrors( |
| 47 const std::vector<std::string>& expected_errors, | 48 PreloadCheck::Errors expected_errors, |
| 48 const std::vector<std::string>& actual_errors) { | 49 PreloadCheck::Errors actual_errors) { |
| 49 ASSERT_EQ(expected_errors, actual_errors); | 50 ASSERT_EQ(expected_errors, actual_errors); |
| 50 } | 51 } |
| 51 | 52 |
| 52 // This should only be called once per test instance. Calling more than once | 53 // 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 // will result in stale information in the GPUDataManager which will throw off |
| 54 // the RequirementsChecker. | 55 // the RequirementsChecker. |
| 55 void BlackListGPUFeatures(const std::vector<std::string>& features) { | 56 void BlackListGPUFeatures(const std::vector<std::string>& features) { |
| 56 #if !defined(NDEBUG) | 57 #if !defined(NDEBUG) |
| 57 static bool called = false; | 58 static bool called = false; |
| 58 DCHECK(!called); | 59 DCHECK(!called); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 76 } | 77 } |
| 77 | 78 |
| 78 protected: | 79 protected: |
| 79 std::unique_ptr<RequirementsChecker> checker_; | 80 std::unique_ptr<RequirementsChecker> checker_; |
| 80 }; | 81 }; |
| 81 | 82 |
| 82 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, CheckEmptyExtension) { | 83 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, CheckEmptyExtension) { |
| 83 scoped_refptr<const Extension> extension( | 84 scoped_refptr<const Extension> extension( |
| 84 LoadExtensionFromDirName("no_requirements")); | 85 LoadExtensionFromDirName("no_requirements")); |
| 85 ASSERT_TRUE(extension.get()); | 86 ASSERT_TRUE(extension.get()); |
| 86 checker_->Check(extension, base::Bind( | 87 |
| 88 checker_ = base::MakeUnique<RequirementsChecker>(extension.get()); |
| 89 checker_->Start(base::Bind( |
| 87 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, | 90 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, |
| 88 base::Unretained(this), std::vector<std::string>())); | 91 base::Unretained(this), PreloadCheck::Errors())); |
| 89 content::RunAllBlockingPoolTasksUntilIdle(); | 92 content::RunAllBlockingPoolTasksUntilIdle(); |
| 90 } | 93 } |
| 91 | 94 |
| 92 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, CheckNpapiExtension) { | 95 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, CheckNpapiExtension) { |
| 93 scoped_refptr<const Extension> extension( | 96 scoped_refptr<const Extension> extension( |
| 94 LoadExtensionFromDirName("require_npapi")); | 97 LoadExtensionFromDirName("require_npapi")); |
| 95 ASSERT_TRUE(extension.get()); | 98 ASSERT_TRUE(extension.get()); |
| 96 | 99 |
| 97 std::vector<std::string> expected_errors; | 100 PreloadCheck::Errors expected_errors; |
| 98 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 101 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 99 expected_errors.push_back(l10n_util::GetStringUTF8( | 102 expected_errors.insert(PreloadCheck::NPAPI_NOT_SUPPORTED); |
| 100 IDS_EXTENSION_NPAPI_NOT_SUPPORTED)); | |
| 101 #endif | 103 #endif |
| 102 | 104 |
| 103 checker_->Check(extension, base::Bind( | 105 checker_ = base::MakeUnique<RequirementsChecker>(extension.get()); |
| 106 checker_->Start(base::Bind( |
| 104 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, | 107 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, |
| 105 base::Unretained(this), expected_errors)); | 108 base::Unretained(this), expected_errors)); |
| 106 content::RunAllBlockingPoolTasksUntilIdle(); | 109 content::RunAllBlockingPoolTasksUntilIdle(); |
| 107 } | 110 } |
| 108 | 111 |
| 109 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, | 112 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, |
| 110 CheckWindowShapeExtension) { | 113 CheckWindowShapeExtension) { |
| 111 scoped_refptr<const Extension> extension( | 114 scoped_refptr<const Extension> extension( |
| 112 LoadExtensionFromDirName("require_window_shape")); | 115 LoadExtensionFromDirName("require_window_shape")); |
| 113 ASSERT_TRUE(extension.get()); | 116 ASSERT_TRUE(extension.get()); |
| 114 | 117 |
| 115 std::vector<std::string> expected_errors; | 118 PreloadCheck::Errors expected_errors; |
| 116 #if !defined(USE_AURA) | 119 #if !defined(USE_AURA) |
| 117 expected_errors.push_back(l10n_util::GetStringUTF8( | 120 expected_errors.insert(PreloadCheck::WINDOW_SHAPE_NOT_SUPPORTED); |
| 118 IDS_EXTENSION_WINDOW_SHAPE_NOT_SUPPORTED)); | |
| 119 #endif // !defined(USE_AURA) | 121 #endif // !defined(USE_AURA) |
| 120 | 122 |
| 121 checker_->Check(extension, base::Bind( | 123 checker_ = base::MakeUnique<RequirementsChecker>(extension.get()); |
| 124 checker_->Start(base::Bind( |
| 122 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, | 125 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, |
| 123 base::Unretained(this), expected_errors)); | 126 base::Unretained(this), expected_errors)); |
| 124 content::RunAllBlockingPoolTasksUntilIdle(); | 127 content::RunAllBlockingPoolTasksUntilIdle(); |
| 125 } | 128 } |
| 126 | 129 |
| 127 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, DisallowWebGL) { | 130 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, DisallowWebGL) { |
| 128 scoped_refptr<const Extension> extension( | 131 scoped_refptr<const Extension> extension( |
| 129 LoadExtensionFromDirName("require_3d")); | 132 LoadExtensionFromDirName("require_3d")); |
| 130 ASSERT_TRUE(extension.get()); | 133 ASSERT_TRUE(extension.get()); |
| 131 | 134 |
| 132 // Backlist webgl | 135 // Backlist webgl |
| 133 std::vector<std::string> blacklisted_features; | 136 std::vector<std::string> blacklisted_features; |
| 134 blacklisted_features.push_back("webgl"); | 137 blacklisted_features.push_back("webgl"); |
| 135 BlackListGPUFeatures(blacklisted_features); | 138 BlackListGPUFeatures(blacklisted_features); |
| 136 content::RunAllBlockingPoolTasksUntilIdle(); | 139 content::RunAllBlockingPoolTasksUntilIdle(); |
| 137 | 140 |
| 138 std::vector<std::string> expected_errors; | 141 PreloadCheck::Errors expected_errors; |
| 139 expected_errors.push_back(l10n_util::GetStringUTF8( | 142 expected_errors.insert(PreloadCheck::WEBGL_NOT_SUPPORTED); |
| 140 IDS_EXTENSION_WEBGL_NOT_SUPPORTED)); | |
| 141 | 143 |
| 142 checker_->Check(extension, base::Bind( | 144 checker_ = base::MakeUnique<RequirementsChecker>(extension.get()); |
| 145 checker_->Start(base::Bind( |
| 143 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, | 146 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, |
| 144 base::Unretained(this), expected_errors)); | 147 base::Unretained(this), expected_errors)); |
| 145 content::RunAllBlockingPoolTasksUntilIdle(); | 148 content::RunAllBlockingPoolTasksUntilIdle(); |
| 146 } | 149 } |
| 147 | 150 |
| 148 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, Check3DExtension) { | 151 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, Check3DExtension) { |
| 149 scoped_refptr<const Extension> extension( | 152 scoped_refptr<const Extension> extension( |
| 150 LoadExtensionFromDirName("require_3d")); | 153 LoadExtensionFromDirName("require_3d")); |
| 151 ASSERT_TRUE(extension.get()); | 154 ASSERT_TRUE(extension.get()); |
| 152 | 155 |
| 153 std::vector<std::string> expected_errors; | 156 PreloadCheck::Errors expected_errors; |
| 154 | 157 |
| 155 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL)) { | 158 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(nullptr)) |
| 156 expected_errors.push_back(l10n_util::GetStringUTF8( | 159 expected_errors.insert(PreloadCheck::WEBGL_NOT_SUPPORTED); |
| 157 IDS_EXTENSION_WEBGL_NOT_SUPPORTED)); | |
| 158 } | |
| 159 | 160 |
| 160 checker_->Check(extension, base::Bind( | 161 checker_ = base::MakeUnique<RequirementsChecker>(extension.get()); |
| 162 checker_->Start(base::Bind( |
| 161 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, | 163 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, |
| 162 base::Unretained(this), expected_errors)); | 164 base::Unretained(this), expected_errors)); |
| 163 content::RunAllBlockingPoolTasksUntilIdle(); | 165 content::RunAllBlockingPoolTasksUntilIdle(); |
| 164 } | 166 } |
| 165 | 167 |
| 166 } // namespace extensions | 168 } // namespace extensions |
| OLD | NEW |