| 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/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" | 12 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" |
| 13 #include "chrome/browser/extensions/bundle_installer.h" | 13 #include "chrome/browser/extensions/bundle_installer.h" |
| 14 #include "chrome/browser/extensions/extension_apitest.h" | 14 #include "chrome/browser/extensions/extension_apitest.h" |
| 15 #include "chrome/browser/extensions/extension_function_test_utils.h" | 15 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 16 #include "chrome/browser/extensions/extension_install_prompt.h" | 16 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/extensions/webstore_installer.h" | 18 #include "chrome/browser/extensions/webstore_installer.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 22 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/test/base/ui_test_utils.h" | 23 #include "chrome/test/base/ui_test_utils.h" |
| 24 #include "content/public/browser/gpu_data_manager.h" | 24 #include "content/public/browser/gpu_data_manager.h" |
| 25 #include "content/public/browser/notification_observer.h" | 25 #include "content/public/browser/notification_observer.h" |
| 26 #include "content/public/browser/notification_registrar.h" | 26 #include "content/public/browser/notification_registrar.h" |
| 27 #include "content/public/test/browser_test_utils.h" | 27 #include "content/public/test/browser_test_utils.h" |
| 28 #include "extensions/browser/api/management/management_api.h" | 28 #include "extensions/browser/api/management/management_api.h" |
| 29 #include "extensions/browser/extension_dialog_auto_confirm.h" |
| 29 #include "extensions/browser/extension_system.h" | 30 #include "extensions/browser/extension_system.h" |
| 30 #include "extensions/browser/install/extension_install_ui.h" | 31 #include "extensions/browser/install/extension_install_ui.h" |
| 31 #include "gpu/config/gpu_feature_type.h" | 32 #include "gpu/config/gpu_feature_type.h" |
| 32 #include "gpu/config/gpu_info.h" | 33 #include "gpu/config/gpu_info.h" |
| 33 #include "net/dns/mock_host_resolver.h" | 34 #include "net/dns/mock_host_resolver.h" |
| 34 #include "ui/app_list/app_list_switches.h" | 35 #include "ui/app_list/app_list_switches.h" |
| 35 #include "ui/gl/gl_switches.h" | 36 #include "ui/gl/gl_switches.h" |
| 36 | 37 |
| 37 using gpu::GpuFeatureType; | 38 using gpu::GpuFeatureType; |
| 38 | 39 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // Start up the test server and get us ready for calling the install | 111 // Start up the test server and get us ready for calling the install |
| 111 // API functions. | 112 // API functions. |
| 112 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | 113 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
| 113 ASSERT_TRUE(StartSpawnedTestServer()); | 114 ASSERT_TRUE(StartSpawnedTestServer()); |
| 114 extensions::ExtensionInstallUI::set_disable_failure_ui_for_tests(); | 115 extensions::ExtensionInstallUI::set_disable_failure_ui_for_tests(); |
| 115 } | 116 } |
| 116 | 117 |
| 117 void SetUpOnMainThread() override { | 118 void SetUpOnMainThread() override { |
| 118 ExtensionApiTest::SetUpOnMainThread(); | 119 ExtensionApiTest::SetUpOnMainThread(); |
| 119 | 120 |
| 120 ExtensionInstallPrompt::g_auto_confirm_for_tests = | 121 auto_confirm_install_.reset(new ScopedExtensionDialogAutoConfirm( |
| 121 ExtensionInstallPrompt::ACCEPT; | 122 &g_auto_confirm_install_for_testing, AUTO_CONFIRM_ACCEPT)); |
| 122 | 123 |
| 123 ASSERT_TRUE(webstore_install_dir_.CreateUniqueTempDir()); | 124 ASSERT_TRUE(webstore_install_dir_.CreateUniqueTempDir()); |
| 124 webstore_install_dir_copy_ = webstore_install_dir_.path(); | 125 webstore_install_dir_copy_ = webstore_install_dir_.path(); |
| 125 WebstoreInstaller::SetDownloadDirectoryForTests( | 126 WebstoreInstaller::SetDownloadDirectoryForTests( |
| 126 &webstore_install_dir_copy_); | 127 &webstore_install_dir_copy_); |
| 127 } | 128 } |
| 128 | 129 |
| 129 protected: | 130 protected: |
| 130 // Returns a test server URL, but with host 'www.example.com' so it matches | 131 // Returns a test server URL, but with host 'www.example.com' so it matches |
| 131 // the web store app's extent that we set up via command line flags. | 132 // the web store app's extent that we set up via command line flags. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 142 | 143 |
| 143 virtual GURL GetTestServerURL(const std::string& path) { | 144 virtual GURL GetTestServerURL(const std::string& path) { |
| 144 return DoGetTestServerURL( | 145 return DoGetTestServerURL( |
| 145 std::string("files/extensions/api_test/webstore_private/") + path); | 146 std::string("files/extensions/api_test/webstore_private/") + path); |
| 146 } | 147 } |
| 147 | 148 |
| 148 // Navigates to |page| and runs the Extension API test there. Any downloads | 149 // Navigates to |page| and runs the Extension API test there. Any downloads |
| 149 // of extensions will return the contents of |crx_file|. | 150 // of extensions will return the contents of |crx_file|. |
| 150 bool RunInstallTest(const std::string& page, const std::string& crx_file) { | 151 bool RunInstallTest(const std::string& page, const std::string& crx_file) { |
| 151 // Auto-confirm the uninstallation dialog. | 152 // Auto-confirm the uninstallation dialog. |
| 152 ManagementUninstallFunction::SetAutoConfirmForTest(true); | 153 ScopedExtensionDialogAutoConfirm auto_confirm( |
| 154 &g_auto_confirm_uninstall_for_testing, AUTO_CONFIRM_ACCEPT); |
| 153 #if defined(OS_WIN) && !defined(NDEBUG) | 155 #if defined(OS_WIN) && !defined(NDEBUG) |
| 154 // See http://crbug.com/177163 for details. | 156 // See http://crbug.com/177163 for details. |
| 155 return true; | 157 return true; |
| 156 #else | 158 #else |
| 157 GURL crx_url = GetTestServerURL(crx_file); | 159 GURL crx_url = GetTestServerURL(crx_file); |
| 158 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 160 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 159 switches::kAppsGalleryUpdateURL, crx_url.spec()); | 161 switches::kAppsGalleryUpdateURL, crx_url.spec()); |
| 160 | 162 |
| 161 GURL page_url = GetTestServerURL(page); | 163 GURL page_url = GetTestServerURL(page); |
| 162 return RunPageTest(page_url.spec()); | 164 return RunPageTest(page_url.spec()); |
| 163 #endif | 165 #endif |
| 164 } | 166 } |
| 165 | 167 |
| 166 content::WebContents* GetWebContents() { | 168 content::WebContents* GetWebContents() { |
| 167 return browser()->tab_strip_model()->GetActiveWebContents(); | 169 return browser()->tab_strip_model()->GetActiveWebContents(); |
| 168 } | 170 } |
| 169 | 171 |
| 170 ExtensionService* service() { | 172 ExtensionService* service() { |
| 171 return ExtensionSystem::Get(browser()->profile())->extension_service(); | 173 return ExtensionSystem::Get(browser()->profile())->extension_service(); |
| 172 } | 174 } |
| 173 | 175 |
| 174 private: | 176 private: |
| 175 base::ScopedTempDir webstore_install_dir_; | 177 base::ScopedTempDir webstore_install_dir_; |
| 176 // WebstoreInstaller needs a reference to a FilePath when setting the download | 178 // WebstoreInstaller needs a reference to a FilePath when setting the download |
| 177 // directory for testing. | 179 // directory for testing. |
| 178 base::FilePath webstore_install_dir_copy_; | 180 base::FilePath webstore_install_dir_copy_; |
| 181 |
| 182 scoped_ptr<ScopedExtensionDialogAutoConfirm> auto_confirm_install_; |
| 179 }; | 183 }; |
| 180 | 184 |
| 181 // Test cases for webstore origin frame blocking. | 185 // Test cases for webstore origin frame blocking. |
| 182 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into | 186 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into |
| 183 // Chromium, see crbug.com/226018. | 187 // Chromium, see crbug.com/226018. |
| 184 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, | 188 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
| 185 DISABLED_FrameWebstorePageBlocked) { | 189 DISABLED_FrameWebstorePageBlocked) { |
| 186 base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank"); | 190 base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank"); |
| 187 base::string16 failure_title = base::UTF8ToUTF16("FAIL"); | 191 base::string16 failure_title = base::UTF8ToUTF16("FAIL"); |
| 188 content::TitleWatcher watcher(GetWebContents(), expected_title); | 192 content::TitleWatcher watcher(GetWebContents(), expected_title); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 EXPECT_TRUE(base::DeleteFile(missing_directory, true)); | 235 EXPECT_TRUE(base::DeleteFile(missing_directory, true)); |
| 232 } | 236 } |
| 233 | 237 |
| 234 // Tests passing a localized name. | 238 // Tests passing a localized name. |
| 235 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallLocalized) { | 239 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallLocalized) { |
| 236 ASSERT_TRUE(RunInstallTest("localized.html", "localized_extension.crx")); | 240 ASSERT_TRUE(RunInstallTest("localized.html", "localized_extension.crx")); |
| 237 } | 241 } |
| 238 | 242 |
| 239 // Now test the case where the user cancels the confirmation dialog. | 243 // Now test the case where the user cancels the confirmation dialog. |
| 240 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallCancelled) { | 244 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallCancelled) { |
| 241 ExtensionInstallPrompt::g_auto_confirm_for_tests = | 245 ScopedExtensionDialogAutoConfirm auto_cancel( |
| 242 ExtensionInstallPrompt::CANCEL; | 246 &g_auto_confirm_install_for_testing, AUTO_CONFIRM_CANCEL); |
| 243 ASSERT_TRUE(RunInstallTest("cancelled.html", "extension.crx")); | 247 ASSERT_TRUE(RunInstallTest("cancelled.html", "extension.crx")); |
| 244 } | 248 } |
| 245 | 249 |
| 246 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, IncorrectManifest1) { | 250 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, IncorrectManifest1) { |
| 247 ASSERT_TRUE(RunInstallTest("incorrect_manifest1.html", "extension.crx")); | 251 ASSERT_TRUE(RunInstallTest("incorrect_manifest1.html", "extension.crx")); |
| 248 } | 252 } |
| 249 | 253 |
| 250 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, IncorrectManifest2) { | 254 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, IncorrectManifest2) { |
| 251 ASSERT_TRUE(RunInstallTest("incorrect_manifest2.html", "extension.crx")); | 255 ASSERT_TRUE(RunInstallTest("incorrect_manifest2.html", "extension.crx")); |
| 252 } | 256 } |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 // CRX, 1 fails due to the manifests not matching, and 1 fails due to a missing | 482 // CRX, 1 fails due to the manifests not matching, and 1 fails due to a missing |
| 479 // crx file). | 483 // crx file). |
| 480 IN_PROC_BROWSER_TEST_F(BundleWebstorePrivateApiTest, InstallBundleInvalid) { | 484 IN_PROC_BROWSER_TEST_F(BundleWebstorePrivateApiTest, InstallBundleInvalid) { |
| 481 extensions::BundleInstaller::SetAutoApproveForTesting(true); | 485 extensions::BundleInstaller::SetAutoApproveForTesting(true); |
| 482 | 486 |
| 483 ASSERT_TRUE( | 487 ASSERT_TRUE( |
| 484 RunPageTest(GetTestServerURL("install_bundle_invalid.html").spec())); | 488 RunPageTest(GetTestServerURL("install_bundle_invalid.html").spec())); |
| 485 } | 489 } |
| 486 | 490 |
| 487 } // namespace extensions | 491 } // namespace extensions |
| OLD | NEW |