/
githubmirror
/
servo
Обзор
Документация
Войти
/
githubmirror
/
servo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
tests/unit/script/unminify.rs
83 строки
3 KB
Asish Kumar
script: Store unminified data: URL scripts under a generated file name (#45119)
01 июл 2026, 11:55
Не верифицирован
01 июл 2026, 11:55
0f6dd55
Код
Авторство
О чём код?
/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use std::borrow::Cow; use std::io::{ErrorKind, Write}; use script::test::unminify::{create_output_file, substitute_with_local_script}; use servo_url::ServoUrl; #[test] fn test_create_output_file_with_query_string() { let dir = tempfile::tempdir().expect("create temp dir"); let url = ServoUrl::parse("https://example.com/app.js?v=abc123&t=456").unwrap(); let result = create_output_file(dir.path().to_str().unwrap().to_owned(), &url, Some(true)); assert!(result.is_ok(), "file creation failed: {:?}", result.err()); assert!( dir.path().join("example.com/app.js").exists(), "expected file at path without query string" ); assert!( !dir.path() .join("example.com/app.js?v=abc123&t=456") .exists(), "file must not have '?' in its name (reserved on Windows)" ); } #[test] fn test_create_output_file_without_query_string() { let dir = tempfile::tempdir().expect("create temp dir"); let url = ServoUrl::parse("https://example.com/app.js").unwrap(); let result = create_output_file(dir.path().to_str().unwrap().to_owned(), &url, Some(true)); assert!(result.is_ok()); assert!(dir.path().join("example.com/app.js").exists()); } #[test] fn test_create_output_file_with_data_url() { let dir = tempfile::tempdir().expect("create temp dir"); let url = ServoUrl::parse("data:text/javascript,console.log('pass')").unwrap(); let result = create_output_file(dir.path().to_str().unwrap().to_owned(), &url, Some(true)); assert_eq!(result.unwrap_err().kind(), ErrorKind::InvalidInput); assert_eq!(dir.path().read_dir().unwrap().count(), 0); } #[test] fn replace_script_with_query_string() { let dir = tempfile::tempdir().expect("create temp dir"); let url = ServoUrl::parse("https://example.com/app.js?query=true").unwrap(); { let mut result = create_output_file(dir.path().to_str().unwrap().to_owned(), &url, Some(true)).unwrap(); result.write(b"pass").unwrap(); } let mut script = Cow::from("fail"); substitute_with_local_script(&format!("{}", dir.path().display()), &mut script, url); assert_eq!(script, "pass"); } #[test] fn replace_script_without_query_string() { let dir = tempfile::tempdir().expect("create temp dir"); let url = ServoUrl::parse("https://example.com/app.js").unwrap(); { let mut result = create_output_file(dir.path().to_str().unwrap().to_owned(), &url, Some(true)).unwrap(); result.write(b"pass").unwrap(); } let mut script = Cow::from("fail"); substitute_with_local_script(&format!("{}", dir.path().display()), &mut script, url); assert_eq!(script, "pass"); }