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

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

Issue 1551503002: Convert Pass()→std::move() in //chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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
8 #include <string> 7 #include <string>
8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
16 #include "base/test/histogram_tester.h" 16 #include "base/test/histogram_tester.h"
17 #include "base/thread_task_runner_handle.h" 17 #include "base/thread_task_runner_handle.h"
18 #include "chrome/browser/media/router/issue.h" 18 #include "chrome/browser/media/router/issue.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 mojoIssue->title = title; 80 mojoIssue->title = title;
81 mojoIssue->message = "msg"; 81 mojoIssue->message = "msg";
82 mojoIssue->route_id = ""; 82 mojoIssue->route_id = "";
83 mojoIssue->default_action = 83 mojoIssue->default_action =
84 interfaces::Issue::ActionType::ACTION_TYPE_DISMISS; 84 interfaces::Issue::ActionType::ACTION_TYPE_DISMISS;
85 mojoIssue->secondary_actions = 85 mojoIssue->secondary_actions =
86 mojo::Array<interfaces::Issue::ActionType>::New(0); 86 mojo::Array<interfaces::Issue::ActionType>::New(0);
87 mojoIssue->severity = interfaces::Issue::Severity::SEVERITY_WARNING; 87 mojoIssue->severity = interfaces::Issue::Severity::SEVERITY_WARNING;
88 mojoIssue->is_blocking = false; 88 mojoIssue->is_blocking = false;
89 mojoIssue->help_url = ""; 89 mojoIssue->help_url = "";
90 return mojoIssue.Pass(); 90 return mojoIssue;
91 } 91 }
92 92
93 } // namespace 93 } // namespace
94 94
95 class RouteResponseCallbackHandler { 95 class RouteResponseCallbackHandler {
96 public: 96 public:
97 MOCK_METHOD3(Invoke, 97 MOCK_METHOD3(Invoke,
98 void(const MediaRoute* route, 98 void(const MediaRoute* route,
99 const std::string& presentation_id, 99 const std::string& presentation_id,
100 const std::string& error_text)); 100 const std::string& error_text));
101 }; 101 };
102 102
103 class SendMessageCallbackHandler { 103 class SendMessageCallbackHandler {
104 public: 104 public:
105 MOCK_METHOD1(Invoke, void(bool)); 105 MOCK_METHOD1(Invoke, void(bool));
106 }; 106 };
107 107
108 class ListenForMessagesCallbackHandler { 108 class ListenForMessagesCallbackHandler {
109 public: 109 public:
110 ListenForMessagesCallbackHandler( 110 ListenForMessagesCallbackHandler(
111 ScopedVector<content::PresentationSessionMessage> expected_messages, 111 ScopedVector<content::PresentationSessionMessage> expected_messages,
112 bool pass_ownership) 112 bool pass_ownership)
113 : expected_messages_(expected_messages.Pass()), 113 : expected_messages_(std::move(expected_messages)),
114 pass_ownership_(pass_ownership) {} 114 pass_ownership_(pass_ownership) {}
115 void Invoke(const ScopedVector<content::PresentationSessionMessage>& messages, 115 void Invoke(const ScopedVector<content::PresentationSessionMessage>& messages,
116 bool pass_ownership) { 116 bool pass_ownership) {
117 InvokeObserver(); 117 InvokeObserver();
118 EXPECT_EQ(pass_ownership_, pass_ownership); 118 EXPECT_EQ(pass_ownership_, pass_ownership);
119 EXPECT_EQ(messages.size(), expected_messages_.size()); 119 EXPECT_EQ(messages.size(), expected_messages_.size());
120 for (size_t i = 0; i < expected_messages_.size(); ++i) { 120 for (size_t i = 0; i < expected_messages_.size(); ++i) {
121 EXPECT_TRUE(ArePresentationSessionMessagesEqual(expected_messages_[i], 121 EXPECT_TRUE(ArePresentationSessionMessagesEqual(expected_messages_[i],
122 messages[i])); 122 messages[i]));
123 } 123 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // a limitation with GMock::Invoke that prevents it from using move-only types 188 // a limitation with GMock::Invoke that prevents it from using move-only types
189 // in runnable parameter lists. 189 // in runnable parameter lists.
190 EXPECT_CALL(mock_media_route_provider_, 190 EXPECT_CALL(mock_media_route_provider_,
191 CreateRoute(mojo::String(kSource), mojo::String(kSinkId), _, 191 CreateRoute(mojo::String(kSource), mojo::String(kSinkId), _,
192 mojo::String(kOrigin), kInvalidTabId, _)) 192 mojo::String(kOrigin), kInvalidTabId, _))
193 .WillOnce(Invoke([&route]( 193 .WillOnce(Invoke([&route](
194 const mojo::String& source, const mojo::String& sink, 194 const mojo::String& source, const mojo::String& sink,
195 const mojo::String& presentation_id, const mojo::String& origin, 195 const mojo::String& presentation_id, const mojo::String& origin,
196 int tab_id, 196 int tab_id,
197 const interfaces::MediaRouteProvider::CreateRouteCallback& cb) { 197 const interfaces::MediaRouteProvider::CreateRouteCallback& cb) {
198 cb.Run(route.Pass(), mojo::String()); 198 cb.Run(std::move(route), mojo::String());
199 })); 199 }));
200 200
201 // MediaRouterMojoImpl will start observing local displayable routes as a 201 // MediaRouterMojoImpl will start observing local displayable routes as a
202 // result of having one created. 202 // result of having one created.
203 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaRoutes()); 203 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaRoutes());
204 204
205 RouteResponseCallbackHandler handler; 205 RouteResponseCallbackHandler handler;
206 EXPECT_CALL(handler, Invoke(Pointee(Equals(expected_route)), Not(""), "")); 206 EXPECT_CALL(handler, Invoke(Pointee(Equals(expected_route)), Not(""), ""));
207 std::vector<MediaRouteResponseCallback> route_response_callbacks; 207 std::vector<MediaRouteResponseCallback> route_response_callbacks;
208 route_response_callbacks.push_back(base::Bind( 208 route_response_callbacks.push_back(base::Bind(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 // Use a lambda function as an invocation target here to work around 248 // Use a lambda function as an invocation target here to work around
249 // a limitation with GMock::Invoke that prevents it from using move-only types 249 // a limitation with GMock::Invoke that prevents it from using move-only types
250 // in runnable parameter lists. 250 // in runnable parameter lists.
251 EXPECT_CALL(mock_media_route_provider_, 251 EXPECT_CALL(mock_media_route_provider_,
252 JoinRoute(mojo::String(kSource), mojo::String(kPresentationId), 252 JoinRoute(mojo::String(kSource), mojo::String(kPresentationId),
253 mojo::String(kOrigin), kInvalidTabId, _)) 253 mojo::String(kOrigin), kInvalidTabId, _))
254 .WillOnce(Invoke([&route]( 254 .WillOnce(Invoke([&route](
255 const mojo::String& source, const mojo::String& presentation_id, 255 const mojo::String& source, const mojo::String& presentation_id,
256 const mojo::String& origin, int tab_id, 256 const mojo::String& origin, int tab_id,
257 const interfaces::MediaRouteProvider::JoinRouteCallback& cb) { 257 const interfaces::MediaRouteProvider::JoinRouteCallback& cb) {
258 cb.Run(route.Pass(), mojo::String()); 258 cb.Run(std::move(route), mojo::String());
259 })); 259 }));
260 260
261 // MediaRouterMojoImpl will start observing local displayable routes as a 261 // MediaRouterMojoImpl will start observing local displayable routes as a
262 // result of having one created. 262 // result of having one created.
263 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaRoutes()); 263 EXPECT_CALL(mock_media_route_provider_, StartObservingMediaRoutes());
264 264
265 RouteResponseCallbackHandler handler; 265 RouteResponseCallbackHandler handler;
266 EXPECT_CALL(handler, Invoke(Pointee(Equals(expected_route)), Not(""), "")); 266 EXPECT_CALL(handler, Invoke(Pointee(Equals(expected_route)), Not(""), ""));
267 std::vector<MediaRouteResponseCallback> route_response_callbacks; 267 std::vector<MediaRouteResponseCallback> route_response_callbacks;
268 route_response_callbacks.push_back(base::Bind( 268 route_response_callbacks.push_back(base::Bind(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 314
315 interfaces::IssuePtr mojo_issue1 = CreateMojoIssue("title 1"); 315 interfaces::IssuePtr mojo_issue1 = CreateMojoIssue("title 1");
316 const Issue& expected_issue1 = mojo_issue1.To<Issue>(); 316 const Issue& expected_issue1 = mojo_issue1.To<Issue>();
317 317
318 const Issue* issue; 318 const Issue* issue;
319 EXPECT_CALL(issue_observer1, 319 EXPECT_CALL(issue_observer1,
320 OnIssueUpdated(Pointee(EqualsIssue(expected_issue1)))) 320 OnIssueUpdated(Pointee(EqualsIssue(expected_issue1))))
321 .WillOnce(SaveArg<0>(&issue)); 321 .WillOnce(SaveArg<0>(&issue));
322 EXPECT_CALL(issue_observer2, 322 EXPECT_CALL(issue_observer2,
323 OnIssueUpdated(Pointee(EqualsIssue(expected_issue1)))); 323 OnIssueUpdated(Pointee(EqualsIssue(expected_issue1))));
324 media_router_proxy_->OnIssue(mojo_issue1.Pass()); 324 media_router_proxy_->OnIssue(std::move(mojo_issue1));
325 ProcessEventLoop(); 325 ProcessEventLoop();
326 326
327 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1)); 327 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1));
328 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); 328 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2));
329 329
330 EXPECT_CALL(issue_observer1, OnIssueUpdated(nullptr)); 330 EXPECT_CALL(issue_observer1, OnIssueUpdated(nullptr));
331 EXPECT_CALL(issue_observer2, OnIssueUpdated(nullptr)); 331 EXPECT_CALL(issue_observer2, OnIssueUpdated(nullptr));
332 332
333 router()->ClearIssue(issue->id()); 333 router()->ClearIssue(issue->id());
334 334
335 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1)); 335 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1));
336 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); 336 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2));
337 router()->UnregisterIssuesObserver(&issue_observer1); 337 router()->UnregisterIssuesObserver(&issue_observer1);
338 interfaces::IssuePtr mojo_issue2 = CreateMojoIssue("title 2"); 338 interfaces::IssuePtr mojo_issue2 = CreateMojoIssue("title 2");
339 const Issue& expected_issue2 = mojo_issue2.To<Issue>(); 339 const Issue& expected_issue2 = mojo_issue2.To<Issue>();
340 340
341 EXPECT_CALL(issue_observer2, 341 EXPECT_CALL(issue_observer2,
342 OnIssueUpdated(Pointee(EqualsIssue(expected_issue2)))); 342 OnIssueUpdated(Pointee(EqualsIssue(expected_issue2))));
343 router()->AddIssue(expected_issue2); 343 router()->AddIssue(expected_issue2);
344 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); 344 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2));
345 345
346 EXPECT_CALL(issue_observer2, OnIssueUpdated(nullptr)); 346 EXPECT_CALL(issue_observer2, OnIssueUpdated(nullptr));
347 router()->ClearIssue(issue->id()); 347 router()->ClearIssue(issue->id());
348 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); 348 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2));
349 349
350 EXPECT_CALL(issue_observer2, 350 EXPECT_CALL(issue_observer2,
351 OnIssueUpdated(Pointee(EqualsIssue(expected_issue2)))); 351 OnIssueUpdated(Pointee(EqualsIssue(expected_issue2))));
352 media_router_proxy_->OnIssue(mojo_issue2.Pass()); 352 media_router_proxy_->OnIssue(std::move(mojo_issue2));
353 ProcessEventLoop(); 353 ProcessEventLoop();
354 354
355 issue_observer1.UnregisterObserver(); 355 issue_observer1.UnregisterObserver();
356 issue_observer2.UnregisterObserver(); 356 issue_observer2.UnregisterObserver();
357 } 357 }
358 358
359 TEST_F(MediaRouterMojoImplTest, RegisterAndUnregisterMediaSinksObserver) { 359 TEST_F(MediaRouterMojoImplTest, RegisterAndUnregisterMediaSinksObserver) {
360 router()->OnSinkAvailabilityUpdated( 360 router()->OnSinkAvailabilityUpdated(
361 interfaces::MediaRouter::SINK_AVAILABILITY_AVAILABLE); 361 interfaces::MediaRouter::SINK_AVAILABILITY_AVAILABLE);
362 MediaSource media_source(kSource); 362 MediaSource media_source(kSource);
(...skipping 28 matching lines...) Expand all
391 media_router::interfaces::MediaSink::IconType::ICON_TYPE_CAST; 391 media_router::interfaces::MediaSink::IconType::ICON_TYPE_CAST;
392 mojo_sinks[1] = interfaces::MediaSink::New(); 392 mojo_sinks[1] = interfaces::MediaSink::New();
393 mojo_sinks[1]->sink_id = kSinkId2; 393 mojo_sinks[1]->sink_id = kSinkId2;
394 mojo_sinks[1]->name = kSinkName; 394 mojo_sinks[1]->name = kSinkName;
395 mojo_sinks[1]->icon_type = 395 mojo_sinks[1]->icon_type =
396 media_router::interfaces::MediaSink::IconType::ICON_TYPE_CAST; 396 media_router::interfaces::MediaSink::IconType::ICON_TYPE_CAST;
397 397
398 EXPECT_CALL(sinks_observer, OnSinksReceived(SequenceEquals(expected_sinks))); 398 EXPECT_CALL(sinks_observer, OnSinksReceived(SequenceEquals(expected_sinks)));
399 EXPECT_CALL(extra_sinks_observer, 399 EXPECT_CALL(extra_sinks_observer,
400 OnSinksReceived(SequenceEquals(expected_sinks))); 400 OnSinksReceived(SequenceEquals(expected_sinks)));
401 media_router_proxy_->OnSinksReceived(media_source.id(), mojo_sinks.Pass()); 401 media_router_proxy_->OnSinksReceived(media_source.id(),
402 std::move(mojo_sinks));
402 ProcessEventLoop(); 403 ProcessEventLoop();
403 404
404 EXPECT_CALL(mock_media_route_provider_, 405 EXPECT_CALL(mock_media_route_provider_,
405 StopObservingMediaSinks(mojo::String(kSource))); 406 StopObservingMediaSinks(mojo::String(kSource)));
406 EXPECT_CALL(mock_media_route_provider_, 407 EXPECT_CALL(mock_media_route_provider_,
407 StopObservingMediaSinks(mojo::String(kSource2))); 408 StopObservingMediaSinks(mojo::String(kSource2)));
408 router()->UnregisterMediaSinksObserver(&sinks_observer); 409 router()->UnregisterMediaSinksObserver(&sinks_observer);
409 router()->UnregisterMediaSinksObserver(&extra_sinks_observer); 410 router()->UnregisterMediaSinksObserver(&extra_sinks_observer);
410 router()->UnregisterMediaSinksObserver(&unrelated_sinks_observer); 411 router()->UnregisterMediaSinksObserver(&unrelated_sinks_observer);
411 ProcessEventLoop(); 412 ProcessEventLoop();
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 mojo_routes[1]->media_route_id = kRouteId2; 541 mojo_routes[1]->media_route_id = kRouteId2;
541 mojo_routes[1]->media_source = kSource; 542 mojo_routes[1]->media_source = kSource;
542 mojo_routes[1]->media_sink_id = kSinkId; 543 mojo_routes[1]->media_sink_id = kSinkId;
543 mojo_routes[1]->description = kDescription; 544 mojo_routes[1]->description = kDescription;
544 mojo_routes[1]->is_local = false; 545 mojo_routes[1]->is_local = false;
545 546
546 EXPECT_CALL(routes_observer, 547 EXPECT_CALL(routes_observer,
547 OnRoutesUpdated(SequenceEquals(expected_routes))); 548 OnRoutesUpdated(SequenceEquals(expected_routes)));
548 EXPECT_CALL(extra_routes_observer, 549 EXPECT_CALL(extra_routes_observer,
549 OnRoutesUpdated(SequenceEquals(expected_routes))); 550 OnRoutesUpdated(SequenceEquals(expected_routes)));
550 media_router_proxy_->OnRoutesUpdated(mojo_routes.Pass()); 551 media_router_proxy_->OnRoutesUpdated(std::move(mojo_routes));
551 ProcessEventLoop(); 552 ProcessEventLoop();
552 553
553 EXPECT_CALL(mock_router, UnregisterMediaRoutesObserver(&routes_observer)); 554 EXPECT_CALL(mock_router, UnregisterMediaRoutesObserver(&routes_observer));
554 EXPECT_CALL(mock_router, 555 EXPECT_CALL(mock_router,
555 UnregisterMediaRoutesObserver(&extra_routes_observer)); 556 UnregisterMediaRoutesObserver(&extra_routes_observer));
556 router()->UnregisterMediaRoutesObserver(&routes_observer); 557 router()->UnregisterMediaRoutesObserver(&routes_observer);
557 router()->UnregisterMediaRoutesObserver(&extra_routes_observer); 558 router()->UnregisterMediaRoutesObserver(&extra_routes_observer);
558 EXPECT_CALL(mock_media_route_provider_, StopObservingMediaRoutes()); 559 EXPECT_CALL(mock_media_route_provider_, StopObservingMediaRoutes());
559 ProcessEventLoop(); 560 ProcessEventLoop();
560 } 561 }
(...skipping 27 matching lines...) Expand all
588 const MediaRoute::Id& route_id, const std::vector<uint8_t>& data, 589 const MediaRoute::Id& route_id, const std::vector<uint8_t>& data,
589 const interfaces::MediaRouteProvider::SendRouteMessageCallback& cb) { 590 const interfaces::MediaRouteProvider::SendRouteMessageCallback& cb) {
590 EXPECT_EQ( 591 EXPECT_EQ(
591 0, memcmp(kBinaryMessage, &(data[0]), arraysize(kBinaryMessage))); 592 0, memcmp(kBinaryMessage, &(data[0]), arraysize(kBinaryMessage)));
592 cb.Run(true); 593 cb.Run(true);
593 })); 594 }));
594 595
595 SendMessageCallbackHandler handler; 596 SendMessageCallbackHandler handler;
596 EXPECT_CALL(handler, Invoke(true)); 597 EXPECT_CALL(handler, Invoke(true));
597 router()->SendRouteBinaryMessage( 598 router()->SendRouteBinaryMessage(
598 kRouteId, expected_binary_data.Pass(), 599 kRouteId, std::move(expected_binary_data),
599 base::Bind(&SendMessageCallbackHandler::Invoke, 600 base::Bind(&SendMessageCallbackHandler::Invoke,
600 base::Unretained(&handler))); 601 base::Unretained(&handler)));
601 ProcessEventLoop(); 602 ProcessEventLoop();
602 } 603 }
603 604
604 TEST_F(MediaRouterMojoImplTest, PresentationSessionMessagesSingleObserver) { 605 TEST_F(MediaRouterMojoImplTest, PresentationSessionMessagesSingleObserver) {
605 mojo::Array<interfaces::RouteMessagePtr> mojo_messages(2); 606 mojo::Array<interfaces::RouteMessagePtr> mojo_messages(2);
606 mojo_messages[0] = interfaces::RouteMessage::New(); 607 mojo_messages[0] = interfaces::RouteMessage::New();
607 mojo_messages[0]->type = interfaces::RouteMessage::Type::TYPE_TEXT; 608 mojo_messages[0]->type = interfaces::RouteMessage::Type::TYPE_TEXT;
608 mojo_messages[0]->message = "text"; 609 mojo_messages[0]->message = "text";
609 mojo_messages[1] = interfaces::RouteMessage::New(); 610 mojo_messages[1] = interfaces::RouteMessage::New();
610 mojo_messages[1]->type = interfaces::RouteMessage::Type::TYPE_BINARY; 611 mojo_messages[1]->type = interfaces::RouteMessage::Type::TYPE_BINARY;
611 mojo_messages[1]->data.push_back(1); 612 mojo_messages[1]->data.push_back(1);
612 613
613 ScopedVector<content::PresentationSessionMessage> expected_messages; 614 ScopedVector<content::PresentationSessionMessage> expected_messages;
614 scoped_ptr<content::PresentationSessionMessage> message; 615 scoped_ptr<content::PresentationSessionMessage> message;
615 message.reset(new content::PresentationSessionMessage( 616 message.reset(new content::PresentationSessionMessage(
616 content::PresentationMessageType::TEXT)); 617 content::PresentationMessageType::TEXT));
617 message->message = "text"; 618 message->message = "text";
618 expected_messages.push_back(message.Pass()); 619 expected_messages.push_back(std::move(message));
619 620
620 message.reset(new content::PresentationSessionMessage( 621 message.reset(new content::PresentationSessionMessage(
621 content::PresentationMessageType::ARRAY_BUFFER)); 622 content::PresentationMessageType::ARRAY_BUFFER));
622 message->data.reset(new std::vector<uint8_t>(1, 1)); 623 message->data.reset(new std::vector<uint8_t>(1, 1));
623 expected_messages.push_back(message.Pass()); 624 expected_messages.push_back(std::move(message));
624 625
625 MediaRoute::Id expected_route_id("foo"); 626 MediaRoute::Id expected_route_id("foo");
626 interfaces::MediaRouteProvider::ListenForRouteMessagesCallback mojo_callback; 627 interfaces::MediaRouteProvider::ListenForRouteMessagesCallback mojo_callback;
627 EXPECT_CALL(mock_media_route_provider_, 628 EXPECT_CALL(mock_media_route_provider_,
628 ListenForRouteMessages(Eq(expected_route_id), _)) 629 ListenForRouteMessages(Eq(expected_route_id), _))
629 .WillOnce(SaveArg<1>(&mojo_callback)); 630 .WillOnce(SaveArg<1>(&mojo_callback));
630 631
631 // |pass_ownership| param is "true" here because there is only one observer. 632 // |pass_ownership| param is "true" here because there is only one observer.
632 ListenForMessagesCallbackHandler handler(expected_messages.Pass(), true); 633 ListenForMessagesCallbackHandler handler(std::move(expected_messages), true);
633 634
634 EXPECT_CALL(handler, InvokeObserver()); 635 EXPECT_CALL(handler, InvokeObserver());
635 // Creating PresentationSessionMessagesObserver will register itself to the 636 // Creating PresentationSessionMessagesObserver will register itself to the
636 // MediaRouter, which in turn will start listening for route messages. 637 // MediaRouter, which in turn will start listening for route messages.
637 scoped_ptr<PresentationSessionMessagesObserver> observer( 638 scoped_ptr<PresentationSessionMessagesObserver> observer(
638 new PresentationSessionMessagesObserver( 639 new PresentationSessionMessagesObserver(
639 base::Bind(&ListenForMessagesCallbackHandler::Invoke, 640 base::Bind(&ListenForMessagesCallbackHandler::Invoke,
640 base::Unretained(&handler)), 641 base::Unretained(&handler)),
641 expected_route_id, router())); 642 expected_route_id, router()));
642 ProcessEventLoop(); 643 ProcessEventLoop();
643 644
644 // Simulate messages by invoking the saved mojo callback. 645 // Simulate messages by invoking the saved mojo callback.
645 // We expect one more ListenForRouteMessages call since |observer| was 646 // We expect one more ListenForRouteMessages call since |observer| was
646 // still registered when the first set of messages arrived. 647 // still registered when the first set of messages arrived.
647 mojo_callback.Run(mojo_messages.Pass(), false); 648 mojo_callback.Run(std::move(mojo_messages), false);
648 interfaces::MediaRouteProvider::ListenForRouteMessagesCallback 649 interfaces::MediaRouteProvider::ListenForRouteMessagesCallback
649 mojo_callback_2; 650 mojo_callback_2;
650 EXPECT_CALL(mock_media_route_provider_, ListenForRouteMessages(_, _)) 651 EXPECT_CALL(mock_media_route_provider_, ListenForRouteMessages(_, _))
651 .WillOnce(SaveArg<1>(&mojo_callback_2)); 652 .WillOnce(SaveArg<1>(&mojo_callback_2));
652 ProcessEventLoop(); 653 ProcessEventLoop();
653 654
654 // Stop listening for messages. In particular, MediaRouterMojoImpl will not 655 // Stop listening for messages. In particular, MediaRouterMojoImpl will not
655 // call ListenForRouteMessages again when it sees there are no more observers. 656 // call ListenForRouteMessages again when it sees there are no more observers.
656 mojo::Array<interfaces::RouteMessagePtr> mojo_messages_2(1); 657 mojo::Array<interfaces::RouteMessagePtr> mojo_messages_2(1);
657 mojo_messages_2[0] = interfaces::RouteMessage::New(); 658 mojo_messages_2[0] = interfaces::RouteMessage::New();
658 mojo_messages_2[0]->type = interfaces::RouteMessage::Type::TYPE_TEXT; 659 mojo_messages_2[0]->type = interfaces::RouteMessage::Type::TYPE_TEXT;
659 mojo_messages_2[0]->message = "foo"; 660 mojo_messages_2[0]->message = "foo";
660 observer.reset(); 661 observer.reset();
661 mojo_callback_2.Run(mojo_messages_2.Pass(), false); 662 mojo_callback_2.Run(std::move(mojo_messages_2), false);
662 EXPECT_CALL(mock_media_route_provider_, StopListeningForRouteMessages(_)); 663 EXPECT_CALL(mock_media_route_provider_, StopListeningForRouteMessages(_));
663 ProcessEventLoop(); 664 ProcessEventLoop();
664 } 665 }
665 666
666 TEST_F(MediaRouterMojoImplTest, PresentationSessionMessagesMultipleObservers) { 667 TEST_F(MediaRouterMojoImplTest, PresentationSessionMessagesMultipleObservers) {
667 mojo::Array<interfaces::RouteMessagePtr> mojo_messages(2); 668 mojo::Array<interfaces::RouteMessagePtr> mojo_messages(2);
668 mojo_messages[0] = interfaces::RouteMessage::New(); 669 mojo_messages[0] = interfaces::RouteMessage::New();
669 mojo_messages[0]->type = interfaces::RouteMessage::Type::TYPE_TEXT; 670 mojo_messages[0]->type = interfaces::RouteMessage::Type::TYPE_TEXT;
670 mojo_messages[0]->message = "text"; 671 mojo_messages[0]->message = "text";
671 mojo_messages[1] = interfaces::RouteMessage::New(); 672 mojo_messages[1] = interfaces::RouteMessage::New();
672 mojo_messages[1]->type = interfaces::RouteMessage::Type::TYPE_BINARY; 673 mojo_messages[1]->type = interfaces::RouteMessage::Type::TYPE_BINARY;
673 mojo_messages[1]->data.push_back(1); 674 mojo_messages[1]->data.push_back(1);
674 675
675 ScopedVector<content::PresentationSessionMessage> expected_messages; 676 ScopedVector<content::PresentationSessionMessage> expected_messages;
676 scoped_ptr<content::PresentationSessionMessage> message; 677 scoped_ptr<content::PresentationSessionMessage> message;
677 message.reset(new content::PresentationSessionMessage( 678 message.reset(new content::PresentationSessionMessage(
678 content::PresentationMessageType::TEXT)); 679 content::PresentationMessageType::TEXT));
679 message->message = "text"; 680 message->message = "text";
680 expected_messages.push_back(message.Pass()); 681 expected_messages.push_back(std::move(message));
681 682
682 message.reset(new content::PresentationSessionMessage( 683 message.reset(new content::PresentationSessionMessage(
683 content::PresentationMessageType::ARRAY_BUFFER)); 684 content::PresentationMessageType::ARRAY_BUFFER));
684 message->data.reset(new std::vector<uint8_t>(1, 1)); 685 message->data.reset(new std::vector<uint8_t>(1, 1));
685 expected_messages.push_back(message.Pass()); 686 expected_messages.push_back(std::move(message));
686 687
687 MediaRoute::Id expected_route_id("foo"); 688 MediaRoute::Id expected_route_id("foo");
688 interfaces::MediaRouteProvider::ListenForRouteMessagesCallback mojo_callback; 689 interfaces::MediaRouteProvider::ListenForRouteMessagesCallback mojo_callback;
689 EXPECT_CALL(mock_media_route_provider_, 690 EXPECT_CALL(mock_media_route_provider_,
690 ListenForRouteMessages(Eq(expected_route_id), _)) 691 ListenForRouteMessages(Eq(expected_route_id), _))
691 .WillOnce(SaveArg<1>(&mojo_callback)); 692 .WillOnce(SaveArg<1>(&mojo_callback));
692 693
693 // |pass_ownership| param is "false" here because there are more than one 694 // |pass_ownership| param is "false" here because there are more than one
694 // observers. 695 // observers.
695 ListenForMessagesCallbackHandler handler(expected_messages.Pass(), false); 696 ListenForMessagesCallbackHandler handler(std::move(expected_messages), false);
696 697
697 EXPECT_CALL(handler, InvokeObserver()).Times(2); 698 EXPECT_CALL(handler, InvokeObserver()).Times(2);
698 // Creating PresentationSessionMessagesObserver will register itself to the 699 // Creating PresentationSessionMessagesObserver will register itself to the
699 // MediaRouter, which in turn will start listening for route messages. 700 // MediaRouter, which in turn will start listening for route messages.
700 scoped_ptr<PresentationSessionMessagesObserver> observer1( 701 scoped_ptr<PresentationSessionMessagesObserver> observer1(
701 new PresentationSessionMessagesObserver( 702 new PresentationSessionMessagesObserver(
702 base::Bind(&ListenForMessagesCallbackHandler::Invoke, 703 base::Bind(&ListenForMessagesCallbackHandler::Invoke,
703 base::Unretained(&handler)), 704 base::Unretained(&handler)),
704 expected_route_id, router())); 705 expected_route_id, router()));
705 scoped_ptr<PresentationSessionMessagesObserver> observer2( 706 scoped_ptr<PresentationSessionMessagesObserver> observer2(
706 new PresentationSessionMessagesObserver( 707 new PresentationSessionMessagesObserver(
707 base::Bind(&ListenForMessagesCallbackHandler::Invoke, 708 base::Bind(&ListenForMessagesCallbackHandler::Invoke,
708 base::Unretained(&handler)), 709 base::Unretained(&handler)),
709 expected_route_id, router())); 710 expected_route_id, router()));
710 ProcessEventLoop(); 711 ProcessEventLoop();
711 712
712 // Simulate messages by invoking the saved mojo callback. 713 // Simulate messages by invoking the saved mojo callback.
713 // We expect one more ListenForRouteMessages call since |observer| was 714 // We expect one more ListenForRouteMessages call since |observer| was
714 // still registered when the first set of messages arrived. 715 // still registered when the first set of messages arrived.
715 mojo_callback.Run(mojo_messages.Pass(), false); 716 mojo_callback.Run(std::move(mojo_messages), false);
716 interfaces::MediaRouteProvider::ListenForRouteMessagesCallback 717 interfaces::MediaRouteProvider::ListenForRouteMessagesCallback
717 mojo_callback_2; 718 mojo_callback_2;
718 EXPECT_CALL(mock_media_route_provider_, ListenForRouteMessages(_, _)) 719 EXPECT_CALL(mock_media_route_provider_, ListenForRouteMessages(_, _))
719 .WillOnce(SaveArg<1>(&mojo_callback_2)); 720 .WillOnce(SaveArg<1>(&mojo_callback_2));
720 ProcessEventLoop(); 721 ProcessEventLoop();
721 722
722 // Stop listening for messages. In particular, MediaRouterMojoImpl will not 723 // Stop listening for messages. In particular, MediaRouterMojoImpl will not
723 // call ListenForRouteMessages again when it sees there are no more observers. 724 // call ListenForRouteMessages again when it sees there are no more observers.
724 mojo::Array<interfaces::RouteMessagePtr> mojo_messages_2(1); 725 mojo::Array<interfaces::RouteMessagePtr> mojo_messages_2(1);
725 mojo_messages_2[0] = interfaces::RouteMessage::New(); 726 mojo_messages_2[0] = interfaces::RouteMessage::New();
726 mojo_messages_2[0]->type = interfaces::RouteMessage::Type::TYPE_TEXT; 727 mojo_messages_2[0]->type = interfaces::RouteMessage::Type::TYPE_TEXT;
727 mojo_messages_2[0]->message = "foo"; 728 mojo_messages_2[0]->message = "foo";
728 observer1.reset(); 729 observer1.reset();
729 observer2.reset(); 730 observer2.reset();
730 mojo_callback_2.Run(mojo_messages_2.Pass(), false); 731 mojo_callback_2.Run(std::move(mojo_messages_2), false);
731 EXPECT_CALL(mock_media_route_provider_, StopListeningForRouteMessages(_)); 732 EXPECT_CALL(mock_media_route_provider_, StopListeningForRouteMessages(_));
732 ProcessEventLoop(); 733 ProcessEventLoop();
733 } 734 }
734 735
735 TEST_F(MediaRouterMojoImplTest, PresentationSessionMessagesError) { 736 TEST_F(MediaRouterMojoImplTest, PresentationSessionMessagesError) {
736 MediaRoute::Id expected_route_id("foo"); 737 MediaRoute::Id expected_route_id("foo");
737 interfaces::MediaRouteProvider::ListenForRouteMessagesCallback mojo_callback; 738 interfaces::MediaRouteProvider::ListenForRouteMessagesCallback mojo_callback;
738 EXPECT_CALL(mock_media_route_provider_, 739 EXPECT_CALL(mock_media_route_provider_,
739 ListenForRouteMessages(Eq(expected_route_id), _)) 740 ListenForRouteMessages(Eq(expected_route_id), _))
740 .WillOnce(SaveArg<1>(&mojo_callback)); 741 .WillOnce(SaveArg<1>(&mojo_callback));
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 804
804 TEST_F(MediaRouterMojoImplTest, HasLocalRoute) { 805 TEST_F(MediaRouterMojoImplTest, HasLocalRoute) {
805 EXPECT_FALSE(router()->HasLocalDisplayRoute()); 806 EXPECT_FALSE(router()->HasLocalDisplayRoute());
806 interfaces::MediaRoutePtr mojo_route1 = interfaces::MediaRoute::New(); 807 interfaces::MediaRoutePtr mojo_route1 = interfaces::MediaRoute::New();
807 mojo_route1->media_route_id = "routeId1"; 808 mojo_route1->media_route_id = "routeId1";
808 mojo_route1->media_sink_id = "sinkId"; 809 mojo_route1->media_sink_id = "sinkId";
809 mojo_route1->is_local = false; 810 mojo_route1->is_local = false;
810 mojo_route1->for_display = false; 811 mojo_route1->for_display = false;
811 router()->RouteResponseReceived("presentationId1", 812 router()->RouteResponseReceived("presentationId1",
812 std::vector<MediaRouteResponseCallback>(), 813 std::vector<MediaRouteResponseCallback>(),
813 mojo_route1.Pass(), ""); 814 std::move(mojo_route1), "");
814 EXPECT_FALSE(router()->HasLocalDisplayRoute()); 815 EXPECT_FALSE(router()->HasLocalDisplayRoute());
815 816
816 interfaces::MediaRoutePtr mojo_route2 = interfaces::MediaRoute::New(); 817 interfaces::MediaRoutePtr mojo_route2 = interfaces::MediaRoute::New();
817 mojo_route2->media_route_id = "routeId2"; 818 mojo_route2->media_route_id = "routeId2";
818 mojo_route2->media_sink_id = "sinkId"; 819 mojo_route2->media_sink_id = "sinkId";
819 mojo_route2->is_local = false; 820 mojo_route2->is_local = false;
820 mojo_route2->for_display = true; 821 mojo_route2->for_display = true;
821 router()->RouteResponseReceived("presentationId2", 822 router()->RouteResponseReceived("presentationId2",
822 std::vector<MediaRouteResponseCallback>(), 823 std::vector<MediaRouteResponseCallback>(),
823 mojo_route2.Pass(), ""); 824 std::move(mojo_route2), "");
824 EXPECT_FALSE(router()->HasLocalDisplayRoute()); 825 EXPECT_FALSE(router()->HasLocalDisplayRoute());
825 826
826 interfaces::MediaRoutePtr mojo_route3 = interfaces::MediaRoute::New(); 827 interfaces::MediaRoutePtr mojo_route3 = interfaces::MediaRoute::New();
827 mojo_route3->media_route_id = "routeId3"; 828 mojo_route3->media_route_id = "routeId3";
828 mojo_route3->media_sink_id = "sinkId"; 829 mojo_route3->media_sink_id = "sinkId";
829 mojo_route3->is_local = true; 830 mojo_route3->is_local = true;
830 mojo_route3->for_display = false; 831 mojo_route3->for_display = false;
831 router()->RouteResponseReceived("presentationId3", 832 router()->RouteResponseReceived("presentationId3",
832 std::vector<MediaRouteResponseCallback>(), 833 std::vector<MediaRouteResponseCallback>(),
833 mojo_route3.Pass(), ""); 834 std::move(mojo_route3), "");
834 EXPECT_FALSE(router()->HasLocalDisplayRoute()); 835 EXPECT_FALSE(router()->HasLocalDisplayRoute());
835 836
836 interfaces::MediaRoutePtr mojo_route4 = interfaces::MediaRoute::New(); 837 interfaces::MediaRoutePtr mojo_route4 = interfaces::MediaRoute::New();
837 mojo_route4->media_route_id = "routeId4"; 838 mojo_route4->media_route_id = "routeId4";
838 mojo_route4->media_sink_id = "sinkId"; 839 mojo_route4->media_sink_id = "sinkId";
839 mojo_route4->is_local = true; 840 mojo_route4->is_local = true;
840 mojo_route4->for_display = true; 841 mojo_route4->for_display = true;
841 router()->RouteResponseReceived("presentationId4", 842 router()->RouteResponseReceived("presentationId4",
842 std::vector<MediaRouteResponseCallback>(), 843 std::vector<MediaRouteResponseCallback>(),
843 mojo_route4.Pass(), ""); 844 std::move(mojo_route4), "");
844 EXPECT_TRUE(router()->HasLocalDisplayRoute()); 845 EXPECT_TRUE(router()->HasLocalDisplayRoute());
845 } 846 }
846 847
847 TEST_F(MediaRouterMojoImplTest, QueuedWhileAsleep) { 848 TEST_F(MediaRouterMojoImplTest, QueuedWhileAsleep) {
848 EXPECT_CALL(mock_event_page_tracker_, IsEventPageSuspended(extension_id())) 849 EXPECT_CALL(mock_event_page_tracker_, IsEventPageSuspended(extension_id()))
849 .Times(2) 850 .Times(2)
850 .WillRepeatedly(Return(true)); 851 .WillRepeatedly(Return(true));
851 EXPECT_CALL(mock_event_page_tracker_, WakeEventPage(extension_id(), _)) 852 EXPECT_CALL(mock_event_page_tracker_, WakeEventPage(extension_id(), _))
852 .Times(2) 853 .Times(2)
853 .WillRepeatedly(Return(true)); 854 .WillRepeatedly(Return(true));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 } 908 }
908 909
909 void ResetMediaRouteProvider() { 910 void ResetMediaRouteProvider() {
910 binding_.reset(); 911 binding_.reset();
911 media_router_->BindToMojoRequest(mojo::GetProxy(&media_router_proxy_), 912 media_router_->BindToMojoRequest(mojo::GetProxy(&media_router_proxy_),
912 kExtensionId); 913 kExtensionId);
913 } 914 }
914 915
915 void RegisterMediaRouteProvider() { 916 void RegisterMediaRouteProvider() {
916 media_router_proxy_->RegisterMediaRouteProvider( 917 media_router_proxy_->RegisterMediaRouteProvider(
917 media_route_provider_proxy_.Pass(), 918 std::move(media_route_provider_proxy_),
918 base::Bind(&RegisterMediaRouteProviderHandler::Invoke, 919 base::Bind(&RegisterMediaRouteProviderHandler::Invoke,
919 base::Unretained(&provide_handler_))); 920 base::Unretained(&provide_handler_)));
920 } 921 }
921 922
922 void ProcessEventLoop() { 923 void ProcessEventLoop() {
923 message_loop_.RunUntilIdle(); 924 message_loop_.RunUntilIdle();
924 } 925 }
925 926
926 void ExpectWakeReasonBucketCount(MediaRouteProviderWakeReason reason, 927 void ExpectWakeReasonBucketCount(MediaRouteProviderWakeReason reason,
927 int expected_count) { 928 int expected_count) {
928 histogram_tester_.ExpectBucketCount("MediaRouter.Provider.WakeReason", 929 histogram_tester_.ExpectBucketCount("MediaRouter.Provider.WakeReason",
929 static_cast<int>(reason), 930 static_cast<int>(reason),
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))); 1072 EXPECT_CALL(provide_handler_, Invoke(testing::Not("")));
1072 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId)) 1073 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId))
1073 .WillOnce(Return(false)); 1074 .WillOnce(Return(false));
1074 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId2))) 1075 EXPECT_CALL(mock_media_route_provider_, DetachRoute(mojo::String(kRouteId2)))
1075 .Times(kMaxPendingRequests); 1076 .Times(kMaxPendingRequests);
1076 RegisterMediaRouteProvider(); 1077 RegisterMediaRouteProvider();
1077 ProcessEventLoop(); 1078 ProcessEventLoop();
1078 } 1079 }
1079 1080
1080 } // namespace media_router 1081 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698