Skip to main content

settings_test_common/
helpers.rs

1// Copyright 2025 The Fuchsia 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
5use fidl_fuchsia_ui_input::MediaButtonsEvent;
6use fuchsia_async::TestExecutor;
7use futures::task::Poll;
8use std::future::Future;
9
10/// Run the provided `future` via the `executor`.
11pub fn move_executor_forward(
12    executor: &mut TestExecutor,
13    future: impl Future<Output = ()>,
14    panic_msg: &str,
15) {
16    futures::pin_mut!(future);
17    match executor.run_until_stalled(&mut future) {
18        Poll::Ready(res) => res,
19        _ => panic!("{}", panic_msg),
20    }
21}
22
23/// Run the provided `future` via the `executor` and return the result of the future.
24pub fn move_executor_forward_and_get<T>(
25    executor: &mut TestExecutor,
26    future: impl Future<Output = T>,
27    panic_msg: &str,
28) -> T {
29    futures::pin_mut!(future);
30    match executor.run_until_stalled(&mut future) {
31        Poll::Ready(res) => res,
32        _ => panic!("{}", panic_msg),
33    }
34}
35
36pub fn clone_media_buttons_event_without_wake_lease(
37    event: &MediaButtonsEvent,
38) -> MediaButtonsEvent {
39    MediaButtonsEvent {
40        volume: event.volume,
41        mic_mute: event.mic_mute,
42        pause: event.pause,
43        camera_disable: event.camera_disable,
44        power: event.power,
45        function: event.function,
46        device_id: event.device_id,
47        ..Default::default()
48    }
49}