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 "base/base64.h" | 5 #include "base/base64.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "components/crx_file/id_util.h" | 15 #include "components/crx_file/id_util.h" |
| 16 #include "content/public/browser/shell_context.h" |
| 17 #include "content/public/common/content_client.h" |
16 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
17 #include "content/public/test/test_utils.h" | 19 #include "content/public/test/test_utils.h" |
18 #include "extensions/browser/extensions_test.h" | 20 #include "extensions/browser/extensions_test.h" |
19 #include "extensions/browser/sandboxed_unpacker.h" | 21 #include "extensions/browser/sandboxed_unpacker.h" |
20 #include "extensions/common/constants.h" | 22 #include "extensions/common/constants.h" |
21 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
22 #include "extensions/common/extension_paths.h" | 24 #include "extensions/common/extension_paths.h" |
23 #include "extensions/common/switches.h" | 25 #include "extensions/common/switches.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "third_party/skia/include/core/SkBitmap.h" | 27 #include "third_party/skia/include/core/SkBitmap.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 void SetUp() override { | 68 void SetUp() override { |
67 ExtensionsTest::SetUp(); | 69 ExtensionsTest::SetUp(); |
68 ASSERT_TRUE(extensions_dir_.CreateUniqueTempDir()); | 70 ASSERT_TRUE(extensions_dir_.CreateUniqueTempDir()); |
69 browser_threads_.reset(new content::TestBrowserThreadBundle( | 71 browser_threads_.reset(new content::TestBrowserThreadBundle( |
70 content::TestBrowserThreadBundle::IO_MAINLOOP)); | 72 content::TestBrowserThreadBundle::IO_MAINLOOP)); |
71 in_process_utility_thread_helper_.reset( | 73 in_process_utility_thread_helper_.reset( |
72 new content::InProcessUtilityThreadHelper); | 74 new content::InProcessUtilityThreadHelper); |
73 // It will delete itself. | 75 // It will delete itself. |
74 client_ = new MockSandboxedUnpackerClient; | 76 client_ = new MockSandboxedUnpackerClient; |
75 | 77 |
| 78 shell_context_ = content::ShellContext::Create(); |
| 79 |
76 sandboxed_unpacker_ = new SandboxedUnpacker( | 80 sandboxed_unpacker_ = new SandboxedUnpacker( |
77 Manifest::INTERNAL, Extension::NO_FLAGS, extensions_dir_.path(), | 81 Manifest::INTERNAL, Extension::NO_FLAGS, extensions_dir_.path(), |
78 base::ThreadTaskRunnerHandle::Get(), client_); | 82 base::ThreadTaskRunnerHandle::Get(), client_); |
79 } | 83 } |
80 | 84 |
81 void TearDown() override { | 85 void TearDown() override { |
82 // Need to destruct SandboxedUnpacker before the message loop since | 86 // Need to destruct SandboxedUnpacker before the message loop since |
83 // it posts a task to it. | 87 // it posts a task to it. |
84 sandboxed_unpacker_ = NULL; | 88 sandboxed_unpacker_ = NULL; |
85 base::RunLoop().RunUntilIdle(); | 89 base::RunLoop().RunUntilIdle(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 131 |
128 base::string16 GetInstallError() { return client_->unpack_err(); } | 132 base::string16 GetInstallError() { return client_->unpack_err(); } |
129 | 133 |
130 protected: | 134 protected: |
131 base::ScopedTempDir extensions_dir_; | 135 base::ScopedTempDir extensions_dir_; |
132 MockSandboxedUnpackerClient* client_; | 136 MockSandboxedUnpackerClient* client_; |
133 scoped_refptr<SandboxedUnpacker> sandboxed_unpacker_; | 137 scoped_refptr<SandboxedUnpacker> sandboxed_unpacker_; |
134 std::unique_ptr<content::TestBrowserThreadBundle> browser_threads_; | 138 std::unique_ptr<content::TestBrowserThreadBundle> browser_threads_; |
135 std::unique_ptr<content::InProcessUtilityThreadHelper> | 139 std::unique_ptr<content::InProcessUtilityThreadHelper> |
136 in_process_utility_thread_helper_; | 140 in_process_utility_thread_helper_; |
| 141 std::unique_ptr<content::ShellContext> shell_context_; |
137 }; | 142 }; |
138 | 143 |
139 TEST_F(SandboxedUnpackerTest, NoCatalogsSuccess) { | 144 TEST_F(SandboxedUnpackerTest, NoCatalogsSuccess) { |
140 SetupUnpacker("no_l10n.crx", ""); | 145 SetupUnpacker("no_l10n.crx", ""); |
141 // Check that there is no _locales folder. | 146 // Check that there is no _locales folder. |
142 base::FilePath install_path = GetInstallPath().Append(kLocaleFolder); | 147 base::FilePath install_path = GetInstallPath().Append(kLocaleFolder); |
143 EXPECT_FALSE(base::PathExists(install_path)); | 148 EXPECT_FALSE(base::PathExists(install_path)); |
144 } | 149 } |
145 | 150 |
146 TEST_F(SandboxedUnpackerTest, FromDirNoCatalogsSuccess) { | 151 TEST_F(SandboxedUnpackerTest, FromDirNoCatalogsSuccess) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 EXPECT_EQ(base::string16(), GetInstallError()); | 187 EXPECT_EQ(base::string16(), GetInstallError()); |
183 } | 188 } |
184 | 189 |
185 TEST_F(SandboxedUnpackerTest, SkipHashCheck) { | 190 TEST_F(SandboxedUnpackerTest, SkipHashCheck) { |
186 SetupUnpacker("good_l10n.crx", "badhash"); | 191 SetupUnpacker("good_l10n.crx", "badhash"); |
187 // Check that there is no error message. | 192 // Check that there is no error message. |
188 EXPECT_EQ(base::string16(), GetInstallError()); | 193 EXPECT_EQ(base::string16(), GetInstallError()); |
189 } | 194 } |
190 | 195 |
191 } // namespace extensions | 196 } // namespace extensions |
OLD | NEW |