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( |
121 ExtensionInstallPrompt::ACCEPT; | 122 new ScopedTestDialogAutoConfirm(ScopedTestDialogAutoConfirm::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. |
132 GURL DoGetTestServerURL(const std::string& path) { | 133 GURL DoGetTestServerURL(const std::string& path) { |
133 GURL url = test_server()->GetURL(path); | 134 GURL url = test_server()->GetURL(path); |
134 | 135 |
135 // Replace the host with 'www.example.com' so it matches the web store | 136 // Replace the host with 'www.example.com' so it matches the web store |
136 // app's extent. | 137 // app's extent. |
137 GURL::Replacements replace_host; | 138 GURL::Replacements replace_host; |
138 replace_host.SetHostStr("www.example.com"); | 139 replace_host.SetHostStr("www.example.com"); |
139 | 140 |
140 return url.ReplaceComponents(replace_host); | 141 return url.ReplaceComponents(replace_host); |
141 } | 142 } |
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 ManagementUninstallFunction::SetAutoConfirmForTest(true); | |
153 #if defined(OS_WIN) && !defined(NDEBUG) | 152 #if defined(OS_WIN) && !defined(NDEBUG) |
154 // See http://crbug.com/177163 for details. | 153 // See http://crbug.com/177163 for details. |
155 return true; | 154 return true; |
156 #else | 155 #else |
157 GURL crx_url = GetTestServerURL(crx_file); | 156 GURL crx_url = GetTestServerURL(crx_file); |
158 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 157 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
159 switches::kAppsGalleryUpdateURL, crx_url.spec()); | 158 switches::kAppsGalleryUpdateURL, crx_url.spec()); |
160 | 159 |
161 GURL page_url = GetTestServerURL(page); | 160 GURL page_url = GetTestServerURL(page); |
162 return RunPageTest(page_url.spec()); | 161 return RunPageTest(page_url.spec()); |
163 #endif | 162 #endif |
164 } | 163 } |
165 | 164 |
166 content::WebContents* GetWebContents() { | 165 content::WebContents* GetWebContents() { |
167 return browser()->tab_strip_model()->GetActiveWebContents(); | 166 return browser()->tab_strip_model()->GetActiveWebContents(); |
168 } | 167 } |
169 | 168 |
170 ExtensionService* service() { | 169 ExtensionService* service() { |
171 return ExtensionSystem::Get(browser()->profile())->extension_service(); | 170 return ExtensionSystem::Get(browser()->profile())->extension_service(); |
172 } | 171 } |
173 | 172 |
174 private: | 173 private: |
175 base::ScopedTempDir webstore_install_dir_; | 174 base::ScopedTempDir webstore_install_dir_; |
176 // WebstoreInstaller needs a reference to a FilePath when setting the download | 175 // WebstoreInstaller needs a reference to a FilePath when setting the download |
177 // directory for testing. | 176 // directory for testing. |
178 base::FilePath webstore_install_dir_copy_; | 177 base::FilePath webstore_install_dir_copy_; |
| 178 |
| 179 scoped_ptr<ScopedTestDialogAutoConfirm> auto_confirm_install_; |
| 180 |
| 181 DISALLOW_COPY_AND_ASSIGN(ExtensionWebstorePrivateApiTest); |
179 }; | 182 }; |
180 | 183 |
181 // Test cases for webstore origin frame blocking. | 184 // Test cases for webstore origin frame blocking. |
182 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into | 185 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into |
183 // Chromium, see crbug.com/226018. | 186 // Chromium, see crbug.com/226018. |
184 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, | 187 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
185 DISABLED_FrameWebstorePageBlocked) { | 188 DISABLED_FrameWebstorePageBlocked) { |
186 base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank"); | 189 base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank"); |
187 base::string16 failure_title = base::UTF8ToUTF16("FAIL"); | 190 base::string16 failure_title = base::UTF8ToUTF16("FAIL"); |
188 content::TitleWatcher watcher(GetWebContents(), expected_title); | 191 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)); | 234 EXPECT_TRUE(base::DeleteFile(missing_directory, true)); |
232 } | 235 } |
233 | 236 |
234 // Tests passing a localized name. | 237 // Tests passing a localized name. |
235 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallLocalized) { | 238 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallLocalized) { |
236 ASSERT_TRUE(RunInstallTest("localized.html", "localized_extension.crx")); | 239 ASSERT_TRUE(RunInstallTest("localized.html", "localized_extension.crx")); |
237 } | 240 } |
238 | 241 |
239 // Now test the case where the user cancels the confirmation dialog. | 242 // Now test the case where the user cancels the confirmation dialog. |
240 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallCancelled) { | 243 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallCancelled) { |
241 ExtensionInstallPrompt::g_auto_confirm_for_tests = | 244 ScopedTestDialogAutoConfirm auto_cancel(ScopedTestDialogAutoConfirm::CANCEL); |
242 ExtensionInstallPrompt::CANCEL; | |
243 ASSERT_TRUE(RunInstallTest("cancelled.html", "extension.crx")); | 245 ASSERT_TRUE(RunInstallTest("cancelled.html", "extension.crx")); |
244 } | 246 } |
245 | 247 |
246 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, IncorrectManifest1) { | 248 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, IncorrectManifest1) { |
247 ASSERT_TRUE(RunInstallTest("incorrect_manifest1.html", "extension.crx")); | 249 ASSERT_TRUE(RunInstallTest("incorrect_manifest1.html", "extension.crx")); |
248 } | 250 } |
249 | 251 |
250 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, IncorrectManifest2) { | 252 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, IncorrectManifest2) { |
251 ASSERT_TRUE(RunInstallTest("incorrect_manifest2.html", "extension.crx")); | 253 ASSERT_TRUE(RunInstallTest("incorrect_manifest2.html", "extension.crx")); |
252 } | 254 } |
(...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 | 480 // CRX, 1 fails due to the manifests not matching, and 1 fails due to a missing |
479 // crx file). | 481 // crx file). |
480 IN_PROC_BROWSER_TEST_F(BundleWebstorePrivateApiTest, InstallBundleInvalid) { | 482 IN_PROC_BROWSER_TEST_F(BundleWebstorePrivateApiTest, InstallBundleInvalid) { |
481 extensions::BundleInstaller::SetAutoApproveForTesting(true); | 483 extensions::BundleInstaller::SetAutoApproveForTesting(true); |
482 | 484 |
483 ASSERT_TRUE( | 485 ASSERT_TRUE( |
484 RunPageTest(GetTestServerURL("install_bundle_invalid.html").spec())); | 486 RunPageTest(GetTestServerURL("install_bundle_invalid.html").spec())); |
485 } | 487 } |
486 | 488 |
487 } // namespace extensions | 489 } // namespace extensions |
OLD | NEW |