| 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/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "chrome/browser/extensions/bundle_installer.h" |
| 10 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
| 11 #include "chrome/browser/extensions/extension_function_test_utils.h" | 12 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 12 #include "chrome/browser/extensions/extension_install_dialog.h" | 13 #include "chrome/browser/extensions/extension_install_dialog.h" |
| 13 #include "chrome/browser/extensions/extension_install_ui.h" | 14 #include "chrome/browser/extensions/extension_install_ui.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/extensions/extension_webstore_private_api.h" | 16 #include "chrome/browser/extensions/extension_webstore_private_api.h" |
| 16 #include "chrome/browser/extensions/webstore_installer.h" | 17 #include "chrome/browser/extensions/webstore_installer.h" |
| 17 #include "chrome/browser/gpu_blacklist.h" | 18 #include "chrome/browser/gpu_blacklist.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 31 | 32 |
| 32 using namespace extension_function_test_utils; | 33 using namespace extension_function_test_utils; |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| 35 | 36 |
| 36 class WebstoreInstallListener : public WebstoreInstaller::Delegate { | 37 class WebstoreInstallListener : public WebstoreInstaller::Delegate { |
| 37 public: | 38 public: |
| 38 WebstoreInstallListener() | 39 WebstoreInstallListener() |
| 39 : received_failure_(false), received_success_(false), waiting_(false) {} | 40 : received_failure_(false), received_success_(false), waiting_(false) {} |
| 40 | 41 |
| 41 void OnExtensionInstallSuccess(const std::string& id) OVERRIDE; | 42 void OnExtensionInstallSuccess(const std::string& id) OVERRIDE { |
| 43 received_success_ = true; |
| 44 id_ = id; |
| 45 |
| 46 if (waiting_) { |
| 47 waiting_ = false; |
| 48 MessageLoopForUI::current()->Quit(); |
| 49 } |
| 50 } |
| 51 |
| 42 void OnExtensionInstallFailure(const std::string& id, | 52 void OnExtensionInstallFailure(const std::string& id, |
| 43 const std::string& error) OVERRIDE; | 53 const std::string& error) OVERRIDE { |
| 44 void Wait(); | 54 received_failure_ = true; |
| 55 id_ = id; |
| 56 error_ = error; |
| 57 |
| 58 if (waiting_) { |
| 59 waiting_ = false; |
| 60 MessageLoopForUI::current()->Quit(); |
| 61 } |
| 62 } |
| 63 |
| 64 void Wait() { |
| 65 if (received_success_ || received_failure_) |
| 66 return; |
| 67 |
| 68 waiting_ = true; |
| 69 ui_test_utils::RunMessageLoop(); |
| 70 } |
| 45 | 71 |
| 46 bool received_failure() const { return received_failure_; } | 72 bool received_failure() const { return received_failure_; } |
| 47 bool received_success() const { return received_success_; } | 73 bool received_success() const { return received_success_; } |
| 48 const std::string& id() const { return id_; } | 74 const std::string& id() const { return id_; } |
| 49 const std::string& error() const { return error_; } | 75 const std::string& error() const { return error_; } |
| 50 | 76 |
| 51 private: | 77 private: |
| 52 bool received_failure_; | 78 bool received_failure_; |
| 53 bool received_success_; | 79 bool received_success_; |
| 54 bool waiting_; | 80 bool waiting_; |
| 55 std::string id_; | 81 std::string id_; |
| 56 std::string error_; | 82 std::string error_; |
| 57 }; | 83 }; |
| 58 | 84 |
| 59 void WebstoreInstallListener::OnExtensionInstallSuccess(const std::string& id) { | |
| 60 received_success_ = true; | |
| 61 id_ = id; | |
| 62 | |
| 63 if (waiting_) { | |
| 64 waiting_ = false; | |
| 65 MessageLoopForUI::current()->Quit(); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 void WebstoreInstallListener::OnExtensionInstallFailure( | |
| 70 const std::string& id, const std::string& error) { | |
| 71 received_failure_ = true; | |
| 72 id_ = id; | |
| 73 error_ = error; | |
| 74 | |
| 75 if (waiting_) { | |
| 76 waiting_ = false; | |
| 77 MessageLoopForUI::current()->Quit(); | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 void WebstoreInstallListener::Wait() { | |
| 82 if (received_success_ || received_failure_) | |
| 83 return; | |
| 84 | |
| 85 waiting_ = true; | |
| 86 ui_test_utils::RunMessageLoop(); | |
| 87 } | |
| 88 | |
| 89 } // namespace | 85 } // namespace |
| 90 | 86 |
| 91 // A base class for tests below. | 87 // A base class for tests below. |
| 92 class ExtensionWebstorePrivateApiTest : public ExtensionApiTest { | 88 class ExtensionWebstorePrivateApiTest : public ExtensionApiTest { |
| 93 public: | 89 public: |
| 94 void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 90 void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 95 ExtensionApiTest::SetUpCommandLine(command_line); | 91 ExtensionApiTest::SetUpCommandLine(command_line); |
| 96 command_line->AppendSwitchASCII( | 92 command_line->AppendSwitchASCII( |
| 97 switches::kAppsGalleryURL, "http://www.example.com"); | 93 switches::kAppsGalleryURL, "http://www.example.com"); |
| 98 command_line->AppendSwitchASCII( | 94 command_line->AppendSwitchASCII( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 : public ExtensionWebstorePrivateApiTest { | 139 : public ExtensionWebstorePrivateApiTest { |
| 144 public: | 140 public: |
| 145 void SetUpInProcessBrowserTestFixture() OVERRIDE { | 141 void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 146 ExtensionWebstorePrivateApiTest::SetUpInProcessBrowserTestFixture(); | 142 ExtensionWebstorePrivateApiTest::SetUpInProcessBrowserTestFixture(); |
| 147 | 143 |
| 148 // The test server needs to have already started, so setup the switch here | 144 // The test server needs to have already started, so setup the switch here |
| 149 // rather than in SetUpCommandLine. | 145 // rather than in SetUpCommandLine. |
| 150 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 146 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 151 switches::kAppsGalleryDownloadURL, | 147 switches::kAppsGalleryDownloadURL, |
| 152 GetTestServerURL("bundle/%s.crx").spec()); | 148 GetTestServerURL("bundle/%s.crx").spec()); |
| 153 | |
| 154 PackCRX("begfmnajjkbjdgmffnjaojchoncnmngg"); | |
| 155 PackCRX("bmfoocgfinpmkmlbjhcbofejhkhlbchk"); | |
| 156 PackCRX("mpneghmdnmaolkljkipbhaienajcflfe"); | |
| 157 } | 149 } |
| 158 | 150 |
| 159 void TearDownInProcessBrowserTestFixture() OVERRIDE { | 151 void TearDownInProcessBrowserTestFixture() OVERRIDE { |
| 160 ExtensionWebstorePrivateApiTest::TearDownInProcessBrowserTestFixture(); | 152 ExtensionWebstorePrivateApiTest::TearDownInProcessBrowserTestFixture(); |
| 161 for (size_t i = 0; i < test_crx_.size(); ++i) | 153 for (size_t i = 0; i < test_crx_.size(); ++i) |
| 162 ASSERT_TRUE(file_util::Delete(test_crx_[i], false)); | 154 ASSERT_TRUE(file_util::Delete(test_crx_[i], false)); |
| 163 } | 155 } |
| 164 | 156 |
| 165 private: | 157 protected: |
| 166 void PackCRX(const std::string& id) { | 158 void PackCRX(const std::string& id) { |
| 159 FilePath dir_path = test_data_dir_ |
| 160 .AppendASCII("webstore_private/bundle") |
| 161 .AppendASCII(id); |
| 162 |
| 163 PackCRX(id, dir_path); |
| 164 } |
| 165 |
| 166 // Packs the |manifest| file into a CRX using |id|'s PEM key. |
| 167 void PackCRX(const std::string& id, const std::string& manifest) { |
| 168 // Move the extension to a temporary directory. |
| 169 ScopedTempDir tmp; |
| 170 ASSERT_TRUE(tmp.CreateUniqueTempDir()); |
| 171 ASSERT_TRUE(file_util::CreateDirectory(tmp.path())); |
| 172 |
| 173 FilePath tmp_manifest = tmp.path().AppendASCII("manifest.json"); |
| 167 FilePath data_path = test_data_dir_.AppendASCII("webstore_private/bundle"); | 174 FilePath data_path = test_data_dir_.AppendASCII("webstore_private/bundle"); |
| 168 FilePath dir_path = data_path.AppendASCII(id); | 175 FilePath manifest_path = data_path.AppendASCII(manifest); |
| 176 |
| 177 ASSERT_TRUE(file_util::PathExists(manifest_path)); |
| 178 ASSERT_TRUE(file_util::CopyFile(manifest_path, tmp_manifest)); |
| 179 |
| 180 PackCRX(id, tmp.path()); |
| 181 } |
| 182 |
| 183 // Packs the extension at |ext_path| using |id|'s PEM key. |
| 184 void PackCRX(const std::string& id, const FilePath& ext_path) { |
| 185 FilePath data_path = test_data_dir_.AppendASCII("webstore_private/bundle"); |
| 169 FilePath pem_path = data_path.AppendASCII(id + ".pem"); | 186 FilePath pem_path = data_path.AppendASCII(id + ".pem"); |
| 170 FilePath crx_path = data_path.AppendASCII(id + ".crx"); | 187 FilePath crx_path = data_path.AppendASCII(id + ".crx"); |
| 171 FilePath destination = PackExtensionWithOptions( | 188 FilePath destination = PackExtensionWithOptions( |
| 172 dir_path, crx_path, pem_path, FilePath()); | 189 ext_path, crx_path, pem_path, FilePath()); |
| 173 | 190 |
| 174 ASSERT_FALSE(destination.empty()); | 191 ASSERT_FALSE(destination.empty()); |
| 175 ASSERT_EQ(destination, crx_path); | 192 ASSERT_EQ(destination, crx_path); |
| 176 | 193 |
| 177 test_crx_.push_back(destination); | 194 test_crx_.push_back(destination); |
| 178 } | 195 } |
| 179 | 196 |
| 197 // Creates an invalid CRX. |
| 198 void PackInvalidCRX(const std::string& id) { |
| 199 FilePath contents = test_data_dir_ |
| 200 .AppendASCII("webstore_private") |
| 201 .AppendASCII("install_bundle_invalid.html"); |
| 202 FilePath crx_path = test_data_dir_ |
| 203 .AppendASCII("webstore_private/bundle") |
| 204 .AppendASCII(id + ".crx"); |
| 205 |
| 206 ASSERT_TRUE(file_util::CopyFile(contents, crx_path)); |
| 207 |
| 208 test_crx_.push_back(crx_path); |
| 209 } |
| 210 |
| 211 private: |
| 180 std::vector<FilePath> test_crx_; | 212 std::vector<FilePath> test_crx_; |
| 181 }; | 213 }; |
| 182 | 214 |
| 183 class ExtensionWebstoreGetWebGLStatusTest : public InProcessBrowserTest { | 215 class ExtensionWebstoreGetWebGLStatusTest : public InProcessBrowserTest { |
| 184 public: | 216 public: |
| 185 void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 217 void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 186 // In linux, we need to launch GPU process to decide if WebGL is allowed. | 218 // In linux, we need to launch GPU process to decide if WebGL is allowed. |
| 187 // Run it on top of osmesa to avoid bot driver issues. | 219 // Run it on top of osmesa to avoid bot driver issues. |
| 188 #if defined(OS_LINUX) | 220 #if defined(OS_LINUX) |
| 189 CHECK(test_launcher_utils::OverrideGLImplementation( | 221 CHECK(test_launcher_utils::OverrideGLImplementation( |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 | 307 |
| 276 // Tests using the iconUrl parameter to the install function. | 308 // Tests using the iconUrl parameter to the install function. |
| 277 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, | 309 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
| 278 IconUrl) { | 310 IconUrl) { |
| 279 ASSERT_TRUE(RunInstallTest("icon_url.html", "extension.crx")); | 311 ASSERT_TRUE(RunInstallTest("icon_url.html", "extension.crx")); |
| 280 } | 312 } |
| 281 | 313 |
| 282 // Tests using silentlyInstall to install extensions. | 314 // Tests using silentlyInstall to install extensions. |
| 283 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateBundleTest, SilentlyInstall) { | 315 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateBundleTest, SilentlyInstall) { |
| 284 WebstorePrivateApi::SetTrustTestIDsForTesting(true); | 316 WebstorePrivateApi::SetTrustTestIDsForTesting(true); |
| 317 |
| 318 PackCRX("bmfoocgfinpmkmlbjhcbofejhkhlbchk", "extension1.json"); |
| 319 PackCRX("mpneghmdnmaolkljkipbhaienajcflfe", "extension2.json"); |
| 320 PackCRX("begfmnajjkbjdgmffnjaojchoncnmngg", "app2.json"); |
| 321 |
| 285 ASSERT_TRUE(RunPageTest(GetTestServerURL("silently_install.html").spec())); | 322 ASSERT_TRUE(RunPageTest(GetTestServerURL("silently_install.html").spec())); |
| 286 } | 323 } |
| 287 | 324 |
| 325 // Tests successfully installing a bundle of 2 apps and 2 extensions. |
| 326 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateBundleTest, InstallBundle) { |
| 327 extensions::BundleInstaller::SetAutoApproveForTesting(true); |
| 328 |
| 329 PackCRX("bmfoocgfinpmkmlbjhcbofejhkhlbchk", "extension1.json"); |
| 330 PackCRX("pkapffpjmiilhlhbibjhamlmdhfneidj", "extension2.json"); |
| 331 PackCRX("begfmnajjkbjdgmffnjaojchoncnmngg", "app1.json"); |
| 332 PackCRX("mpneghmdnmaolkljkipbhaienajcflfe", "app2.json"); |
| 333 |
| 334 ASSERT_TRUE(RunPageTest(GetTestServerURL("install_bundle.html").spec())); |
| 335 } |
| 336 |
| 337 // Tests the user canceling the bundle install prompt. |
| 338 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateBundleTest, |
| 339 InstallBundleCancel) { |
| 340 // We don't need to create the CRX files since we are aborting the install. |
| 341 extensions::BundleInstaller::SetAutoApproveForTesting(false); |
| 342 ASSERT_TRUE(RunPageTest(GetTestServerURL( |
| 343 "install_bundle_cancel.html").spec())); |
| 344 } |
| 345 |
| 346 // Tests partially installing a bundle (2 succeed, 1 fails due to an invalid |
| 347 // CRX, and 1 fails due to the manifests not matching). |
| 348 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateBundleTest, |
| 349 InstallBundleInvalid) { |
| 350 extensions::BundleInstaller::SetAutoApproveForTesting(true); |
| 351 |
| 352 PackInvalidCRX("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); |
| 353 PackCRX("bmfoocgfinpmkmlbjhcbofejhkhlbchk", "extension1.json"); |
| 354 PackCRX("pkapffpjmiilhlhbibjhamlmdhfneidj", "extension2.json"); |
| 355 PackCRX("begfmnajjkbjdgmffnjaojchoncnmngg", "app1.json"); |
| 356 |
| 357 ASSERT_TRUE(RunPageTest(GetTestServerURL( |
| 358 "install_bundle_invalid.html").spec())); |
| 359 |
| 360 ASSERT_TRUE(service()->GetExtensionById( |
| 361 "begfmnajjkbjdgmffnjaojchoncnmngg", false)); |
| 362 ASSERT_TRUE(service()->GetExtensionById( |
| 363 "pkapffpjmiilhlhbibjhamlmdhfneidj", false)); |
| 364 ASSERT_FALSE(service()->GetExtensionById( |
| 365 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", true)); |
| 366 ASSERT_FALSE(service()->GetExtensionById( |
| 367 "bmfoocgfinpmkmlbjhcbofejhkhlbchk", true)); |
| 368 } |
| 369 |
| 288 // Tests getWebGLStatus function when WebGL is allowed. | 370 // Tests getWebGLStatus function when WebGL is allowed. |
| 289 IN_PROC_BROWSER_TEST_F(ExtensionWebstoreGetWebGLStatusTest, Allowed) { | 371 IN_PROC_BROWSER_TEST_F(ExtensionWebstoreGetWebGLStatusTest, Allowed) { |
| 290 bool webgl_allowed = true; | 372 bool webgl_allowed = true; |
| 291 RunTest(webgl_allowed); | 373 RunTest(webgl_allowed); |
| 292 } | 374 } |
| 293 | 375 |
| 294 // Tests getWebGLStatus function when WebGL is blacklisted. | 376 // Tests getWebGLStatus function when WebGL is blacklisted. |
| 295 IN_PROC_BROWSER_TEST_F(ExtensionWebstoreGetWebGLStatusTest, Blocked) { | 377 IN_PROC_BROWSER_TEST_F(ExtensionWebstoreGetWebGLStatusTest, Blocked) { |
| 296 static const std::string json_blacklist = | 378 static const std::string json_blacklist = |
| 297 "{\n" | 379 "{\n" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 312 ASSERT_TRUE(blacklist->LoadGpuBlacklist( | 394 ASSERT_TRUE(blacklist->LoadGpuBlacklist( |
| 313 "1.0", json_blacklist, GpuBlacklist::kAllOs)); | 395 "1.0", json_blacklist, GpuBlacklist::kAllOs)); |
| 314 blacklist->UpdateGpuDataManager(); | 396 blacklist->UpdateGpuDataManager(); |
| 315 GpuFeatureType type = | 397 GpuFeatureType type = |
| 316 content::GpuDataManager::GetInstance()->GetGpuFeatureType(); | 398 content::GpuDataManager::GetInstance()->GetGpuFeatureType(); |
| 317 EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL); | 399 EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL); |
| 318 | 400 |
| 319 bool webgl_allowed = false; | 401 bool webgl_allowed = false; |
| 320 RunTest(webgl_allowed); | 402 RunTest(webgl_allowed); |
| 321 } | 403 } |
| OLD | NEW |