OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 EXPECT_FALSE(lock->HasAcquired()); | 73 EXPECT_FALSE(lock->HasAcquired()); |
74 // In the posix code, we don't delete the file when releasing the lock. | 74 // In the posix code, we don't delete the file when releasing the lock. |
75 #if !defined(OS_POSIX) | 75 #if !defined(OS_POSIX) |
76 EXPECT_FALSE(file_util::PathExists(lock_file_path)); | 76 EXPECT_FALSE(file_util::PathExists(lock_file_path)); |
77 #endif // !defined(OS_POSIX) | 77 #endif // !defined(OS_POSIX) |
78 } | 78 } |
79 | 79 |
80 // If for some reason the lock file is left behind by the previous owner, we | 80 // If for some reason the lock file is left behind by the previous owner, we |
81 // should still be able to lock it, at least in the Windows implementation. | 81 // should still be able to lock it, at least in the Windows implementation. |
82 TEST_F(FirefoxProfileLockTest, ProfileLockOrphaned) { | 82 TEST_F(FirefoxProfileLockTest, ProfileLockOrphaned) { |
83 std::wstring test_path; | 83 FilePath test_path; |
84 file_util::CreateNewTempDirectory(L"firefox_profile", &test_path); | 84 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("firefox_profile"), |
85 FilePath lock_file_path = FilePath::FromWStringHack(test_path); | 85 &test_path); |
| 86 FilePath lock_file_path = test_path; |
86 FileAutoDeleter deleter(lock_file_path); | 87 FileAutoDeleter deleter(lock_file_path); |
87 lock_file_path = lock_file_path.Append(FirefoxProfileLock::kLockFileName); | 88 lock_file_path = lock_file_path.Append(FirefoxProfileLock::kLockFileName); |
88 | 89 |
89 // Create the orphaned lock file. | 90 // Create the orphaned lock file. |
90 FILE* lock_file = file_util::OpenFile(lock_file_path, "w"); | 91 FILE* lock_file = file_util::OpenFile(lock_file_path, "w"); |
91 ASSERT_TRUE(lock_file); | 92 ASSERT_TRUE(lock_file); |
92 file_util::CloseFile(lock_file); | 93 file_util::CloseFile(lock_file); |
93 EXPECT_TRUE(file_util::PathExists(lock_file_path)); | 94 EXPECT_TRUE(file_util::PathExists(lock_file_path)); |
94 | 95 |
95 scoped_ptr<FirefoxProfileLock> lock; | 96 scoped_ptr<FirefoxProfileLock> lock; |
96 EXPECT_EQ(static_cast<FirefoxProfileLock*>(NULL), lock.get()); | 97 EXPECT_EQ(static_cast<FirefoxProfileLock*>(NULL), lock.get()); |
97 lock.reset(new FirefoxProfileLock(test_path)); | 98 lock.reset(new FirefoxProfileLock(test_path.ToWStringHack())); |
98 EXPECT_TRUE(lock->HasAcquired()); | 99 EXPECT_TRUE(lock->HasAcquired()); |
99 lock->Unlock(); | 100 lock->Unlock(); |
100 EXPECT_FALSE(lock->HasAcquired()); | 101 EXPECT_FALSE(lock->HasAcquired()); |
101 } | 102 } |
102 | 103 |
103 // This is broken on POSIX since the same process is allowed to reacquire a | 104 // This is broken on POSIX since the same process is allowed to reacquire a |
104 // lock. | 105 // lock. |
105 #if !defined(OS_POSIX) | 106 #if !defined(OS_POSIX) |
106 // Tests two locks contending for the same lock file. | 107 // Tests two locks contending for the same lock file. |
107 TEST_F(FirefoxProfileLockTest, ProfileLockContention) { | 108 TEST_F(FirefoxProfileLockTest, ProfileLockContention) { |
(...skipping 13 matching lines...) Expand all Loading... |
121 | 122 |
122 lock1->Unlock(); | 123 lock1->Unlock(); |
123 EXPECT_FALSE(lock1->HasAcquired()); | 124 EXPECT_FALSE(lock1->HasAcquired()); |
124 | 125 |
125 lock2->Lock(); | 126 lock2->Lock(); |
126 EXPECT_TRUE(lock2->HasAcquired()); | 127 EXPECT_TRUE(lock2->HasAcquired()); |
127 lock2->Unlock(); | 128 lock2->Unlock(); |
128 EXPECT_FALSE(lock2->HasAcquired()); | 129 EXPECT_FALSE(lock2->HasAcquired()); |
129 } | 130 } |
130 #endif | 131 #endif |
OLD | NEW |