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