| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/sync_file_system/drive_backend/task_dependency_manager.
h" | 5 #include "chrome/browser/sync_file_system/drive_backend/task_dependency_manager.
h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 #define FPL(path) FILE_PATH_LITERAL(path) | 10 #define FPL(path) FILE_PATH_LITERAL(path) |
| 11 | 11 |
| 12 namespace sync_file_system { | 12 namespace sync_file_system { |
| 13 namespace drive_backend { | 13 namespace drive_backend { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 base::FilePath MakePath(const base::FilePath::StringType& path) { | 17 base::FilePath MakePath(const base::FilePath::StringType& path) { |
| 18 return base::FilePath(path).NormalizePathSeparators(); | 18 return base::FilePath(path).NormalizePathSeparators(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 bool InsertPath(TaskDependencyManager* manager, | 21 bool InsertPath(TaskDependencyManager* manager, |
| 22 const std::string& app_id, | 22 const std::string& app_id, |
| 23 const base::FilePath::StringType& path) { | 23 const base::FilePath::StringType& path) { |
| 24 BlockingFactor blocker; | 24 TaskBlocker blocker; |
| 25 blocker.app_id = app_id; | 25 blocker.app_id = app_id; |
| 26 blocker.paths.push_back(MakePath(path)); | 26 blocker.paths.push_back(MakePath(path)); |
| 27 return manager->Insert(&blocker); | 27 return manager->Insert(&blocker); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void ErasePath(TaskDependencyManager* manager, | 30 void ErasePath(TaskDependencyManager* manager, |
| 31 const std::string& app_id, | 31 const std::string& app_id, |
| 32 const base::FilePath::StringType& path) { | 32 const base::FilePath::StringType& path) { |
| 33 BlockingFactor blocker; | 33 TaskBlocker blocker; |
| 34 blocker.app_id = app_id; | 34 blocker.app_id = app_id; |
| 35 blocker.paths.push_back(MakePath(path)); | 35 blocker.paths.push_back(MakePath(path)); |
| 36 return manager->Erase(&blocker); | 36 return manager->Erase(&blocker); |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool InsertExclusiveTask(TaskDependencyManager* manager) { | 39 bool InsertExclusiveTask(TaskDependencyManager* manager) { |
| 40 BlockingFactor blocker; | 40 TaskBlocker blocker; |
| 41 blocker.exclusive = true; | 41 blocker.exclusive = true; |
| 42 return manager->Insert(&blocker); | 42 return manager->Insert(&blocker); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void EraseExclusiveTask(TaskDependencyManager* manager) { | 45 void EraseExclusiveTask(TaskDependencyManager* manager) { |
| 46 BlockingFactor blocker; | 46 TaskBlocker blocker; |
| 47 blocker.exclusive = true; | 47 blocker.exclusive = true; |
| 48 manager->Erase(&blocker); | 48 manager->Erase(&blocker); |
| 49 } | 49 } |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 TEST(TaskDependencyManagerTest, BasicTest) { | 53 TEST(TaskDependencyManagerTest, BasicTest) { |
| 54 TaskDependencyManager manager; | 54 TaskDependencyManager manager; |
| 55 BlockingFactor blocker; | 55 TaskBlocker blocker; |
| 56 blocker.app_id = "app_id"; | 56 blocker.app_id = "app_id"; |
| 57 blocker.paths.push_back(MakePath(FPL("/folder/file"))); | 57 blocker.paths.push_back(MakePath(FPL("/folder/file"))); |
| 58 blocker.file_ids.push_back("file_id"); | 58 blocker.file_ids.push_back("file_id"); |
| 59 blocker.tracker_ids.push_back(100); | 59 blocker.tracker_ids.push_back(100); |
| 60 | 60 |
| 61 EXPECT_TRUE(manager.Insert(&blocker)); | 61 EXPECT_TRUE(manager.Insert(&blocker)); |
| 62 EXPECT_FALSE(manager.Insert(&blocker)); | 62 EXPECT_FALSE(manager.Insert(&blocker)); |
| 63 | 63 |
| 64 manager.Erase(&blocker); | 64 manager.Erase(&blocker); |
| 65 | 65 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 manager.Erase(NULL); | 118 manager.Erase(NULL); |
| 119 EXPECT_TRUE(InsertExclusiveTask(&manager)); | 119 EXPECT_TRUE(InsertExclusiveTask(&manager)); |
| 120 | 120 |
| 121 EXPECT_FALSE(manager.Insert(NULL)); | 121 EXPECT_FALSE(manager.Insert(NULL)); |
| 122 | 122 |
| 123 EraseExclusiveTask(&manager); | 123 EraseExclusiveTask(&manager); |
| 124 } | 124 } |
| 125 | 125 |
| 126 } // namespace drive_backend | 126 } // namespace drive_backend |
| 127 } // namespace sync_file_system | 127 } // namespace sync_file_system |
| OLD | NEW |