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