chrome_for_testing/api/
known_good_versions.rs

1use crate::api::version::Version;
2use crate::api::{Download, API_BASE_URL};
3use crate::error::Result;
4use serde::Deserialize;
5
6/// JSON Example:
7/// ```json
8/// {
9///     "version": "115.0.5763.0",
10///     "revision": "1141961",
11///     "downloads": {
12///         "chrome": [
13///             {
14///                 "platform": "linux64",
15///                 "url": "https://.../chrome-linux64.zip"
16///             },
17///             ...
18///         ],
19///         "chromedriver": [ /* <- Some versions don't have this field! */
20///             {
21///                 "platform": "linux64",
22///                 "url": "https://.../chromedriver-linux64.zip"
23///             },
24///             ...
25///         ]
26///     }
27/// },
28/// ```
29const KNOWN_GOOD_VERSIONS_WITH_DOWNLOADS_JSON_PATH: &str =
30    "/chrome-for-testing/known-good-versions-with-downloads.json";
31
32/// Download links for Chrome and ChromeDriver binaries.
33#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
34pub struct Downloads {
35    /// Download links for Chrome binaries for various platforms.
36    pub chrome: Vec<Download>,
37
38    /// Download links for ChromeDriver binaries for various platforms.
39    /// Note: Some older Chrome versions may not have ChromeDriver downloads available!
40    pub chromedriver: Option<Vec<Download>>,
41}
42
43/// An entry of the "known good versions" API response, representing one version.
44///
45/// No `Channel` information is provided.
46#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
47pub struct VersionWithoutChannel {
48    /// The version identifier.
49    pub version: Version,
50
51    /// The Chrome revision number.
52    pub revision: String,
53
54    /// Available downloads for this version.
55    pub downloads: Downloads,
56}
57
58/// Response structure for the "known good versions" API endpoint.
59///
60/// Contains a comprehensive list of Chrome versions that have been tested and verified to work.
61/// Unlike the "last known good versions" API, this includes all historical versions without
62/// channel assignments.
63#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
64pub struct KnownGoodVersions {
65    /// When this data was last updated.
66    #[serde(with = "time::serde::rfc3339")]
67    pub timestamp: time::OffsetDateTime,
68
69    /// List of all known good Chrome versions.
70    pub versions: Vec<VersionWithoutChannel>,
71}
72
73impl KnownGoodVersions {
74    /// Fetches the list of all known good Chrome versions from the Chrome for Testing API.
75    ///
76    /// Returns a comprehensive list of Chrome versions that have been tested and verified to work.
77    /// Unlike the "last known good versions" API, this includes all historical versions without
78    /// channel assignments.
79    pub async fn fetch(client: reqwest::Client) -> Result<Self> {
80        Self::fetch_with_base_url(client, API_BASE_URL.clone()).await
81    }
82
83    pub async fn fetch_with_base_url(
84        client: reqwest::Client,
85        base_url: reqwest::Url,
86    ) -> Result<Self> {
87        let result = client
88            .get(base_url.join(KNOWN_GOOD_VERSIONS_WITH_DOWNLOADS_JSON_PATH)?)
89            .send()
90            .await?
91            .json::<Self>()
92            .await?;
93        Ok(result)
94    }
95}
96
97#[cfg(test)]
98mod tests {
99    use super::*;
100    use crate::api::known_good_versions::KnownGoodVersions;
101    use crate::api::platform::Platform;
102    use crate::api::version::Version;
103    use crate::api::Download;
104    use assertr::prelude::*;
105    use time::macros::datetime;
106    use url::Url;
107
108    #[tokio::test]
109    async fn can_request_from_real_world_endpoint() {
110        let result = KnownGoodVersions::fetch(reqwest::Client::new()).await;
111        assert_that(result).is_ok();
112    }
113
114    //noinspection DuplicatedCode
115    #[tokio::test]
116    async fn can_query_known_good_versions_api_endpoint_and_deserialize_response() {
117        let mut server = mockito::Server::new_async().await;
118
119        let _mock = server
120            .mock("GET", KNOWN_GOOD_VERSIONS_WITH_DOWNLOADS_JSON_PATH)
121            .with_status(200)
122            .with_header("content-type", "application/json")
123            .with_body(include_str!(
124                "./../../test-data/known_good_versions_test_response.json"
125            ))
126            .create();
127
128        let url: Url = server.url().parse().unwrap();
129
130        let data = KnownGoodVersions::fetch_with_base_url(reqwest::Client::new(), url)
131            .await
132            .unwrap();
133
134        assert_that(data).is_equal_to(KnownGoodVersions {
135            timestamp: datetime!(2025-01-17 10:09:31.689 UTC),
136            versions: vec![
137                VersionWithoutChannel {
138                    version: Version { major: 113, minor: 0, patch: 5672, build: 0 },
139                    revision: String::from("1121455"),
140                    downloads: Downloads {
141                        chrome: vec![
142                            Download { platform: Platform::Linux64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/113.0.5672.0/linux64/chrome-linux64.zip") },
143                            Download { platform: Platform::MacArm64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/113.0.5672.0/mac-arm64/chrome-mac-arm64.zip") },
144                            Download { platform: Platform::MacX64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/113.0.5672.0/mac-x64/chrome-mac-x64.zip") },
145                            Download { platform: Platform::Win32, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/113.0.5672.0/win32/chrome-win32.zip") },
146                            Download { platform: Platform::Win64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/113.0.5672.0/win64/chrome-win64.zip") },
147                        ],
148                        chromedriver: None,
149                    },
150                },
151                VersionWithoutChannel {
152                    version: Version { major: 134, minor: 0, patch: 6962, build: 0 },
153                    revision: String::from("1407692"),
154                    downloads: Downloads {
155                        chrome: vec![
156                            Download { platform: Platform::Linux64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/134.0.6962.0/linux64/chrome-linux64.zip") },
157                            Download { platform: Platform::MacArm64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/134.0.6962.0/mac-arm64/chrome-mac-arm64.zip") },
158                            Download { platform: Platform::MacX64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/134.0.6962.0/mac-x64/chrome-mac-x64.zip") },
159                            Download { platform: Platform::Win32, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/134.0.6962.0/win32/chrome-win32.zip") },
160                            Download { platform: Platform::Win64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/134.0.6962.0/win64/chrome-win64.zip") },
161                        ],
162                        chromedriver: Some(vec![
163                            Download { platform: Platform::Linux64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/134.0.6962.0/linux64/chromedriver-linux64.zip") },
164                            Download { platform: Platform::MacArm64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/134.0.6962.0/mac-arm64/chromedriver-mac-arm64.zip") },
165                            Download { platform: Platform::MacX64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/134.0.6962.0/mac-x64/chromedriver-mac-x64.zip") },
166                            Download { platform: Platform::Win32, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/134.0.6962.0/win32/chromedriver-win32.zip") },
167                            Download { platform: Platform::Win64, url: String::from("https://storage.googleapis.com/chrome-for-testing-public/134.0.6962.0/win64/chromedriver-win64.zip") },
168                        ]),
169                    },
170                },
171            ],
172        });
173    }
174}