fidl_fuchsia_ui_focus_test_helpers/
test_helpers.rs

1// Copyright 2022 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
5//! Helper methods for tests involving `FocusChain`.
6
7use fidl_fuchsia_ui_focus::FocusChain;
8use fidl_fuchsia_ui_views::ViewRefControl;
9use fuchsia_scenic::ViewRefPair;
10
11/// Makes a focus chain of the given length, returning both the `FocusChain` instance and a vector
12/// of all the corresponding `ViewRefControl`s, in the same order.
13///
14/// The `ViewRef`s are real, but of course do not correspond to any actual views.
15pub fn make_focus_chain(length: usize) -> (FocusChain, Vec<ViewRefControl>) {
16    let mut view_refs = vec![];
17    let mut control_refs = vec![];
18    for _ in 0..length {
19        let ViewRefPair { control_ref, view_ref } = ViewRefPair::new().expect("making ViewRefPair");
20        view_refs.push(view_ref);
21        control_refs.push(control_ref);
22    }
23    let focus_chain = FocusChain { focus_chain: Some(view_refs), ..Default::default() };
24    (focus_chain, control_refs)
25}