OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/containers/scoped_ptr_hash_map.h" | 7 #include "base/containers/scoped_ptr_hash_map.h" |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "components/resource_provider/public/cpp/resource_loader.h" | 10 #include "components/resource_provider/public/cpp/resource_loader.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 ResourceProviderApplicationTest() {} | 49 ResourceProviderApplicationTest() {} |
50 ~ResourceProviderApplicationTest() override {} | 50 ~ResourceProviderApplicationTest() override {} |
51 | 51 |
52 protected: | 52 protected: |
53 using ResourceContentsMap = std::map<std::string, std::string>; | 53 using ResourceContentsMap = std::map<std::string, std::string>; |
54 | 54 |
55 // Queries ResourceProvider for the specified resources, blocking until the | 55 // Queries ResourceProvider for the specified resources, blocking until the |
56 // resources are returned. The return map maps from the path to the contents | 56 // resources are returned. The return map maps from the path to the contents |
57 // of the file at the specified path. | 57 // of the file at the specified path. |
58 ResourceContentsMap GetResources(const std::set<std::string>& paths) { | 58 ResourceContentsMap GetResources(const std::set<std::string>& paths) { |
59 ResourceLoader loader(application_impl()->shell(), paths); | 59 ResourceLoader loader(application_impl(), paths); |
60 loader.BlockUntilLoaded(); | 60 loader.BlockUntilLoaded(); |
61 | 61 |
62 // Load the contents of each of the handles. | 62 // Load the contents of each of the handles. |
63 ResourceContentsMap results; | 63 ResourceContentsMap results; |
64 for (auto& path : paths) { | 64 for (auto& path : paths) { |
65 base::File file(loader.ReleaseFile(path)); | 65 base::File file(loader.ReleaseFile(path)); |
66 results[path] = ReadFile(&file); | 66 results[path] = ReadFile(&file); |
67 } | 67 } |
68 return results; | 68 return results; |
69 } | 69 } |
(...skipping 18 matching lines...) Expand all Loading... |
88 GetResources(SetWithStrings("sample", "dir/sample2"))); | 88 GetResources(SetWithStrings("sample", "dir/sample2"))); |
89 ASSERT_TRUE(results.count("sample") > 0u); | 89 ASSERT_TRUE(results.count("sample") > 0u); |
90 EXPECT_EQ("test data\n", results["sample"]); | 90 EXPECT_EQ("test data\n", results["sample"]); |
91 | 91 |
92 ASSERT_TRUE(results.count("dir/sample2") > 0u); | 92 ASSERT_TRUE(results.count("dir/sample2") > 0u); |
93 EXPECT_EQ("xxyy\n", results["dir/sample2"]); | 93 EXPECT_EQ("xxyy\n", results["dir/sample2"]); |
94 } | 94 } |
95 | 95 |
96 } // namespace | 96 } // namespace |
97 } // namespace resource_provider | 97 } // namespace resource_provider |
OLD | NEW |