Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: components/resource_provider/resource_provider_apptest.cc

Issue 1132083003: Makes ResourceLoader own handles and return Files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/resource_provider/public/cpp/resource_loader.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
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()->shell(), paths);
60 loader.BlockUntilLoaded(); 60 loader.BlockUntilLoaded();
61 const ResourceLoader::ResourceMap& resource_loader_results(
62 loader.resource_map());
63 61
64 // Load the contents of each of the handles. 62 // Load the contents of each of the handles.
65 ResourceContentsMap results; 63 ResourceContentsMap results;
66 for (auto& pair : resource_loader_results) { 64 for (auto& path : paths) {
67 base::File file(pair.second); 65 base::File file(loader.ReleaseFile(path));
68 results[pair.first] = ReadFile(&file); 66 results[path] = ReadFile(&file);
69 } 67 }
70 return results; 68 return results;
71 } 69 }
72 70
73 // ApplicationTestBase: 71 // ApplicationTestBase:
74 void SetUp() override { 72 void SetUp() override {
75 ApplicationTestBase::SetUp(); 73 ApplicationTestBase::SetUp();
76 } 74 }
77 75
78 private: 76 private:
(...skipping 11 matching lines...) Expand all
90 GetResources(SetWithStrings("sample", "dir/sample2"))); 88 GetResources(SetWithStrings("sample", "dir/sample2")));
91 ASSERT_TRUE(results.count("sample") > 0u); 89 ASSERT_TRUE(results.count("sample") > 0u);
92 EXPECT_EQ("test data\n", results["sample"]); 90 EXPECT_EQ("test data\n", results["sample"]);
93 91
94 ASSERT_TRUE(results.count("dir/sample2") > 0u); 92 ASSERT_TRUE(results.count("dir/sample2") > 0u);
95 EXPECT_EQ("xxyy\n", results["dir/sample2"]); 93 EXPECT_EQ("xxyy\n", results["dir/sample2"]);
96 } 94 }
97 95
98 } // namespace 96 } // namespace
99 } // namespace resource_provider 97 } // namespace resource_provider
OLDNEW
« no previous file with comments | « components/resource_provider/public/cpp/resource_loader.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698