mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Move user input logic into servoshell (#30238)
* cleanup and move user input logix into servoshell * fix fmt * moves test from servoshell file * move command-line args into servoshell * remove feature media-gstreamer * fix fmt * move user input logic code into lib to make it more testable * remove opts_matches in fn instead get it from main2 * remove pub and fix import * add licence in new file * revert passing Matches, instead pass Option String * review update, also move sanitize fn to parser file * fmt fix * review fix: remove extra line
This commit is contained in:
parent
f137b2f2c3
commit
3df284cf54
9 changed files with 84 additions and 66 deletions
|
@ -24,9 +24,6 @@ use url::{self, Url};
|
|||
pub struct Opts {
|
||||
pub is_running_problem_test: bool,
|
||||
|
||||
/// The initial URL to load.
|
||||
pub url: Option<ServoUrl>,
|
||||
|
||||
/// Whether or not the legacy layout system is enabled.
|
||||
pub legacy_layout: bool,
|
||||
|
||||
|
@ -386,7 +383,6 @@ pub fn multiprocess() -> bool {
|
|||
pub fn default_opts() -> Opts {
|
||||
Opts {
|
||||
is_running_problem_test: false,
|
||||
url: None,
|
||||
legacy_layout: false,
|
||||
tile_size: 512,
|
||||
time_profiling: None,
|
||||
|
@ -598,15 +594,6 @@ pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingR
|
|||
url.starts_with("http://web-platform.test:8000/_mozilla/css/canvas_over_area.html")
|
||||
});
|
||||
|
||||
let url_opt = url_opt.and_then(|url_string| {
|
||||
parse_url_or_filename(&cwd, url_string)
|
||||
.map_err(|error| {
|
||||
warn!("URL parsing failed ({:?}).", error);
|
||||
error
|
||||
})
|
||||
.ok()
|
||||
});
|
||||
|
||||
let tile_size: usize = match opt_match.opt_str("s") {
|
||||
Some(tile_size_str) => tile_size_str
|
||||
.parse()
|
||||
|
@ -752,7 +739,6 @@ pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingR
|
|||
let opts = Opts {
|
||||
debug: debug_options.clone(),
|
||||
is_running_problem_test,
|
||||
url: url_opt,
|
||||
legacy_layout,
|
||||
tile_size,
|
||||
time_profiling,
|
||||
|
@ -815,13 +801,3 @@ pub fn set_options(opts: Opts) {
|
|||
pub fn get() -> RwLockReadGuard<'static, Opts> {
|
||||
OPTIONS.read().unwrap()
|
||||
}
|
||||
|
||||
pub fn parse_url_or_filename(cwd: &Path, input: &str) -> Result<ServoUrl, ()> {
|
||||
match ServoUrl::parse(input) {
|
||||
Ok(url) => Ok(url),
|
||||
Err(url::ParseError::RelativeUrlWithoutBase) => {
|
||||
Url::from_file_path(&*cwd.join(input)).map(ServoUrl::from_url)
|
||||
},
|
||||
Err(_) => Err(()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,86 +0,0 @@
|
|||
/* 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 servo_config::opts::parse_url_or_filename;
|
||||
use std::path::Path;
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
const FAKE_CWD: &'static str = "/fake/cwd";
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
const FAKE_CWD: &'static str = "C:/fake/cwd";
|
||||
|
||||
#[test]
|
||||
fn test_argument_parsing() {
|
||||
let fake_cwd = Path::new(FAKE_CWD);
|
||||
assert!(parse_url_or_filename(fake_cwd, "http://example.net:invalid").is_err());
|
||||
|
||||
let url = parse_url_or_filename(fake_cwd, "http://example.net").unwrap();
|
||||
assert_eq!(url.scheme(), "http");
|
||||
|
||||
let url = parse_url_or_filename(fake_cwd, "file:///foo/bar.html").unwrap();
|
||||
assert_eq!(url.scheme(), "file");
|
||||
assert_eq!(
|
||||
url.path_segments().unwrap().collect::<Vec<_>>(),
|
||||
["foo", "bar.html"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
fn test_file_path_parsing() {
|
||||
let fake_cwd = Path::new(FAKE_CWD);
|
||||
|
||||
let url = parse_url_or_filename(fake_cwd, "bar.html").unwrap();
|
||||
assert_eq!(url.scheme(), "file");
|
||||
assert_eq!(
|
||||
url.path_segments().unwrap().collect::<Vec<_>>(),
|
||||
["fake", "cwd", "bar.html"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "windows")]
|
||||
fn test_file_path_parsing() {
|
||||
let fake_cwd = Path::new(FAKE_CWD);
|
||||
|
||||
let url = parse_url_or_filename(fake_cwd, "bar.html").unwrap();
|
||||
assert_eq!(url.scheme(), "file");
|
||||
assert_eq!(
|
||||
url.path_segments().unwrap().collect::<Vec<_>>(),
|
||||
["C:", "fake", "cwd", "bar.html"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
// Windows file paths can't contain ?
|
||||
fn test_argument_parsing_special() {
|
||||
let fake_cwd = Path::new(FAKE_CWD);
|
||||
|
||||
// '?' and '#' have a special meaning in URLs...
|
||||
let url = parse_url_or_filename(fake_cwd, "file:///foo/bar?baz#buzz.html").unwrap();
|
||||
assert_eq!(&*url.to_file_path().unwrap(), Path::new("/foo/bar"));
|
||||
assert_eq!(url.scheme(), "file");
|
||||
assert_eq!(
|
||||
url.path_segments().unwrap().collect::<Vec<_>>(),
|
||||
["foo", "bar"]
|
||||
);
|
||||
assert_eq!(url.query(), Some("baz"));
|
||||
assert_eq!(url.fragment(), Some("buzz.html"));
|
||||
|
||||
// but not in file names.
|
||||
let url = parse_url_or_filename(fake_cwd, "./bar?baz#buzz.html").unwrap();
|
||||
assert_eq!(
|
||||
&*url.to_file_path().unwrap(),
|
||||
Path::new("/fake/cwd/bar?baz#buzz.html")
|
||||
);
|
||||
assert_eq!(url.scheme(), "file");
|
||||
assert_eq!(
|
||||
url.path_segments().unwrap().collect::<Vec<_>>(),
|
||||
["fake", "cwd", "bar%3Fbaz%23buzz.html"]
|
||||
);
|
||||
assert_eq!(url.query(), None);
|
||||
assert_eq!(url.fragment(), None);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue