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

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

Issue 1674903003: Extract shell methods from ApplicationImpl into a base class, and pass this to Initialize() instead. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojom
Patch Set: . Created 4 years, 10 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
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/containers/scoped_ptr_hash_map.h" 8 #include "base/containers/scoped_ptr_hash_map.h"
9 #include "base/files/file.h" 9 #include "base/files/file.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "components/resource_provider/public/cpp/resource_loader.h" 12 #include "components/resource_provider/public/cpp/resource_loader.h"
13 #include "components/resource_provider/public/interfaces/resource_provider.mojom .h" 13 #include "components/resource_provider/public/interfaces/resource_provider.mojom .h"
14 #include "mojo/common/common_type_converters.h" 14 #include "mojo/common/common_type_converters.h"
15 #include "mojo/platform_handle/platform_handle_functions.h" 15 #include "mojo/platform_handle/platform_handle_functions.h"
16 #include "mojo/public/cpp/bindings/array.h" 16 #include "mojo/public/cpp/bindings/array.h"
17 #include "mojo/public/cpp/system/macros.h" 17 #include "mojo/public/cpp/system/macros.h"
18 #include "mojo/shell/public/cpp/application_delegate.h" 18 #include "mojo/shell/public/cpp/application_delegate.h"
19 #include "mojo/shell/public/cpp/application_impl.h"
20 #include "mojo/shell/public/cpp/application_test_base.h" 19 #include "mojo/shell/public/cpp/application_test_base.h"
21 #include "mojo/shell/public/cpp/service_provider_impl.h" 20 #include "mojo/shell/public/cpp/service_provider_impl.h"
22 21
23 namespace resource_provider { 22 namespace resource_provider {
24 namespace { 23 namespace {
25 24
26 std::string ReadFile(base::File* file) { 25 std::string ReadFile(base::File* file) {
27 const size_t kBufferSize = 1 << 16; 26 const size_t kBufferSize = 1 << 16;
28 scoped_ptr<char[]> buffer(new char[kBufferSize]); 27 scoped_ptr<char[]> buffer(new char[kBufferSize]);
29 const int read = file->ReadAtCurrentPos(buffer.get(), kBufferSize); 28 const int read = file->ReadAtCurrentPos(buffer.get(), kBufferSize);
(...skipping 21 matching lines...) Expand all
51 ResourceProviderApplicationTest() {} 50 ResourceProviderApplicationTest() {}
52 ~ResourceProviderApplicationTest() override {} 51 ~ResourceProviderApplicationTest() override {}
53 52
54 protected: 53 protected:
55 using ResourceContentsMap = std::map<std::string, std::string>; 54 using ResourceContentsMap = std::map<std::string, std::string>;
56 55
57 // Queries ResourceProvider for the specified resources, blocking until the 56 // Queries ResourceProvider for the specified resources, blocking until the
58 // resources are returned. The return map maps from the path to the contents 57 // resources are returned. The return map maps from the path to the contents
59 // of the file at the specified path. 58 // of the file at the specified path.
60 ResourceContentsMap GetResources(const std::set<std::string>& paths) { 59 ResourceContentsMap GetResources(const std::set<std::string>& paths) {
61 ResourceLoader loader(application_impl(), paths); 60 ResourceLoader loader(shell(), paths);
62 loader.BlockUntilLoaded(); 61 loader.BlockUntilLoaded();
63 62
64 // Load the contents of each of the handles. 63 // Load the contents of each of the handles.
65 ResourceContentsMap results; 64 ResourceContentsMap results;
66 for (auto& path : paths) { 65 for (auto& path : paths) {
67 base::File file(loader.ReleaseFile(path)); 66 base::File file(loader.ReleaseFile(path));
68 results[path] = ReadFile(&file); 67 results[path] = ReadFile(&file);
69 } 68 }
70 return results; 69 return results;
71 } 70 }
(...skipping 18 matching lines...) Expand all
90 GetResources(SetWithStrings("sample", "dir/sample2"))); 89 GetResources(SetWithStrings("sample", "dir/sample2")));
91 ASSERT_TRUE(results.count("sample") > 0u); 90 ASSERT_TRUE(results.count("sample") > 0u);
92 EXPECT_EQ("test data\n", results["sample"]); 91 EXPECT_EQ("test data\n", results["sample"]);
93 92
94 ASSERT_TRUE(results.count("dir/sample2") > 0u); 93 ASSERT_TRUE(results.count("dir/sample2") > 0u);
95 EXPECT_EQ("xxyy\n", results["dir/sample2"]); 94 EXPECT_EQ("xxyy\n", results["dir/sample2"]);
96 } 95 }
97 96
98 } // namespace 97 } // namespace
99 } // namespace resource_provider 98 } // namespace resource_provider
OLDNEW
« no previous file with comments | « components/resource_provider/resource_provider_app.cc ('k') | components/web_view/frame_apptest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698