| 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/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 .WillByDefault(Invoke(::OnUnpackSuccess)); | 56 .WillByDefault(Invoke(::OnUnpackSuccess)); |
| 57 } | 57 } |
| 58 | 58 |
| 59 protected: | 59 protected: |
| 60 virtual ~MockSandboxedUnpackerClient() {} | 60 virtual ~MockSandboxedUnpackerClient() {} |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 class SandboxedUnpackerTest : public testing::Test { | 63 class SandboxedUnpackerTest : public testing::Test { |
| 64 public: | 64 public: |
| 65 virtual void SetUp() { | 65 virtual void SetUp() { |
| 66 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 66 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 67 ASSERT_TRUE(extensions_dir_.CreateUniqueTempDir()); |
| 67 file_thread_.reset(new content::TestBrowserThread(BrowserThread::FILE, | 68 file_thread_.reset(new content::TestBrowserThread(BrowserThread::FILE, |
| 68 &loop_)); | 69 &loop_)); |
| 69 // It will delete itself. | 70 // It will delete itself. |
| 70 client_ = new MockSandboxedUnpackerClient; | 71 client_ = new MockSandboxedUnpackerClient; |
| 71 client_->DelegateToFake(); | 72 client_->DelegateToFake(); |
| 72 } | 73 } |
| 73 | 74 |
| 74 virtual void TearDown() { | 75 virtual void TearDown() { |
| 75 // Need to destruct SandboxedUnpacker before the message loop since | 76 // Need to destruct SandboxedUnpacker before the message loop since |
| 76 // it posts a task to it. | 77 // it posts a task to it. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 97 unpacker_.reset(new Unpacker( | 98 unpacker_.reset(new Unpacker( |
| 98 crx_path, std::string(), Extension::INTERNAL, Extension::NO_FLAGS)); | 99 crx_path, std::string(), Extension::INTERNAL, Extension::NO_FLAGS)); |
| 99 | 100 |
| 100 // Build a temp area where the extension will be unpacked. | 101 // Build a temp area where the extension will be unpacked. |
| 101 temp_path_ = | 102 temp_path_ = |
| 102 temp_dir_.path().AppendASCII("sandboxed_unpacker_test_Temp"); | 103 temp_dir_.path().AppendASCII("sandboxed_unpacker_test_Temp"); |
| 103 ASSERT_TRUE(file_util::CreateDirectory(temp_path_)); | 104 ASSERT_TRUE(file_util::CreateDirectory(temp_path_)); |
| 104 | 105 |
| 105 sandboxed_unpacker_ = | 106 sandboxed_unpacker_ = |
| 106 new SandboxedUnpacker(crx_path, false, Extension::INTERNAL, | 107 new SandboxedUnpacker(crx_path, false, Extension::INTERNAL, |
| 107 Extension::NO_FLAGS, client_); | 108 Extension::NO_FLAGS, extensions_dir_.path(), |
| 109 client_); |
| 108 | 110 |
| 109 // Hack since SandboxedUnpacker gets its background thread id from | 111 // Hack since SandboxedUnpacker gets its background thread id from |
| 110 // the Start call, but we don't call it here. | 112 // the Start call, but we don't call it here. |
| 111 sandboxed_unpacker_->thread_identifier_ = BrowserThread::FILE; | 113 sandboxed_unpacker_->thread_identifier_ = BrowserThread::FILE; |
| 112 EXPECT_TRUE(PrepareUnpackerEnv()); | 114 EXPECT_TRUE(PrepareUnpackerEnv()); |
| 113 } | 115 } |
| 114 | 116 |
| 115 bool PrepareUnpackerEnv() { | 117 bool PrepareUnpackerEnv() { |
| 116 sandboxed_unpacker_->extension_root_ = | 118 sandboxed_unpacker_->extension_root_ = |
| 117 temp_dir_.path().AppendASCII(extension_filenames::kTempExtensionName); | 119 temp_dir_.path().AppendASCII(extension_filenames::kTempExtensionName); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 items_not_removed++; | 152 items_not_removed++; |
| 151 EXPECT_STREQ(FILE_PATH_LITERAL(""), item_in_temp.value().c_str()) | 153 EXPECT_STREQ(FILE_PATH_LITERAL(""), item_in_temp.value().c_str()) |
| 152 << "File was not removed on success."; | 154 << "File was not removed on success."; |
| 153 item_in_temp = temp_iterator.Next(); | 155 item_in_temp = temp_iterator.Next(); |
| 154 } | 156 } |
| 155 return (items_not_removed == 0); | 157 return (items_not_removed == 0); |
| 156 } | 158 } |
| 157 | 159 |
| 158 protected: | 160 protected: |
| 159 ScopedTempDir temp_dir_; | 161 ScopedTempDir temp_dir_; |
| 162 ScopedTempDir extensions_dir_; |
| 160 FilePath temp_path_; | 163 FilePath temp_path_; |
| 161 MockSandboxedUnpackerClient* client_; | 164 MockSandboxedUnpackerClient* client_; |
| 162 scoped_ptr<Unpacker> unpacker_; | 165 scoped_ptr<Unpacker> unpacker_; |
| 163 scoped_refptr<SandboxedUnpacker> sandboxed_unpacker_; | 166 scoped_refptr<SandboxedUnpacker> sandboxed_unpacker_; |
| 164 MessageLoop loop_; | 167 MessageLoop loop_; |
| 165 scoped_ptr<content::TestBrowserThread> file_thread_; | 168 scoped_ptr<content::TestBrowserThread> file_thread_; |
| 166 }; | 169 }; |
| 167 | 170 |
| 168 TEST_F(SandboxedUnpackerTest, NoCatalogsSuccess) { | 171 TEST_F(SandboxedUnpackerTest, NoCatalogsSuccess) { |
| 169 EXPECT_CALL(*client_, OnUnpackSuccess(_, _, _, _)); | 172 EXPECT_CALL(*client_, OnUnpackSuccess(_, _, _, _)); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 // Check that there is newer _locales/en_US/messages.json file. | 217 // Check that there is newer _locales/en_US/messages.json file. |
| 215 base::PlatformFileInfo new_info; | 218 base::PlatformFileInfo new_info; |
| 216 EXPECT_TRUE(file_util::GetFileInfo(messages_file, &new_info)); | 219 EXPECT_TRUE(file_util::GetFileInfo(messages_file, &new_info)); |
| 217 | 220 |
| 218 EXPECT_TRUE(new_info.last_modified > old_info.last_modified); | 221 EXPECT_TRUE(new_info.last_modified > old_info.last_modified); |
| 219 | 222 |
| 220 ASSERT_TRUE(TempFilesRemoved()); | 223 ASSERT_TRUE(TempFilesRemoved()); |
| 221 } | 224 } |
| 222 | 225 |
| 223 } // namespace extensions | 226 } // namespace extensions |
| OLD | NEW |