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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/containers/hash_tables.h" | 6 #include "base/containers/hash_tables.h" |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "chrome/browser/media/router/media_sinks_observer.h" | 10 #include "chrome/browser/media/router/media_sinks_observer.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 } // namespace | 35 } // namespace |
36 | 36 |
37 class QueryResultManagerTest : public ::testing::Test { | 37 class QueryResultManagerTest : public ::testing::Test { |
38 public: | 38 public: |
39 QueryResultManagerTest() | 39 QueryResultManagerTest() |
40 : mock_router_(), query_result_manager_(&mock_router_) { | 40 : mock_router_(), query_result_manager_(&mock_router_) { |
41 } | 41 } |
42 | 42 |
43 void DiscoverSinks(MediaCastMode cast_mode, const MediaSource& source) { | 43 void DiscoverSinks(MediaCastMode cast_mode, const MediaSource& source) { |
44 EXPECT_CALL(mock_router_, RegisterMediaSinksObserver(_)) | 44 EXPECT_CALL(mock_router_, RegisterMediaSinksObserver(_)).Times(1); |
45 .WillOnce(Return(true)); | |
46 EXPECT_CALL(mock_observer_, OnResultsUpdated(_)).Times(1); | 45 EXPECT_CALL(mock_observer_, OnResultsUpdated(_)).Times(1); |
47 query_result_manager_.StartSinksQuery(cast_mode, source); | 46 query_result_manager_.StartSinksQuery(cast_mode, source); |
48 } | 47 } |
49 | 48 |
50 MockMediaRouter mock_router_; | 49 MockMediaRouter mock_router_; |
51 QueryResultManager query_result_manager_; | 50 QueryResultManager query_result_manager_; |
52 MockObserver mock_observer_; | 51 MockObserver mock_observer_; |
53 | 52 |
54 private: | 53 private: |
55 DISALLOW_COPY_AND_ASSIGN(QueryResultManagerTest); | 54 DISALLOW_COPY_AND_ASSIGN(QueryResultManagerTest); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 TEST_F(QueryResultManagerTest, StartStopSinksQuery) { | 87 TEST_F(QueryResultManagerTest, StartStopSinksQuery) { |
89 CastModeSet cast_modes; | 88 CastModeSet cast_modes; |
90 | 89 |
91 query_result_manager_.GetSupportedCastModes(&cast_modes); | 90 query_result_manager_.GetSupportedCastModes(&cast_modes); |
92 EXPECT_TRUE(cast_modes.empty()); | 91 EXPECT_TRUE(cast_modes.empty()); |
93 MediaSource actual_source = | 92 MediaSource actual_source = |
94 query_result_manager_.GetSourceForCastMode(MediaCastMode::DEFAULT); | 93 query_result_manager_.GetSourceForCastMode(MediaCastMode::DEFAULT); |
95 EXPECT_TRUE(actual_source.Empty()); | 94 EXPECT_TRUE(actual_source.Empty()); |
96 | 95 |
97 MediaSource source(ForPresentationUrl("http://fooUrl")); | 96 MediaSource source(ForPresentationUrl("http://fooUrl")); |
98 EXPECT_CALL(mock_router_, RegisterMediaSinksObserver(_)) | 97 EXPECT_CALL(mock_router_, RegisterMediaSinksObserver(_)).Times(1); |
99 .WillOnce(Return(true)); | |
100 query_result_manager_.StartSinksQuery(MediaCastMode::DEFAULT, source); | 98 query_result_manager_.StartSinksQuery(MediaCastMode::DEFAULT, source); |
101 | 99 |
102 query_result_manager_.GetSupportedCastModes(&cast_modes); | 100 query_result_manager_.GetSupportedCastModes(&cast_modes); |
103 EXPECT_EQ(1u, cast_modes.size()); | 101 EXPECT_EQ(1u, cast_modes.size()); |
104 EXPECT_TRUE(ContainsKey(cast_modes, MediaCastMode::DEFAULT)); | 102 EXPECT_TRUE(ContainsKey(cast_modes, MediaCastMode::DEFAULT)); |
105 actual_source = query_result_manager_.GetSourceForCastMode( | 103 actual_source = query_result_manager_.GetSourceForCastMode( |
106 MediaCastMode::DEFAULT); | 104 MediaCastMode::DEFAULT); |
107 EXPECT_TRUE(source.Equals(actual_source)); | 105 EXPECT_TRUE(source.Equals(actual_source)); |
108 | 106 |
109 // Register a different source for the same cast mode. | 107 // Register a different source for the same cast mode. |
110 MediaSource another_source(ForPresentationUrl("http://barUrl")); | 108 MediaSource another_source(ForPresentationUrl("http://barUrl")); |
111 EXPECT_CALL(mock_router_, UnregisterMediaSinksObserver(_)).Times(1); | 109 EXPECT_CALL(mock_router_, UnregisterMediaSinksObserver(_)).Times(1); |
112 EXPECT_CALL(mock_router_, RegisterMediaSinksObserver(_)) | 110 EXPECT_CALL(mock_router_, RegisterMediaSinksObserver(_)).Times(1); |
113 .WillOnce(Return(true)); | |
114 query_result_manager_.StartSinksQuery( | 111 query_result_manager_.StartSinksQuery( |
115 MediaCastMode::DEFAULT, another_source); | 112 MediaCastMode::DEFAULT, another_source); |
116 | 113 |
117 query_result_manager_.GetSupportedCastModes(&cast_modes); | 114 query_result_manager_.GetSupportedCastModes(&cast_modes); |
118 EXPECT_EQ(1u, cast_modes.size()); | 115 EXPECT_EQ(1u, cast_modes.size()); |
119 EXPECT_TRUE(ContainsKey(cast_modes, MediaCastMode::DEFAULT)); | 116 EXPECT_TRUE(ContainsKey(cast_modes, MediaCastMode::DEFAULT)); |
120 actual_source = query_result_manager_.GetSourceForCastMode( | 117 actual_source = query_result_manager_.GetSourceForCastMode( |
121 MediaCastMode::DEFAULT); | 118 MediaCastMode::DEFAULT); |
122 EXPECT_TRUE(another_source.Equals(actual_source)); | 119 EXPECT_TRUE(another_source.Equals(actual_source)); |
123 | 120 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 // Sinks: [2 -> {TAB_MIRROR}, 3 -> {TAB_MIRROR}, 4 -> {TAB_MIRROR}] | 197 // Sinks: [2 -> {TAB_MIRROR}, 3 -> {TAB_MIRROR}, 4 -> {TAB_MIRROR}] |
201 expected_sinks.clear(); | 198 expected_sinks.clear(); |
202 expected_sinks.push_back(MediaSinkWithCastModes(sink2)); | 199 expected_sinks.push_back(MediaSinkWithCastModes(sink2)); |
203 expected_sinks.back().cast_modes.insert(MediaCastMode::TAB_MIRROR); | 200 expected_sinks.back().cast_modes.insert(MediaCastMode::TAB_MIRROR); |
204 expected_sinks.push_back(MediaSinkWithCastModes(sink3)); | 201 expected_sinks.push_back(MediaSinkWithCastModes(sink3)); |
205 expected_sinks.back().cast_modes.insert(MediaCastMode::TAB_MIRROR); | 202 expected_sinks.back().cast_modes.insert(MediaCastMode::TAB_MIRROR); |
206 expected_sinks.push_back(MediaSinkWithCastModes(sink4)); | 203 expected_sinks.push_back(MediaSinkWithCastModes(sink4)); |
207 expected_sinks.back().cast_modes.insert(MediaCastMode::TAB_MIRROR); | 204 expected_sinks.back().cast_modes.insert(MediaCastMode::TAB_MIRROR); |
208 | 205 |
209 EXPECT_CALL(mock_router_, UnregisterMediaSinksObserver(_)).Times(1); | 206 EXPECT_CALL(mock_router_, UnregisterMediaSinksObserver(_)).Times(1); |
210 EXPECT_CALL(mock_router_, RegisterMediaSinksObserver(_)) | 207 EXPECT_CALL(mock_router_, RegisterMediaSinksObserver(_)).Times(1); |
211 .WillOnce(Return(true)); | |
212 EXPECT_CALL(mock_observer_, | 208 EXPECT_CALL(mock_observer_, |
213 OnResultsUpdated(VectorEquals(expected_sinks))).Times(1); | 209 OnResultsUpdated(VectorEquals(expected_sinks))).Times(1); |
214 query_result_manager_.StartSinksQuery( | 210 query_result_manager_.StartSinksQuery( |
215 MediaCastMode::DEFAULT, | 211 MediaCastMode::DEFAULT, |
216 ForPresentationUrl("http://bazurl.com")); | 212 ForPresentationUrl("http://bazurl.com")); |
217 | 213 |
218 // Action: Remove TAB_MIRROR observer | 214 // Action: Remove TAB_MIRROR observer |
219 // Expected result: | 215 // Expected result: |
220 // Sinks: [] | 216 // Sinks: [] |
221 expected_sinks.clear(); | 217 expected_sinks.clear(); |
222 EXPECT_CALL(mock_observer_, | 218 EXPECT_CALL(mock_observer_, |
223 OnResultsUpdated(VectorEquals(expected_sinks))).Times(1); | 219 OnResultsUpdated(VectorEquals(expected_sinks))).Times(1); |
224 EXPECT_CALL(mock_router_, UnregisterMediaSinksObserver(_)).Times(1); | 220 EXPECT_CALL(mock_router_, UnregisterMediaSinksObserver(_)).Times(1); |
225 query_result_manager_.StopSinksQuery(MediaCastMode::TAB_MIRROR); | 221 query_result_manager_.StopSinksQuery(MediaCastMode::TAB_MIRROR); |
226 | 222 |
227 // Remaining observers: DEFAULT observer, which will be removed on destruction | 223 // Remaining observers: DEFAULT observer, which will be removed on destruction |
228 EXPECT_CALL(mock_router_, UnregisterMediaSinksObserver(_)).Times(1); | 224 EXPECT_CALL(mock_router_, UnregisterMediaSinksObserver(_)).Times(1); |
229 } | 225 } |
230 | 226 |
231 } // namespace media_router | 227 } // namespace media_router |
OLD | NEW |