Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: media/base/android/mock_android_overlay.h

Issue 2813303003: Add AndroidVideoSurfaceChooser to manage overlays. (Closed)
Patch Set: removed most weak factories Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 MEDIA_BASE_ANDROID_MOCK_ANDROID_OVERLAY_H_
6 #define MEDIA_BASE_ANDROID_MOCK_ANDROID_OVERLAY_H_
7
8 #include "media/base/android/android_overlay.h"
9
10 #include "base/callback.h"
11 #include "base/memory/weak_ptr.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13
14 namespace media {
15
16 // AndroidOverlay implementation that supports weak ptrs.
17 class MockAndroidOverlay : public ::testing::StrictMock<AndroidOverlay> {
18 private:
19 class DestructionObserverInterface {
20 public:
21 DestructionObserverInterface() = default;
22 virtual ~DestructionObserverInterface() {}
23
24 // Called when the overlay is destroyed. Feel free to set
25 // expectations on it.
26 virtual void OnOverlayDestroyed() = 0;
27
28 private:
29 DISALLOW_COPY_AND_ASSIGN(DestructionObserverInterface);
30 };
31
32 public:
33 MockAndroidOverlay();
34 ~MockAndroidOverlay() override;
35
36 MOCK_METHOD1(ScheduleLayout, void(const gfx::Rect&));
37 MOCK_CONST_METHOD0(GetJavaSurface, base::android::JavaRef<jobject>&());
38
DaleCurtis 2017/04/25 23:25:33 Why not just MOCK_METHOD0(OnOverlayDestroyed)) tha
liberato (no reviews please) 2017/04/26 17:53:57 how would one set the expectation in the test? we
DaleCurtis 2017/04/26 18:28:10 You have to set expectations before destruction an
liberato (no reviews please) 2017/04/27 18:30:12 (per offline discussion)
39 // Set |config_|. Sometimes, it's convenient to do this after construction,
40 // especially if one must create the overlay before the factory provides it
41 // via CreateOverlay. That's helpful to set test expectations.
42 void SetConfig(const Config& config);
43
44 // Set of callbacks that we provide to control the overlay once you've handed
45 // off ownership of it. Will return false if the overlay has been destroyed.
46 using ControlCallback = base::Callback<bool()>;
47 struct Callbacks {
48 Callbacks();
49 Callbacks(const Callbacks&);
50 ~Callbacks();
51
52 ControlCallback OverlayReady;
53 ControlCallback OverlayFailed;
54 ControlCallback SurfaceDestroyed;
55 };
56
57 // Return callbacks that can be used to control the overlay.
58 Callbacks GetCallbacks();
59
60 // Set a callback that will be called when |this| is deleted. Replaces any
61 // previous callback.
62 void SetDestructionCallback(const base::Closure& destruction_cb);
63
64 // Mock that calls OnOverlayDestroyed when the overlay is destroyed. This
65 // will replace the destruction callback on the mock.
66 class DestructionObserver : StrictMock<DestructionObserverInterface> {
67 protected:
68 DestructionObserver(MockAndroidOverlay*);
69
70 public:
71 ~DestructionObserver();
72
73 // Called when the overlay is destroyed. Feel free to set
74 // expectations on it.
75 MOCK_METHOD0(OnOverlayDestroyed, void());
76
77 private:
78 friend class MockAndroidOverlay;
79
80 base::WeakPtrFactory<DestructionObserver> weak_factory_;
81
82 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
83 };
84
85 // Create a DestructionObserver for us. There can be only one.
86 std::unique_ptr<DestructionObserver> CreateDestructionObserver();
87
88 private:
89 // Trampoline to promote |wp| and call |cb|, or return false.
90 static bool CallbackTrampoline(void (MockAndroidOverlay::*cb)(),
91 base::WeakPtr<MockAndroidOverlay> wp);
92
93 // Send callbacks.
94 void OnOverlayReady();
95 void OnOverlayFailed();
96 void OnSurfaceDestroyed();
97
98 base::WeakPtr<MockAndroidOverlay> GetWeakPtr();
DaleCurtis 2017/04/25 23:25:33 No point if private?
liberato (no reviews please) 2017/04/26 17:53:57 removed, see comment in avda.h
99
100 // Initial configuration, mostly for callbacks.
101 Config config_;
102
103 base::Closure destruction_cb_;
104
105 base::WeakPtrFactory<MockAndroidOverlay> weak_factory_;
106
107 DISALLOW_COPY_AND_ASSIGN(MockAndroidOverlay);
108 };
109
110 } // namespace media
111
112 #endif // MEDIA_BASE_ANDROID_MOCK_ANDROID_OVERLAY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698