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

Side by Side Diff: mojo/public/cpp/bindings/tests/pickle_unittest.cc

Issue 1832703002: Mojo: Simplify typemap usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-bindings-variant-import
Patch Set: add missing mash dependency Created 4 years, 8 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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "mojo/public/cpp/bindings/binding_set.h" 12 #include "mojo/public/cpp/bindings/binding_set.h"
13 #include "mojo/public/cpp/bindings/interface_request.h" 13 #include "mojo/public/cpp/bindings/interface_request.h"
14 #include "mojo/public/cpp/bindings/tests/pickled_struct_blink.h" 14 #include "mojo/public/cpp/bindings/tests/pickled_struct_blink.h"
15 #include "mojo/public/cpp/bindings/tests/pickled_struct_chromium.h" 15 #include "mojo/public/cpp/bindings/tests/pickled_struct_chromium.h"
16 #include "mojo/public/cpp/bindings/tests/variant_test_util.h" 16 #include "mojo/public/cpp/bindings/tests/variant_test_util.h"
17 #include "mojo/public/interfaces/bindings/tests/test_native_types.mojom-blink.h" 17 #include "mojo/public/interfaces/bindings/tests/test_native_types.mojom-wtf.h"
18 #include "mojo/public/interfaces/bindings/tests/test_native_types.mojom-chromium .h" 18 #include "mojo/public/interfaces/bindings/tests/test_native_types.mojom.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 20
21 namespace mojo { 21 namespace mojo {
22 namespace test { 22 namespace test {
23 namespace { 23 namespace {
24 24
25 template <typename T> 25 template <typename T>
26 void DoExpectResult(int foo, 26 void DoExpectResult(int foo,
27 int bar, 27 int bar,
28 const base::Closure& callback, 28 const base::Closure& callback,
(...skipping 18 matching lines...) Expand all
47 base::Callback<void(const T&)> Fail(const std::string& reason) { 47 base::Callback<void(const T&)> Fail(const std::string& reason) {
48 return base::Bind(&DoFail<T>, reason); 48 return base::Bind(&DoFail<T>, reason);
49 } 49 }
50 50
51 template <typename T> 51 template <typename T>
52 void ExpectError(InterfacePtr<T>* proxy, const base::Closure& callback) { 52 void ExpectError(InterfacePtr<T>* proxy, const base::Closure& callback) {
53 proxy->set_connection_error_handler(callback); 53 proxy->set_connection_error_handler(callback);
54 } 54 }
55 55
56 // This implements the generated Chromium variant of PicklePasser. 56 // This implements the generated Chromium variant of PicklePasser.
57 class ChromiumPicklePasserImpl : public chromium::PicklePasser { 57 class ChromiumPicklePasserImpl : public PicklePasser {
58 public: 58 public:
59 ChromiumPicklePasserImpl() {} 59 ChromiumPicklePasserImpl() {}
60 60
61 // mojo::test::chromium::PicklePasser: 61 // mojo::test::PicklePasser:
62 void PassPickle(const PickledStructChromium& pickle, 62 void PassPickle(const PickledStructChromium& pickle,
63 const PassPickleCallback& callback) override { 63 const PassPickleCallback& callback) override {
64 callback.Run(pickle); 64 callback.Run(pickle);
65 } 65 }
66 66
67 void PassPickleContainer( 67 void PassPickleContainer(
68 chromium::PickleContainerPtr container, 68 PickleContainerPtr container,
69 const PassPickleContainerCallback& callback) override { 69 const PassPickleContainerCallback& callback) override {
70 callback.Run(std::move(container)); 70 callback.Run(std::move(container));
71 } 71 }
72 72
73 void PassPickles(Array<PickledStructChromium> pickles, 73 void PassPickles(Array<PickledStructChromium> pickles,
74 const PassPicklesCallback& callback) override { 74 const PassPicklesCallback& callback) override {
75 callback.Run(std::move(pickles)); 75 callback.Run(std::move(pickles));
76 } 76 }
77 77
78 void PassPickleArrays(Array<Array<PickledStructChromium>> pickle_arrays, 78 void PassPickleArrays(Array<Array<PickledStructChromium>> pickle_arrays,
79 const PassPickleArraysCallback& callback) override { 79 const PassPickleArraysCallback& callback) override {
80 callback.Run(std::move(pickle_arrays)); 80 callback.Run(std::move(pickle_arrays));
81 } 81 }
82 }; 82 };
83 83
84 // This implements the generated Blink variant of PicklePasser. 84 // This implements the generated Blink variant of PicklePasser.
85 class BlinkPicklePasserImpl : public blink::PicklePasser { 85 class BlinkPicklePasserImpl : public wtf::PicklePasser {
86 public: 86 public:
87 BlinkPicklePasserImpl() {} 87 BlinkPicklePasserImpl() {}
88 88
89 // mojo::test::blink::PicklePasser: 89 // mojo::test::wtf::PicklePasser:
90 void PassPickle(const PickledStructBlink& pickle, 90 void PassPickle(const PickledStructBlink& pickle,
91 const PassPickleCallback& callback) override { 91 const PassPickleCallback& callback) override {
92 callback.Run(pickle); 92 callback.Run(pickle);
93 } 93 }
94 94
95 void PassPickleContainer( 95 void PassPickleContainer(
96 blink::PickleContainerPtr container, 96 wtf::PickleContainerPtr container,
97 const PassPickleContainerCallback& callback) override { 97 const PassPickleContainerCallback& callback) override {
98 callback.Run(std::move(container)); 98 callback.Run(std::move(container));
99 } 99 }
100 100
101 void PassPickles(Array<PickledStructBlink> pickles, 101 void PassPickles(WTFArray<PickledStructBlink> pickles,
102 const PassPicklesCallback& callback) override { 102 const PassPicklesCallback& callback) override {
103 callback.Run(std::move(pickles)); 103 callback.Run(std::move(pickles));
104 } 104 }
105 105
106 void PassPickleArrays(Array<Array<PickledStructBlink>> pickle_arrays, 106 void PassPickleArrays(WTFArray<WTFArray<PickledStructBlink>> pickle_arrays,
107 const PassPickleArraysCallback& callback) override { 107 const PassPickleArraysCallback& callback) override {
108 callback.Run(std::move(pickle_arrays)); 108 callback.Run(std::move(pickle_arrays));
109 } 109 }
110 }; 110 };
111 111
112 // A test which runs both Chromium and Blink implementations of the 112 // A test which runs both Chromium and Blink implementations of the
113 // PicklePasser service. 113 // PicklePasser service.
114 class PickleTest : public testing::Test { 114 class PickleTest : public testing::Test {
115 public: 115 public:
116 PickleTest() {} 116 PickleTest() {}
117 117
118 template <typename ProxyType = chromium::PicklePasser> 118 template <typename ProxyType = PicklePasser>
119 InterfacePtr<ProxyType> ConnectToChromiumService() { 119 InterfacePtr<ProxyType> ConnectToChromiumService() {
120 InterfacePtr<ProxyType> proxy; 120 InterfacePtr<ProxyType> proxy;
121 InterfaceRequest<ProxyType> request = GetProxy(&proxy); 121 InterfaceRequest<ProxyType> request = GetProxy(&proxy);
122 chromium_bindings_.AddBinding( 122 chromium_bindings_.AddBinding(
123 &chromium_service_, 123 &chromium_service_,
124 ConvertInterfaceRequest<chromium::PicklePasser>(std::move(request))); 124 ConvertInterfaceRequest<PicklePasser>(std::move(request)));
125 return proxy; 125 return proxy;
126 } 126 }
127 127
128 template <typename ProxyType = blink::PicklePasser> 128 template <typename ProxyType = wtf::PicklePasser>
129 InterfacePtr<ProxyType> ConnectToBlinkService() { 129 InterfacePtr<ProxyType> ConnectToBlinkService() {
130 InterfacePtr<ProxyType> proxy; 130 InterfacePtr<ProxyType> proxy;
131 InterfaceRequest<ProxyType> request = GetProxy(&proxy); 131 InterfaceRequest<ProxyType> request = GetProxy(&proxy);
132 blink_bindings_.AddBinding( 132 blink_bindings_.AddBinding(
133 &blink_service_, 133 &blink_service_,
134 ConvertInterfaceRequest<blink::PicklePasser>(std::move(request))); 134 ConvertInterfaceRequest<wtf::PicklePasser>(std::move(request)));
135 return proxy; 135 return proxy;
136 } 136 }
137 137
138 private: 138 private:
139 base::MessageLoop loop_; 139 base::MessageLoop loop_;
140 ChromiumPicklePasserImpl chromium_service_; 140 ChromiumPicklePasserImpl chromium_service_;
141 BindingSet<chromium::PicklePasser> chromium_bindings_; 141 BindingSet<PicklePasser> chromium_bindings_;
142 BlinkPicklePasserImpl blink_service_; 142 BlinkPicklePasserImpl blink_service_;
143 BindingSet<blink::PicklePasser> blink_bindings_; 143 BindingSet<wtf::PicklePasser> blink_bindings_;
144 }; 144 };
145 145
146 } // namespace 146 } // namespace
147 147
148 TEST_F(PickleTest, ChromiumProxyToChromiumService) { 148 TEST_F(PickleTest, ChromiumProxyToChromiumService) {
149 auto chromium_proxy = ConnectToChromiumService(); 149 auto chromium_proxy = ConnectToChromiumService();
150 { 150 {
151 base::RunLoop loop; 151 base::RunLoop loop;
152 chromium_proxy->PassPickle( 152 chromium_proxy->PassPickle(
153 PickledStructChromium(1, 2), 153 PickledStructChromium(1, 2),
154 ExpectResult(PickledStructChromium(1, 2), loop.QuitClosure())); 154 ExpectResult(PickledStructChromium(1, 2), loop.QuitClosure()));
155 loop.Run(); 155 loop.Run();
156 } 156 }
157 { 157 {
158 base::RunLoop loop; 158 base::RunLoop loop;
159 chromium_proxy->PassPickle( 159 chromium_proxy->PassPickle(
160 PickledStructChromium(4, 5), 160 PickledStructChromium(4, 5),
161 ExpectResult(PickledStructChromium(4, 5), loop.QuitClosure())); 161 ExpectResult(PickledStructChromium(4, 5), loop.QuitClosure()));
162 loop.Run(); 162 loop.Run();
163 } 163 }
164 } 164 }
165 165
166 TEST_F(PickleTest, ChromiumProxyToBlinkService) { 166 TEST_F(PickleTest, ChromiumProxyToBlinkService) {
167 auto chromium_proxy = ConnectToBlinkService<chromium::PicklePasser>(); 167 auto chromium_proxy = ConnectToBlinkService<PicklePasser>();
168 { 168 {
169 base::RunLoop loop; 169 base::RunLoop loop;
170 chromium_proxy->PassPickle( 170 chromium_proxy->PassPickle(
171 PickledStructChromium(1, 2), 171 PickledStructChromium(1, 2),
172 ExpectResult(PickledStructChromium(1, 2), loop.QuitClosure())); 172 ExpectResult(PickledStructChromium(1, 2), loop.QuitClosure()));
173 loop.Run(); 173 loop.Run();
174 } 174 }
175 { 175 {
176 base::RunLoop loop; 176 base::RunLoop loop;
177 chromium_proxy->PassPickle( 177 chromium_proxy->PassPickle(
(...skipping 18 matching lines...) Expand all
196 { 196 {
197 base::RunLoop loop; 197 base::RunLoop loop;
198 blink_proxy->PassPickle( 198 blink_proxy->PassPickle(
199 PickledStructBlink(1, 1), 199 PickledStructBlink(1, 1),
200 ExpectResult(PickledStructBlink(1, 1), loop.QuitClosure())); 200 ExpectResult(PickledStructBlink(1, 1), loop.QuitClosure()));
201 loop.Run(); 201 loop.Run();
202 } 202 }
203 } 203 }
204 204
205 TEST_F(PickleTest, BlinkProxyToChromiumService) { 205 TEST_F(PickleTest, BlinkProxyToChromiumService) {
206 auto blink_proxy = ConnectToChromiumService<blink::PicklePasser>(); 206 auto blink_proxy = ConnectToChromiumService<wtf::PicklePasser>();
207 { 207 {
208 base::RunLoop loop; 208 base::RunLoop loop;
209 blink_proxy->PassPickle( 209 blink_proxy->PassPickle(
210 PickledStructBlink(1, 1), 210 PickledStructBlink(1, 1),
211 ExpectResult(PickledStructBlink(1, 1), loop.QuitClosure())); 211 ExpectResult(PickledStructBlink(1, 1), loop.QuitClosure()));
212 loop.Run(); 212 loop.Run();
213 } 213 }
214 } 214 }
215 215
216 TEST_F(PickleTest, PickleArray) { 216 TEST_F(PickleTest, PickleArray) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 EXPECT_EQ(8, passed[1][1].bar()); 284 EXPECT_EQ(8, passed[1][1].bar());
285 EXPECT_EQ(0, passed[1][1].baz()); 285 EXPECT_EQ(0, passed[1][1].baz());
286 run_loop.Quit(); 286 run_loop.Quit();
287 }); 287 });
288 run_loop.Run(); 288 run_loop.Run();
289 } 289 }
290 } 290 }
291 291
292 TEST_F(PickleTest, PickleContainer) { 292 TEST_F(PickleTest, PickleContainer) {
293 auto proxy = ConnectToChromiumService(); 293 auto proxy = ConnectToChromiumService();
294 chromium::PickleContainerPtr pickle_container = 294 PickleContainerPtr pickle_container = PickleContainer::New();
295 chromium::PickleContainer::New();
296 pickle_container->pickle.set_foo(42); 295 pickle_container->pickle.set_foo(42);
297 pickle_container->pickle.set_bar(43); 296 pickle_container->pickle.set_bar(43);
298 pickle_container->pickle.set_baz(44); 297 pickle_container->pickle.set_baz(44);
299 { 298 {
300 base::RunLoop run_loop; 299 base::RunLoop run_loop;
301 proxy->PassPickleContainer( 300 proxy->PassPickleContainer(std::move(pickle_container),
302 std::move(pickle_container), 301 [&](PickleContainerPtr passed) {
303 [&](chromium::PickleContainerPtr passed) { 302 ASSERT_FALSE(passed.is_null());
304 ASSERT_FALSE(passed.is_null()); 303 EXPECT_EQ(42, passed->pickle.foo());
305 EXPECT_EQ(42, passed->pickle.foo()); 304 EXPECT_EQ(43, passed->pickle.bar());
306 EXPECT_EQ(43, passed->pickle.bar()); 305 EXPECT_EQ(0, passed->pickle.baz());
307 EXPECT_EQ(0, passed->pickle.baz()); 306 run_loop.Quit();
308 run_loop.Quit(); 307 });
309 });
310 run_loop.Run(); 308 run_loop.Run();
311 } 309 }
312 } 310 }
313 311
314 } // namespace test 312 } // namespace test
315 } // namespace mojo 313 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/chromium_typemaps.gni ('k') | mojo/public/cpp/bindings/tests/rect_blink.typemap » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698