scene_management_mocks/
mock_scene_manager.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2022 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use anyhow::Error;
use async_trait::async_trait;
use fidl_fuchsia_ui_views::ViewRef;
use scene_management::{DisplayMetrics, InjectorViewportSubscriber, SceneManagerTrait};
use std::cell::Cell;
use {fidl_fuchsia_ui_app as ui_app, fidl_fuchsia_ui_views as ui_views};

pub struct MockSceneManager {
    was_present_root_view_called: Cell<bool>,
    was_set_root_view_called: Cell<bool>,
    set_root_view_viewport_token: Cell<Option<ui_views::ViewportCreationToken>>,
    set_root_view_view_ref: Cell<Option<ViewRef>>,
}

impl MockSceneManager {
    pub fn new() -> Self {
        MockSceneManager {
            was_present_root_view_called: Cell::new(false),
            was_set_root_view_called: Cell::new(false),
            set_root_view_viewport_token: Cell::new(None),
            set_root_view_view_ref: Cell::new(None),
        }
    }

    pub fn assert_present_root_view_called(&self) {
        assert!(self.was_present_root_view_called.get() == true);
        self.was_present_root_view_called.set(false);
    }

    pub fn get_set_root_view_called_args(
        &self,
    ) -> (ui_views::ViewportCreationToken, Option<ui_views::ViewRef>) {
        assert!(self.was_set_root_view_called.get() == true);
        (
            self.set_root_view_viewport_token
                .take()
                .expect("Expected to have a viewport_token from a previous call to set_root_view."),
            self.set_root_view_view_ref.take(),
        )
    }
}

#[async_trait]
#[allow(unused_variables)]
impl SceneManagerTrait for MockSceneManager {
    fn present_root_view(&self) {
        self.was_present_root_view_called.set(true);
    }

    async fn set_root_view(
        &mut self,
        viewport_creation_token: ui_views::ViewportCreationToken,
        view_ref: Option<ui_views::ViewRef>,
    ) -> Result<(), Error> {
        self.was_set_root_view_called.set(true);
        self.set_root_view_viewport_token.set(Some(viewport_creation_token));
        self.set_root_view_view_ref.set(view_ref);
        Ok(())
    }

    // Leave everything else unimplemented.

    async fn set_root_view_deprecated(
        &mut self,
        view_provider: ui_app::ViewProviderProxy,
    ) -> Result<ui_views::ViewRef, Error> {
        unimplemented!()
    }

    fn set_cursor_position(&mut self, position_physical_px: input_pipeline::Position) {
        unimplemented!()
    }

    fn set_cursor_visibility(&mut self, visible: bool) {
        unimplemented!()
    }

    fn get_pointerinjection_view_refs(&self) -> (ui_views::ViewRef, ui_views::ViewRef) {
        unimplemented!()
    }

    fn get_pointerinjection_display_size(&self) -> input_pipeline::Size {
        unimplemented!()
    }

    fn get_pointerinjector_viewport_watcher_subscription(&self) -> InjectorViewportSubscriber {
        unimplemented!()
    }

    fn get_display_metrics(&self) -> &DisplayMetrics {
        unimplemented!()
    }
}