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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc
diff --git a/chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc b/chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc
index b15227d4943889df3e14a3447032bd9008646d41..857ac7763da6a6420ce2af08e3d75dfe0267ff24 100644
--- a/chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc
+++ b/chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc
@@ -27,6 +27,10 @@
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "net/base/mock_host_resolver.h"
+#include "net/url_request/url_fetcher.h"
+#include "net/url_request/url_request.h"
+#include "net/url_request/url_request_job_manager.h"
+#include "net/url_request/url_request_test_job.h"
#include "ui/gl/gl_switches.h"
using content::GpuFeatureType;
@@ -85,6 +89,52 @@ class WebstoreInstallListener : public WebstoreInstaller::Delegate {
std::string error_;
};
+class EmptyRequestJob : public net::URLRequestTestJob {
+ public:
+ EmptyRequestJob(net::URLRequest* request,
+ net::NetworkDelegate* network_delegate)
+ : net::URLRequestTestJob(request,
+ network_delegate,
+ net::URLRequestTestJob::test_headers(),
+ std::string(),
+ true) {
+ }
+
+ virtual int GetResponseCode() const { return 204; }
+
+ private:
+ ~EmptyRequestJob() {}
+};
+
+
+class EmptyCRXInterceptor
+ : public net::URLRequest::Interceptor,
+ public base::RefCountedThreadSafe<EmptyCRXInterceptor> {
+ public:
+ EmptyCRXInterceptor() {
+ net::URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(this);
+ }
+
+ ~EmptyCRXInterceptor() {
+ net::URLRequestJobManager::GetInstance()->
+ UnregisterRequestInterceptor(this);
+ }
+
+ virtual net::URLRequestJob* MaybeIntercept(net::URLRequest* request,
+ net::NetworkDelegate* network_delegate) OVERRIDE {
asargent_no_longer_on_chrome 2012/09/10 23:52:10 formatting nit: http://dev.chromium.org/develope
+
+ if (request->url().scheme() != "http" ||
+ request->url().host() != "www.example.com")
+ return NULL;
+
+ if (!EndsWith(request->url().path(), ".crx", false))
+ return NULL;
+
+ return new EmptyRequestJob(request, network_delegate);
+ }
+};
+
+
} // namespace
// A base class for tests below.
@@ -293,21 +343,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallCancelled) {
}
IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, IncorrectManifest1) {
- WebstoreInstallListener listener;
- WebstorePrivateApi::SetWebstoreInstallerDelegateForTesting(&listener);
ASSERT_TRUE(RunInstallTest("incorrect_manifest1.html", "extension.crx"));
- listener.Wait();
- ASSERT_TRUE(listener.received_failure());
- ASSERT_EQ("Manifest file is invalid.", listener.error());
}
IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, IncorrectManifest2) {
- WebstoreInstallListener listener;
- WebstorePrivateApi::SetWebstoreInstallerDelegateForTesting(&listener);
ASSERT_TRUE(RunInstallTest("incorrect_manifest2.html", "extension.crx"));
- listener.Wait();
- EXPECT_TRUE(listener.received_failure());
- ASSERT_EQ("Manifest file is invalid.", listener.error());
}
// Tests that we can request an app installed bubble (instead of the default
@@ -357,6 +397,14 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallTheme) {
ASSERT_EQ("iamefpfkojoapidjnbafmgkgncegbkad", listener.id());
}
+// Tests that an error is properly reported when a 204 is returned
+// while trying to download a the crx
+IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, Test204) {
+ scoped_refptr<EmptyCRXInterceptor> interceptor(new EmptyCRXInterceptor());
+ net::URLFetcher::SetEnableInterceptionForTests(true);
+ ASSERT_TRUE(RunInstallTest("error204.html", "extension.crx"));
+}
+
// Tests successfully installing a bundle of 2 apps and 2 extensions.
IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateBundleTest, InstallBundle) {
extensions::BundleInstaller::SetAutoApproveForTesting(true);

Powered by Google App Engine
This is Rietveld 408576698