OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" | 11 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" |
12 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
13 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
14 #include "chrome/common/extensions/extension_constants.h" | 14 #include "chrome/common/extensions/extension_constants.h" |
15 #include "chrome/common/extensions/extension_unpacker.h" | 15 #include "chrome/common/extensions/extension_unpacker.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
19 | 19 |
20 namespace errors = extension_manifest_errors; | 20 namespace errors = extension_manifest_errors; |
21 namespace keys = extension_manifest_keys; | 21 namespace keys = extension_manifest_keys; |
22 | 22 |
23 using testing::_; | 23 using testing::_; |
24 using testing::Invoke; | 24 using testing::Invoke; |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 void OnUnpackSuccess(const FilePath& temp_dir, | 28 void OnUnpackSuccess(const FilePath& temp_dir, |
29 const FilePath& extension_root, | 29 const FilePath& extension_root, |
| 30 const DictionaryValue* original_manifest, |
30 const Extension* extension) { | 31 const Extension* extension) { |
31 // Don't delete temp_dir here, we need to do some post op checking. | 32 // Don't delete temp_dir here, we need to do some post op checking. |
32 } | 33 } |
33 | 34 |
34 } // namespace | 35 } // namespace |
35 | 36 |
36 class MockSandboxedExtensionUnpackerClient | 37 class MockSandboxedExtensionUnpackerClient |
37 : public SandboxedExtensionUnpackerClient { | 38 : public SandboxedExtensionUnpackerClient { |
38 public: | 39 public: |
39 virtual ~MockSandboxedExtensionUnpackerClient() {} | 40 virtual ~MockSandboxedExtensionUnpackerClient() {} |
40 | 41 |
41 MOCK_METHOD3(OnUnpackSuccess, | 42 MOCK_METHOD4(OnUnpackSuccess, |
42 void(const FilePath& temp_dir, | 43 void(const FilePath& temp_dir, |
43 const FilePath& extension_root, | 44 const FilePath& extension_root, |
| 45 const DictionaryValue* original_manifest, |
44 const Extension* extension)); | 46 const Extension* extension)); |
45 | 47 |
46 MOCK_METHOD1(OnUnpackFailure, | 48 MOCK_METHOD1(OnUnpackFailure, |
47 void(const std::string& error)); | 49 void(const std::string& error)); |
48 | 50 |
49 void DelegateToFake() { | 51 void DelegateToFake() { |
50 ON_CALL(*this, OnUnpackSuccess(_, _, _)) | 52 ON_CALL(*this, OnUnpackSuccess(_, _, _, _)) |
51 .WillByDefault(Invoke(::OnUnpackSuccess)); | 53 .WillByDefault(Invoke(::OnUnpackSuccess)); |
52 } | 54 } |
53 }; | 55 }; |
54 | 56 |
55 class SandboxedExtensionUnpackerTest : public testing::Test { | 57 class SandboxedExtensionUnpackerTest : public testing::Test { |
56 public: | 58 public: |
57 virtual void SetUp() { | 59 virtual void SetUp() { |
58 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 60 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
59 file_thread_.reset(new BrowserThread(BrowserThread::FILE, &loop_)); | 61 file_thread_.reset(new BrowserThread(BrowserThread::FILE, &loop_)); |
60 // It will delete itself. | 62 // It will delete itself. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 ScopedTempDir temp_dir_; | 152 ScopedTempDir temp_dir_; |
151 FilePath temp_path_; | 153 FilePath temp_path_; |
152 MockSandboxedExtensionUnpackerClient* client_; | 154 MockSandboxedExtensionUnpackerClient* client_; |
153 scoped_ptr<ExtensionUnpacker> unpacker_; | 155 scoped_ptr<ExtensionUnpacker> unpacker_; |
154 scoped_refptr<SandboxedExtensionUnpacker> sandboxed_unpacker_; | 156 scoped_refptr<SandboxedExtensionUnpacker> sandboxed_unpacker_; |
155 MessageLoop loop_; | 157 MessageLoop loop_; |
156 scoped_ptr<BrowserThread> file_thread_; | 158 scoped_ptr<BrowserThread> file_thread_; |
157 }; | 159 }; |
158 | 160 |
159 TEST_F(SandboxedExtensionUnpackerTest, NoCatalogsSuccess) { | 161 TEST_F(SandboxedExtensionUnpackerTest, NoCatalogsSuccess) { |
160 EXPECT_CALL(*client_, OnUnpackSuccess(_, _, _)); | 162 EXPECT_CALL(*client_, OnUnpackSuccess(_, _, _, _)); |
161 EXPECT_CALL(*client_, OnUnpackFailure(_)).Times(0); | 163 EXPECT_CALL(*client_, OnUnpackFailure(_)).Times(0); |
162 | 164 |
163 SetupUnpacker("no_l10n.crx"); | 165 SetupUnpacker("no_l10n.crx"); |
164 ASSERT_TRUE(unpacker_->Run()); | 166 ASSERT_TRUE(unpacker_->Run()); |
165 ASSERT_TRUE(unpacker_->DumpImagesToFile()); | 167 ASSERT_TRUE(unpacker_->DumpImagesToFile()); |
166 ASSERT_TRUE(unpacker_->DumpMessageCatalogsToFile()); | 168 ASSERT_TRUE(unpacker_->DumpMessageCatalogsToFile()); |
167 | 169 |
168 // Check that there is no _locales folder. | 170 // Check that there is no _locales folder. |
169 FilePath install_path = | 171 FilePath install_path = |
170 GetInstallPath().Append(Extension::kLocaleFolder); | 172 GetInstallPath().Append(Extension::kLocaleFolder); |
171 EXPECT_FALSE(file_util::PathExists(install_path)); | 173 EXPECT_FALSE(file_util::PathExists(install_path)); |
172 | 174 |
173 OnUnpackSucceeded(); | 175 OnUnpackSucceeded(); |
174 | 176 |
175 // Check that there still is no _locales folder. | 177 // Check that there still is no _locales folder. |
176 EXPECT_FALSE(file_util::PathExists(install_path)); | 178 EXPECT_FALSE(file_util::PathExists(install_path)); |
177 | 179 |
178 ASSERT_TRUE(TempFilesRemoved()); | 180 ASSERT_TRUE(TempFilesRemoved()); |
179 } | 181 } |
180 | 182 |
181 TEST_F(SandboxedExtensionUnpackerTest, WithCatalogsSuccess) { | 183 TEST_F(SandboxedExtensionUnpackerTest, WithCatalogsSuccess) { |
182 EXPECT_CALL(*client_, OnUnpackSuccess(_, _, _)); | 184 EXPECT_CALL(*client_, OnUnpackSuccess(_, _, _, _)); |
183 EXPECT_CALL(*client_, OnUnpackFailure(_)).Times(0); | 185 EXPECT_CALL(*client_, OnUnpackFailure(_)).Times(0); |
184 | 186 |
185 SetupUnpacker("good_l10n.crx"); | 187 SetupUnpacker("good_l10n.crx"); |
186 ASSERT_TRUE(unpacker_->Run()); | 188 ASSERT_TRUE(unpacker_->Run()); |
187 ASSERT_TRUE(unpacker_->DumpImagesToFile()); | 189 ASSERT_TRUE(unpacker_->DumpImagesToFile()); |
188 ASSERT_TRUE(unpacker_->DumpMessageCatalogsToFile()); | 190 ASSERT_TRUE(unpacker_->DumpMessageCatalogsToFile()); |
189 | 191 |
190 // Set timestamp on _locales/en_US/messages.json into the past. | 192 // Set timestamp on _locales/en_US/messages.json into the past. |
191 FilePath messages_file; | 193 FilePath messages_file; |
192 messages_file = GetInstallPath().Append(Extension::kLocaleFolder) | 194 messages_file = GetInstallPath().Append(Extension::kLocaleFolder) |
(...skipping 10 matching lines...) Expand all Loading... |
203 OnUnpackSucceeded(); | 205 OnUnpackSucceeded(); |
204 | 206 |
205 // Check that there is newer _locales/en_US/messages.json file. | 207 // Check that there is newer _locales/en_US/messages.json file. |
206 base::PlatformFileInfo new_info; | 208 base::PlatformFileInfo new_info; |
207 EXPECT_TRUE(file_util::GetFileInfo(messages_file, &new_info)); | 209 EXPECT_TRUE(file_util::GetFileInfo(messages_file, &new_info)); |
208 | 210 |
209 EXPECT_TRUE(new_info.last_modified > old_info.last_modified); | 211 EXPECT_TRUE(new_info.last_modified > old_info.last_modified); |
210 | 212 |
211 ASSERT_TRUE(TempFilesRemoved()); | 213 ASSERT_TRUE(TempFilesRemoved()); |
212 } | 214 } |
OLD | NEW |