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

Unified Diff: chrome/browser/extensions/zipfile_installer_unittest.cc

Issue 406713002: Allow drag-and-drop of zipped extensions on chrome://extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add test Created 6 years, 4 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/zipfile_installer_unittest.cc
diff --git a/chrome/browser/extensions/zipfile_installer_unittest.cc b/chrome/browser/extensions/zipfile_installer_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..679cf857024a005ad088fc287c21de59e520f020
--- /dev/null
+++ b/chrome/browser/extensions/zipfile_installer_unittest.cc
@@ -0,0 +1,123 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/bind.h"
+#include "base/command_line.h"
+#include "base/file_util.h"
+#include "base/memory/ref_counted.h"
+#include "base/message_loop/message_loop.h"
+#include "base/path_service.h"
+#include "base/run_loop.h"
+#include "base/strings/string_util.h"
+#include "base/values.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/test_extension_system.h"
+#include "chrome/browser/extensions/zipfile_installer.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/test/base/testing_profile.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "content/public/test/test_utils.h"
+#include "extensions/common/constants.h"
+#include "extensions/common/extension.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace extensions {
+
+class MockZipFileInstallerClient : public ZipFileInstallerClient {
+ public:
+ void WaitForUnzip() {
+ scoped_refptr<content::MessageLoopRunner> runner =
+ new content::MessageLoopRunner;
+ quit_closure_ = runner->QuitClosure();
+ runner->Run();
+ }
+
+ base::FilePath temp_dir() const { return temp_dir_; }
+
+ private:
+ virtual ~MockZipFileInstallerClient() {}
+
+ virtual void OnUnzipSuccess(const base::FilePath& temp_dir) OVERRIDE {
+ temp_dir_ = temp_dir;
+ quit_closure_.Run();
+ }
+
+ virtual void OnUnzipFailure(const std::string& error) OVERRIDE {
+ ASSERT_TRUE(false);
+ }
+
+ base::Closure quit_closure_;
+ base::FilePath temp_dir_;
+};
+
+class ZipFileInstallerTest : public testing::Test {
+ public:
+ virtual void SetUp() {
+ browser_threads_.reset(new content::TestBrowserThreadBundle(
+ content::TestBrowserThreadBundle::IO_MAINLOOP));
+ in_process_utility_thread_helper_.reset(
+ new content::InProcessUtilityThreadHelper);
+
+ // Create profile for extension service.
+ profile_.reset(new TestingProfile());
+ TestExtensionSystem* system =
+ static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile_.get()));
+ extension_service_ = system->CreateExtensionService(
+ base::CommandLine::ForCurrentProcess(), base::FilePath(), false);
+
+ // It will delete itself.
+ client_ = new MockZipFileInstallerClient;
+ }
+
+ virtual void TearDown() {
+ // Need to destruct ZipFileInstaller before the message loop since
+ // it posts a task to it.
+ zipfile_installer_ = NULL;
+ profile_.reset();
+ base::RunLoop().RunUntilIdle();
+ }
+
+ void SetupInstaller(const std::string& zip_name) {
+ base::FilePath original_path;
+ ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &original_path));
+ original_path = original_path.AppendASCII("extensions")
+ .AppendASCII("zipfile_installer")
+ .AppendASCII(zip_name);
+ ASSERT_TRUE(base::PathExists(original_path)) << original_path.value();
+
+ zipfile_installer_ = ZipFileInstaller::Create(extension_service_, client_);
+
+ base::MessageLoopProxy::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&ZipFileInstaller::LoadFromZipFile,
+ zipfile_installer_.get(),
+ original_path));
+ client_->WaitForUnzip();
+ }
+
+ protected:
+ MockZipFileInstallerClient* client_;
+ scoped_refptr<ZipFileInstaller> zipfile_installer_;
+
+ scoped_ptr<TestingProfile> profile_;
+ ExtensionService* extension_service_;
+
+ scoped_ptr<content::TestBrowserThreadBundle> browser_threads_;
+ scoped_ptr<content::InProcessUtilityThreadHelper>
+ in_process_utility_thread_helper_;
+};
+
+TEST_F(ZipFileInstallerTest, GoodZip) {
+ SetupInstaller("good.zip");
+}
+
+TEST_F(ZipFileInstallerTest, ZipWithPublicKey) {
+ SetupInstaller("public_key.zip");
+ // TODO(elijahtaylor): Test that the installed extension has this ID. This
elijahtaylor1 2014/08/06 00:31:54 I tried to register an extension registry observer
+ // requires either observing extension installs or hooking into the unpacked
+ // installer which is currently not tested in this manner.
+ // const char kIdForPublicKey[] = "ikppjpenhoddphklkpdfdfdabbakkpal";
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698