OLD | NEW |
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 "content/browser/media/session/media_session_impl.h" | 5 #include "content/browser/media/session/media_session_impl.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "content/browser/media/session/media_session_player_observer.h" | 10 #include "content/browser/media/session/media_session_player_observer.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 void TearDown() override { | 68 void TearDown() override { |
69 services_.clear(); | 69 services_.clear(); |
70 | 70 |
71 RenderViewHostImplTestHarness::TearDown(); | 71 RenderViewHostImplTestHarness::TearDown(); |
72 } | 72 } |
73 | 73 |
74 protected: | 74 protected: |
75 void CreateServiceForFrame(TestRenderFrameHost* frame) { | 75 void CreateServiceForFrame(TestRenderFrameHost* frame) { |
76 services_[frame] = base::MakeUnique<MockMediaSessionServiceImpl>(frame); | 76 services_[frame] = base::MakeUnique<MockMediaSessionServiceImpl>(frame); |
77 services_[frame]->SetMetadata(MediaMetadata()); | 77 } |
| 78 |
| 79 void DestroyServiceForFrame(TestRenderFrameHost* frame) { |
| 80 services_.erase(frame); |
78 } | 81 } |
79 | 82 |
80 void StartPlayerForFrame(TestRenderFrameHost* frame) { | 83 void StartPlayerForFrame(TestRenderFrameHost* frame) { |
81 players_[frame] = base::MakeUnique<MockMediaSessionPlayerObserver>(frame); | 84 players_[frame] = base::MakeUnique<MockMediaSessionPlayerObserver>(frame); |
82 MediaSessionImpl::Get(contents()) | 85 MediaSessionImpl::Get(contents()) |
83 ->AddPlayer(players_[frame].get(), kPlayerId, | 86 ->AddPlayer(players_[frame].get(), kPlayerId, |
84 media::MediaContentType::Persistent); | 87 media::MediaContentType::Persistent); |
85 } | 88 } |
86 | 89 |
87 void ClearPlayersForFrame(TestRenderFrameHost* frame) { | 90 void ClearPlayersForFrame(TestRenderFrameHost* frame) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 } | 129 } |
127 | 130 |
128 TEST_F(MediaSessionImplServiceRoutingTest, | 131 TEST_F(MediaSessionImplServiceRoutingTest, |
129 OnlySubFrameProducesAudioButHasNoService) { | 132 OnlySubFrameProducesAudioButHasNoService) { |
130 StartPlayerForFrame(sub_frame_); | 133 StartPlayerForFrame(sub_frame_); |
131 | 134 |
132 ASSERT_EQ(nullptr, ComputeServiceForRouting()); | 135 ASSERT_EQ(nullptr, ComputeServiceForRouting()); |
133 } | 136 } |
134 | 137 |
135 TEST_F(MediaSessionImplServiceRoutingTest, | 138 TEST_F(MediaSessionImplServiceRoutingTest, |
136 OnlyMainFrameProducesAudioButHasInactiveService) { | 139 OnlyMainFrameProducesAudioButHasDestroyedService) { |
| 140 CreateServiceForFrame(main_frame_); |
137 StartPlayerForFrame(main_frame_); | 141 StartPlayerForFrame(main_frame_); |
138 | 142 DestroyServiceForFrame(main_frame_); |
139 CreateServiceForFrame(main_frame_); | |
140 services_[main_frame_]->SetMetadata(base::nullopt); | |
141 | 143 |
142 ASSERT_EQ(nullptr, ComputeServiceForRouting()); | 144 ASSERT_EQ(nullptr, ComputeServiceForRouting()); |
143 } | 145 } |
144 | 146 |
145 TEST_F(MediaSessionImplServiceRoutingTest, | 147 TEST_F(MediaSessionImplServiceRoutingTest, |
146 OnlySubFrameProducesAudioButHasInactiveService) { | 148 OnlySubFrameProducesAudioButHasDestroyedService) { |
| 149 CreateServiceForFrame(sub_frame_); |
147 StartPlayerForFrame(sub_frame_); | 150 StartPlayerForFrame(sub_frame_); |
148 | 151 DestroyServiceForFrame(sub_frame_); |
149 CreateServiceForFrame(sub_frame_); | |
150 services_[sub_frame_]->SetMetadata(base::nullopt); | |
151 | 152 |
152 ASSERT_EQ(nullptr, ComputeServiceForRouting()); | 153 ASSERT_EQ(nullptr, ComputeServiceForRouting()); |
153 } | 154 } |
154 | 155 |
155 TEST_F(MediaSessionImplServiceRoutingTest, | 156 TEST_F(MediaSessionImplServiceRoutingTest, |
| 157 OnlyMainFrameProducesAudioAndServiceIsCreatedAfterwards) { |
| 158 StartPlayerForFrame(main_frame_); |
| 159 CreateServiceForFrame(main_frame_); |
| 160 |
| 161 ASSERT_EQ(services_[main_frame_].get(), ComputeServiceForRouting()); |
| 162 } |
| 163 |
| 164 TEST_F(MediaSessionImplServiceRoutingTest, |
| 165 OnlySubFrameProducesAudioAndServiceIsCreatedAfterwards) { |
| 166 StartPlayerForFrame(sub_frame_); |
| 167 CreateServiceForFrame(sub_frame_); |
| 168 |
| 169 ASSERT_EQ(services_[sub_frame_].get(), ComputeServiceForRouting()); |
| 170 } |
| 171 |
| 172 TEST_F(MediaSessionImplServiceRoutingTest, |
156 BothFrameProducesAudioButOnlySubFrameHasService) { | 173 BothFrameProducesAudioButOnlySubFrameHasService) { |
157 StartPlayerForFrame(main_frame_); | 174 StartPlayerForFrame(main_frame_); |
158 StartPlayerForFrame(sub_frame_); | 175 StartPlayerForFrame(sub_frame_); |
159 | 176 |
160 CreateServiceForFrame(sub_frame_); | 177 CreateServiceForFrame(sub_frame_); |
161 | 178 |
162 ASSERT_EQ(services_[sub_frame_].get(), ComputeServiceForRouting()); | 179 ASSERT_EQ(services_[sub_frame_].get(), ComputeServiceForRouting()); |
163 } | 180 } |
164 | 181 |
165 TEST_F(MediaSessionImplServiceRoutingTest, PreferTopMostFrame) { | 182 TEST_F(MediaSessionImplServiceRoutingTest, PreferTopMostFrame) { |
(...skipping 13 matching lines...) Expand all Loading... |
179 | 196 |
180 CreateServiceForFrame(main_frame_); | 197 CreateServiceForFrame(main_frame_); |
181 CreateServiceForFrame(sub_frame_); | 198 CreateServiceForFrame(sub_frame_); |
182 | 199 |
183 ClearPlayersForFrame(main_frame_); | 200 ClearPlayersForFrame(main_frame_); |
184 | 201 |
185 ASSERT_EQ(services_[sub_frame_].get(), ComputeServiceForRouting()); | 202 ASSERT_EQ(services_[sub_frame_].get(), ComputeServiceForRouting()); |
186 } | 203 } |
187 | 204 |
188 } // namespace content | 205 } // namespace content |
OLD | NEW |