| 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/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 "ui/base/l10n/l10n_util.h" | |
| 24 | |
| 25 namespace extensions { | |
| 26 | |
| 27 class RequirementsCheckerBrowserTest : public ExtensionBrowserTest { | |
| 28 public: | |
| 29 RequirementsCheckerBrowserTest() | |
| 30 : checker_(new ChromeRequirementsChecker()) {} | |
| 31 | |
| 32 scoped_refptr<const Extension> LoadExtensionFromDirName( | |
| 33 const std::string& extension_dir_name) { | |
| 34 base::FilePath extension_path; | |
| 35 std::string load_error; | |
| 36 PathService::Get(chrome::DIR_TEST_DATA, &extension_path); | |
| 37 extension_path = extension_path.AppendASCII("requirements_checker") | |
| 38 .AppendASCII(extension_dir_name); | |
| 39 scoped_refptr<const Extension> extension = file_util::LoadExtension( | |
| 40 extension_path, Manifest::UNPACKED, 0, &load_error); | |
| 41 CHECK_EQ(0U, load_error.length()); | |
| 42 return extension; | |
| 43 } | |
| 44 | |
| 45 void ValidateRequirementErrors( | |
| 46 const std::vector<std::string>& expected_errors, | |
| 47 const std::vector<std::string>& actual_errors) { | |
| 48 ASSERT_EQ(expected_errors, actual_errors); | |
| 49 } | |
| 50 | |
| 51 protected: | |
| 52 std::unique_ptr<RequirementsChecker> checker_; | |
| 53 }; | |
| 54 | |
| 55 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, CheckEmptyExtension) { | |
| 56 scoped_refptr<const Extension> extension( | |
| 57 LoadExtensionFromDirName("no_requirements")); | |
| 58 ASSERT_TRUE(extension.get()); | |
| 59 checker_->Check(extension, base::Bind( | |
| 60 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, | |
| 61 base::Unretained(this), std::vector<std::string>())); | |
| 62 content::RunAllBlockingPoolTasksUntilIdle(); | |
| 63 } | |
| 64 | |
| 65 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, CheckNpapiExtension) { | |
| 66 scoped_refptr<const Extension> extension( | |
| 67 LoadExtensionFromDirName("require_npapi")); | |
| 68 ASSERT_TRUE(extension.get()); | |
| 69 | |
| 70 std::vector<std::string> expected_errors; | |
| 71 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
| 72 expected_errors.push_back(l10n_util::GetStringUTF8( | |
| 73 IDS_EXTENSION_NPAPI_NOT_SUPPORTED)); | |
| 74 #endif | |
| 75 | |
| 76 checker_->Check(extension, base::Bind( | |
| 77 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, | |
| 78 base::Unretained(this), expected_errors)); | |
| 79 content::RunAllBlockingPoolTasksUntilIdle(); | |
| 80 } | |
| 81 | |
| 82 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, | |
| 83 CheckWindowShapeExtension) { | |
| 84 scoped_refptr<const Extension> extension( | |
| 85 LoadExtensionFromDirName("require_window_shape")); | |
| 86 ASSERT_TRUE(extension.get()); | |
| 87 | |
| 88 std::vector<std::string> expected_errors; | |
| 89 #if !defined(USE_AURA) | |
| 90 expected_errors.push_back(l10n_util::GetStringUTF8( | |
| 91 IDS_EXTENSION_WINDOW_SHAPE_NOT_SUPPORTED)); | |
| 92 #endif // !defined(USE_AURA) | |
| 93 | |
| 94 checker_->Check(extension, base::Bind( | |
| 95 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, | |
| 96 base::Unretained(this), expected_errors)); | |
| 97 content::RunAllBlockingPoolTasksUntilIdle(); | |
| 98 } | |
| 99 | |
| 100 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, DisallowWebGL) { | |
| 101 scoped_refptr<const Extension> extension( | |
| 102 LoadExtensionFromDirName("require_3d")); | |
| 103 ASSERT_TRUE(extension.get()); | |
| 104 | |
| 105 content::GpuDataManager::GetInstance()->BlacklistWebGLForTesting(); | |
| 106 content::RunAllBlockingPoolTasksUntilIdle(); | |
| 107 | |
| 108 std::vector<std::string> expected_errors; | |
| 109 expected_errors.push_back(l10n_util::GetStringUTF8( | |
| 110 IDS_EXTENSION_WEBGL_NOT_SUPPORTED)); | |
| 111 | |
| 112 checker_->Check(extension, base::Bind( | |
| 113 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, | |
| 114 base::Unretained(this), expected_errors)); | |
| 115 content::RunAllBlockingPoolTasksUntilIdle(); | |
| 116 } | |
| 117 | |
| 118 IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, Check3DExtension) { | |
| 119 scoped_refptr<const Extension> extension( | |
| 120 LoadExtensionFromDirName("require_3d")); | |
| 121 ASSERT_TRUE(extension.get()); | |
| 122 | |
| 123 std::vector<std::string> expected_errors; | |
| 124 | |
| 125 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL)) { | |
| 126 expected_errors.push_back(l10n_util::GetStringUTF8( | |
| 127 IDS_EXTENSION_WEBGL_NOT_SUPPORTED)); | |
| 128 } | |
| 129 | |
| 130 checker_->Check(extension, base::Bind( | |
| 131 &RequirementsCheckerBrowserTest::ValidateRequirementErrors, | |
| 132 base::Unretained(this), expected_errors)); | |
| 133 content::RunAllBlockingPoolTasksUntilIdle(); | |
| 134 } | |
| 135 | |
| 136 } // namespace extensions | |
| OLD | NEW |