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