| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_MOCK_OBJECTS_H_ | 11 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_MOCK_OBJECTS_H_ |
| 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_MOCK_OBJECTS_H_ | 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_MOCK_OBJECTS_H_ |
| 13 | 13 |
| 14 #include "webrtc/modules/desktop_capture/screen_capturer.h" |
| 15 |
| 16 #include <memory> |
| 17 |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "webrtc/base/constructormagic.h" | 19 #include "webrtc/base/constructormagic.h" |
| 16 #include "webrtc/modules/desktop_capture/screen_capturer.h" | 20 #include "webrtc/modules/desktop_capture/desktop_geometry.h" |
| 21 #include "webrtc/modules/desktop_capture/desktop_region.h" |
| 22 #include "webrtc/modules/desktop_capture/shared_memory.h" |
| 17 | 23 |
| 18 namespace webrtc { | 24 namespace webrtc { |
| 19 | 25 |
| 20 class MockScreenCapturer : public ScreenCapturer { | 26 class MockScreenCapturer : public ScreenCapturer { |
| 21 public: | 27 public: |
| 22 MockScreenCapturer() {} | 28 MockScreenCapturer(); |
| 23 virtual ~MockScreenCapturer() {} | 29 // TODO(zijiehe): Use override instead of virtual for overrided functions, |
| 30 // once http://crbug.com/428099 has been addressed. |
| 31 virtual ~MockScreenCapturer(); |
| 24 | 32 |
| 25 MOCK_METHOD1(Start, void(Callback* callback)); | 33 MOCK_METHOD1(Start, void(Callback*)); |
| 26 MOCK_METHOD1(Capture, void(const DesktopRegion& region)); | 34 MOCK_METHOD1(Capture, void(const DesktopRegion&)); |
| 27 MOCK_METHOD1(GetScreenList, bool(ScreenList* screens)); | 35 MOCK_METHOD1(GetScreenList, bool(ScreenList*)); |
| 28 MOCK_METHOD1(SelectScreen, bool(ScreenId id)); | 36 MOCK_METHOD1(SelectScreen, bool(ScreenId)); |
| 37 |
| 38 // MOCK_METHOD* cannot accept std::unique_ptr as parameter. |
| 39 virtual void SetSharedMemoryFactory( |
| 40 std::unique_ptr<SharedMemoryFactory> shared_memory_factory); |
| 41 |
| 42 // The size of the frame which will be returned in next Capture() callback. |
| 43 DesktopSize* size() { return &size_; } |
| 44 |
| 45 // The dirty regions of the frame which will be returned in next Capture() |
| 46 // callback. MockScreenCapturer will return a white frame, with black in the |
| 47 // dirty_region_. Each Capture() function call with return_frame_ as true will |
| 48 // consume dirty_region_. |
| 49 DesktopRegion* dirty_region() { return &dirty_region_; } |
| 50 |
| 51 // The result which will be returned in next Capture() callback. |
| 52 Result* result() { return &result_; } |
| 53 |
| 54 // Decides whether MockScreenCapturer returns a frame in next Capture() |
| 55 // callback. If return_frame_ is true, MockScreenCapturer will create a frame |
| 56 // according to both size_ and dirty_region_. |
| 57 bool* return_frame() { return &return_frame_; } |
| 58 |
| 59 // Decides whether MockScreenCapturer returns a frame with dirty regions. |
| 60 // MockScreenCapturer will keep DesktopFrame::dirty_region() empty if this |
| 61 // field is false. |
| 62 bool* provide_dirty_region_hints() { return &provide_dirty_region_hints_; } |
| 63 |
| 64 // Decides whether MockScreenCapturer randomly enlarges dirty regions in the |
| 65 // DesktopFrame. Set this field to true to simulate an inaccurate dirty |
| 66 // regions' return from OS APIs. |
| 67 bool* enlarge_dirty_region() { return &enlarge_dirty_region_; } |
| 68 |
| 69 // The range to enlarge a dirty region if |enlarge_dirty_region_| is true. |
| 70 // This field cannot be less than or equal to zero. |
| 71 int* enlarge_range() { return &enlarge_range_; } |
| 72 |
| 73 // Decides whether MockScreenCapturer randomly add some dirty regions in the |
| 74 // DesktopFrame. Set this field to true to simulate an |
| 75 // inaccurate dirty regions' return from OS APIs. |
| 76 bool* random_dirty_region() { return &random_dirty_region_; } |
| 29 | 77 |
| 30 private: | 78 private: |
| 79 Callback* callback_; |
| 80 std::unique_ptr<SharedMemoryFactory> shared_memory_factory_; |
| 81 DesktopSize size_; |
| 82 DesktopRegion dirty_region_; |
| 83 Result result_; |
| 84 bool return_frame_; |
| 85 bool provide_dirty_region_hints_; |
| 86 bool enlarge_dirty_region_; |
| 87 int enlarge_range_; |
| 88 bool random_dirty_region_; |
| 89 |
| 31 RTC_DISALLOW_COPY_AND_ASSIGN(MockScreenCapturer); | 90 RTC_DISALLOW_COPY_AND_ASSIGN(MockScreenCapturer); |
| 32 }; | 91 }; |
| 33 | 92 |
| 34 class MockScreenCapturerCallback : public ScreenCapturer::Callback { | 93 class MockScreenCapturerCallback : public ScreenCapturer::Callback { |
| 35 public: | 94 public: |
| 36 MockScreenCapturerCallback() {} | 95 MockScreenCapturerCallback() {} |
| 37 virtual ~MockScreenCapturerCallback() {} | 96 virtual ~MockScreenCapturerCallback() {} |
| 38 | 97 |
| 39 MOCK_METHOD2(OnCaptureResultPtr, | 98 MOCK_METHOD2(OnCaptureResultPtr, |
| 40 void(DesktopCapturer::Result result, | 99 void(DesktopCapturer::Result result, |
| 41 std::unique_ptr<DesktopFrame>* frame)); | 100 std::unique_ptr<DesktopFrame>* frame)); |
| 42 void OnCaptureResult(DesktopCapturer::Result result, | 101 void OnCaptureResult(DesktopCapturer::Result result, |
| 43 std::unique_ptr<DesktopFrame> frame) override { | 102 std::unique_ptr<DesktopFrame> frame) override { |
| 44 OnCaptureResultPtr(result, &frame); | 103 OnCaptureResultPtr(result, &frame); |
| 45 } | 104 } |
| 46 | 105 |
| 47 private: | 106 private: |
| 48 RTC_DISALLOW_COPY_AND_ASSIGN(MockScreenCapturerCallback); | 107 RTC_DISALLOW_COPY_AND_ASSIGN(MockScreenCapturerCallback); |
| 49 }; | 108 }; |
| 50 | 109 |
| 51 } // namespace webrtc | 110 } // namespace webrtc |
| 52 | 111 |
| 53 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_MOCK_OBJECTS_H_ | 112 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_MOCK_OBJECTS_H_ |
| OLD | NEW |