Chromium Code Reviews| Index: chrome/installer/util/installer_state_unittest.cc |
| =================================================================== |
| --- chrome/installer/util/installer_state_unittest.cc (revision 91508) |
| +++ chrome/installer/util/installer_state_unittest.cc (working copy) |
| @@ -47,6 +47,9 @@ |
| void set_target_path(const FilePath& target_path) { |
| target_path_ = target_path; |
| } |
| + bool IsFileInUse(const FilePath& file) { |
|
grt (UTC plus 2)
2011/07/15 13:58:09
nit: what do you think about making this static, t
robertshield
2011/07/15 17:19:12
Done.
|
| + return InstallerState::IsFileInUse(file); |
| + } |
| }; |
| // Simple function to dump some text into a new file. |
| @@ -457,3 +460,31 @@ |
| scoped_ptr<Version> version(installer_state.GetCurrentVersion(machine_state)); |
| EXPECT_TRUE(version.get() != NULL); |
| } |
| + |
| +TEST_F(InstallerStateTest, IsFileInUse) { |
| + ScopedTempDir temp_dir; |
| + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| + |
| + FilePath temp_file; |
| + ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir.path(), &temp_file)); |
| + |
| + MockInstallerState mock_installer_state; |
| + EXPECT_FALSE(mock_installer_state.IsFileInUse(temp_file)); |
| + |
| + { |
| + // Open a handle to the file with the same access mode and sharing options |
| + // as the loader. |
| + base::win::ScopedHandle temp_handle( |
| + CreateFile(temp_file.value().c_str(), |
| + SYNCHRONIZE | FILE_EXECUTE, |
| + FILE_SHARE_DELETE | FILE_SHARE_READ, |
| + NULL, OPEN_EXISTING, 0, 0)); |
| + ASSERT_TRUE(temp_handle != NULL); |
| + |
| + // The file should now be in use. |
| + EXPECT_TRUE(mock_installer_state.IsFileInUse(temp_file)); |
| + } |
| + |
| + // And once the handle is gone, it should no longer be in use. |
| + EXPECT_FALSE(mock_installer_state.IsFileInUse(temp_file)); |
| +} |