<!DOCTYPE HTML>
<link rel="help" href="http://url.spec.whatwg.org/#dom-url-origin">
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
function assertOrigin(url, expectedOrigin) {
var url = new URL(url);
assert_equals(url.origin, expectedOrigin);
}
test(function() {
assertOrigin('http://example.com/foo/bar', 'http://example.com');
assertOrigin('HTTP://example.com/foo/bar', 'http://example.com');
assertOrigin('https://example.com/ttt?ggg', 'https://example.com');
assertOrigin('ftp://example.com/ttt?ggg', 'ftp://example.com');
assertOrigin('file:///home/abarth', 'file://');
// The following are implementation specific.
assertOrigin('data:text/html,<b>foo</b>', 'null');
assertOrigin('about:blank', 'null');
}, 'origin property');
test(function() {
var url = new URL('http://www.domain.com/');
url.origin = 'changed'; // readonly
assert_equals(url.origin, 'http://www.domain.com');
}, 'origin property is readonly');
test(function() {
var url = new URL('http://www.domain.com/');
var expected = 'http://www.domain.com';
assert_equals(url.origin, expected);
assert_throws_js(TypeError, () => { url.href = 'invalid'; });
assert_equals(url.origin, expected);
}, 'origin property invalid URL');
</script>