//! Browser-generic browsing context capability policy models.

/// Allow or deny a capability for a browsing context.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum CapabilityPolicy {
    #[default]
    Allow,
    Deny,
}

/// IPC policy for a browsing context.
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub enum IpcPolicy {
    #[default]
    Deny,
    Allow {
        allowed_origins: Vec<String>,
    },
}

/// Create-time capability policy for a browsing context.
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct BrowsingContextPolicy {
    pub ipc: IpcPolicy,
    pub extensions: CapabilityPolicy,
}

#[cfg(test)]
mod tests {
    use super::{BrowsingContextPolicy, CapabilityPolicy, IpcPolicy};

    #[test]
    fn default_policy_matches_legacy_defaults() {
        assert_eq!(
            BrowsingContextPolicy::default(),
            BrowsingContextPolicy {
                ipc: IpcPolicy::Deny,
                extensions: CapabilityPolicy::Allow,
            }
        );
    }
}
