delegate resource reading to embedder

This commit is contained in:
Paul Rouget 2018-04-11 16:04:07 +08:00
parent 21517504cb
commit 9fb5795f37
52 changed files with 472 additions and 396 deletions

View file

@ -13,6 +13,7 @@ doctest = false
[dependencies]
cookie = "0.10"
embedder_traits = { path = "../embedder_traits" }
hyper = "0.10"
hyper_serde = "0.8"
image = "0.18"

View file

@ -6,6 +6,7 @@
#![deny(unsafe_code)]
extern crate cookie as cookie_rs;
extern crate embedder_traits;
extern crate hyper;
extern crate hyper_serde;
extern crate image as piston_image;
@ -18,7 +19,6 @@ extern crate msg;
extern crate num_traits;
#[macro_use] extern crate serde;
extern crate servo_arc;
extern crate servo_config;
extern crate servo_url;
extern crate url;
extern crate uuid;

View file

@ -14,11 +14,10 @@
//! we don't need to make the code more complex for it. The `mach` update command makes sure that
//! those cases are not present.
use servo_config::resource_files::read_resource_file;
use embedder_traits::resources::{self, Resource};
use servo_url::{Host, ImmutableOrigin, ServoUrl};
use std::collections::HashSet;
use std::iter::FromIterator;
use std::str::from_utf8;
#[derive(Clone, Debug)]
pub struct PubDomainRules {
@ -121,9 +120,7 @@ impl PubDomainRules {
}
fn load_pub_domains() -> PubDomainRules {
let content = read_resource_file("public_domains.txt").expect("Could not find public suffix list file");
let content = from_utf8(&content).expect("Could not read public suffix list file");
PubDomainRules::parse(content)
PubDomainRules::parse(&resources::read_string(Resource::DomainList))
}
pub fn pub_suffix(domain: &str) -> &str {

View file

@ -2,14 +2,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
extern crate embedder_traits;
extern crate net_traits;
use embedder_traits::resources::register_resources_for_tests;
use net_traits::pub_domains::{is_pub_domain, is_reg_domain, pub_suffix, reg_suffix};
// These tests may need to be updated if the PSL changes.
#[test]
fn test_is_pub_domain_plain() {
register_resources_for_tests();
assert!(is_pub_domain("com"));
assert!(is_pub_domain(".org"));
assert!(is_pub_domain("za.org"));
@ -19,6 +22,7 @@ fn test_is_pub_domain_plain() {
#[test]
fn test_is_pub_domain_wildcard() {
register_resources_for_tests();
assert!(is_pub_domain("hello.bd"));
assert!(is_pub_domain("world.jm"));
assert!(is_pub_domain("toto.kobe.jp"));
@ -26,6 +30,7 @@ fn test_is_pub_domain_wildcard() {
#[test]
fn test_is_pub_domain_exception() {
register_resources_for_tests();
assert_eq!(is_pub_domain("www.ck"), false);
assert_eq!(is_pub_domain("city.kawasaki.jp"), false);
assert_eq!(is_pub_domain("city.nagoya.jp"), false);
@ -34,6 +39,7 @@ fn test_is_pub_domain_exception() {
#[test]
fn test_is_pub_domain_not() {
register_resources_for_tests();
assert_eq!(is_pub_domain(""), false);
assert_eq!(is_pub_domain("."), false);
assert_eq!(is_pub_domain("..."), false);
@ -46,6 +52,7 @@ fn test_is_pub_domain_not() {
#[test]
fn test_is_pub_domain() {
register_resources_for_tests();
assert!(!is_pub_domain("city.yokohama.jp"));
assert!(!is_pub_domain("foo.bar.baz.yokohama.jp"));
assert!(!is_pub_domain("foo.bar.city.yokohama.jp"));
@ -64,6 +71,7 @@ fn test_is_pub_domain() {
#[test]
fn test_is_reg_domain() {
register_resources_for_tests();
assert!(!is_reg_domain("com"));
assert!(!is_reg_domain("foo.bar.baz.yokohama.jp"));
assert!(!is_reg_domain("foo.bar.com"));
@ -81,6 +89,7 @@ fn test_is_reg_domain() {
#[test]
fn test_pub_suffix() {
register_resources_for_tests();
assert_eq!(pub_suffix("city.yokohama.jp"), "yokohama.jp");
assert_eq!(pub_suffix("com"), "com");
assert_eq!(pub_suffix("foo.bar.baz.yokohama.jp"), "baz.yokohama.jp");
@ -98,6 +107,7 @@ fn test_pub_suffix() {
#[test]
fn test_reg_suffix() {
register_resources_for_tests();
assert_eq!(reg_suffix("city.yokohama.jp"), "city.yokohama.jp");
assert_eq!(reg_suffix("com"), "com");
assert_eq!(reg_suffix("foo.bar.baz.yokohama.jp"), "bar.baz.yokohama.jp");
@ -115,6 +125,7 @@ fn test_reg_suffix() {
#[test]
fn test_weirdness() {
register_resources_for_tests();
// These are weird results, but AFAICT they are spec-compliant.
assert_ne!(pub_suffix("city.yokohama.jp"), pub_suffix(pub_suffix("city.yokohama.jp")));
assert!(!is_pub_domain(pub_suffix("city.yokohama.jp")));