Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1336)

Side by Side Diff: chrome/browser/importer/firefox_profile_lock_unittest.cc

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/path_service.h" 7 #include "base/path_service.h"
8 #include "base/process_util.h" 8 #include "base/process_util.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 21 matching lines...) Expand all
32 32
33 // Tests basic functionality and verifies that the lock file is deleted after 33 // Tests basic functionality and verifies that the lock file is deleted after
34 // use. 34 // use.
35 TEST_F(FirefoxProfileLockTest, ProfileLock) { 35 TEST_F(FirefoxProfileLockTest, ProfileLock) {
36 base::FilePath test_path = temp_dir_.path(); 36 base::FilePath test_path = temp_dir_.path();
37 base::FilePath lock_file_path = 37 base::FilePath lock_file_path =
38 test_path.Append(FirefoxProfileLock::kLockFileName); 38 test_path.Append(FirefoxProfileLock::kLockFileName);
39 39
40 scoped_ptr<FirefoxProfileLock> lock; 40 scoped_ptr<FirefoxProfileLock> lock;
41 EXPECT_EQ(static_cast<FirefoxProfileLock*>(NULL), lock.get()); 41 EXPECT_EQ(static_cast<FirefoxProfileLock*>(NULL), lock.get());
42 EXPECT_FALSE(file_util::PathExists(lock_file_path)); 42 EXPECT_FALSE(base::PathExists(lock_file_path));
43 lock.reset(new FirefoxProfileLock(test_path)); 43 lock.reset(new FirefoxProfileLock(test_path));
44 EXPECT_TRUE(lock->HasAcquired()); 44 EXPECT_TRUE(lock->HasAcquired());
45 EXPECT_TRUE(file_util::PathExists(lock_file_path)); 45 EXPECT_TRUE(base::PathExists(lock_file_path));
46 lock->Unlock(); 46 lock->Unlock();
47 EXPECT_FALSE(lock->HasAcquired()); 47 EXPECT_FALSE(lock->HasAcquired());
48 48
49 // In the posix code, we don't delete the file when releasing the lock. 49 // In the posix code, we don't delete the file when releasing the lock.
50 #if !defined(OS_POSIX) 50 #if !defined(OS_POSIX)
51 EXPECT_FALSE(file_util::PathExists(lock_file_path)); 51 EXPECT_FALSE(base::PathExists(lock_file_path));
52 #endif // !defined(OS_POSIX) 52 #endif // !defined(OS_POSIX)
53 lock->Lock(); 53 lock->Lock();
54 EXPECT_TRUE(lock->HasAcquired()); 54 EXPECT_TRUE(lock->HasAcquired());
55 EXPECT_TRUE(file_util::PathExists(lock_file_path)); 55 EXPECT_TRUE(base::PathExists(lock_file_path));
56 lock->Lock(); 56 lock->Lock();
57 EXPECT_TRUE(lock->HasAcquired()); 57 EXPECT_TRUE(lock->HasAcquired());
58 lock->Unlock(); 58 lock->Unlock();
59 EXPECT_FALSE(lock->HasAcquired()); 59 EXPECT_FALSE(lock->HasAcquired());
60 // In the posix code, we don't delete the file when releasing the lock. 60 // In the posix code, we don't delete the file when releasing the lock.
61 #if !defined(OS_POSIX) 61 #if !defined(OS_POSIX)
62 EXPECT_FALSE(file_util::PathExists(lock_file_path)); 62 EXPECT_FALSE(base::PathExists(lock_file_path));
63 #endif // !defined(OS_POSIX) 63 #endif // !defined(OS_POSIX)
64 } 64 }
65 65
66 // If for some reason the lock file is left behind by the previous owner, we 66 // If for some reason the lock file is left behind by the previous owner, we
67 // should still be able to lock it, at least in the Windows implementation. 67 // should still be able to lock it, at least in the Windows implementation.
68 TEST_F(FirefoxProfileLockTest, ProfileLockOrphaned) { 68 TEST_F(FirefoxProfileLockTest, ProfileLockOrphaned) {
69 base::FilePath test_path = temp_dir_.path(); 69 base::FilePath test_path = temp_dir_.path();
70 base::FilePath lock_file_path = 70 base::FilePath lock_file_path =
71 test_path.Append(FirefoxProfileLock::kLockFileName); 71 test_path.Append(FirefoxProfileLock::kLockFileName);
72 72
73 // Create the orphaned lock file. 73 // Create the orphaned lock file.
74 FILE* lock_file = file_util::OpenFile(lock_file_path, "w"); 74 FILE* lock_file = file_util::OpenFile(lock_file_path, "w");
75 ASSERT_TRUE(lock_file); 75 ASSERT_TRUE(lock_file);
76 file_util::CloseFile(lock_file); 76 file_util::CloseFile(lock_file);
77 EXPECT_TRUE(file_util::PathExists(lock_file_path)); 77 EXPECT_TRUE(base::PathExists(lock_file_path));
78 78
79 scoped_ptr<FirefoxProfileLock> lock; 79 scoped_ptr<FirefoxProfileLock> lock;
80 EXPECT_EQ(static_cast<FirefoxProfileLock*>(NULL), lock.get()); 80 EXPECT_EQ(static_cast<FirefoxProfileLock*>(NULL), lock.get());
81 lock.reset(new FirefoxProfileLock(test_path)); 81 lock.reset(new FirefoxProfileLock(test_path));
82 EXPECT_TRUE(lock->HasAcquired()); 82 EXPECT_TRUE(lock->HasAcquired());
83 lock->Unlock(); 83 lock->Unlock();
84 EXPECT_FALSE(lock->HasAcquired()); 84 EXPECT_FALSE(lock->HasAcquired());
85 } 85 }
86 86
87 // This is broken on POSIX since the same process is allowed to reacquire a 87 // This is broken on POSIX since the same process is allowed to reacquire a
(...skipping 15 matching lines...) Expand all
103 103
104 lock1->Unlock(); 104 lock1->Unlock();
105 EXPECT_FALSE(lock1->HasAcquired()); 105 EXPECT_FALSE(lock1->HasAcquired());
106 106
107 lock2->Lock(); 107 lock2->Lock();
108 EXPECT_TRUE(lock2->HasAcquired()); 108 EXPECT_TRUE(lock2->HasAcquired());
109 lock2->Unlock(); 109 lock2->Unlock();
110 EXPECT_FALSE(lock2->HasAcquired()); 110 EXPECT_FALSE(lock2->HasAcquired());
111 } 111 }
112 #endif 112 #endif
OLDNEW
« no previous file with comments | « chrome/browser/importer/firefox_importer_utils_win.cc ('k') | chrome/browser/importer/safari_importer.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698