| 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 <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-wtf.h" | 17 #include "mojo/public/interfaces/bindings/tests/test_native_types.mojom-blink.h" |
| 18 #include "mojo/public/interfaces/bindings/tests/test_native_types.mojom.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, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 wtf::PicklePasser { | 85 class BlinkPicklePasserImpl : public blink::PicklePasser { |
| 86 public: | 86 public: |
| 87 BlinkPicklePasserImpl() {} | 87 BlinkPicklePasserImpl() {} |
| 88 | 88 |
| 89 // mojo::test::wtf::PicklePasser: | 89 // mojo::test::blink::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 wtf::PickleContainerPtr container, | 96 blink::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(WTFArray<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(WTFArray<WTFArray<PickledStructBlink>> pickle_arrays, | 106 void PassPickleArrays(WTFArray<WTFArray<PickledStructBlink>> pickle_arrays, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 118 template <typename ProxyType = 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<PicklePasser>(std::move(request))); | 124 ConvertInterfaceRequest<PicklePasser>(std::move(request))); |
| 125 return proxy; | 125 return proxy; |
| 126 } | 126 } |
| 127 | 127 |
| 128 template <typename ProxyType = wtf::PicklePasser> | 128 template <typename ProxyType = blink::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<wtf::PicklePasser>(std::move(request))); | 134 ConvertInterfaceRequest<blink::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<PicklePasser> chromium_bindings_; | 141 BindingSet<PicklePasser> chromium_bindings_; |
| 142 BlinkPicklePasserImpl blink_service_; | 142 BlinkPicklePasserImpl blink_service_; |
| 143 BindingSet<wtf::PicklePasser> blink_bindings_; | 143 BindingSet<blink::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), |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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<wtf::PicklePasser>(); | 206 auto blink_proxy = ConnectToChromiumService<blink::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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 EXPECT_EQ(43, passed->pickle.bar()); | 304 EXPECT_EQ(43, passed->pickle.bar()); |
| 305 EXPECT_EQ(0, passed->pickle.baz()); | 305 EXPECT_EQ(0, passed->pickle.baz()); |
| 306 run_loop.Quit(); | 306 run_loop.Quit(); |
| 307 }); | 307 }); |
| 308 run_loop.Run(); | 308 run_loop.Run(); |
| 309 } | 309 } |
| 310 } | 310 } |
| 311 | 311 |
| 312 } // namespace test | 312 } // namespace test |
| 313 } // namespace mojo | 313 } // namespace mojo |
| OLD | NEW |