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; |
} |
+ static bool IsFileInUse(const FilePath& file) { |
+ return InstallerState::IsFileInUse(file); |
+ } |
}; |
// Simple function to dump some text into a new file. |
@@ -457,3 +460,30 @@ |
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)); |
+ |
+ EXPECT_FALSE(MockInstallerState::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(MockInstallerState::IsFileInUse(temp_file)); |
+ } |
+ |
+ // And once the handle is gone, it should no longer be in use. |
+ EXPECT_FALSE(MockInstallerState::IsFileInUse(temp_file)); |
+} |