gecko-dev/servo/tests/unit/script/origin.rs
Connor Brewster 757c29a90e servo: Merge #15438 - Add ImmutableOrigin to allow for serializing origins (from asajeffrey:url-serializable-origin); r=jdm
<!-- Please describe your changes on the following line: -->

This PR adds a serializable type `ImmutableOrigin` and a non-serializable type `MutableOrigin`. The immutable type represents an origin with `null` domain, and the mutable type represents an origin with a mutable domain. This separation is needed for implementing setting `document.domain`.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #14892.
- [X] These changes do not require tests because it's a refactoring which will enable other features.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: 78e8c31a4d1890260dda83f2db85672f693c1e97

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 3f155b8a66957ab70878c9287541a2dfc9bbb7ef
2017-02-22 09:46:27 -08:00

64 lines
2.1 KiB
Rust

/* 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 servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
#[test]
fn same_origin() {
let a = MutableOrigin::new(ServoUrl::parse("http://example.com/a.html").unwrap().origin());
let b = MutableOrigin::new(ServoUrl::parse("http://example.com/b.html").unwrap().origin());
assert!(a.same_origin(&b));
assert_eq!(a.is_tuple(), true);
}
#[test]
fn identical_origin() {
let a = MutableOrigin::new(ServoUrl::parse("http://example.com/a.html").unwrap().origin());
assert!(a.same_origin(&a));
}
#[test]
fn cross_origin() {
let a = MutableOrigin::new(ServoUrl::parse("http://example.com/a.html").unwrap().origin());
let b = MutableOrigin::new(ServoUrl::parse("http://example.org/b.html").unwrap().origin());
assert!(!a.same_origin(&b));
}
#[test]
fn clone_same_origin() {
let a = MutableOrigin::new(ServoUrl::parse("http://example.com/a.html").unwrap().origin());
let b = MutableOrigin::new(ServoUrl::parse("http://example.com/b.html").unwrap().origin());
let c = b.clone();
assert!(a.same_origin(&c));
assert!(b.same_origin(&b));
assert!(c.same_origin(&b));
assert_eq!(c.is_tuple(), true);
}
#[test]
fn clone_cross_origin() {
let a = MutableOrigin::new(ServoUrl::parse("http://example.com/a.html").unwrap().origin());
let b = MutableOrigin::new(ServoUrl::parse("http://example.org/b.html").unwrap().origin());
let c = b.clone();
assert!(!a.same_origin(&c));
assert!(b.same_origin(&c));
assert!(c.same_origin(&c));
}
#[test]
fn opaque() {
let a = MutableOrigin::new(ImmutableOrigin::new_opaque());
let b = MutableOrigin::new(ImmutableOrigin::new_opaque());
assert!(!a.same_origin(&b));
assert_eq!(a.is_tuple(), false);
}
#[test]
fn opaque_clone() {
let a = MutableOrigin::new(ImmutableOrigin::new_opaque());
let b = a.clone();
assert!(a.same_origin(&b));
assert_eq!(a.is_tuple(), false);
}