marionette.rs (1923B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 use serde::{Deserialize, Serialize}; 6 7 use crate::common::BoolValue; 8 9 #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] 10 #[allow(non_camel_case_types)] 11 pub enum AppStatus { 12 eAttemptQuit, 13 eConsiderQuit, 14 eForceQuit, 15 eRestart, 16 } 17 18 #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] 19 pub enum Command { 20 #[serde(rename = "Marionette:AcceptConnections")] 21 AcceptConnections(BoolValue), 22 #[serde(rename = "Marionette:Quit")] 23 DeleteSession { flags: Vec<AppStatus> }, 24 #[serde(rename = "Marionette:GetContext")] 25 GetContext, 26 #[serde(rename = "Marionette:GetScreenOrientation")] 27 GetScreenOrientation, 28 } 29 30 #[cfg(test)] 31 mod tests { 32 use super::*; 33 use crate::test::assert_ser_de; 34 use serde_json::json; 35 36 #[test] 37 fn test_json_command_accept_connections() { 38 assert_ser_de( 39 &Command::AcceptConnections(BoolValue::new(false)), 40 json!({"Marionette:AcceptConnections": {"value": false }}), 41 ); 42 } 43 44 #[test] 45 fn test_json_command_delete_session() { 46 let data = &Command::DeleteSession { 47 flags: vec![AppStatus::eForceQuit], 48 }; 49 assert_ser_de(data, json!({"Marionette:Quit": {"flags": ["eForceQuit"]}})); 50 } 51 52 #[test] 53 fn test_json_command_get_context() { 54 assert_ser_de(&Command::GetContext, json!("Marionette:GetContext")); 55 } 56 57 #[test] 58 fn test_json_command_get_screen_orientation() { 59 assert_ser_de( 60 &Command::GetScreenOrientation, 61 json!("Marionette:GetScreenOrientation"), 62 ); 63 } 64 65 #[test] 66 fn test_json_command_invalid() { 67 assert!(serde_json::from_value::<Command>(json!("foo")).is_err()); 68 } 69 }