OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/browser_watcher/stability_paths.h" |
| 6 |
| 7 #include "base/files/file_util.h" |
| 8 #include "base/files/scoped_file.h" |
| 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 namespace browser_watcher { |
| 14 |
| 15 TEST(StabilityPathsTest, GetStabilityFiles) { |
| 16 base::ScopedTempDir temp_dir; |
| 17 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 18 |
| 19 // Create files. |
| 20 std::vector<base::FilePath> expected_paths; |
| 21 std::set<base::FilePath> excluded_paths; |
| 22 { |
| 23 // Matches the pattern. |
| 24 base::FilePath path = temp_dir.GetPath().AppendASCII("foo1.pma"); |
| 25 base::ScopedFILE file(base::OpenFile(path, "w")); |
| 26 ASSERT_NE(file.get(), nullptr); |
| 27 expected_paths.push_back(path); |
| 28 |
| 29 // Matches the pattern, but is excluded. |
| 30 path = temp_dir.GetPath().AppendASCII("foo2.pma"); |
| 31 file.reset(base::OpenFile(path, "w")); |
| 32 ASSERT_NE(file.get(), nullptr); |
| 33 ASSERT_TRUE(excluded_paths.insert(path).second); |
| 34 |
| 35 // Matches the pattern. |
| 36 path = temp_dir.GetPath().AppendASCII("foo3.pma"); |
| 37 file.reset(base::OpenFile(path, "w")); |
| 38 ASSERT_NE(file.get(), nullptr); |
| 39 expected_paths.push_back(path); |
| 40 |
| 41 // Does not match the pattern. |
| 42 path = temp_dir.GetPath().AppendASCII("bar.baz"); |
| 43 file.reset(base::OpenFile(path, "w")); |
| 44 ASSERT_NE(file.get(), nullptr); |
| 45 } |
| 46 |
| 47 EXPECT_THAT(GetStabilityFiles(temp_dir.GetPath(), |
| 48 FILE_PATH_LITERAL("foo*.pma"), excluded_paths), |
| 49 testing::UnorderedElementsAreArray(expected_paths)); |
| 50 } |
| 51 |
| 52 } // namespace browser_watcher |
OLD | NEW |