OLD | NEW |
---|---|
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 | 5 |
6 #include "base/file_util.h" | 6 #include "base/file_util.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/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/memory/scoped_temp_dir.h" | |
10 #include "build/build_config.h" | 11 #include "build/build_config.h" |
11 #include "chrome/browser/importer/firefox_profile_lock.h" | 12 #include "chrome/browser/importer/firefox_profile_lock.h" |
12 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
13 #include "chrome/test/file_test_utils.h" | 14 #include "chrome/test/file_test_utils.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 class FirefoxProfileLockTest : public testing::Test { | 17 class FirefoxProfileLockTest : public testing::Test { |
17 public: | 18 public: |
Paweł Hajdan Jr.
2011/04/08 15:58:17
nit: Can this "public:" bit be removed?
Mike West
2011/04/11 14:47:04
Done.
| |
18 protected: | 19 protected: |
19 virtual void SetUp() { | 20 virtual void SetUp() { |
20 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_path_)); | 21 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
21 FilePath::StringType dir_name = FILE_PATH_LITERAL("FirefoxProfileLockTest"); | |
22 dir_name.append(StringPrintf( | |
23 FILE_PATH_LITERAL("-%d"), base::GetCurrentProcId())); | |
24 test_path_ = test_path_.Append(dir_name); | |
25 file_util::Delete(test_path_, true); | |
26 file_util::CreateDirectory(test_path_); | |
27 } | 22 } |
28 | 23 |
29 virtual void TearDown() { | 24 virtual void TearDown() { |
Paweł Hajdan Jr.
2011/04/08 15:58:17
An empty TearDown can just be removed.
Mike West
2011/04/11 14:47:04
Done.
| |
30 ASSERT_TRUE(file_util::Delete(test_path_, true)); | |
31 ASSERT_FALSE(file_util::PathExists(test_path_)); | |
32 } | 25 } |
33 | 26 |
34 FilePath test_path_; | 27 ScopedTempDir temp_dir_; |
35 }; | 28 }; |
36 | 29 |
37 TEST_F(FirefoxProfileLockTest, LockTest) { | 30 TEST_F(FirefoxProfileLockTest, LockTest) { |
38 FirefoxProfileLock lock1(test_path_); | 31 FirefoxProfileLock lock1(temp_dir_.path()); |
39 ASSERT_TRUE(lock1.HasAcquired()); | 32 ASSERT_TRUE(lock1.HasAcquired()); |
40 lock1.Unlock(); | 33 lock1.Unlock(); |
41 ASSERT_FALSE(lock1.HasAcquired()); | 34 ASSERT_FALSE(lock1.HasAcquired()); |
42 lock1.Lock(); | 35 lock1.Lock(); |
43 ASSERT_TRUE(lock1.HasAcquired()); | 36 ASSERT_TRUE(lock1.HasAcquired()); |
44 } | 37 } |
45 | 38 |
46 // Tests basic functionality and verifies that the lock file is deleted after | 39 // Tests basic functionality and verifies that the lock file is deleted after |
47 // use. | 40 // use. |
48 TEST_F(FirefoxProfileLockTest, ProfileLock) { | 41 TEST_F(FirefoxProfileLockTest, ProfileLock) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 | 118 |
126 lock1->Unlock(); | 119 lock1->Unlock(); |
127 EXPECT_FALSE(lock1->HasAcquired()); | 120 EXPECT_FALSE(lock1->HasAcquired()); |
128 | 121 |
129 lock2->Lock(); | 122 lock2->Lock(); |
130 EXPECT_TRUE(lock2->HasAcquired()); | 123 EXPECT_TRUE(lock2->HasAcquired()); |
131 lock2->Unlock(); | 124 lock2->Unlock(); |
132 EXPECT_FALSE(lock2->HasAcquired()); | 125 EXPECT_FALSE(lock2->HasAcquired()); |
133 } | 126 } |
134 #endif | 127 #endif |
OLD | NEW |