mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Implement origin concept.
This commit is contained in:
parent
e8e354d5d3
commit
a8233a135e
8 changed files with 215 additions and 9 deletions
|
@ -11,8 +11,14 @@ doctest = false
|
|||
[dependencies.msg]
|
||||
path = "../../../components/msg"
|
||||
|
||||
[dependencies.plugins]
|
||||
path = "../../../components/plugins"
|
||||
|
||||
[dependencies.script]
|
||||
path = "../../../components/script"
|
||||
|
||||
[dependencies.util]
|
||||
path = "../../../components/util"
|
||||
|
||||
[dependencies]
|
||||
url = {version = "0.5.8", features = ["heap_size"]}
|
||||
|
|
|
@ -2,10 +2,15 @@
|
|||
* 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/. */
|
||||
|
||||
#![feature(plugin)]
|
||||
#![plugin(plugins)]
|
||||
|
||||
extern crate msg;
|
||||
extern crate script;
|
||||
extern crate url;
|
||||
extern crate util;
|
||||
|
||||
#[cfg(test)] mod origin;
|
||||
#[cfg(all(test, target_pointer_width = "64"))] mod size_of;
|
||||
#[cfg(test)] mod textinput;
|
||||
#[cfg(test)] mod dom {
|
||||
|
|
105
tests/unit/script/origin.rs
Normal file
105
tests/unit/script/origin.rs
Normal file
|
@ -0,0 +1,105 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use script::origin::Origin;
|
||||
|
||||
#[test]
|
||||
fn same_origin() {
|
||||
let a = Origin::new(&url!("http://example.com/a.html"));
|
||||
let b = Origin::new(&url!("http://example.com/b.html"));
|
||||
assert!(a.same_origin(&b));
|
||||
assert_eq!(a.is_scheme_host_port_tuple(), true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn identical_origin() {
|
||||
let a = Origin::new(&url!("http://example.com/a.html"));
|
||||
assert!(a.same_origin(&a));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cross_origin() {
|
||||
let a = Origin::new(&url!("http://example.com/a.html"));
|
||||
let b = Origin::new(&url!("http://example.org/b.html"));
|
||||
assert!(!a.same_origin(&b));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alias_same_origin() {
|
||||
let a = Origin::new(&url!("http://example.com/a.html"));
|
||||
let b = Origin::new(&url!("http://example.com/b.html"));
|
||||
let c = b.alias();
|
||||
assert!(a.same_origin(&c));
|
||||
assert!(b.same_origin(&b));
|
||||
assert!(c.same_origin(&b));
|
||||
assert_eq!(c.is_scheme_host_port_tuple(), true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alias_cross_origin() {
|
||||
let a = Origin::new(&url!("http://example.com/a.html"));
|
||||
let b = Origin::new(&url!("http://example.org/b.html"));
|
||||
let c = b.alias();
|
||||
assert!(!a.same_origin(&c));
|
||||
assert!(b.same_origin(&c));
|
||||
assert!(c.same_origin(&c));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alias_update_same_origin() {
|
||||
let a = Origin::new(&url!("http://example.com/a.html"));
|
||||
let b = Origin::new(&url!("http://example.org/b.html"));
|
||||
let c = b.alias();
|
||||
b.set(url!("http://example.com/c.html").origin());
|
||||
assert!(a.same_origin(&c));
|
||||
assert!(b.same_origin(&c));
|
||||
assert!(c.same_origin(&c));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alias_update_cross_origin() {
|
||||
let a = Origin::new(&url!("http://example.com/a.html"));
|
||||
let b = Origin::new(&url!("http://example.com/b.html"));
|
||||
let c = b.alias();
|
||||
b.set(url!("http://example.org/c.html").origin());
|
||||
assert!(!a.same_origin(&c));
|
||||
assert!(b.same_origin(&c));
|
||||
assert!(c.same_origin(&c));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alias_chain() {
|
||||
let a = Origin::new(&url!("http://example.com/a.html"));
|
||||
let b = Origin::new(&url!("http://example.com/b.html"));
|
||||
let c = b.copy();
|
||||
let d = c.alias();
|
||||
let e = d.alias();
|
||||
assert!(a.same_origin(&e));
|
||||
assert!(b.same_origin(&e));
|
||||
assert!(c.same_origin(&e));
|
||||
assert!(d.same_origin(&e));
|
||||
assert!(e.same_origin(&e));
|
||||
c.set(url!("http://example.org/c.html").origin());
|
||||
assert!(a.same_origin(&b));
|
||||
assert!(!b.same_origin(&c));
|
||||
assert!(c.same_origin(&d));
|
||||
assert!(d.same_origin(&e));
|
||||
assert!(!e.same_origin(&a));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opaque() {
|
||||
let a = Origin::opaque_identifier();
|
||||
let b = Origin::opaque_identifier();
|
||||
assert!(!a.same_origin(&b));
|
||||
assert_eq!(a.is_scheme_host_port_tuple(), false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opaque_clone() {
|
||||
let a = Origin::opaque_identifier();
|
||||
let b = a.alias();
|
||||
assert!(a.same_origin(&b));
|
||||
assert_eq!(a.is_scheme_host_port_tuple(), false);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue