| 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 "base/tuple.h" | 5 #include "base/tuple.h" |
| 6 #include "content/browser/media/android/media_session.h" | 6 #include "content/browser/media/media_web_contents_observer.h" |
| 7 #include "content/browser/media/android/media_session_controller.h" | 7 #include "content/browser/media/session/media_session.h" |
| 8 #include "content/browser/media/android/media_web_contents_observer_android.h" | 8 #include "content/browser/media/session/media_session_controller.h" |
| 9 #include "content/common/media/media_player_delegate_messages.h" | 9 #include "content/common/media/media_player_delegate_messages.h" |
| 10 #include "content/test/test_render_view_host.h" | 10 #include "content/test/test_render_view_host.h" |
| 11 #include "content/test/test_web_contents.h" | 11 #include "content/test/test_web_contents.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 class MediaSessionControllerTest : public RenderViewHostImplTestHarness { | 16 class MediaSessionControllerTest : public RenderViewHostImplTestHarness { |
| 17 public: | 17 public: |
| 18 void SetUp() override { | 18 void SetUp() override { |
| 19 RenderViewHostImplTestHarness::SetUp(); | 19 RenderViewHostImplTestHarness::SetUp(); |
| 20 id_ = WebContentsObserver::MediaPlayerId(contents()->GetMainFrame(), 0); | 20 id_ = WebContentsObserver::MediaPlayerId(contents()->GetMainFrame(), 0); |
| 21 observer_ = MediaWebContentsObserverAndroid::FromWebContents(contents()); | |
| 22 controller_ = CreateController(); | 21 controller_ = CreateController(); |
| 23 } | 22 } |
| 24 | 23 |
| 25 void TearDown() override { | 24 void TearDown() override { |
| 26 // Destruct the controller prior to any other teardown to avoid out of order | 25 // Destruct the controller prior to any other teardown to avoid out of order |
| 27 // destruction relative to the MediaSession instance. | 26 // destruction relative to the MediaSession instance. |
| 28 controller_.reset(); | 27 controller_.reset(); |
| 29 RenderViewHostImplTestHarness::TearDown(); | 28 RenderViewHostImplTestHarness::TearDown(); |
| 30 } | 29 } |
| 31 | 30 |
| 32 protected: | 31 protected: |
| 33 scoped_ptr<MediaSessionController> CreateController() { | 32 scoped_ptr<MediaSessionController> CreateController() { |
| 34 return scoped_ptr<MediaSessionController>( | 33 return scoped_ptr<MediaSessionController>(new MediaSessionController( |
| 35 new MediaSessionController(id_, observer_)); | 34 id_, contents()->media_web_contents_observer())); |
| 36 } | 35 } |
| 37 | 36 |
| 38 MediaSession* media_session() { return MediaSession::Get(contents()); } | 37 MediaSession* media_session() { return MediaSession::Get(contents()); } |
| 39 | 38 |
| 40 IPC::TestSink& test_sink() { return main_test_rfh()->GetProcess()->sink(); } | 39 IPC::TestSink& test_sink() { return main_test_rfh()->GetProcess()->sink(); } |
| 41 | 40 |
| 42 void Suspend() { | 41 void Suspend() { |
| 43 controller_->OnSuspend(controller_->get_player_id_for_testing()); | 42 controller_->OnSuspend(controller_->get_player_id_for_testing()); |
| 44 } | 43 } |
| 45 | 44 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 EXPECT_EQ(id_.second, base::get<0>(result)); | 91 EXPECT_EQ(id_.second, base::get<0>(result)); |
| 93 if (id_.second != base::get<0>(result)) | 92 if (id_.second != base::get<0>(result)) |
| 94 return false; | 93 return false; |
| 95 | 94 |
| 96 EXPECT_EQ(expected_multiplier, base::get<1>(result)); | 95 EXPECT_EQ(expected_multiplier, base::get<1>(result)); |
| 97 test_sink().ClearMessages(); | 96 test_sink().ClearMessages(); |
| 98 return expected_multiplier == base::get<1>(result); | 97 return expected_multiplier == base::get<1>(result); |
| 99 } | 98 } |
| 100 | 99 |
| 101 WebContentsObserver::MediaPlayerId id_; | 100 WebContentsObserver::MediaPlayerId id_; |
| 102 MediaWebContentsObserverAndroid* observer_; | |
| 103 scoped_ptr<MediaSessionController> controller_; | 101 scoped_ptr<MediaSessionController> controller_; |
| 104 }; | 102 }; |
| 105 | 103 |
| 106 TEST_F(MediaSessionControllerTest, NoAudioNoSession) { | 104 TEST_F(MediaSessionControllerTest, NoAudioNoSession) { |
| 107 ASSERT_TRUE(controller_->Initialize(false, false, DurationJustRight())); | 105 ASSERT_TRUE(controller_->Initialize(false, false, DurationJustRight())); |
| 108 EXPECT_TRUE(media_session()->IsSuspended()); | 106 EXPECT_TRUE(media_session()->IsSuspended()); |
| 109 EXPECT_FALSE(media_session()->IsControllable()); | 107 EXPECT_FALSE(media_session()->IsControllable()); |
| 110 } | 108 } |
| 111 | 109 |
| 112 TEST_F(MediaSessionControllerTest, IsRemoteNoSession) { | 110 TEST_F(MediaSessionControllerTest, IsRemoteNoSession) { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 EXPECT_EQ(current_player_id, controller_->get_player_id_for_testing()); | 205 EXPECT_EQ(current_player_id, controller_->get_player_id_for_testing()); |
| 208 | 206 |
| 209 // Switch to a remote player, which should release the session. | 207 // Switch to a remote player, which should release the session. |
| 210 ASSERT_TRUE(controller_->Initialize(true, true, DurationJustRight())); | 208 ASSERT_TRUE(controller_->Initialize(true, true, DurationJustRight())); |
| 211 EXPECT_TRUE(media_session()->IsSuspended()); | 209 EXPECT_TRUE(media_session()->IsSuspended()); |
| 212 EXPECT_FALSE(media_session()->IsControllable()); | 210 EXPECT_FALSE(media_session()->IsControllable()); |
| 213 EXPECT_EQ(current_player_id, controller_->get_player_id_for_testing()); | 211 EXPECT_EQ(current_player_id, controller_->get_player_id_for_testing()); |
| 214 } | 212 } |
| 215 | 213 |
| 216 } // namespace content | 214 } // namespace content |
| OLD | NEW |