| 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/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 const char kError[] = "error"; | 38 const char kError[] = "error"; |
| 39 const char kExtensionId[] = "extension1234"; | 39 const char kExtensionId[] = "extension1234"; |
| 40 const char kMessage[] = "message"; | 40 const char kMessage[] = "message"; |
| 41 const char kSource[] = "source1"; | 41 const char kSource[] = "source1"; |
| 42 const char kSource2[] = "source2"; | 42 const char kSource2[] = "source2"; |
| 43 const char kRouteId[] = "routeId"; | 43 const char kRouteId[] = "routeId"; |
| 44 const char kRouteId2[] = "routeId2"; | 44 const char kRouteId2[] = "routeId2"; |
| 45 const char kSink[] = "sink"; | 45 const char kSink[] = "sink"; |
| 46 const char kSink2[] = "sink2"; | 46 const char kSink2[] = "sink2"; |
| 47 const char kSinkName[] = "sinkName"; | 47 const char kSinkName[] = "sinkName"; |
| 48 const char kPresentationId[] = "presentationId"; |
| 49 const char kOrigin[] = "http://origin/"; |
| 50 const int kTabId = 123; |
| 48 | 51 |
| 49 } // namespace | 52 } // namespace |
| 50 | 53 |
| 51 // Adapts Invoke(), which takes a move-only scoped_ptr parameter (not mockable) | 54 // Adapts Invoke(), which takes a move-only scoped_ptr parameter (not mockable) |
| 52 // to a variant that accepts raw pointers instead (mock friendly). | 55 // to a variant that accepts raw pointers instead (mock friendly). |
| 53 class RouteResponseCallbackHandler { | 56 class RouteResponseCallbackHandler { |
| 54 public: | 57 public: |
| 55 void Invoke(scoped_ptr<MediaRoute> route, const std::string& error_text) { | 58 void Invoke(scoped_ptr<MediaRoute> route, const std::string& error_text) { |
| 56 InvokeObserver(route.get(), error_text); | 59 InvokeObserver(route.get(), error_text); |
| 57 } | 60 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 route->media_sink = interfaces::MediaSink::New(); | 119 route->media_sink = interfaces::MediaSink::New(); |
| 117 route->media_sink->sink_id = kSink; | 120 route->media_sink->sink_id = kSink; |
| 118 route->media_sink->name = kSinkName; | 121 route->media_sink->name = kSinkName; |
| 119 route->media_route_id = kRouteId; | 122 route->media_route_id = kRouteId; |
| 120 route->description = kDescription; | 123 route->description = kDescription; |
| 121 | 124 |
| 122 // Use a lambda function as an invocation target here to work around | 125 // Use a lambda function as an invocation target here to work around |
| 123 // a limitation with GMock::Invoke that prevents it from using move-only types | 126 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 124 // in runnable parameter lists. | 127 // in runnable parameter lists. |
| 125 EXPECT_CALL(mock_mojo_media_router_service_, | 128 EXPECT_CALL(mock_mojo_media_router_service_, |
| 126 CreateRoute(mojo::String(kSource), mojo::String(kSink), _)) | 129 CreateRoute(mojo::String(kSource), mojo::String(kSink), _, |
| 127 .WillOnce(Invoke( | 130 mojo::String(kOrigin), kTabId, _)) |
| 128 [&route](const mojo::String& source, const mojo::String& sink, | 131 .WillOnce(Invoke([&route]( |
| 129 const interfaces::MediaRouter::CreateRouteCallback& cb) { | 132 const mojo::String& source, const mojo::String& sink, |
| 130 cb.Run(route.Pass(), mojo::String()); | 133 const mojo::String& presentation_id, const mojo::String& origin, |
| 131 })); | 134 int tab_id, const interfaces::MediaRouter::CreateRouteCallback& cb) { |
| 135 cb.Run(route.Pass(), mojo::String()); |
| 136 })); |
| 132 | 137 |
| 133 RouteResponseCallbackHandler handler; | 138 RouteResponseCallbackHandler handler; |
| 134 EXPECT_CALL(handler, InvokeObserver(Pointee(Equals(expected_route)), "")); | 139 EXPECT_CALL(handler, InvokeObserver(Pointee(Equals(expected_route)), "")); |
| 135 router()->CreateRoute(kSource, kSink, | 140 router()->CreateRoute(kSource, kSink, GURL(kOrigin), kTabId, |
| 136 base::Bind(&RouteResponseCallbackHandler::Invoke, | 141 base::Bind(&RouteResponseCallbackHandler::Invoke, |
| 137 base::Unretained(&handler))); | 142 base::Unretained(&handler))); |
| 138 ProcessEventLoop(); | 143 ProcessEventLoop(); |
| 139 } | 144 } |
| 140 | 145 |
| 141 TEST_F(MediaRouterMojoImplTest, CreateRouteFails) { | 146 TEST_F(MediaRouterMojoImplTest, CreateRouteFails) { |
| 142 EXPECT_CALL(mock_mojo_media_router_service_, | 147 EXPECT_CALL(mock_mojo_media_router_service_, |
| 143 CreateRoute(mojo::String(kSource), mojo::String(kSink), _)) | 148 CreateRoute(mojo::String(kSource), mojo::String(kSink), _, |
| 144 .WillOnce( | 149 mojo::String(kOrigin), kTabId, _)) |
| 145 Invoke([](const mojo::String& source, const mojo::String& sink, | 150 .WillOnce(Invoke([]( |
| 146 const interfaces::MediaRouter::CreateRouteCallback& cb) { | 151 const mojo::String& source, const mojo::String& sink, |
| 152 const mojo::String& presentation_id, const mojo::String& origin, |
| 153 int tab_id, const interfaces::MediaRouter::CreateRouteCallback& cb) { |
| 154 cb.Run(interfaces::MediaRoutePtr(), mojo::String(kError)); |
| 155 })); |
| 156 |
| 157 RouteResponseCallbackHandler handler; |
| 158 EXPECT_CALL(handler, InvokeObserver(nullptr, kError)); |
| 159 router()->CreateRoute(kSource, kSink, GURL(kOrigin), kTabId, |
| 160 base::Bind(&RouteResponseCallbackHandler::Invoke, |
| 161 base::Unretained(&handler))); |
| 162 ProcessEventLoop(); |
| 163 } |
| 164 |
| 165 TEST_F(MediaRouterMojoImplTest, JoinRoute) { |
| 166 MediaRoute expected_route(kRouteId, MediaSource(std::string(kSource)), |
| 167 MediaSink(kSink, kSinkName), "", false); |
| 168 interfaces::MediaRoutePtr route = interfaces::MediaRoute::New(); |
| 169 route->media_source = kSource; |
| 170 route->media_sink = interfaces::MediaSink::New(); |
| 171 route->media_sink->sink_id = kSink; |
| 172 route->media_sink->name = kSinkName; |
| 173 route->media_route_id = kRouteId; |
| 174 route->description = kDescription; |
| 175 |
| 176 // Use a lambda function as an invocation target here to work around |
| 177 // a limitation with GMock::Invoke that prevents it from using move-only types |
| 178 // in runnable parameter lists. |
| 179 EXPECT_CALL(mock_mojo_media_router_service_, |
| 180 JoinRoute(mojo::String(kSource), mojo::String(kPresentationId), |
| 181 mojo::String(kOrigin), kTabId, _)) |
| 182 .WillOnce(Invoke([&route]( |
| 183 const mojo::String& source, const mojo::String& presentation_id, |
| 184 const mojo::String& origin, int tab_id, |
| 185 const interfaces::MediaRouter::JoinRouteCallback& cb) { |
| 186 cb.Run(route.Pass(), mojo::String()); |
| 187 })); |
| 188 |
| 189 RouteResponseCallbackHandler handler; |
| 190 EXPECT_CALL(handler, InvokeObserver(Pointee(Equals(expected_route)), "")); |
| 191 router()->JoinRoute(kSource, kPresentationId, GURL(kOrigin), kTabId, |
| 192 base::Bind(&RouteResponseCallbackHandler::Invoke, |
| 193 base::Unretained(&handler))); |
| 194 ProcessEventLoop(); |
| 195 } |
| 196 |
| 197 TEST_F(MediaRouterMojoImplTest, JoinRouteFails) { |
| 198 EXPECT_CALL(mock_mojo_media_router_service_, |
| 199 JoinRoute(mojo::String(kSource), mojo::String(kPresentationId), |
| 200 mojo::String(kOrigin), kTabId, _)) |
| 201 .WillOnce(Invoke( |
| 202 [](const mojo::String& source, const mojo::String& presentation_id, |
| 203 const mojo::String& origin, int tab_id, |
| 204 const interfaces::MediaRouter::JoinRouteCallback& cb) { |
| 147 cb.Run(interfaces::MediaRoutePtr(), mojo::String(kError)); | 205 cb.Run(interfaces::MediaRoutePtr(), mojo::String(kError)); |
| 148 })); | 206 })); |
| 149 | 207 |
| 150 RouteResponseCallbackHandler handler; | 208 RouteResponseCallbackHandler handler; |
| 151 EXPECT_CALL(handler, InvokeObserver(nullptr, kError)); | 209 EXPECT_CALL(handler, InvokeObserver(nullptr, kError)); |
| 152 router()->CreateRoute(kSource, kSink, | 210 router()->JoinRoute(kSource, kPresentationId, GURL(kOrigin), kTabId, |
| 153 base::Bind(&RouteResponseCallbackHandler::Invoke, | 211 base::Bind(&RouteResponseCallbackHandler::Invoke, |
| 154 base::Unretained(&handler))); | 212 base::Unretained(&handler))); |
| 155 ProcessEventLoop(); | 213 ProcessEventLoop(); |
| 156 } | 214 } |
| 157 | 215 |
| 158 TEST_F(MediaRouterMojoImplTest, CloseRoute) { | 216 TEST_F(MediaRouterMojoImplTest, CloseRoute) { |
| 159 EXPECT_CALL(mock_mojo_media_router_service_, | 217 EXPECT_CALL(mock_mojo_media_router_service_, |
| 160 CloseRoute(mojo::String(kRouteId))); | 218 CloseRoute(mojo::String(kRouteId))); |
| 161 router()->CloseRoute(kRouteId); | 219 router()->CloseRoute(kRouteId); |
| 162 ProcessEventLoop(); | 220 ProcessEventLoop(); |
| 163 } | 221 } |
| 164 | 222 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 CloseRoute(mojo::String(kRouteId2))); | 445 CloseRoute(mojo::String(kRouteId2))); |
| 388 binding.reset(new mojo::Binding<interfaces::MediaRouter>( | 446 binding.reset(new mojo::Binding<interfaces::MediaRouter>( |
| 389 &mock_mojo_media_router_service, mojo::GetProxy(&mojo_media_router))); | 447 &mock_mojo_media_router_service, mojo::GetProxy(&mojo_media_router))); |
| 390 mojo_media_router_observer->ProvideMediaRouter( | 448 mojo_media_router_observer->ProvideMediaRouter( |
| 391 mojo_media_router.Pass(), base::Bind(&ProvideMediaRouterHandler::Invoke, | 449 mojo_media_router.Pass(), base::Bind(&ProvideMediaRouterHandler::Invoke, |
| 392 base::Unretained(&provide_handler))); | 450 base::Unretained(&provide_handler))); |
| 393 message_loop.RunUntilIdle(); | 451 message_loop.RunUntilIdle(); |
| 394 } | 452 } |
| 395 | 453 |
| 396 } // namespace media_router | 454 } // namespace media_router |
| OLD | NEW |