Chromium Code Reviews| 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/macros.h" | 8 #include "base/macros.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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 | 87 |
| 88 TEST_F(QueryResultManagerTest, StartStopSinksQuery) { | 88 TEST_F(QueryResultManagerTest, StartStopSinksQuery) { |
| 89 CastModeSet cast_modes; | 89 CastModeSet cast_modes; |
| 90 | 90 |
| 91 query_result_manager_.GetSupportedCastModes(&cast_modes); | 91 query_result_manager_.GetSupportedCastModes(&cast_modes); |
| 92 EXPECT_TRUE(cast_modes.empty()); | 92 EXPECT_TRUE(cast_modes.empty()); |
| 93 MediaSource actual_source = | 93 MediaSource actual_source = |
| 94 query_result_manager_.GetSourceForCastMode(MediaCastMode::DEFAULT); | 94 query_result_manager_.GetSourceForCastMode(MediaCastMode::DEFAULT); |
| 95 EXPECT_TRUE(actual_source.Empty()); | 95 EXPECT_TRUE(actual_source.Empty()); |
| 96 | 96 |
| 97 MediaSource source(MediaSourceForPresentationUrl("http://fooUrl")); | 97 MediaSource source(MediaSourceForPresentationUrl("http://fooUrl.com", |
| 98 "http://fooUrl.com")); | |
|
mark a. foltz
2016/03/03 22:58:37
url != origin here and below
matt.boetger
2016/03/04 00:22:11
Done.
| |
| 98 EXPECT_CALL(mock_router_, RegisterMediaSinksObserver(_)) | 99 EXPECT_CALL(mock_router_, RegisterMediaSinksObserver(_)) |
| 99 .WillOnce(Return(true)); | 100 .WillOnce(Return(true)); |
| 100 query_result_manager_.StartSinksQuery(MediaCastMode::DEFAULT, source); | 101 query_result_manager_.StartSinksQuery(MediaCastMode::DEFAULT, source); |
| 101 | 102 |
| 102 query_result_manager_.GetSupportedCastModes(&cast_modes); | 103 query_result_manager_.GetSupportedCastModes(&cast_modes); |
| 103 EXPECT_EQ(1u, cast_modes.size()); | 104 EXPECT_EQ(1u, cast_modes.size()); |
| 104 EXPECT_TRUE(ContainsKey(cast_modes, MediaCastMode::DEFAULT)); | 105 EXPECT_TRUE(ContainsKey(cast_modes, MediaCastMode::DEFAULT)); |
| 105 actual_source = query_result_manager_.GetSourceForCastMode( | 106 actual_source = query_result_manager_.GetSourceForCastMode( |
| 106 MediaCastMode::DEFAULT); | 107 MediaCastMode::DEFAULT); |
| 107 EXPECT_TRUE(source.Equals(actual_source)); | 108 EXPECT_TRUE(source.Equals(actual_source)); |
| 108 | 109 |
| 109 // Register a different source for the same cast mode. | 110 // Register a different source for the same cast mode. |
| 110 MediaSource another_source(MediaSourceForPresentationUrl("http://barUrl")); | 111 MediaSource another_source( |
| 112 MediaSourceForPresentationUrl("http://barUrl.com", "http://barUrl.com")); | |
| 111 EXPECT_CALL(mock_router_, UnregisterMediaSinksObserver(_)).Times(1); | 113 EXPECT_CALL(mock_router_, UnregisterMediaSinksObserver(_)).Times(1); |
| 112 EXPECT_CALL(mock_router_, RegisterMediaSinksObserver(_)) | 114 EXPECT_CALL(mock_router_, RegisterMediaSinksObserver(_)) |
| 113 .WillOnce(Return(true)); | 115 .WillOnce(Return(true)); |
| 114 query_result_manager_.StartSinksQuery( | 116 query_result_manager_.StartSinksQuery( |
| 115 MediaCastMode::DEFAULT, another_source); | 117 MediaCastMode::DEFAULT, another_source); |
| 116 | 118 |
| 117 query_result_manager_.GetSupportedCastModes(&cast_modes); | 119 query_result_manager_.GetSupportedCastModes(&cast_modes); |
| 118 EXPECT_EQ(1u, cast_modes.size()); | 120 EXPECT_EQ(1u, cast_modes.size()); |
| 119 EXPECT_TRUE(ContainsKey(cast_modes, MediaCastMode::DEFAULT)); | 121 EXPECT_TRUE(ContainsKey(cast_modes, MediaCastMode::DEFAULT)); |
| 120 actual_source = query_result_manager_.GetSourceForCastMode( | 122 actual_source = query_result_manager_.GetSourceForCastMode( |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 133 | 135 |
| 134 TEST_F(QueryResultManagerTest, MultipleQueries) { | 136 TEST_F(QueryResultManagerTest, MultipleQueries) { |
| 135 MediaSink sink1("sinkId1", "Sink 1", MediaSink::IconType::CAST); | 137 MediaSink sink1("sinkId1", "Sink 1", MediaSink::IconType::CAST); |
| 136 MediaSink sink2("sinkId2", "Sink 2", MediaSink::IconType::CAST); | 138 MediaSink sink2("sinkId2", "Sink 2", MediaSink::IconType::CAST); |
| 137 MediaSink sink3("sinkId3", "Sink 3", MediaSink::IconType::CAST); | 139 MediaSink sink3("sinkId3", "Sink 3", MediaSink::IconType::CAST); |
| 138 MediaSink sink4("sinkId4", "Sink 4", MediaSink::IconType::CAST); | 140 MediaSink sink4("sinkId4", "Sink 4", MediaSink::IconType::CAST); |
| 139 MediaSink sink5("sinkId5", "Sink 5", MediaSink::IconType::CAST); | 141 MediaSink sink5("sinkId5", "Sink 5", MediaSink::IconType::CAST); |
| 140 | 142 |
| 141 query_result_manager_.AddObserver(&mock_observer_); | 143 query_result_manager_.AddObserver(&mock_observer_); |
| 142 DiscoverSinks(MediaCastMode::DEFAULT, | 144 DiscoverSinks(MediaCastMode::DEFAULT, |
| 143 MediaSourceForPresentationUrl("http://barUrl")); | 145 MediaSourceForPresentationUrl("http://barUrl.com", |
| 144 DiscoverSinks(MediaCastMode::TAB_MIRROR, MediaSourceForTab(123)); | 146 "http://barUrl.com")); |
| 147 DiscoverSinks(MediaCastMode::TAB_MIRROR, | |
| 148 MediaSourceForTab(123)); | |
| 145 | 149 |
| 146 // Scenario (results in this order): | 150 // Scenario (results in this order): |
| 147 // Action: DEFAULT -> [1, 2, 3] | 151 // Action: DEFAULT -> [1, 2, 3] |
| 148 // Expected result: | 152 // Expected result: |
| 149 // Sinks: [1 -> {DEFAULT}, 2 -> {DEFAULT}, 3 -> {DEFAULT}] | 153 // Sinks: [1 -> {DEFAULT}, 2 -> {DEFAULT}, 3 -> {DEFAULT}] |
| 150 std::vector<MediaSinkWithCastModes> expected_sinks; | 154 std::vector<MediaSinkWithCastModes> expected_sinks; |
| 151 expected_sinks.push_back(MediaSinkWithCastModes(sink1)); | 155 expected_sinks.push_back(MediaSinkWithCastModes(sink1)); |
| 152 expected_sinks.back().cast_modes.insert(MediaCastMode::DEFAULT); | 156 expected_sinks.back().cast_modes.insert(MediaCastMode::DEFAULT); |
| 153 expected_sinks.push_back(MediaSinkWithCastModes(sink2)); | 157 expected_sinks.push_back(MediaSinkWithCastModes(sink2)); |
| 154 expected_sinks.back().cast_modes.insert(MediaCastMode::DEFAULT); | 158 expected_sinks.back().cast_modes.insert(MediaCastMode::DEFAULT); |
| 155 expected_sinks.push_back(MediaSinkWithCastModes(sink3)); | 159 expected_sinks.push_back(MediaSinkWithCastModes(sink3)); |
| 156 expected_sinks.back().cast_modes.insert(MediaCastMode::DEFAULT); | 160 expected_sinks.back().cast_modes.insert(MediaCastMode::DEFAULT); |
| 157 | 161 |
| 158 const auto& sinks_observers = query_result_manager_.sinks_observers_; | 162 const auto& sinks_observers = query_result_manager_.sinks_observers_; |
| 159 auto sinks_observer_it = sinks_observers.find(MediaCastMode::DEFAULT); | 163 auto sinks_observer_it = sinks_observers.find(MediaCastMode::DEFAULT); |
| 160 ASSERT_TRUE(sinks_observer_it != sinks_observers.end()); | 164 ASSERT_TRUE(sinks_observer_it != sinks_observers.end()); |
| 161 ASSERT_TRUE(sinks_observer_it->second.get()); | 165 ASSERT_TRUE(sinks_observer_it->second.get()); |
| 162 | 166 |
| 163 std::vector<MediaSink> sinks_query_result; | 167 std::vector<MediaSink> sinks_query_result; |
| 164 sinks_query_result.push_back(sink1); | 168 sinks_query_result.push_back(sink1); |
| 165 sinks_query_result.push_back(sink2); | 169 sinks_query_result.push_back(sink2); |
| 166 sinks_query_result.push_back(sink3); | 170 sinks_query_result.push_back(sink3); |
| 167 EXPECT_CALL(mock_observer_, | 171 EXPECT_CALL(mock_observer_, |
| 168 OnResultsUpdated(VectorEquals(expected_sinks))).Times(1); | 172 OnResultsUpdated(VectorEquals(expected_sinks))).Times(1); |
| 169 sinks_observer_it->second->OnSinksReceived(sinks_query_result); | 173 EXPECT_CALL(mock_observer_, |
| 170 | 174 OnResultsUpdated(VectorEquals(expected_sinks))).Times(1); |
| 175 sinks_observer_it->second->OnSinksReceived( | |
| 176 MediaSourceForPresentationUrl("http://barUrl.com", "http://barUrl.com"), | |
| 177 sinks_query_result); | |
| 178 sinks_observer_it->second->OnSinksReceived(MediaSourceForTab(123), | |
| 179 sinks_query_result); | |
| 171 // Action: TAB_MIRROR -> [2, 3, 4] | 180 // Action: TAB_MIRROR -> [2, 3, 4] |
| 172 // Expected result: | 181 // Expected result: |
| 173 // Sinks: [1 -> {DEFAULT}, 2 -> {DEFAULT, TAB_MIRROR}, | 182 // Sinks: [1 -> {DEFAULT}, 2 -> {DEFAULT, TAB_MIRROR}, |
| 174 // 3 -> {DEFAULT, TAB_MIRROR}, 4 -> {TAB_MIRROR}] | 183 // 3 -> {DEFAULT, TAB_MIRROR}, 4 -> {TAB_MIRROR}] |
| 175 expected_sinks.clear(); | 184 expected_sinks.clear(); |
| 176 expected_sinks.push_back(MediaSinkWithCastModes(sink1)); | 185 expected_sinks.push_back(MediaSinkWithCastModes(sink1)); |
| 177 expected_sinks.back().cast_modes.insert(MediaCastMode::DEFAULT); | 186 expected_sinks.back().cast_modes.insert(MediaCastMode::DEFAULT); |
| 178 expected_sinks.push_back(MediaSinkWithCastModes(sink2)); | 187 expected_sinks.push_back(MediaSinkWithCastModes(sink2)); |
| 179 expected_sinks.back().cast_modes.insert(MediaCastMode::DEFAULT); | 188 expected_sinks.back().cast_modes.insert(MediaCastMode::DEFAULT); |
| 180 expected_sinks.back().cast_modes.insert(MediaCastMode::TAB_MIRROR); | 189 expected_sinks.back().cast_modes.insert(MediaCastMode::TAB_MIRROR); |
| 181 expected_sinks.push_back(MediaSinkWithCastModes(sink3)); | 190 expected_sinks.push_back(MediaSinkWithCastModes(sink3)); |
| 182 expected_sinks.back().cast_modes.insert(MediaCastMode::DEFAULT); | 191 expected_sinks.back().cast_modes.insert(MediaCastMode::DEFAULT); |
| 183 expected_sinks.back().cast_modes.insert(MediaCastMode::TAB_MIRROR); | 192 expected_sinks.back().cast_modes.insert(MediaCastMode::TAB_MIRROR); |
| 184 expected_sinks.push_back(MediaSinkWithCastModes(sink4)); | 193 expected_sinks.push_back(MediaSinkWithCastModes(sink4)); |
| 185 expected_sinks.back().cast_modes.insert(MediaCastMode::TAB_MIRROR); | 194 expected_sinks.back().cast_modes.insert(MediaCastMode::TAB_MIRROR); |
| 186 | 195 |
| 187 sinks_query_result.clear(); | 196 sinks_query_result.clear(); |
| 188 sinks_query_result.push_back(sink2); | 197 sinks_query_result.push_back(sink2); |
| 189 sinks_query_result.push_back(sink3); | 198 sinks_query_result.push_back(sink3); |
| 190 sinks_query_result.push_back(sink4); | 199 sinks_query_result.push_back(sink4); |
| 191 | 200 |
| 192 sinks_observer_it = sinks_observers.find(MediaCastMode::TAB_MIRROR); | 201 sinks_observer_it = sinks_observers.find(MediaCastMode::TAB_MIRROR); |
| 193 ASSERT_TRUE(sinks_observer_it != sinks_observers.end()); | 202 ASSERT_TRUE(sinks_observer_it != sinks_observers.end()); |
| 194 ASSERT_TRUE(sinks_observer_it->second.get()); | 203 ASSERT_TRUE(sinks_observer_it->second.get()); |
| 195 EXPECT_CALL(mock_observer_, | 204 EXPECT_CALL(mock_observer_, |
| 196 OnResultsUpdated(VectorEquals(expected_sinks))).Times(1); | 205 OnResultsUpdated(VectorEquals(expected_sinks))).Times(1); |
| 197 sinks_observer_it->second->OnSinksReceived(sinks_query_result); | 206 sinks_observer_it->second->OnSinksReceived( |
| 198 | 207 MediaSourceForPresentationUrl("http://barUrl.com", "http://barUrl.com"), |
| 208 sinks_query_result); | |
| 199 // Action: Update default presentation URL | 209 // Action: Update default presentation URL |
| 200 // Expected result: | 210 // Expected result: |
| 201 // Sinks: [2 -> {TAB_MIRROR}, 3 -> {TAB_MIRROR}, 4 -> {TAB_MIRROR}] | 211 // Sinks: [2 -> {TAB_MIRROR}, 3 -> {TAB_MIRROR}, 4 -> {TAB_MIRROR}] |
| 202 expected_sinks.clear(); | 212 expected_sinks.clear(); |
| 203 expected_sinks.push_back(MediaSinkWithCastModes(sink2)); | 213 expected_sinks.push_back(MediaSinkWithCastModes(sink2)); |
| 204 expected_sinks.back().cast_modes.insert(MediaCastMode::TAB_MIRROR); | 214 expected_sinks.back().cast_modes.insert(MediaCastMode::TAB_MIRROR); |
| 205 expected_sinks.push_back(MediaSinkWithCastModes(sink3)); | 215 expected_sinks.push_back(MediaSinkWithCastModes(sink3)); |
| 206 expected_sinks.back().cast_modes.insert(MediaCastMode::TAB_MIRROR); | 216 expected_sinks.back().cast_modes.insert(MediaCastMode::TAB_MIRROR); |
| 207 expected_sinks.push_back(MediaSinkWithCastModes(sink4)); | 217 expected_sinks.push_back(MediaSinkWithCastModes(sink4)); |
| 208 expected_sinks.back().cast_modes.insert(MediaCastMode::TAB_MIRROR); | 218 expected_sinks.back().cast_modes.insert(MediaCastMode::TAB_MIRROR); |
| 209 | 219 |
| 210 EXPECT_CALL(mock_router_, UnregisterMediaSinksObserver(_)).Times(1); | 220 EXPECT_CALL(mock_router_, UnregisterMediaSinksObserver(_)).Times(1); |
| 211 EXPECT_CALL(mock_router_, RegisterMediaSinksObserver(_)) | 221 EXPECT_CALL(mock_router_, RegisterMediaSinksObserver(_)) |
| 212 .WillOnce(Return(true)); | 222 .WillOnce(Return(true)); |
| 213 EXPECT_CALL(mock_observer_, | 223 EXPECT_CALL(mock_observer_, |
| 214 OnResultsUpdated(VectorEquals(expected_sinks))).Times(1); | 224 OnResultsUpdated(VectorEquals(expected_sinks))).Times(1); |
| 215 query_result_manager_.StartSinksQuery( | 225 query_result_manager_.StartSinksQuery( |
| 216 MediaCastMode::DEFAULT, | 226 MediaCastMode::DEFAULT, |
| 217 MediaSourceForPresentationUrl("http://bazurl.com")); | 227 MediaSourceForPresentationUrl("http://bazurl.com", |
| 228 "http://barurl.com")); | |
| 218 | 229 |
| 219 // Action: Remove TAB_MIRROR observer | 230 // Action: Remove TAB_MIRROR observer |
| 220 // Expected result: | 231 // Expected result: |
| 221 // Sinks: [] | 232 // Sinks: [] |
| 222 expected_sinks.clear(); | 233 expected_sinks.clear(); |
| 223 EXPECT_CALL(mock_observer_, | 234 EXPECT_CALL(mock_observer_, |
| 224 OnResultsUpdated(VectorEquals(expected_sinks))).Times(1); | 235 OnResultsUpdated(VectorEquals(expected_sinks))).Times(1); |
| 225 EXPECT_CALL(mock_router_, UnregisterMediaSinksObserver(_)).Times(1); | 236 EXPECT_CALL(mock_router_, UnregisterMediaSinksObserver(_)).Times(1); |
| 226 query_result_manager_.StopSinksQuery(MediaCastMode::TAB_MIRROR); | 237 query_result_manager_.StopSinksQuery(MediaCastMode::TAB_MIRROR); |
| 227 | 238 |
| 228 // Remaining observers: DEFAULT observer, which will be removed on destruction | 239 // Remaining observers: DEFAULT observer, which will be removed on destruction |
| 229 EXPECT_CALL(mock_router_, UnregisterMediaSinksObserver(_)).Times(1); | 240 EXPECT_CALL(mock_router_, UnregisterMediaSinksObserver(_)).Times(1); |
| 230 } | 241 } |
| 231 | 242 |
| 232 } // namespace media_router | 243 } // namespace media_router |
| OLD | NEW |