Chromium Code Reviews| Index: media/base/android/mock_android_overlay.h |
| diff --git a/media/base/android/mock_android_overlay.h b/media/base/android/mock_android_overlay.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8b72c2963392aacd0c164cffab18ea455babd980 |
| --- /dev/null |
| +++ b/media/base/android/mock_android_overlay.h |
| @@ -0,0 +1,112 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MEDIA_BASE_ANDROID_MOCK_ANDROID_OVERLAY_H_ |
| +#define MEDIA_BASE_ANDROID_MOCK_ANDROID_OVERLAY_H_ |
| + |
| +#include "media/base/android/android_overlay.h" |
| + |
| +#include "base/callback.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| + |
| +namespace media { |
| + |
| +// AndroidOverlay implementation that supports weak ptrs. |
| +class MockAndroidOverlay : public ::testing::StrictMock<AndroidOverlay> { |
| + private: |
| + class DestructionObserverInterface { |
| + public: |
| + DestructionObserverInterface() = default; |
| + virtual ~DestructionObserverInterface() {} |
| + |
| + // Called when the overlay is destroyed. Feel free to set |
| + // expectations on it. |
| + virtual void OnOverlayDestroyed() = 0; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(DestructionObserverInterface); |
| + }; |
| + |
| + public: |
| + MockAndroidOverlay(); |
| + ~MockAndroidOverlay() override; |
| + |
| + MOCK_METHOD1(ScheduleLayout, void(const gfx::Rect&)); |
| + MOCK_CONST_METHOD0(GetJavaSurface, base::android::JavaRef<jobject>&()); |
| + |
|
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)
|
| + // Set |config_|. Sometimes, it's convenient to do this after construction, |
| + // especially if one must create the overlay before the factory provides it |
| + // via CreateOverlay. That's helpful to set test expectations. |
| + void SetConfig(const Config& config); |
| + |
| + // Set of callbacks that we provide to control the overlay once you've handed |
| + // off ownership of it. Will return false if the overlay has been destroyed. |
| + using ControlCallback = base::Callback<bool()>; |
| + struct Callbacks { |
| + Callbacks(); |
| + Callbacks(const Callbacks&); |
| + ~Callbacks(); |
| + |
| + ControlCallback OverlayReady; |
| + ControlCallback OverlayFailed; |
| + ControlCallback SurfaceDestroyed; |
| + }; |
| + |
| + // Return callbacks that can be used to control the overlay. |
| + Callbacks GetCallbacks(); |
| + |
| + // Set a callback that will be called when |this| is deleted. Replaces any |
| + // previous callback. |
| + void SetDestructionCallback(const base::Closure& destruction_cb); |
| + |
| + // Mock that calls OnOverlayDestroyed when the overlay is destroyed. This |
| + // will replace the destruction callback on the mock. |
| + class DestructionObserver : StrictMock<DestructionObserverInterface> { |
| + protected: |
| + DestructionObserver(MockAndroidOverlay*); |
| + |
| + public: |
| + ~DestructionObserver(); |
| + |
| + // Called when the overlay is destroyed. Feel free to set |
| + // expectations on it. |
| + MOCK_METHOD0(OnOverlayDestroyed, void()); |
| + |
| + private: |
| + friend class MockAndroidOverlay; |
| + |
| + base::WeakPtrFactory<DestructionObserver> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DestructionObserver); |
| + }; |
| + |
| + // Create a DestructionObserver for us. There can be only one. |
| + std::unique_ptr<DestructionObserver> CreateDestructionObserver(); |
| + |
| + private: |
| + // Trampoline to promote |wp| and call |cb|, or return false. |
| + static bool CallbackTrampoline(void (MockAndroidOverlay::*cb)(), |
| + base::WeakPtr<MockAndroidOverlay> wp); |
| + |
| + // Send callbacks. |
| + void OnOverlayReady(); |
| + void OnOverlayFailed(); |
| + void OnSurfaceDestroyed(); |
| + |
| + 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
|
| + |
| + // Initial configuration, mostly for callbacks. |
| + Config config_; |
| + |
| + base::Closure destruction_cb_; |
| + |
| + base::WeakPtrFactory<MockAndroidOverlay> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MockAndroidOverlay); |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_BASE_ANDROID_MOCK_ANDROID_OVERLAY_H_ |