cbf-chrome 0.1.0-alpha.7

Chromium-specific safe API layer for CBF.
Documentation
//! Chrome transport execution state for tabs.

use cbf::data::execution::BrowsingContextExecutionState;

/// Represents the execution state of a Chromium tab.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ChromeTabExecutionState {
    Running,
    Suspended,
}

impl From<BrowsingContextExecutionState> for ChromeTabExecutionState {
    fn from(value: BrowsingContextExecutionState) -> Self {
        match value {
            BrowsingContextExecutionState::Running => Self::Running,
            BrowsingContextExecutionState::Suspended => Self::Suspended,
        }
    }
}

impl From<ChromeTabExecutionState> for BrowsingContextExecutionState {
    fn from(value: ChromeTabExecutionState) -> Self {
        match value {
            ChromeTabExecutionState::Running => Self::Running,
            ChromeTabExecutionState::Suspended => Self::Suspended,
        }
    }
}

#[cfg(test)]
mod tests {
    use cbf::data::execution::BrowsingContextExecutionState;

    use super::ChromeTabExecutionState;

    #[test]
    fn execution_state_round_trips_between_generic_and_chrome_types() {
        let state = ChromeTabExecutionState::from(BrowsingContextExecutionState::Suspended);

        assert_eq!(state, ChromeTabExecutionState::Suspended);
        assert_eq!(
            BrowsingContextExecutionState::from(state),
            BrowsingContextExecutionState::Suspended
        );
    }
}