summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/browsers/history/the-location-interface/no-browsing-context.window.js
blob: 4077d90971935be71aa291e0f7c7f8bceca64994 (plain)
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
test(() => {
  const frame = document.body.appendChild(document.createElement("iframe")),
        win = frame.contentWindow,
        loc = win.location;
  frame.remove();
  assert_equals(win.location, loc);
}, "Window and Location are 1:1 after browsing context removal");

function bcLessLocation() {
  const frame = document.body.appendChild(document.createElement("iframe")),
        win = frame.contentWindow,
        loc = win.location;
  frame.remove();
  return loc;
}

[
  {
    "property": "href",
    "expected": "about:blank",
    "values": ["https://example.com/", "/", "http://test:test/", "test test", "test:test", "chrome:fail"]
  },
  {
    "property": "protocol",
    "expected": "about:",
    "values": ["http", "about", "test"]
  },
  {
    "property": "host",
    "expected": "",
    "values": ["example.com", "test test", "()"]
  },
  {
    "property": "hostname",
    "expected": "",
    "values": ["example.com"]
  },
  {
    "property": "port",
    "expected": "",
    "values": ["80", "", "443", "notaport"]
  },
  {
    "property": "pathname",
    "expected": "blank",
    "values": ["/", "x"]
  },
  {
    "property": "search",
    "expected": "",
    "values": ["test"]
  },
  {
    "property": "hash",
    "expected": "",
    "values": ["test", "#"]
  }
].forEach(testSetup => {
  testSetup.values.forEach(value => {
  	test(() => {
  	  const loc = bcLessLocation();
  	  loc[testSetup.property] = value;
  	  assert_equals(loc[testSetup.property], testSetup.expected);
  	}, "Setting `" + testSetup.property + "` to `" + value + "` of a `Location` object sans browsing context is a no-op");
  });
});

test(() => {
  const loc = bcLessLocation();
  assert_equals(loc.origin, "null");
}, "Getting `origin` of a `Location` object sans browsing context should be \"null\"");

["assign", "replace", "reload"].forEach(method => {
  ["about:blank", "https://example.com/", "/", "http://test:test/", "test test", "test:test", "chrome:fail"].forEach(value => {
    test(() => {
      const loc = bcLessLocation();
      loc[method](value);
      assert_equals(loc.href, "about:blank");
    }, "Invoking `" + method + "` with `" + value + "` on a `Location` object sans browsing context is a no-op");
  });
});

test(() => {
  const loc = bcLessLocation();
  assert_array_equals(loc.ancestorOrigins, []);
}, "Getting `ancestorOrigins` of a `Location` object sans browsing context should be []");