| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "content/public/renderer/media_stream_renderer_factory.h" | 9 #include "content/public/renderer/media_stream_renderer_factory.h" |
| 10 #include "content/renderer/media/webmediaplayer_ms.h" | 10 #include "content/renderer/media/webmediaplayer_ms.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } | 48 } |
| 49 | 49 |
| 50 void RemoveObserver(int delegate_id) override { | 50 void RemoveObserver(int delegate_id) override { |
| 51 EXPECT_EQ(delegate_id_, delegate_id); | 51 EXPECT_EQ(delegate_id_, delegate_id); |
| 52 observer_ = nullptr; | 52 observer_ = nullptr; |
| 53 } | 53 } |
| 54 | 54 |
| 55 void DidPlay(int delegate_id, | 55 void DidPlay(int delegate_id, |
| 56 bool has_video, | 56 bool has_video, |
| 57 bool has_audio, | 57 bool has_audio, |
| 58 bool is_remote, | |
| 59 media::MediaContentType type) override { | 58 media::MediaContentType type) override { |
| 60 EXPECT_EQ(delegate_id_, delegate_id); | 59 EXPECT_EQ(delegate_id_, delegate_id); |
| 61 EXPECT_FALSE(playing_); | 60 EXPECT_FALSE(playing_); |
| 62 playing_ = true; | 61 playing_ = true; |
| 62 has_video_ = has_video; |
| 63 is_gone_ = false; | 63 is_gone_ = false; |
| 64 } | 64 } |
| 65 | 65 |
| 66 void DidPause(int delegate_id, bool reached_end_of_stream) override { | 66 void DidPause(int delegate_id) override { |
| 67 EXPECT_EQ(delegate_id_, delegate_id); | 67 EXPECT_EQ(delegate_id_, delegate_id); |
| 68 EXPECT_TRUE(playing_); | 68 EXPECT_TRUE(playing_); |
| 69 EXPECT_FALSE(is_gone_); | 69 EXPECT_FALSE(is_gone_); |
| 70 playing_ = false; | 70 playing_ = false; |
| 71 } | 71 } |
| 72 | 72 |
| 73 void PlayerGone(int delegate_id) override { | 73 void PlayerGone(int delegate_id) override { |
| 74 EXPECT_EQ(delegate_id_, delegate_id); | 74 EXPECT_EQ(delegate_id_, delegate_id); |
| 75 is_gone_ = true; | 75 is_gone_ = true; |
| 76 } | 76 } |
| 77 | 77 |
| 78 bool IsHidden() override { return is_hidden_; } | 78 void SetIdle(int delegate_id, bool is_idle) override { |
| 79 EXPECT_EQ(delegate_id_, delegate_id); |
| 80 is_idle_ = is_idle; |
| 81 } |
| 79 | 82 |
| 80 bool IsPlayingBackgroundVideo() override { return false; } | 83 bool IsIdle(int delegate_id) override { |
| 84 EXPECT_EQ(delegate_id_, delegate_id); |
| 85 return is_idle_; |
| 86 } |
| 87 |
| 88 void ClearStaleFlag(int delegate_id) override { |
| 89 EXPECT_EQ(delegate_id_, delegate_id); |
| 90 } |
| 91 |
| 92 bool IsStale(int delegate_id) override { |
| 93 EXPECT_EQ(delegate_id_, delegate_id); |
| 94 return false; |
| 95 } |
| 96 |
| 97 bool IsFrameHidden() override { return is_hidden_; } |
| 98 bool IsFrameClosed() override { return false; } |
| 99 bool IsBackgroundVideoPlaybackUnlocked() override { return false; } |
| 81 | 100 |
| 82 void set_hidden(bool is_hidden) { is_hidden_ = is_hidden; } | 101 void set_hidden(bool is_hidden) { is_hidden_ = is_hidden; } |
| 83 | 102 |
| 84 private: | 103 private: |
| 85 int delegate_id_ = 1234; | 104 int delegate_id_ = 1234; |
| 86 Observer* observer_ = nullptr; | 105 Observer* observer_ = nullptr; |
| 87 bool playing_ = false; | 106 bool playing_ = false; |
| 107 bool has_video_ = false; |
| 88 bool is_hidden_ = false; | 108 bool is_hidden_ = false; |
| 89 bool is_gone_ = true; | 109 bool is_gone_ = true; |
| 110 bool is_idle_ = false; |
| 90 | 111 |
| 91 DISALLOW_COPY_AND_ASSIGN(FakeWebMediaPlayerDelegate); | 112 DISALLOW_COPY_AND_ASSIGN(FakeWebMediaPlayerDelegate); |
| 92 }; | 113 }; |
| 93 | 114 |
| 94 class ReusableMessageLoopEvent { | 115 class ReusableMessageLoopEvent { |
| 95 public: | 116 public: |
| 96 ReusableMessageLoopEvent() : event_(new media::WaitableMessageLoopEvent()) {} | 117 ReusableMessageLoopEvent() : event_(new media::WaitableMessageLoopEvent()) {} |
| 97 | 118 |
| 98 base::Closure GetClosure() const { return event_->GetClosure(); } | 119 base::Closure GetClosure() const { return event_->GetClosure(); } |
| 99 | 120 |
| (...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 player_->play(); | 921 player_->play(); |
| 901 EXPECT_FALSE(player_->paused()); | 922 EXPECT_FALSE(player_->paused()); |
| 902 | 923 |
| 903 // A pause delivered via the delegate should not pause the video since these | 924 // A pause delivered via the delegate should not pause the video since these |
| 904 // calls are currently ignored. | 925 // calls are currently ignored. |
| 905 player_->OnPause(); | 926 player_->OnPause(); |
| 906 EXPECT_FALSE(player_->paused()); | 927 EXPECT_FALSE(player_->paused()); |
| 907 | 928 |
| 908 // A hidden player should start still be playing upon shown. | 929 // A hidden player should start still be playing upon shown. |
| 909 delegate_.set_hidden(false); | 930 delegate_.set_hidden(false); |
| 910 player_->OnShown(); | 931 player_->OnFrameShown(); |
| 911 EXPECT_FALSE(player_->paused()); | 932 EXPECT_FALSE(player_->paused()); |
| 912 | 933 |
| 913 // A hidden event should not pause the player. | 934 // A hidden event should not pause the player. |
| 914 delegate_.set_hidden(true); | 935 delegate_.set_hidden(true); |
| 915 player_->OnHidden(); | 936 player_->OnFrameHidden(); |
| 916 EXPECT_FALSE(player_->paused()); | 937 EXPECT_FALSE(player_->paused()); |
| 917 | 938 |
| 918 // A user generated pause() should clear the automatic resumption. | 939 // A user generated pause() should clear the automatic resumption. |
| 919 player_->pause(); | 940 player_->pause(); |
| 920 delegate_.set_hidden(false); | 941 delegate_.set_hidden(false); |
| 921 player_->OnShown(); | 942 player_->OnFrameShown(); |
| 922 EXPECT_TRUE(player_->paused()); | 943 EXPECT_TRUE(player_->paused()); |
| 923 | 944 |
| 924 // A user generated play() should start playback. | 945 // A user generated play() should start playback. |
| 925 player_->play(); | 946 player_->play(); |
| 926 EXPECT_FALSE(player_->paused()); | 947 EXPECT_FALSE(player_->paused()); |
| 927 | 948 |
| 928 // An OnSuspendRequested() without forced suspension should do nothing. | 949 // An OnSuspendRequested() without forced suspension should do nothing. |
| 929 player_->OnSuspendRequested(false); | 950 player_->OnIdleTimeout(); |
| 930 EXPECT_FALSE(player_->paused()); | 951 EXPECT_FALSE(player_->paused()); |
| 931 | 952 |
| 932 // An OnSuspendRequested() with forced suspension should pause playback. | 953 // An OnSuspendRequested() with forced suspension should pause playback. |
| 933 player_->OnSuspendRequested(true); | 954 player_->OnFrameClosed(); |
| 934 EXPECT_TRUE(player_->paused()); | 955 EXPECT_TRUE(player_->paused()); |
| 935 | 956 |
| 936 // OnShown() should restart after a forced suspension. | 957 // OnShown() should restart after a forced suspension. |
| 937 player_->OnShown(); | 958 player_->OnFrameShown(); |
| 938 EXPECT_FALSE(player_->paused()); | 959 EXPECT_FALSE(player_->paused()); |
| 939 EXPECT_CALL(*this, DoSetWebLayer(false)); | 960 EXPECT_CALL(*this, DoSetWebLayer(false)); |
| 940 | 961 |
| 941 base::RunLoop().RunUntilIdle(); | 962 base::RunLoop().RunUntilIdle(); |
| 942 } | 963 } |
| 943 #endif | 964 #endif |
| 944 | 965 |
| 945 } // namespace content | 966 } // namespace content |
| OLD | NEW |