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 <tuple> |
| 6 |
5 #include "base/bind.h" | 7 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
7 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
8 #include "base/test/simple_test_tick_clock.h" | 10 #include "base/test/simple_test_tick_clock.h" |
9 #include "base/tuple.h" | |
10 #include "content/common/media/media_player_delegate_messages.h" | 11 #include "content/common/media/media_player_delegate_messages.h" |
11 #include "content/public/renderer/render_view.h" | 12 #include "content/public/renderer/render_view.h" |
12 #include "content/public/test/render_view_test.h" | 13 #include "content/public/test/render_view_test.h" |
13 #include "content/renderer/media/renderer_webmediaplayer_delegate.h" | 14 #include "content/renderer/media/renderer_webmediaplayer_delegate.h" |
14 #include "content/renderer/render_process.h" | 15 #include "content/renderer/render_process.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 namespace media { | 19 namespace media { |
19 | 20 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 { | 72 { |
72 const bool kHasVideo = true, kHasAudio = false, kIsRemote = false; | 73 const bool kHasVideo = true, kHasAudio = false, kIsRemote = false; |
73 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(5); | 74 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(5); |
74 delegate_manager_->DidPlay(delegate_id, kHasVideo, kHasAudio, kIsRemote, | 75 delegate_manager_->DidPlay(delegate_id, kHasVideo, kHasAudio, kIsRemote, |
75 kDuration); | 76 kDuration); |
76 | 77 |
77 const IPC::Message* msg = test_sink().GetUniqueMessageMatching( | 78 const IPC::Message* msg = test_sink().GetUniqueMessageMatching( |
78 MediaPlayerDelegateHostMsg_OnMediaPlaying::ID); | 79 MediaPlayerDelegateHostMsg_OnMediaPlaying::ID); |
79 ASSERT_TRUE(msg); | 80 ASSERT_TRUE(msg); |
80 | 81 |
81 base::Tuple<int, bool, bool, bool, base::TimeDelta> result; | 82 std::tuple<int, bool, bool, bool, base::TimeDelta> result; |
82 ASSERT_TRUE(MediaPlayerDelegateHostMsg_OnMediaPlaying::Read(msg, &result)); | 83 ASSERT_TRUE(MediaPlayerDelegateHostMsg_OnMediaPlaying::Read(msg, &result)); |
83 EXPECT_EQ(delegate_id, base::get<0>(result)); | 84 EXPECT_EQ(delegate_id, std::get<0>(result)); |
84 EXPECT_EQ(kHasVideo, base::get<1>(result)); | 85 EXPECT_EQ(kHasVideo, std::get<1>(result)); |
85 EXPECT_EQ(kHasAudio, base::get<2>(result)); | 86 EXPECT_EQ(kHasAudio, std::get<2>(result)); |
86 EXPECT_EQ(kIsRemote, base::get<3>(result)); | 87 EXPECT_EQ(kIsRemote, std::get<3>(result)); |
87 EXPECT_EQ(kDuration, base::get<4>(result)); | 88 EXPECT_EQ(kDuration, std::get<4>(result)); |
88 } | 89 } |
89 | 90 |
90 // Verify the paused message. | 91 // Verify the paused message. |
91 { | 92 { |
92 test_sink().ClearMessages(); | 93 test_sink().ClearMessages(); |
93 const bool kReachedEndOfStream = true; | 94 const bool kReachedEndOfStream = true; |
94 delegate_manager_->DidPause(delegate_id, kReachedEndOfStream); | 95 delegate_manager_->DidPause(delegate_id, kReachedEndOfStream); |
95 | 96 |
96 const IPC::Message* msg = test_sink().GetUniqueMessageMatching( | 97 const IPC::Message* msg = test_sink().GetUniqueMessageMatching( |
97 MediaPlayerDelegateHostMsg_OnMediaPaused::ID); | 98 MediaPlayerDelegateHostMsg_OnMediaPaused::ID); |
98 ASSERT_TRUE(msg); | 99 ASSERT_TRUE(msg); |
99 | 100 |
100 base::Tuple<int, bool> result; | 101 std::tuple<int, bool> result; |
101 ASSERT_TRUE(MediaPlayerDelegateHostMsg_OnMediaPaused::Read(msg, &result)); | 102 ASSERT_TRUE(MediaPlayerDelegateHostMsg_OnMediaPaused::Read(msg, &result)); |
102 EXPECT_EQ(delegate_id, base::get<0>(result)); | 103 EXPECT_EQ(delegate_id, std::get<0>(result)); |
103 EXPECT_EQ(kReachedEndOfStream, base::get<1>(result)); | 104 EXPECT_EQ(kReachedEndOfStream, std::get<1>(result)); |
104 } | 105 } |
105 | 106 |
106 // Verify the destruction message. | 107 // Verify the destruction message. |
107 { | 108 { |
108 test_sink().ClearMessages(); | 109 test_sink().ClearMessages(); |
109 delegate_manager_->PlayerGone(delegate_id); | 110 delegate_manager_->PlayerGone(delegate_id); |
110 const IPC::Message* msg = test_sink().GetUniqueMessageMatching( | 111 const IPC::Message* msg = test_sink().GetUniqueMessageMatching( |
111 MediaPlayerDelegateHostMsg_OnMediaDestroyed::ID); | 112 MediaPlayerDelegateHostMsg_OnMediaDestroyed::ID); |
112 ASSERT_TRUE(msg); | 113 ASSERT_TRUE(msg); |
113 | 114 |
114 base::Tuple<int> result; | 115 std::tuple<int> result; |
115 ASSERT_TRUE( | 116 ASSERT_TRUE( |
116 MediaPlayerDelegateHostMsg_OnMediaDestroyed::Read(msg, &result)); | 117 MediaPlayerDelegateHostMsg_OnMediaDestroyed::Read(msg, &result)); |
117 EXPECT_EQ(delegate_id, base::get<0>(result)); | 118 EXPECT_EQ(delegate_id, std::get<0>(result)); |
118 } | 119 } |
119 | 120 |
120 delegate_manager_->RemoveObserver(delegate_id); | 121 delegate_manager_->RemoveObserver(delegate_id); |
121 } | 122 } |
122 | 123 |
123 TEST_F(RendererWebMediaPlayerDelegateTest, DeliversObserverNotifications) { | 124 TEST_F(RendererWebMediaPlayerDelegateTest, DeliversObserverNotifications) { |
124 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer; | 125 testing::StrictMock<MockWebMediaPlayerDelegateObserver> observer; |
125 const int delegate_id = delegate_manager_->AddObserver(&observer); | 126 const int delegate_id = delegate_manager_->AddObserver(&observer); |
126 | 127 |
127 EXPECT_CALL(observer, OnHidden()); | 128 EXPECT_CALL(observer, OnHidden()); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1)); | 258 tick_clock.Advance(kIdleTimeout + base::TimeDelta::FromMicroseconds(1)); |
258 run_loop.Run(); | 259 run_loop.Run(); |
259 | 260 |
260 // Even though the player did not call PlayerGone() it should be removed from | 261 // Even though the player did not call PlayerGone() it should be removed from |
261 // future idle cleanup polls. | 262 // future idle cleanup polls. |
262 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); | 263 EXPECT_FALSE(delegate_manager_->IsIdleCleanupTimerRunningForTesting()); |
263 delegate_manager_->RemoveObserver(delegate_id_1); | 264 delegate_manager_->RemoveObserver(delegate_id_1); |
264 } | 265 } |
265 | 266 |
266 } // namespace media | 267 } // namespace media |
OLD | NEW |