| 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 <tuple> |
| 6 |
| 6 #include "content/browser/media/media_web_contents_observer.h" | 7 #include "content/browser/media/media_web_contents_observer.h" |
| 7 #include "content/browser/media/session/media_session.h" | 8 #include "content/browser/media/session/media_session.h" |
| 8 #include "content/browser/media/session/media_session_controller.h" | 9 #include "content/browser/media/session/media_session_controller.h" |
| 9 #include "content/common/media/media_player_delegate_messages.h" | 10 #include "content/common/media/media_player_delegate_messages.h" |
| 10 #include "content/test/test_render_view_host.h" | 11 #include "content/test/test_render_view_host.h" |
| 11 #include "content/test/test_web_contents.h" | 12 #include "content/test/test_web_contents.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 return base::TimeDelta::FromSeconds( | 63 return base::TimeDelta::FromSeconds( |
| 63 MediaSessionController::kMinimumDurationForContentSecs); | 64 MediaSessionController::kMinimumDurationForContentSecs); |
| 64 } | 65 } |
| 65 | 66 |
| 66 template <typename T> | 67 template <typename T> |
| 67 bool ReceivedMessagePlayPause() { | 68 bool ReceivedMessagePlayPause() { |
| 68 const IPC::Message* msg = test_sink().GetUniqueMessageMatching(T::ID); | 69 const IPC::Message* msg = test_sink().GetUniqueMessageMatching(T::ID); |
| 69 if (!msg) | 70 if (!msg) |
| 70 return false; | 71 return false; |
| 71 | 72 |
| 72 base::Tuple<int> result; | 73 std::tuple<int> result; |
| 73 if (!T::Read(msg, &result)) | 74 if (!T::Read(msg, &result)) |
| 74 return false; | 75 return false; |
| 75 | 76 |
| 76 EXPECT_EQ(id_.second, base::get<0>(result)); | 77 EXPECT_EQ(id_.second, std::get<0>(result)); |
| 77 test_sink().ClearMessages(); | 78 test_sink().ClearMessages(); |
| 78 return id_.second == base::get<0>(result); | 79 return id_.second == std::get<0>(result); |
| 79 } | 80 } |
| 80 | 81 |
| 81 template <typename T> | 82 template <typename T> |
| 82 bool ReceivedMessageVolumeMultiplierUpdate(double expected_multiplier) { | 83 bool ReceivedMessageVolumeMultiplierUpdate(double expected_multiplier) { |
| 83 const IPC::Message* msg = test_sink().GetUniqueMessageMatching(T::ID); | 84 const IPC::Message* msg = test_sink().GetUniqueMessageMatching(T::ID); |
| 84 if (!msg) | 85 if (!msg) |
| 85 return false; | 86 return false; |
| 86 | 87 |
| 87 base::Tuple<int, double> result; | 88 std::tuple<int, double> result; |
| 88 if (!T::Read(msg, &result)) | 89 if (!T::Read(msg, &result)) |
| 89 return false; | 90 return false; |
| 90 | 91 |
| 91 EXPECT_EQ(id_.second, base::get<0>(result)); | 92 EXPECT_EQ(id_.second, std::get<0>(result)); |
| 92 if (id_.second != base::get<0>(result)) | 93 if (id_.second != std::get<0>(result)) |
| 93 return false; | 94 return false; |
| 94 | 95 |
| 95 EXPECT_EQ(expected_multiplier, base::get<1>(result)); | 96 EXPECT_EQ(expected_multiplier, std::get<1>(result)); |
| 96 test_sink().ClearMessages(); | 97 test_sink().ClearMessages(); |
| 97 return expected_multiplier == base::get<1>(result); | 98 return expected_multiplier == std::get<1>(result); |
| 98 } | 99 } |
| 99 | 100 |
| 100 WebContentsObserver::MediaPlayerId id_; | 101 WebContentsObserver::MediaPlayerId id_; |
| 101 std::unique_ptr<MediaSessionController> controller_; | 102 std::unique_ptr<MediaSessionController> controller_; |
| 102 }; | 103 }; |
| 103 | 104 |
| 104 TEST_F(MediaSessionControllerTest, NoAudioNoSession) { | 105 TEST_F(MediaSessionControllerTest, NoAudioNoSession) { |
| 105 ASSERT_TRUE(controller_->Initialize(false, false, DurationJustRight())); | 106 ASSERT_TRUE(controller_->Initialize(false, false, DurationJustRight())); |
| 106 EXPECT_TRUE(media_session()->IsSuspended()); | 107 EXPECT_TRUE(media_session()->IsSuspended()); |
| 107 EXPECT_FALSE(media_session()->IsControllable()); | 108 EXPECT_FALSE(media_session()->IsControllable()); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 EXPECT_EQ(current_player_id, controller_->get_player_id_for_testing()); | 206 EXPECT_EQ(current_player_id, controller_->get_player_id_for_testing()); |
| 206 | 207 |
| 207 // Switch to a remote player, which should release the session. | 208 // Switch to a remote player, which should release the session. |
| 208 ASSERT_TRUE(controller_->Initialize(true, true, DurationJustRight())); | 209 ASSERT_TRUE(controller_->Initialize(true, true, DurationJustRight())); |
| 209 EXPECT_TRUE(media_session()->IsSuspended()); | 210 EXPECT_TRUE(media_session()->IsSuspended()); |
| 210 EXPECT_FALSE(media_session()->IsControllable()); | 211 EXPECT_FALSE(media_session()->IsControllable()); |
| 211 EXPECT_EQ(current_player_id, controller_->get_player_id_for_testing()); | 212 EXPECT_EQ(current_player_id, controller_->get_player_id_for_testing()); |
| 212 } | 213 } |
| 213 | 214 |
| 214 } // namespace content | 215 } // namespace content |
| OLD | NEW |