darkwing/server/services/browser_profile_services/config/
fonts.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//! Module for handling browser font configurations across different platforms.
//! Currently returns an empty font list as the font formation logic is
//! commented out.

use crate::server::{
  dtos::{
    browser_profile_dto::BrowserProfileFullData, start_dto::StartRequest,
  },
  error::Error,
};
use serde::{Deserialize, Serialize};

use super::{FromStartRequest, Navigator, Screen};

/// Represents a collection of system fonts available to the browser profile.
///
/// This struct holds a vector of font names that should be available to the
/// browser based on the platform (Windows, macOS, or Linux).
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct Fonts(
  /// Vector of font names.
  pub(super) Vec<String>,
);

impl FromStartRequest<Fonts> for Fonts {
  /// Creates a new `Fonts` instance from the start request parameters.
  ///
  /// Currently returns an empty vector as the font formation logic is
  /// temporarily commented out in the local-api implementation.
  ///
  /// # Arguments
  /// * `_bp` - Browser profile data containing platform information
  /// * `_request` - Start request parameters
  /// * `_navigator` - Navigator configuration
  /// * `_screen` - Screen configuration
  /// * `_token` - Authentication token
  ///
  /// # Returns
  /// * `Result<Self, Error>` - A new Fonts instance with an empty vector
  fn from_start_request(
    _bp: &BrowserProfileFullData,
    _request: &StartRequest,
    _navigator: &Navigator,
    _screen: &Screen,
    _token: &str,
  ) -> Result<Self, Error> {
    // Currently by some reason fonts forming is _commented_ in local-api, so
    // transferring this logic here.

    // let fonts = match bp.platform {
    //   Platform::Macos => MACOS_FONTS.to_vec(),
    //   Platform::Windows => WINDOWS_FONTS.to_vec(),
    //   Platform::Linux => LINUX_FONTS.to_vec(),
    // };

    // Ok(Self(fonts.into_iter().map(String::from).collect()))
    Ok(Self(vec![]))
  }
}

#[cfg(test)]
mod tests {
  use super::*;

  use crate::database::browser_profile::Platform;
  use crate::server::dtos::browser_profile_dto::BrowserProfileFullData;
  use crate::server::dtos::start_dto::StartRequest;
  use crate::server::services::browser_profile_services::config::consts::LINUX_MOCK_PROFILE;

  fn create_test_profile(platform: Platform) -> BrowserProfileFullData {
    let mut profile = LINUX_MOCK_PROFILE.clone();
    profile.platform = platform;
    profile
  }

  // Currently by some reason fonts forming is _commented_ in local-api, so this
  // test is _temporary_.
  #[test]
  fn test_fonts_from_start_request_empty() {
    let profile = create_test_profile(Platform::Linux);
    let request = StartRequest::get_mock();
    let navigator = Navigator::default();
    let screen = Screen::default();
    let token = String::from("dummy_token");

    let fonts = Fonts::from_start_request(
      &profile, &request, &navigator, &screen, &token,
    )
    .expect("Should create fonts");

    assert_eq!(fonts.0.len(), 0, "Fonts should be empty");
  }

  #[test]
  #[ignore = "Currently by some reason fonts forming is _commented_ in local-api, so skipping this test"]
  fn test_fonts_from_start_request_windows() {
    let profile = create_test_profile(Platform::Windows);
    let request = StartRequest::get_mock();
    let navigator = Navigator::default();
    let screen = Screen::default();
    let token = String::from("dummy_token");

    let fonts = Fonts::from_start_request(
      &profile, &request, &navigator, &screen, &token,
    )
    .expect("Should create fonts");

    assert!(fonts.0.contains(&String::from("Arial")));
    assert!(fonts.0.len() > 0);
  }

  #[test]
  #[ignore = "Currently by some reason fonts forming is _commented_ in local-api, so skipping this test"]
  fn test_fonts_from_start_request_macos() {
    let profile = create_test_profile(Platform::Macos);
    let request = StartRequest::get_mock();
    let navigator = Navigator::default();
    let screen = Screen::default();
    let token = String::from("dummy_token");

    let fonts = Fonts::from_start_request(
      &profile, &request, &navigator, &screen, &token,
    )
    .expect("Should create fonts");

    assert!(fonts.0.contains(&String::from("Helvetica")));
    assert!(fonts.0.len() > 0);
  }

  #[test]
  #[ignore = "Currently by some reason fonts forming is _commented_ in local-api, so skipping this test"]
  fn test_fonts_from_start_request_linux() {
    let profile = create_test_profile(Platform::Linux);
    let request = StartRequest::get_mock();
    let navigator = Navigator::default();
    let screen = Screen::default();
    let token = String::from("dummy_token");

    let fonts = Fonts::from_start_request(
      &profile, &request, &navigator, &screen, &token,
    )
    .expect("Should create fonts");

    assert_eq!(fonts.0.len(), 0, "Fonts on _Linux_ should be empty");
  }
}