Skip to main content

cbf_chrome/data/
profile.rs

1//! Chrome-specific profile information, with conversions to/from `cbf::data::profile::ProfileInfo`.
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub struct ChromeProfileInfo {
5    pub profile_id: String,
6    pub profile_path: String,
7    pub display_name: String,
8    pub is_default: bool,
9}
10
11impl From<ChromeProfileInfo> for cbf::data::profile::ProfileInfo {
12    fn from(value: ChromeProfileInfo) -> Self {
13        Self {
14            profile_id: value.profile_id,
15            profile_path: value.profile_path,
16            display_name: value.display_name,
17            is_default: value.is_default,
18        }
19    }
20}
21
22impl From<cbf::data::profile::ProfileInfo> for ChromeProfileInfo {
23    fn from(value: cbf::data::profile::ProfileInfo) -> Self {
24        Self {
25            profile_id: value.profile_id,
26            profile_path: value.profile_path,
27            display_name: value.display_name,
28            is_default: value.is_default,
29        }
30    }
31}
32
33#[cfg(test)]
34mod tests {
35    use super::ChromeProfileInfo;
36
37    #[test]
38    fn round_trip_preserves_is_default() {
39        let chrome = ChromeProfileInfo {
40            profile_id: "profile-a".to_string(),
41            profile_path: "/tmp/profile-a".to_string(),
42            display_name: "Profile A".to_string(),
43            is_default: true,
44        };
45
46        let generic: cbf::data::profile::ProfileInfo = chrome.clone().into();
47        let round_tripped: ChromeProfileInfo = generic.into();
48
49        assert_eq!(round_tripped, chrome);
50    }
51}