1 // Copyright 2019 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 #ifndef CONTENT_PUBLIC_TEST_MEDIA_START_STOP_OBSERVER_H_
6 #define CONTENT_PUBLIC_TEST_MEDIA_START_STOP_OBSERVER_H_
7 
8 #include "base/macros.h"
9 #include "base/run_loop.h"
10 #include "content/public/browser/web_contents_observer.h"
11 
12 namespace content {
13 
14 class WebContents;
15 
16 // Used in tests to wait for media in a WebContents to start or stop playing.
17 class MediaStartStopObserver : public WebContentsObserver {
18  public:
19   enum class Type {
20     kStart,
21     kStop,
22     kEnterPictureInPicture,
23     kExitPictureInPicture
24   };
25 
26   MediaStartStopObserver(WebContents* web_contents, Type type);
27   ~MediaStartStopObserver() override;
28 
29   // WebContentsObserver implementation.
30   void MediaStartedPlaying(const MediaPlayerInfo& info,
31                            const MediaPlayerId& id) override;
32   void MediaStoppedPlaying(
33       const MediaPlayerInfo& info,
34       const MediaPlayerId& id,
35       WebContentsObserver::MediaStoppedReason reason) override;
36 
37   void MediaPictureInPictureChanged(bool is_picture_in_picture) override;
38 
39   void Wait();
40 
41  private:
42   base::RunLoop run_loop_;
43   const Type type_;
44 
45   DISALLOW_COPY_AND_ASSIGN(MediaStartStopObserver);
46 };
47 
48 }  // namespace content
49 
50 #endif  // CONTENT_PUBLIC_TEST_MEDIA_START_STOP_OBSERVER_H_
51