From ec1e8e5e54cfe046c8fb1d2312078eb1882830cd Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Fri, 9 Nov 2018 16:56:27 +0000 Subject: [PATCH] Bug 1497567 [wpt PR 13435] - Test Location sans browsing context, a=testonly Automatic update from web-platform-testsTest Location sans browsing context For https://github.com/whatwg/html/issues/3959 and https://github.com/whatwg/html/pull/4076. -- wpt-commits: fce65ebd7656136f5f8452378146f1b7af30bf79 wpt-pr: 13435 --- .../no-browsing-context.window.js | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 testing/web-platform/tests/html/browsers/history/the-location-interface/no-browsing-context.window.js diff --git a/testing/web-platform/tests/html/browsers/history/the-location-interface/no-browsing-context.window.js b/testing/web-platform/tests/html/browsers/history/the-location-interface/no-browsing-context.window.js new file mode 100644 index 000000000000..dfdcd4688dfa --- /dev/null +++ b/testing/web-platform/tests/html/browsers/history/the-location-interface/no-browsing-context.window.js @@ -0,0 +1,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": "", + "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 []");