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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/bind.h"
6 #include "base/command_line.h"
7 #include "base/file_util.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/path_service.h"
11 #include "base/run_loop.h"
12 #include "base/strings/string_util.h"
13 #include "base/values.h"
14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/extensions/test_extension_system.h"
16 #include "chrome/browser/extensions/zipfile_installer.h"
17 #include "chrome/common/chrome_paths.h"
18 #include "chrome/test/base/testing_profile.h"
19 #include "content/public/test/test_browser_thread_bundle.h"
20 #include "content/public/test/test_utils.h"
21 #include "extensions/common/constants.h"
22 #include "extensions/common/extension.h"
23 #include "testing/gtest/include/gtest/gtest.h"
24
25 namespace extensions {
26
27 class MockZipFileInstallerClient : public ZipFileInstallerClient {
28 public:
29 void WaitForUnzip() {
30 scoped_refptr<content::MessageLoopRunner> runner =
31 new content::MessageLoopRunner;
32 quit_closure_ = runner->QuitClosure();
33 runner->Run();
34 }
35
36 base::FilePath temp_dir() const { return temp_dir_; }
37
38 private:
39 virtual ~MockZipFileInstallerClient() {}
40
41 virtual void OnUnzipSuccess(const base::FilePath& temp_dir) OVERRIDE {
42 temp_dir_ = temp_dir;
43 quit_closure_.Run();
44 }
45
46 virtual void OnUnzipFailure(const std::string& error) OVERRIDE {
47 ASSERT_TRUE(false);
48 }
49
50 base::Closure quit_closure_;
51 base::FilePath temp_dir_;
52 };
53
54 class ZipFileInstallerTest : public testing::Test {
55 public:
56 virtual void SetUp() {
57 browser_threads_.reset(new content::TestBrowserThreadBundle(
58 content::TestBrowserThreadBundle::IO_MAINLOOP));
59 in_process_utility_thread_helper_.reset(
60 new content::InProcessUtilityThreadHelper);
61
62 // Create profile for extension service.
63 profile_.reset(new TestingProfile());
64 TestExtensionSystem* system =
65 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile_.get()));
66 extension_service_ = system->CreateExtensionService(
67 base::CommandLine::ForCurrentProcess(), base::FilePath(), false);
68
69 // It will delete itself.
70 client_ = new MockZipFileInstallerClient;
71 }
72
73 virtual void TearDown() {
74 // Need to destruct ZipFileInstaller before the message loop since
75 // it posts a task to it.
76 zipfile_installer_ = NULL;
77 profile_.reset();
78 base::RunLoop().RunUntilIdle();
79 }
80
81 void SetupInstaller(const std::string& zip_name) {
82 base::FilePath original_path;
83 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &original_path));
84 original_path = original_path.AppendASCII("extensions")
85 .AppendASCII("zipfile_installer")
86 .AppendASCII(zip_name);
87 ASSERT_TRUE(base::PathExists(original_path)) << original_path.value();
88
89 zipfile_installer_ = ZipFileInstaller::Create(extension_service_, client_);
90
91 base::MessageLoopProxy::current()->PostTask(
92 FROM_HERE,
93 base::Bind(&ZipFileInstaller::LoadFromZipFile,
94 zipfile_installer_.get(),
95 original_path));
96 client_->WaitForUnzip();
97 }
98
99 protected:
100 MockZipFileInstallerClient* client_;
101 scoped_refptr<ZipFileInstaller> zipfile_installer_;
102
103 scoped_ptr<TestingProfile> profile_;
104 ExtensionService* extension_service_;
105
106 scoped_ptr<content::TestBrowserThreadBundle> browser_threads_;
107 scoped_ptr<content::InProcessUtilityThreadHelper>
108 in_process_utility_thread_helper_;
109 };
110
111 TEST_F(ZipFileInstallerTest, GoodZip) {
112 SetupInstaller("good.zip");
113 }
114
115 TEST_F(ZipFileInstallerTest, ZipWithPublicKey) {
116 SetupInstaller("public_key.zip");
117 // 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
118 // requires either observing extension installs or hooking into the unpacked
119 // installer which is currently not tested in this manner.
120 // const char kIdForPublicKey[] = "ikppjpenhoddphklkpdfdfdabbakkpal";
121 }
122
123 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698