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

Side by Side Diff: chrome/browser/media/router/media_router_mojo_impl_unittest.cc

Issue 1173753003: [Media Router] Implement JoinRoute + update CreateRoute API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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/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
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 route->media_sink = interfaces::MediaSink::New(); 114 route->media_sink = interfaces::MediaSink::New();
112 route->media_sink->sink_id = kSink; 115 route->media_sink->sink_id = kSink;
113 route->media_sink->name = kSinkName; 116 route->media_sink->name = kSinkName;
114 route->media_route_id = kRouteId; 117 route->media_route_id = kRouteId;
115 route->description = kDescription; 118 route->description = kDescription;
116 119
117 // Use a lambda function as an invocation target here to work around 120 // Use a lambda function as an invocation target here to work around
118 // a limitation with GMock::Invoke that prevents it from using move-only types 121 // a limitation with GMock::Invoke that prevents it from using move-only types
119 // in runnable parameter lists. 122 // in runnable parameter lists.
120 EXPECT_CALL(mock_mojo_media_router_service_, 123 EXPECT_CALL(mock_mojo_media_router_service_,
121 CreateRoute(mojo::String(kSource), mojo::String(kSink), _)) 124 CreateRoute(mojo::String(kSource), mojo::String(kSink), _,
122 .WillOnce(Invoke( 125 mojo::String(kOrigin), kTabId, _))
123 [&route](const mojo::String& source, const mojo::String& sink, 126 .WillOnce(Invoke([&route](
124 const interfaces::MediaRouter::CreateRouteCallback& cb) { 127 const mojo::String& source, const mojo::String& sink,
125 cb.Run(route.Pass(), mojo::String()); 128 const mojo::String& presentation_id, const mojo::String& origin,
126 })); 129 int tab_id, const interfaces::MediaRouter::CreateRouteCallback& cb) {
130 cb.Run(route.Pass(), mojo::String());
131 }));
127 132
128 RouteResponseCallbackHandler handler; 133 RouteResponseCallbackHandler handler;
129 EXPECT_CALL(handler, InvokeObserver(Pointee(Equals(expected_route)), "")); 134 EXPECT_CALL(handler, InvokeObserver(Pointee(Equals(expected_route)), ""));
130 router()->CreateRoute(kSource, kSink, 135 router()->CreateRoute(kSource, kSink, GURL(kOrigin), kTabId,
131 base::Bind(&RouteResponseCallbackHandler::Invoke, 136 base::Bind(&RouteResponseCallbackHandler::Invoke,
132 base::Unretained(&handler))); 137 base::Unretained(&handler)));
133 ProcessEventLoop(); 138 ProcessEventLoop();
134 } 139 }
135 140
136 TEST_F(MediaRouterMojoImplTest, CreateRouteFails) { 141 TEST_F(MediaRouterMojoImplTest, CreateRouteFails) {
137 EXPECT_CALL(mock_mojo_media_router_service_, 142 EXPECT_CALL(mock_mojo_media_router_service_,
138 CreateRoute(mojo::String(kSource), mojo::String(kSink), _)) 143 CreateRoute(mojo::String(kSource), mojo::String(kSink), _,
139 .WillOnce( 144 mojo::String(kOrigin), kTabId, _))
140 Invoke([](const mojo::String& source, const mojo::String& sink, 145 .WillOnce(Invoke([](
141 const interfaces::MediaRouter::CreateRouteCallback& cb) { 146 const mojo::String& source, const mojo::String& sink,
147 const mojo::String& presentation_id, const mojo::String& origin,
148 int tab_id, const interfaces::MediaRouter::CreateRouteCallback& cb) {
149 cb.Run(interfaces::MediaRoutePtr(), mojo::String(kError));
150 }));
151
152 RouteResponseCallbackHandler handler;
153 EXPECT_CALL(handler, InvokeObserver(nullptr, kError));
154 router()->CreateRoute(kSource, kSink, GURL(kOrigin), kTabId,
155 base::Bind(&RouteResponseCallbackHandler::Invoke,
156 base::Unretained(&handler)));
157 ProcessEventLoop();
158 }
159
160 TEST_F(MediaRouterMojoImplTest, JoinRoute) {
161 MediaRoute expected_route(kRouteId, MediaSource(std::string(kSource)),
162 MediaSink(kSink, kSinkName), "", false);
163 interfaces::MediaRoutePtr route = interfaces::MediaRoute::New();
164 route->media_source = kSource;
165 route->media_sink = interfaces::MediaSink::New();
166 route->media_sink->sink_id = kSink;
167 route->media_sink->name = kSinkName;
168 route->media_route_id = kRouteId;
169 route->description = kDescription;
170
171 // Use a lambda function as an invocation target here to work around
172 // a limitation with GMock::Invoke that prevents it from using move-only types
173 // in runnable parameter lists.
174 EXPECT_CALL(mock_mojo_media_router_service_,
175 JoinRoute(mojo::String(kSource), mojo::String(kPresentationId),
176 mojo::String(kOrigin), kTabId, _))
177 .WillOnce(Invoke([&route](
178 const mojo::String& source, const mojo::String& presentation_id,
179 const mojo::String& origin, int tab_id,
180 const interfaces::MediaRouter::JoinRouteCallback& cb) {
181 cb.Run(route.Pass(), mojo::String());
182 }));
183
184 RouteResponseCallbackHandler handler;
185 EXPECT_CALL(handler, InvokeObserver(Pointee(Equals(expected_route)), ""));
186 router()->JoinRoute(kSource, kPresentationId, GURL(kOrigin), kTabId,
187 base::Bind(&RouteResponseCallbackHandler::Invoke,
188 base::Unretained(&handler)));
189 ProcessEventLoop();
190 }
191
192 TEST_F(MediaRouterMojoImplTest, JoinRouteFails) {
193 EXPECT_CALL(mock_mojo_media_router_service_,
194 JoinRoute(mojo::String(kSource), mojo::String(kPresentationId),
195 mojo::String(kOrigin), kTabId, _))
196 .WillOnce(Invoke(
197 [](const mojo::String& source, const mojo::String& presentation_id,
198 const mojo::String& origin, int tab_id,
199 const interfaces::MediaRouter::JoinRouteCallback& cb) {
142 cb.Run(interfaces::MediaRoutePtr(), mojo::String(kError)); 200 cb.Run(interfaces::MediaRoutePtr(), mojo::String(kError));
143 })); 201 }));
144 202
145 RouteResponseCallbackHandler handler; 203 RouteResponseCallbackHandler handler;
146 EXPECT_CALL(handler, InvokeObserver(nullptr, kError)); 204 EXPECT_CALL(handler, InvokeObserver(nullptr, kError));
147 router()->CreateRoute(kSource, kSink, 205 router()->JoinRoute(kSource, kPresentationId, GURL(kOrigin), kTabId,
148 base::Bind(&RouteResponseCallbackHandler::Invoke, 206 base::Bind(&RouteResponseCallbackHandler::Invoke,
149 base::Unretained(&handler))); 207 base::Unretained(&handler)));
150 ProcessEventLoop(); 208 ProcessEventLoop();
151 } 209 }
152 210
153 TEST_F(MediaRouterMojoImplTest, CloseRoute) { 211 TEST_F(MediaRouterMojoImplTest, CloseRoute) {
154 EXPECT_CALL(mock_mojo_media_router_service_, 212 EXPECT_CALL(mock_mojo_media_router_service_,
155 CloseRoute(mojo::String(kRouteId))); 213 CloseRoute(mojo::String(kRouteId)));
156 router()->CloseRoute(kRouteId); 214 router()->CloseRoute(kRouteId);
157 ProcessEventLoop(); 215 ProcessEventLoop();
158 } 216 }
159 217
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 CloseRoute(mojo::String(kRouteId2))); 429 CloseRoute(mojo::String(kRouteId2)));
372 binding.reset(new mojo::Binding<interfaces::MediaRouter>( 430 binding.reset(new mojo::Binding<interfaces::MediaRouter>(
373 &mock_mojo_media_router_service, mojo::GetProxy(&mojo_media_router))); 431 &mock_mojo_media_router_service, mojo::GetProxy(&mojo_media_router)));
374 mojo_media_router_observer->ProvideMediaRouter( 432 mojo_media_router_observer->ProvideMediaRouter(
375 mojo_media_router.Pass(), base::Bind(&ProvideMediaRouterHandler::Invoke, 433 mojo_media_router.Pass(), base::Bind(&ProvideMediaRouterHandler::Invoke,
376 base::Unretained(&provide_handler))); 434 base::Unretained(&provide_handler)));
377 message_loop.RunUntilIdle(); 435 message_loop.RunUntilIdle();
378 } 436 }
379 437
380 } // namespace media_router 438 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698