OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <stddef.h> |
| 6 #include <vector> |
| 7 |
| 8 #include "content/browser/media/session/media_session_observer.h" |
| 9 |
| 10 namespace content { |
| 11 |
| 12 // MockMediaSessionObserver is a mock implementation of MediaSessionObserver to |
| 13 // be used in tests. |
| 14 class MockMediaSessionObserver : public MediaSessionObserver { |
| 15 public: |
| 16 MockMediaSessionObserver(); |
| 17 ~MockMediaSessionObserver() override; |
| 18 |
| 19 // Implements MediaSessionObserver. |
| 20 void OnSuspend(int player_id) override; |
| 21 void OnResume(int player_id) override; |
| 22 void OnSetVolumeMultiplier(int player_id, double volume_multiplier) override; |
| 23 |
| 24 // Simulate that a new player started. |
| 25 // Returns the player_id. |
| 26 int StartNewPlayer(); |
| 27 |
| 28 // Returns whether |player_id| is playing. |
| 29 bool IsPlaying(size_t player_id); |
| 30 |
| 31 // Returns the volume multiplier of |player_id|. |
| 32 double GetVolumeMultiplier(size_t player_id); |
| 33 |
| 34 // Simulate a play state change for |player_id|. |
| 35 void SetPlaying(size_t player_id, bool playing); |
| 36 |
| 37 int received_suspend_calls() const; |
| 38 int received_resume_calls() const; |
| 39 |
| 40 private: |
| 41 // Internal representation of the players to keep track of their statuses. |
| 42 struct MockPlayer { |
| 43 public: |
| 44 MockPlayer(bool is_playing = true, double volume_multiplier = 1.0f) |
| 45 : is_playing_(is_playing), |
| 46 volume_multiplier_(volume_multiplier) {} |
| 47 bool is_playing_; |
| 48 double volume_multiplier_; |
| 49 }; |
| 50 |
| 51 // Basic representation of the players. The position in the vector is the |
| 52 // player_id. The value of the vector is the playing status and volume. |
| 53 std::vector<MockPlayer> players_; |
| 54 |
| 55 int received_resume_calls_ = 0; |
| 56 int received_suspend_calls_ = 0; |
| 57 }; |
| 58 |
| 59 } // namespace content |
OLD | NEW |