aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/script/origin.rs
blob: e3a8e52595f159176f622d4db427c1af3b51f92b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* 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_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);
}