OLD | NEW |
| (Empty) |
1 // Copyright 2016 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 "chrome/browser/extensions/api/file_handlers/directory_util.h" | |
6 | |
7 #include <memory> | |
8 #include <set> | |
9 #include <string> | |
10 #include <vector> | |
11 | |
12 #include "base/files/file_path.h" | |
13 #include "base/files/file_util.h" | |
14 #include "base/run_loop.h" | |
15 #include "chrome/test/base/testing_profile.h" | |
16 #include "content/public/browser/browser_thread.h" | |
17 #include "content/public/test/test_browser_thread_bundle.h" | |
18 #include "content/public/test/test_utils.h" | |
19 #include "testing/gtest/include/gtest/gtest.h" | |
20 | |
21 namespace extensions { | |
22 namespace app_file_handler_util { | |
23 namespace { | |
24 | |
25 const char kRandomPath[] = "/random/path"; | |
26 | |
27 void OnCollectForEntriesPath( | |
28 std::set<base::FilePath>* output, | |
29 std::unique_ptr<std::set<base::FilePath>> path_directory_set) { | |
30 *output = *path_directory_set; | |
31 } | |
32 | |
33 } // namespace | |
34 | |
35 class IsDirectoryUtilTest : public testing::Test { | |
36 protected: | |
37 IsDirectoryUtilTest() {} | |
38 ~IsDirectoryUtilTest() override {} | |
39 | |
40 void SetUp() override { | |
41 EXPECT_TRUE( | |
42 base::CreateNewTempDirectory(base::FilePath::StringType(), &dir_path_)); | |
43 EXPECT_TRUE(base::CreateTemporaryFile(&file_path_)); | |
44 } | |
45 | |
46 content::TestBrowserThreadBundle thread_bundle_; | |
47 TestingProfile profile_; | |
48 base::FilePath dir_path_; | |
49 base::FilePath file_path_; | |
50 }; | |
51 | |
52 TEST_F(IsDirectoryUtilTest, CollectForEntriesPaths) { | |
53 std::vector<base::FilePath> paths; | |
54 paths.push_back(dir_path_); | |
55 paths.push_back(file_path_); | |
56 paths.push_back(base::FilePath::FromUTF8Unsafe(kRandomPath)); | |
57 | |
58 IsDirectoryCollector collector(&profile_); | |
59 std::set<base::FilePath> result; | |
60 collector.CollectForEntriesPaths( | |
61 paths, base::Bind(&OnCollectForEntriesPath, &result)); | |
62 content::RunAllBlockingPoolTasksUntilIdle(); | |
63 | |
64 ASSERT_EQ(1u, result.size()); | |
65 EXPECT_GT(result.count(dir_path_), 0u); | |
66 } | |
67 | |
68 } // namespace app_file_handler_util | |
69 } // namespace extensions | |
OLD | NEW |