| 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/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/files/file_enumerator.h" | 6 #include "base/files/file_enumerator.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 sandboxed_unpacker_ = NULL; | 75 sandboxed_unpacker_ = NULL; |
| 76 loop_.RunUntilIdle(); | 76 loop_.RunUntilIdle(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void SetupUnpacker(const std::string& crx_name) { | 79 void SetupUnpacker(const std::string& crx_name) { |
| 80 base::FilePath original_path; | 80 base::FilePath original_path; |
| 81 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &original_path)); | 81 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &original_path)); |
| 82 original_path = original_path.AppendASCII("extensions") | 82 original_path = original_path.AppendASCII("extensions") |
| 83 .AppendASCII("unpacker") | 83 .AppendASCII("unpacker") |
| 84 .AppendASCII(crx_name); | 84 .AppendASCII(crx_name); |
| 85 ASSERT_TRUE(file_util::PathExists(original_path)) << original_path.value(); | 85 ASSERT_TRUE(base::PathExists(original_path)) << original_path.value(); |
| 86 | 86 |
| 87 // Try bots won't let us write into DIR_TEST_DATA, so we have to write the | 87 // Try bots won't let us write into DIR_TEST_DATA, so we have to write the |
| 88 // CRX to the temp directory, and create a subdirectory into which to | 88 // CRX to the temp directory, and create a subdirectory into which to |
| 89 // unpack it. | 89 // unpack it. |
| 90 base::FilePath crx_path = temp_dir_.path().AppendASCII(crx_name); | 90 base::FilePath crx_path = temp_dir_.path().AppendASCII(crx_name); |
| 91 ASSERT_TRUE(base::CopyFile(original_path, crx_path)) << | 91 ASSERT_TRUE(base::CopyFile(original_path, crx_path)) << |
| 92 "Original path: " << original_path.value() << | 92 "Original path: " << original_path.value() << |
| 93 ", Crx path: " << crx_path.value(); | 93 ", Crx path: " << crx_path.value(); |
| 94 | 94 |
| 95 unpacker_.reset(new Unpacker( | 95 unpacker_.reset(new Unpacker( |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 EXPECT_CALL(*client_, OnUnpackFailure(_)).Times(0); | 170 EXPECT_CALL(*client_, OnUnpackFailure(_)).Times(0); |
| 171 | 171 |
| 172 SetupUnpacker("no_l10n.crx"); | 172 SetupUnpacker("no_l10n.crx"); |
| 173 ASSERT_TRUE(unpacker_->Run()); | 173 ASSERT_TRUE(unpacker_->Run()); |
| 174 ASSERT_TRUE(unpacker_->DumpImagesToFile()); | 174 ASSERT_TRUE(unpacker_->DumpImagesToFile()); |
| 175 ASSERT_TRUE(unpacker_->DumpMessageCatalogsToFile()); | 175 ASSERT_TRUE(unpacker_->DumpMessageCatalogsToFile()); |
| 176 | 176 |
| 177 // Check that there is no _locales folder. | 177 // Check that there is no _locales folder. |
| 178 base::FilePath install_path = | 178 base::FilePath install_path = |
| 179 GetInstallPath().Append(kLocaleFolder); | 179 GetInstallPath().Append(kLocaleFolder); |
| 180 EXPECT_FALSE(file_util::PathExists(install_path)); | 180 EXPECT_FALSE(base::PathExists(install_path)); |
| 181 | 181 |
| 182 OnUnpackSucceeded(); | 182 OnUnpackSucceeded(); |
| 183 | 183 |
| 184 // Check that there still is no _locales folder. | 184 // Check that there still is no _locales folder. |
| 185 EXPECT_FALSE(file_util::PathExists(install_path)); | 185 EXPECT_FALSE(base::PathExists(install_path)); |
| 186 | 186 |
| 187 ASSERT_TRUE(TempFilesRemoved()); | 187 ASSERT_TRUE(TempFilesRemoved()); |
| 188 } | 188 } |
| 189 | 189 |
| 190 TEST_F(SandboxedUnpackerTest, WithCatalogsSuccess) { | 190 TEST_F(SandboxedUnpackerTest, WithCatalogsSuccess) { |
| 191 EXPECT_CALL(*client_, OnUnpackSuccess(_, _, _, _)); | 191 EXPECT_CALL(*client_, OnUnpackSuccess(_, _, _, _)); |
| 192 EXPECT_CALL(*client_, OnUnpackFailure(_)).Times(0); | 192 EXPECT_CALL(*client_, OnUnpackFailure(_)).Times(0); |
| 193 | 193 |
| 194 SetupUnpacker("good_l10n.crx"); | 194 SetupUnpacker("good_l10n.crx"); |
| 195 ASSERT_TRUE(unpacker_->Run()); | 195 ASSERT_TRUE(unpacker_->Run()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 214 // Check that there is newer _locales/en_US/messages.json file. | 214 // Check that there is newer _locales/en_US/messages.json file. |
| 215 base::PlatformFileInfo new_info; | 215 base::PlatformFileInfo new_info; |
| 216 EXPECT_TRUE(file_util::GetFileInfo(messages_file, &new_info)); | 216 EXPECT_TRUE(file_util::GetFileInfo(messages_file, &new_info)); |
| 217 | 217 |
| 218 EXPECT_TRUE(new_info.last_modified > old_info.last_modified); | 218 EXPECT_TRUE(new_info.last_modified > old_info.last_modified); |
| 219 | 219 |
| 220 ASSERT_TRUE(TempFilesRemoved()); | 220 ASSERT_TRUE(TempFilesRemoved()); |
| 221 } | 221 } |
| 222 | 222 |
| 223 } // namespace extensions | 223 } // namespace extensions |
| OLD | NEW |