Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc

Issue 10911158: Pass on download or installation errors from WebstoreInstaller to the CompleteInstall function. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/bundle_installer.h"
11 #include "chrome/browser/extensions/extension_apitest.h" 11 #include "chrome/browser/extensions/extension_apitest.h"
12 #include "chrome/browser/extensions/extension_function_test_utils.h" 12 #include "chrome/browser/extensions/extension_function_test_utils.h"
13 #include "chrome/browser/extensions/extension_install_dialog.h" 13 #include "chrome/browser/extensions/extension_install_dialog.h"
14 #include "chrome/browser/extensions/extension_install_prompt.h" 14 #include "chrome/browser/extensions/extension_install_prompt.h"
15 #include "chrome/browser/extensions/extension_install_ui.h" 15 #include "chrome/browser/extensions/extension_install_ui.h"
16 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" 17 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h"
18 #include "chrome/browser/extensions/webstore_installer.h" 18 #include "chrome/browser/extensions/webstore_installer.h"
19 #include "chrome/browser/gpu_blacklist.h" 19 #include "chrome/browser/gpu_blacklist.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
22 #include "chrome/common/chrome_notification_types.h" 22 #include "chrome/common/chrome_notification_types.h"
23 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
24 #include "chrome/test/base/test_launcher_utils.h" 24 #include "chrome/test/base/test_launcher_utils.h"
25 #include "chrome/test/base/ui_test_utils.h" 25 #include "chrome/test/base/ui_test_utils.h"
26 #include "content/public/browser/gpu_data_manager.h" 26 #include "content/public/browser/gpu_data_manager.h"
27 #include "content/public/browser/notification_observer.h" 27 #include "content/public/browser/notification_observer.h"
28 #include "content/public/browser/notification_registrar.h" 28 #include "content/public/browser/notification_registrar.h"
29 #include "net/base/mock_host_resolver.h" 29 #include "net/base/mock_host_resolver.h"
30 #include "net/url_request/url_fetcher.h"
31 #include "net/url_request/url_request.h"
32 #include "net/url_request/url_request_job_manager.h"
33 #include "net/url_request/url_request_test_job.h"
30 #include "ui/gl/gl_switches.h" 34 #include "ui/gl/gl_switches.h"
31 35
32 using content::GpuFeatureType; 36 using content::GpuFeatureType;
33 37
34 namespace utils = extension_function_test_utils; 38 namespace utils = extension_function_test_utils;
35 39
36 namespace extensions { 40 namespace extensions {
37 41
38 namespace { 42 namespace {
39 43
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 const std::string& error() const { return error_; } 82 const std::string& error() const { return error_; }
79 83
80 private: 84 private:
81 bool received_failure_; 85 bool received_failure_;
82 bool received_success_; 86 bool received_success_;
83 bool waiting_; 87 bool waiting_;
84 std::string id_; 88 std::string id_;
85 std::string error_; 89 std::string error_;
86 }; 90 };
87 91
92 class EmptyRequestJob : public net::URLRequestTestJob {
93 public:
94 EmptyRequestJob(net::URLRequest* request,
95 net::NetworkDelegate* network_delegate)
96 : net::URLRequestTestJob(request,
97 network_delegate,
98 net::URLRequestTestJob::test_headers(),
99 std::string(),
100 true) {
101 }
102
103 virtual int GetResponseCode() const { return 204; }
104
105 private:
106 ~EmptyRequestJob() {}
107 };
108
109
110 class EmptyCRXInterceptor
111 : public net::URLRequest::Interceptor,
112 public base::RefCountedThreadSafe<EmptyCRXInterceptor> {
113 public:
114 EmptyCRXInterceptor() {
115 net::URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(this);
116 }
117
118 ~EmptyCRXInterceptor() {
119 net::URLRequestJobManager::GetInstance()->
120 UnregisterRequestInterceptor(this);
121 }
122
123 virtual net::URLRequestJob* MaybeIntercept(net::URLRequest* request,
124 net::NetworkDelegate* network_delegate) OVERRIDE {
asargent_no_longer_on_chrome 2012/09/10 23:52:10 formatting nit: http://dev.chromium.org/develope
125
126 if (request->url().scheme() != "http" ||
127 request->url().host() != "www.example.com")
128 return NULL;
129
130 if (!EndsWith(request->url().path(), ".crx", false))
131 return NULL;
132
133 return new EmptyRequestJob(request, network_delegate);
134 }
135 };
136
137
88 } // namespace 138 } // namespace
89 139
90 // A base class for tests below. 140 // A base class for tests below.
91 class ExtensionWebstorePrivateApiTest : public ExtensionApiTest { 141 class ExtensionWebstorePrivateApiTest : public ExtensionApiTest {
92 public: 142 public:
93 void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 143 void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
94 ExtensionApiTest::SetUpCommandLine(command_line); 144 ExtensionApiTest::SetUpCommandLine(command_line);
95 command_line->AppendSwitchASCII( 145 command_line->AppendSwitchASCII(
96 switches::kAppsGalleryURL, "http://www.example.com"); 146 switches::kAppsGalleryURL, "http://www.example.com");
97 command_line->AppendSwitchASCII( 147 command_line->AppendSwitchASCII(
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 336 }
287 337
288 // Now test the case where the user cancels the confirmation dialog. 338 // Now test the case where the user cancels the confirmation dialog.
289 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallCancelled) { 339 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallCancelled) {
290 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 340 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
291 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel"); 341 switches::kAppsGalleryInstallAutoConfirmForTests, "cancel");
292 ASSERT_TRUE(RunInstallTest("cancelled.html", "extension.crx")); 342 ASSERT_TRUE(RunInstallTest("cancelled.html", "extension.crx"));
293 } 343 }
294 344
295 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, IncorrectManifest1) { 345 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, IncorrectManifest1) {
296 WebstoreInstallListener listener;
297 WebstorePrivateApi::SetWebstoreInstallerDelegateForTesting(&listener);
298 ASSERT_TRUE(RunInstallTest("incorrect_manifest1.html", "extension.crx")); 346 ASSERT_TRUE(RunInstallTest("incorrect_manifest1.html", "extension.crx"));
299 listener.Wait();
300 ASSERT_TRUE(listener.received_failure());
301 ASSERT_EQ("Manifest file is invalid.", listener.error());
302 } 347 }
303 348
304 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, IncorrectManifest2) { 349 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, IncorrectManifest2) {
305 WebstoreInstallListener listener;
306 WebstorePrivateApi::SetWebstoreInstallerDelegateForTesting(&listener);
307 ASSERT_TRUE(RunInstallTest("incorrect_manifest2.html", "extension.crx")); 350 ASSERT_TRUE(RunInstallTest("incorrect_manifest2.html", "extension.crx"));
308 listener.Wait();
309 EXPECT_TRUE(listener.received_failure());
310 ASSERT_EQ("Manifest file is invalid.", listener.error());
311 } 351 }
312 352
313 // Tests that we can request an app installed bubble (instead of the default 353 // Tests that we can request an app installed bubble (instead of the default
314 // UI when an app is installed). 354 // UI when an app is installed).
315 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, AppInstallBubble) { 355 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, AppInstallBubble) {
316 WebstoreInstallListener listener; 356 WebstoreInstallListener listener;
317 WebstorePrivateApi::SetWebstoreInstallerDelegateForTesting(&listener); 357 WebstorePrivateApi::SetWebstoreInstallerDelegateForTesting(&listener);
318 ASSERT_TRUE(RunInstallTest("app_install_bubble.html", "app.crx")); 358 ASSERT_TRUE(RunInstallTest("app_install_bubble.html", "app.crx"));
319 listener.Wait(); 359 listener.Wait();
320 ASSERT_TRUE(listener.received_success()); 360 ASSERT_TRUE(listener.received_success());
(...skipping 29 matching lines...) Expand all
350 // Tests that themes are installed without an install prompt. 390 // Tests that themes are installed without an install prompt.
351 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallTheme) { 391 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallTheme) {
352 WebstoreInstallListener listener; 392 WebstoreInstallListener listener;
353 WebstorePrivateApi::SetWebstoreInstallerDelegateForTesting(&listener); 393 WebstorePrivateApi::SetWebstoreInstallerDelegateForTesting(&listener);
354 ASSERT_TRUE(RunInstallTest("theme.html", "../../../theme.crx")); 394 ASSERT_TRUE(RunInstallTest("theme.html", "../../../theme.crx"));
355 listener.Wait(); 395 listener.Wait();
356 ASSERT_TRUE(listener.received_success()); 396 ASSERT_TRUE(listener.received_success());
357 ASSERT_EQ("iamefpfkojoapidjnbafmgkgncegbkad", listener.id()); 397 ASSERT_EQ("iamefpfkojoapidjnbafmgkgncegbkad", listener.id());
358 } 398 }
359 399
400 // Tests that an error is properly reported when a 204 is returned
401 // while trying to download a the crx
402 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, Test204) {
403 scoped_refptr<EmptyCRXInterceptor> interceptor(new EmptyCRXInterceptor());
404 net::URLFetcher::SetEnableInterceptionForTests(true);
405 ASSERT_TRUE(RunInstallTest("error204.html", "extension.crx"));
406 }
407
360 // Tests successfully installing a bundle of 2 apps and 2 extensions. 408 // Tests successfully installing a bundle of 2 apps and 2 extensions.
361 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateBundleTest, InstallBundle) { 409 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateBundleTest, InstallBundle) {
362 extensions::BundleInstaller::SetAutoApproveForTesting(true); 410 extensions::BundleInstaller::SetAutoApproveForTesting(true);
363 411
364 PackCRX("bmfoocgfinpmkmlbjhcbofejhkhlbchk", "extension1.json"); 412 PackCRX("bmfoocgfinpmkmlbjhcbofejhkhlbchk", "extension1.json");
365 PackCRX("pkapffpjmiilhlhbibjhamlmdhfneidj", "extension2.json"); 413 PackCRX("pkapffpjmiilhlhbibjhamlmdhfneidj", "extension2.json");
366 PackCRX("begfmnajjkbjdgmffnjaojchoncnmngg", "app1.json"); 414 PackCRX("begfmnajjkbjdgmffnjaojchoncnmngg", "app1.json");
367 PackCRX("mpneghmdnmaolkljkipbhaienajcflfe", "app2.json"); 415 PackCRX("mpneghmdnmaolkljkipbhaienajcflfe", "app2.json");
368 416
369 ASSERT_TRUE(RunPageTest(GetTestServerURL("install_bundle.html").spec())); 417 ASSERT_TRUE(RunPageTest(GetTestServerURL("install_bundle.html").spec()));
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 blacklist->UpdateGpuDataManager(); 491 blacklist->UpdateGpuDataManager();
444 GpuFeatureType type = 492 GpuFeatureType type =
445 content::GpuDataManager::GetInstance()->GetBlacklistedFeatures(); 493 content::GpuDataManager::GetInstance()->GetBlacklistedFeatures();
446 EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL); 494 EXPECT_EQ(type, content::GPU_FEATURE_TYPE_WEBGL);
447 495
448 bool webgl_allowed = false; 496 bool webgl_allowed = false;
449 RunTest(webgl_allowed); 497 RunTest(webgl_allowed);
450 } 498 }
451 499
452 } // namespace extensions 500 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698