Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / HTMLBaseElement / href-attribute-resolves-with-respect-to-document.html
blob5739008dc273538074c85c7842ed26d7ed338f43
1 <!DOCTYPE html>
2 <script src="../../../resources/js-test.js"></script>
3 <base href="foo/bar/">
4 <body></body>
5 <script>
7 if (window.testRunner) {
8 // FIXME: setCanOpenWindows needs the test to be async or the Apple port crashes.
9 // https://bugs.webkit.org/show_bug.cgi?id=99465
10 window.jsTestIsAsync = true;
11 testRunner.waitUntilDone();
12 testRunner.setCanOpenWindows();
15 function endsWith(string, substring)
17 var length = string.length - substring.length;
18 return length >= 0 && string.indexOf(substring, length) === length;
21 var base = document.querySelector('base');
22 shouldBeTrue("endsWith(document.querySelector('base').href, 'foo/bar/')");
23 shouldBeFalse("endsWith(document.querySelector('base').href, 'foo/bar/foo/bar/')");
25 base.href = null;
26 shouldBeTrue("endsWith(document.querySelector('base').href, '/null')");
28 // When a document does not have a URL, base cannot be resolved
30 // Make sure that we don't use the creator document as the base.
31 var documentWithoutAView = document.implementation.createHTMLDocument('');
32 base = documentWithoutAView.head.appendChild(documentWithoutAView.createElement('base'));
33 base.setAttribute('href', 'foo/bar/');
34 shouldBeEqualToString("documentWithoutAView.querySelector('base').href", '');
35 base.setAttribute('href', 'http://webkit.org/');
36 shouldBeEqualToString("documentWithoutAView.querySelector('base').href", 'http://webkit.org/');
38 // Make sure that we use the parent document as the base.
39 var iframe = document.body.appendChild(document.createElement('iframe'));
40 base = iframe.contentDocument.head.appendChild(iframe.contentDocument.createElement('base'));
41 base.setAttribute('href', 'foo/bar/');
42 shouldBeEqualToString("iframe.contentDocument.querySelector('base').href", '');
44 // Make sure that we don't use the opener document as the base.
45 var newWindow = window.open('about:blank');
46 base = newWindow.document.head.appendChild(newWindow.document.createElement('base'));
47 base.setAttribute('href', 'foo/bar/');
48 shouldBeEqualToString("newWindow.document.querySelector('base').href", '');
49 newWindow.close();
51 </script>
52 <script>
54 finishJSTest();
56 </script>