Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Rakina Zata Amni | c7bc8263 | 2019-12-09 05:21:22 | [diff] [blame] | 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_BROWSER_PRESENTATION_PRESENTATION_TEST_UTILS_H_ |
| 6 | #define CONTENT_BROWSER_PRESENTATION_PRESENTATION_TEST_UTILS_H_ |
| 7 | |
| 8 | #include "content/browser/presentation/presentation_service_impl.h" |
| 9 | #include "content/public/browser/presentation_request.h" |
| 10 | #include "content/public/browser/presentation_service_delegate.h" |
| 11 | #include "testing/gmock/include/gmock/gmock.h" |
| 12 | |
| 13 | using blink::mojom::PresentationConnection; |
| 14 | using blink::mojom::PresentationConnectionCloseReason; |
| 15 | using blink::mojom::PresentationConnectionMessagePtr; |
| 16 | using blink::mojom::PresentationConnectionResult; |
| 17 | using blink::mojom::PresentationConnectionResultPtr; |
| 18 | using blink::mojom::PresentationConnectionState; |
| 19 | using blink::mojom::PresentationController; |
| 20 | using blink::mojom::PresentationError; |
| 21 | using blink::mojom::PresentationErrorPtr; |
| 22 | using blink::mojom::PresentationErrorType; |
| 23 | using blink::mojom::PresentationInfo; |
| 24 | using blink::mojom::PresentationInfoPtr; |
| 25 | using blink::mojom::ScreenAvailability; |
| 26 | using ::testing::_; |
| 27 | using ::testing::Eq; |
| 28 | using ::testing::Mock; |
| 29 | using ::testing::Return; |
| 30 | using ::testing::SaveArg; |
| 31 | using NewPresentationCallback = |
| 32 | content::PresentationServiceImpl::NewPresentationCallback; |
| 33 | |
| 34 | namespace content { |
| 35 | |
| 36 | namespace { |
| 37 | |
| 38 | MATCHER_P(PresentationUrlsAre, expected_urls, "") { |
| 39 | return arg.presentation_urls == expected_urls; |
| 40 | } |
| 41 | |
| 42 | // Matches blink::mojom::PresentationInfo. |
| 43 | MATCHER_P(InfoEquals, expected, "") { |
| 44 | return expected.url == arg.url && expected.id == arg.id; |
| 45 | } |
| 46 | |
| 47 | // Matches blink::mojom::PresentationInfoPtr. |
| 48 | MATCHER_P(InfoPtrEquals, expected, "") { |
| 49 | return expected.url == arg->url && expected.id == arg->id; |
| 50 | } |
| 51 | |
| 52 | ACTION_TEMPLATE(SaveArgByMove, |
| 53 | HAS_1_TEMPLATE_PARAMS(int, k), |
| 54 | AND_1_VALUE_PARAMS(pointer)) { |
| 55 | *pointer = std::move(::testing::get<k>(args)); |
| 56 | } |
| 57 | |
| 58 | } // namespace |
| 59 | |
| 60 | class MockPresentationServiceDelegate |
| 61 | : public ControllerPresentationServiceDelegate { |
| 62 | public: |
| 63 | MockPresentationServiceDelegate(); |
| 64 | ~MockPresentationServiceDelegate() override; |
| 65 | |
| 66 | MOCK_METHOD3(AddObserver, |
| 67 | void(int render_process_id, |
| 68 | int render_frame_id, |
| 69 | PresentationServiceDelegate::Observer* observer)); |
| 70 | MOCK_METHOD2(RemoveObserver, |
| 71 | void(int render_process_id, int render_frame_id)); |
| 72 | |
| 73 | bool AddScreenAvailabilityListener( |
| 74 | int render_process_id, |
| 75 | int routing_id, |
| 76 | PresentationScreenAvailabilityListener* listener) override; |
| 77 | |
| 78 | MOCK_METHOD0(AddScreenAvailabilityListener, bool()); |
| 79 | |
| 80 | MOCK_METHOD3(RemoveScreenAvailabilityListener, |
| 81 | void(int render_process_id, |
| 82 | int routing_id, |
| 83 | PresentationScreenAvailabilityListener* listener)); |
| 84 | MOCK_METHOD2(Reset, void(int render_process_id, int routing_id)); |
| 85 | MOCK_METHOD2(SetDefaultPresentationUrls, |
| 86 | void(const PresentationRequest& request, |
| 87 | DefaultPresentationConnectionCallback callback)); |
| 88 | MOCK_METHOD3(StartPresentation, |
| 89 | void(const PresentationRequest& request, |
| 90 | PresentationConnectionCallback success_cb, |
| 91 | PresentationConnectionErrorCallback error_cb)); |
| 92 | MOCK_METHOD4(ReconnectPresentation, |
| 93 | void(const PresentationRequest& request, |
| 94 | const std::string& presentation_id, |
| 95 | PresentationConnectionCallback success_cb, |
| 96 | PresentationConnectionErrorCallback error_cb)); |
| 97 | MOCK_METHOD3(CloseConnection, |
| 98 | void(int render_process_id, |
| 99 | int render_frame_id, |
| 100 | const std::string& presentation_id)); |
| 101 | MOCK_METHOD3(Terminate, |
| 102 | void(int render_process_id, |
| 103 | int render_frame_id, |
| 104 | const std::string& presentation_id)); |
| 105 | MOCK_METHOD3(GetFlingingController, |
| 106 | std::unique_ptr<media::FlingingController>( |
| 107 | int render_process_id, |
| 108 | int render_frame_id, |
| 109 | const std::string& presentation_id)); |
| 110 | MOCK_METHOD5(SendMessage, |
| 111 | void(int render_process_id, |
| 112 | int render_frame_id, |
| 113 | const PresentationInfo& presentation_info, |
| 114 | PresentationConnectionMessagePtr message, |
| 115 | const SendMessageCallback& send_message_cb)); |
| 116 | MOCK_METHOD4( |
| 117 | ListenForConnectionStateChange, |
| 118 | void(int render_process_id, |
| 119 | int render_frame_id, |
| 120 | const PresentationInfo& connection, |
| 121 | const PresentationConnectionStateChangedCallback& state_changed_cb)); |
| 122 | |
| 123 | void set_screen_availability_listening_supported(bool value) { |
| 124 | screen_availability_listening_supported_ = value; |
| 125 | } |
| 126 | |
| 127 | private: |
| 128 | bool screen_availability_listening_supported_ = true; |
| 129 | }; |
| 130 | |
| 131 | class MockPresentationReceiver : public blink::mojom::PresentationReceiver { |
| 132 | public: |
| 133 | MockPresentationReceiver(); |
| 134 | ~MockPresentationReceiver() override; |
| 135 | |
Wei4 Wang | e1c8c00 | 2023-04-24 23:30:25 | [diff] [blame] | 136 | MOCK_METHOD1(OnReceiverConnectionAvailable, |
| 137 | void(PresentationConnectionResultPtr result)); |
Rakina Zata Amni | c7bc8263 | 2019-12-09 05:21:22 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | class MockReceiverPresentationServiceDelegate |
| 141 | : public ReceiverPresentationServiceDelegate { |
| 142 | public: |
| 143 | MockReceiverPresentationServiceDelegate(); |
| 144 | ~MockReceiverPresentationServiceDelegate() override; |
| 145 | MOCK_METHOD3(AddObserver, |
| 146 | void(int render_process_id, |
| 147 | int render_frame_id, |
| 148 | PresentationServiceDelegate::Observer* observer)); |
| 149 | MOCK_METHOD2(RemoveObserver, |
| 150 | void(int render_process_id, int render_frame_id)); |
| 151 | MOCK_METHOD2(Reset, void(int render_process_id, int routing_id)); |
| 152 | MOCK_METHOD1(RegisterReceiverConnectionAvailableCallback, |
| 153 | void(const ReceiverConnectionAvailableCallback&)); |
| 154 | }; |
| 155 | |
| 156 | class MockPresentationConnection : public PresentationConnection { |
| 157 | public: |
| 158 | MockPresentationConnection(); |
| 159 | ~MockPresentationConnection() override; |
| 160 | |
| 161 | MOCK_METHOD1(OnMessage, void(PresentationConnectionMessagePtr message)); |
| 162 | MOCK_METHOD1(DidChangeState, void(PresentationConnectionState state)); |
| 163 | MOCK_METHOD1(DidClose, void(blink::mojom::PresentationConnectionCloseReason)); |
| 164 | }; |
| 165 | |
| 166 | class MockPresentationController : public blink::mojom::PresentationController { |
| 167 | public: |
| 168 | MockPresentationController(); |
| 169 | ~MockPresentationController() override; |
| 170 | MOCK_METHOD2(OnScreenAvailabilityUpdated, |
| 171 | void(const GURL& url, ScreenAvailability availability)); |
| 172 | MOCK_METHOD2(OnConnectionStateChanged, |
| 173 | void(PresentationInfoPtr connection, |
| 174 | PresentationConnectionState new_state)); |
| 175 | MOCK_METHOD3(OnConnectionClosed, |
| 176 | void(PresentationInfoPtr connection, |
| 177 | PresentationConnectionCloseReason reason, |
| 178 | const std::string& message)); |
| 179 | MOCK_METHOD2( |
| 180 | OnConnectionMessagesReceived, |
| 181 | void(const PresentationInfo& presentation_info, |
| 182 | const std::vector<PresentationConnectionMessagePtr>& messages)); |
| 183 | MOCK_METHOD1(OnDefaultPresentationStarted, |
| 184 | void(PresentationConnectionResultPtr result)); |
| 185 | }; |
| 186 | |
| 187 | } // namespace content |
| 188 | |
| 189 | #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_TEST_UTILS_H_ |