| 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/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/sandboxed_unpacker.h" | 12 #include "chrome/browser/extensions/sandboxed_unpacker.h" |
| 13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
| 14 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" | 14 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" |
| 15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/common/extensions/manifest_handler.h" | 16 #include "chrome/common/extensions/manifest_handler.h" |
| 17 #include "chrome/common/extensions/unpacker.h" | 17 #include "chrome/common/extensions/unpacker.h" |
| 18 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
| 19 #include "extensions/common/constants.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "third_party/skia/include/core/SkBitmap.h" | 22 #include "third_party/skia/include/core/SkBitmap.h" |
| 22 | 23 |
| 23 using content::BrowserThread; | 24 using content::BrowserThread; |
| 24 using testing::_; | 25 using testing::_; |
| 25 using testing::Invoke; | 26 using testing::Invoke; |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 EXPECT_CALL(*client_, OnUnpackSuccess(_, _, _, _)); | 171 EXPECT_CALL(*client_, OnUnpackSuccess(_, _, _, _)); |
| 171 EXPECT_CALL(*client_, OnUnpackFailure(_)).Times(0); | 172 EXPECT_CALL(*client_, OnUnpackFailure(_)).Times(0); |
| 172 | 173 |
| 173 SetupUnpacker("no_l10n.crx"); | 174 SetupUnpacker("no_l10n.crx"); |
| 174 ASSERT_TRUE(unpacker_->Run()); | 175 ASSERT_TRUE(unpacker_->Run()); |
| 175 ASSERT_TRUE(unpacker_->DumpImagesToFile()); | 176 ASSERT_TRUE(unpacker_->DumpImagesToFile()); |
| 176 ASSERT_TRUE(unpacker_->DumpMessageCatalogsToFile()); | 177 ASSERT_TRUE(unpacker_->DumpMessageCatalogsToFile()); |
| 177 | 178 |
| 178 // Check that there is no _locales folder. | 179 // Check that there is no _locales folder. |
| 179 base::FilePath install_path = | 180 base::FilePath install_path = |
| 180 GetInstallPath().Append(Extension::kLocaleFolder); | 181 GetInstallPath().Append(kLocaleFolder); |
| 181 EXPECT_FALSE(file_util::PathExists(install_path)); | 182 EXPECT_FALSE(file_util::PathExists(install_path)); |
| 182 | 183 |
| 183 OnUnpackSucceeded(); | 184 OnUnpackSucceeded(); |
| 184 | 185 |
| 185 // Check that there still is no _locales folder. | 186 // Check that there still is no _locales folder. |
| 186 EXPECT_FALSE(file_util::PathExists(install_path)); | 187 EXPECT_FALSE(file_util::PathExists(install_path)); |
| 187 | 188 |
| 188 ASSERT_TRUE(TempFilesRemoved()); | 189 ASSERT_TRUE(TempFilesRemoved()); |
| 189 } | 190 } |
| 190 | 191 |
| 191 TEST_F(SandboxedUnpackerTest, WithCatalogsSuccess) { | 192 TEST_F(SandboxedUnpackerTest, WithCatalogsSuccess) { |
| 192 EXPECT_CALL(*client_, OnUnpackSuccess(_, _, _, _)); | 193 EXPECT_CALL(*client_, OnUnpackSuccess(_, _, _, _)); |
| 193 EXPECT_CALL(*client_, OnUnpackFailure(_)).Times(0); | 194 EXPECT_CALL(*client_, OnUnpackFailure(_)).Times(0); |
| 194 | 195 |
| 195 SetupUnpacker("good_l10n.crx"); | 196 SetupUnpacker("good_l10n.crx"); |
| 196 ASSERT_TRUE(unpacker_->Run()); | 197 ASSERT_TRUE(unpacker_->Run()); |
| 197 ASSERT_TRUE(unpacker_->DumpImagesToFile()); | 198 ASSERT_TRUE(unpacker_->DumpImagesToFile()); |
| 198 ASSERT_TRUE(unpacker_->DumpMessageCatalogsToFile()); | 199 ASSERT_TRUE(unpacker_->DumpMessageCatalogsToFile()); |
| 199 | 200 |
| 200 // Set timestamp on _locales/en_US/messages.json into the past. | 201 // Set timestamp on _locales/en_US/messages.json into the past. |
| 201 base::FilePath messages_file; | 202 base::FilePath messages_file; |
| 202 messages_file = GetInstallPath().Append(Extension::kLocaleFolder) | 203 messages_file = GetInstallPath().Append(kLocaleFolder) |
| 203 .AppendASCII("en_US") | 204 .AppendASCII("en_US") |
| 204 .Append(Extension::kMessagesFilename); | 205 .Append(kMessagesFilename); |
| 205 base::PlatformFileInfo old_info; | 206 base::PlatformFileInfo old_info; |
| 206 EXPECT_TRUE(file_util::GetFileInfo(messages_file, &old_info)); | 207 EXPECT_TRUE(file_util::GetFileInfo(messages_file, &old_info)); |
| 207 base::Time old_time = | 208 base::Time old_time = |
| 208 old_info.last_modified - base::TimeDelta::FromSeconds(2); | 209 old_info.last_modified - base::TimeDelta::FromSeconds(2); |
| 209 EXPECT_TRUE(file_util::SetLastModifiedTime(messages_file, old_time)); | 210 EXPECT_TRUE(file_util::SetLastModifiedTime(messages_file, old_time)); |
| 210 // Refresh old_info, just to be sure. | 211 // Refresh old_info, just to be sure. |
| 211 EXPECT_TRUE(file_util::GetFileInfo(messages_file, &old_info)); | 212 EXPECT_TRUE(file_util::GetFileInfo(messages_file, &old_info)); |
| 212 | 213 |
| 213 OnUnpackSucceeded(); | 214 OnUnpackSucceeded(); |
| 214 | 215 |
| 215 // Check that there is newer _locales/en_US/messages.json file. | 216 // Check that there is newer _locales/en_US/messages.json file. |
| 216 base::PlatformFileInfo new_info; | 217 base::PlatformFileInfo new_info; |
| 217 EXPECT_TRUE(file_util::GetFileInfo(messages_file, &new_info)); | 218 EXPECT_TRUE(file_util::GetFileInfo(messages_file, &new_info)); |
| 218 | 219 |
| 219 EXPECT_TRUE(new_info.last_modified > old_info.last_modified); | 220 EXPECT_TRUE(new_info.last_modified > old_info.last_modified); |
| 220 | 221 |
| 221 ASSERT_TRUE(TempFilesRemoved()); | 222 ASSERT_TRUE(TempFilesRemoved()); |
| 222 } | 223 } |
| 223 | 224 |
| 224 } // namespace extensions | 225 } // namespace extensions |
| OLD | NEW |