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

Side by Side Diff: chrome/browser/media/cast_remoting_connector_unittest.cc

Issue 2382623003: CastRemotingConnector: Fix wrong assumption about MR route filtering. (Closed)
Patch Set: Tweak variable name. Created 4 years, 2 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
« no previous file with comments | « chrome/browser/media/cast_remoting_connector.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/media/cast_remoting_connector.h" 5 #include "chrome/browser/media/cast_remoting_connector.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 using ::testing::AtLeast; 42 using ::testing::AtLeast;
43 43
44 namespace { 44 namespace {
45 45
46 constexpr char kRemotingMediaSource[] = 46 constexpr char kRemotingMediaSource[] =
47 "urn:x-org.chromium.media:source:tab_content_remoting:123"; 47 "urn:x-org.chromium.media:source:tab_content_remoting:123";
48 constexpr char kRemotingMediaSink[] = "wiggles"; 48 constexpr char kRemotingMediaSink[] = "wiggles";
49 constexpr char kRemotingMediaRoute[] = 49 constexpr char kRemotingMediaRoute[] =
50 "urn:x-org.chromium:media:route:garbly_gook_ssi7m4oa8oma7rasd/cast-wiggles"; 50 "urn:x-org.chromium:media:route:garbly_gook_ssi7m4oa8oma7rasd/cast-wiggles";
51 51
52 constexpr char kTabMirroringMediaSource[] =
53 "urn:x-org.chromium.media:source:tab:123";
54 constexpr char kTabMirroringMediaRoute[] =
55 "urn:x-org.chromium:media:route:bloopity_blop_ohun48i56nh9oid/cast-wiggles";
56
52 // Implements basic functionality of a subset of the MediaRouter for use by the 57 // Implements basic functionality of a subset of the MediaRouter for use by the
53 // unit tests in this module. Note that MockMediaRouter will complain at runtime 58 // unit tests in this module. Note that MockMediaRouter will complain at runtime
54 // if any methods were called that should not have been called. 59 // if any methods were called that should not have been called.
55 class FakeMediaRouter : public media_router::MockMediaRouter { 60 class FakeMediaRouter : public media_router::MockMediaRouter {
56 public: 61 public:
57 FakeMediaRouter() 62 FakeMediaRouter()
58 : routes_observer_(nullptr), message_observer_(nullptr), 63 : routes_observer_(nullptr), message_observer_(nullptr),
59 weak_factory_(this) {} 64 weak_factory_(this) {}
60 ~FakeMediaRouter() final {} 65 ~FakeMediaRouter() final {}
61 66
62 // 67 //
63 // These methods are called by test code to create/destroy a media route and 68 // These methods are called by test code to create/destroy a media route and
64 // pass messages in both directions. 69 // pass messages in both directions.
65 // 70 //
66 71
67 void OnRemotingRouteExists(bool exists) { 72 void OnRemotingRouteExists(bool exists) {
68 routes_.clear(); 73 routes_.clear();
74
75 // Always add a non-remoting route to make sure CastRemotingConnector
76 // ignores non-remoting routes.
77 routes_.push_back(MediaRoute(
78 kTabMirroringMediaRoute, MediaSource(kTabMirroringMediaSource),
79 kRemotingMediaSink, "Cast Tab Mirroring", false, "", false));
80
69 if (exists) { 81 if (exists) {
70 routes_.push_back(MediaRoute( 82 routes_.push_back(MediaRoute(
71 kRemotingMediaRoute, MediaSource(routes_observer_->source_id()), 83 kRemotingMediaRoute, MediaSource(kRemotingMediaSource),
72 kRemotingMediaSink, "Cast Media Remoting", false, "", false)); 84 kRemotingMediaSink, "Cast Media Remoting", false, "", false));
73 } else { 85 } else {
74 // Cancel delivery of all messages in both directions. 86 // Cancel delivery of all messages in both directions.
75 inbound_messages_.clear(); 87 inbound_messages_.clear();
76 for (const auto& entry : outbound_messages_) { 88 for (const auto& entry : outbound_messages_) {
77 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 89 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
78 base::Bind(entry.second, false)); 90 base::Bind(entry.second, false));
79 } 91 }
80 outbound_messages_.clear(); 92 outbound_messages_.clear();
81 } 93 }
94
82 BrowserThread::PostTask( 95 BrowserThread::PostTask(
83 BrowserThread::UI, FROM_HERE, 96 BrowserThread::UI, FROM_HERE,
84 base::Bind(&FakeMediaRouter::DoUpdateRoutes, 97 base::Bind(&FakeMediaRouter::DoUpdateRoutes,
85 weak_factory_.GetWeakPtr())); 98 weak_factory_.GetWeakPtr()));
86 } 99 }
87 100
88 void OnMessageFromProvider(const std::string& message) { 101 void OnMessageFromProvider(const std::string& message) {
89 inbound_messages_.push_back(RouteMessage()); 102 inbound_messages_.push_back(RouteMessage());
90 inbound_messages_.back().type = RouteMessage::TEXT; 103 inbound_messages_.back().type = RouteMessage::TEXT;
91 inbound_messages_.back().text = message; 104 inbound_messages_.back().text = message;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 231
219 private: 232 private:
220 mojo::Binding<media::mojom::RemotingSource> binding_; 233 mojo::Binding<media::mojom::RemotingSource> binding_;
221 }; 234 };
222 235
223 } // namespace 236 } // namespace
224 237
225 class CastRemotingConnectorTest : public ::testing::Test { 238 class CastRemotingConnectorTest : public ::testing::Test {
226 public: 239 public:
227 CastRemotingConnectorTest() 240 CastRemotingConnectorTest()
228 : remoting_source_(kRemotingMediaSource), 241 : connector_(&media_router_, kRemotingMediaSource) {}
229 connector_(&media_router_, remoting_source_.id()) {}
230 242
231 void TearDown() final { 243 void TearDown() final {
232 // Allow any pending Mojo operations to complete before destruction. For 244 // Allow any pending Mojo operations to complete before destruction. For
233 // example, when one end of a Mojo message pipe is closed, a task is posted 245 // example, when one end of a Mojo message pipe is closed, a task is posted
234 // to later destroy objects that were owned by the message pipe. 246 // to later destroy objects that were owned by the message pipe.
235 RunUntilIdle(); 247 RunUntilIdle();
236 } 248 }
237 249
238 protected: 250 protected:
239 RemoterPtr CreateRemoter(MockRemotingSource* source) { 251 RemoterPtr CreateRemoter(MockRemotingSource* source) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 media_router_.OnRemotingRouteExists(false); 321 media_router_.OnRemotingRouteExists(false);
310 } 322 }
311 323
312 static void RunUntilIdle() { 324 static void RunUntilIdle() {
313 base::RunLoop().RunUntilIdle(); 325 base::RunLoop().RunUntilIdle();
314 } 326 }
315 327
316 private: 328 private:
317 content::TestBrowserThreadBundle browser_thread_bundle_; 329 content::TestBrowserThreadBundle browser_thread_bundle_;
318 FakeMediaRouter media_router_; 330 FakeMediaRouter media_router_;
319 const MediaSource remoting_source_;
320 CastRemotingConnector connector_; 331 CastRemotingConnector connector_;
321 }; 332 };
322 333
323 TEST_F(CastRemotingConnectorTest, NeverNotifiesThatSinkIsAvailable) { 334 TEST_F(CastRemotingConnectorTest, NeverNotifiesThatSinkIsAvailable) {
324 MockRemotingSource source; 335 MockRemotingSource source;
325 RemoterPtr remoter = CreateRemoter(&source); 336 RemoterPtr remoter = CreateRemoter(&source);
326 337
327 EXPECT_CALL(source, OnSinkAvailable()).Times(0); 338 EXPECT_CALL(source, OnSinkAvailable()).Times(0);
328 EXPECT_CALL(source, OnSinkGone()).Times(AtLeast(0)); 339 EXPECT_CALL(source, OnSinkGone()).Times(AtLeast(0));
329 RunUntilIdle(); 340 RunUntilIdle();
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 break; 598 break;
588 } 599 }
589 } 600 }
590 } 601 }
591 602
592 INSTANTIATE_TEST_CASE_P(, CastRemotingConnectorFullSessionTest, 603 INSTANTIATE_TEST_CASE_P(, CastRemotingConnectorFullSessionTest,
593 ::testing::Values(SOURCE_TERMINATES, 604 ::testing::Values(SOURCE_TERMINATES,
594 MOJO_PIPE_CLOSES, 605 MOJO_PIPE_CLOSES,
595 ROUTE_TERMINATES, 606 ROUTE_TERMINATES,
596 EXTERNAL_FAILURE)); 607 EXTERNAL_FAILURE));
OLDNEW
« no previous file with comments | « chrome/browser/media/cast_remoting_connector.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698