OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../../../resources/js-test.js"></script> | 2 <script src="../../../resources/js-test.js"></script> |
3 <base href="foo/bar/"> | 3 <base href="foo/bar/"> |
4 <body></body> | 4 <body></body> |
5 <script> | 5 <script> |
6 | 6 |
7 if (window.testRunner) { | 7 if (window.testRunner) { |
8 // FIXME: setCanOpenWindows needs the test to be async or the Apple port cra
shes. | 8 // FIXME: setCanOpenWindows needs the test to be async or the Apple port cra
shes. |
9 // https://bugs.webkit.org/show_bug.cgi?id=99465 | 9 // https://bugs.webkit.org/show_bug.cgi?id=99465 |
10 window.jsTestIsAsync = true; | 10 window.jsTestIsAsync = true; |
11 testRunner.waitUntilDone(); | 11 testRunner.waitUntilDone(); |
12 testRunner.setCanOpenWindows(); | 12 testRunner.setCanOpenWindows(); |
13 } | 13 } |
14 | 14 |
15 function endsWith(string, substring) | 15 function endsWith(string, substring) |
16 { | 16 { |
17 var length = string.length - substring.length; | 17 var length = string.length - substring.length; |
18 return length >= 0 && string.indexOf(substring, length) === length; | 18 return length >= 0 && string.indexOf(substring, length) === length; |
19 } | 19 } |
20 | 20 |
21 var base = document.querySelector('base'); | 21 var base = document.querySelector('base'); |
22 shouldBeTrue("endsWith(document.querySelector('base').href, 'foo/bar/')"); | 22 shouldBeTrue("endsWith(document.querySelector('base').href, 'foo/bar/')"); |
23 shouldBeFalse("endsWith(document.querySelector('base').href, 'foo/bar/foo/bar/')
"); | 23 shouldBeFalse("endsWith(document.querySelector('base').href, 'foo/bar/foo/bar/')
"); |
24 | 24 |
25 base.href = null; | 25 base.href = null; |
26 shouldBeFalse("document.querySelector('base').hasAttribute('href')"); | 26 shouldBeTrue("endsWith(document.querySelector('base').href, '/null')"); |
27 shouldBeTrue("endsWith(document.querySelector('base').href, '/href-attribute-res
olves-with-respect-to-document.html')"); | |
28 | 27 |
29 // When a document does not have a URL, base cannot be resolved | 28 // When a document does not have a URL, base cannot be resolved |
30 | 29 |
31 // Make sure that we don't use the creator document as the base. | 30 // Make sure that we don't use the creator document as the base. |
32 var documentWithoutAView = document.implementation.createHTMLDocument(''); | 31 var documentWithoutAView = document.implementation.createHTMLDocument(''); |
33 base = documentWithoutAView.head.appendChild(documentWithoutAView.createElement(
'base')); | 32 base = documentWithoutAView.head.appendChild(documentWithoutAView.createElement(
'base')); |
34 base.setAttribute('href', 'foo/bar/'); | 33 base.setAttribute('href', 'foo/bar/'); |
35 shouldBeEqualToString("documentWithoutAView.querySelector('base').href", ''); | 34 shouldBeEqualToString("documentWithoutAView.querySelector('base').href", ''); |
36 base.setAttribute('href', 'http://webkit.org/'); | 35 base.setAttribute('href', 'http://webkit.org/'); |
37 shouldBeEqualToString("documentWithoutAView.querySelector('base').href", 'http:/
/webkit.org/'); | 36 shouldBeEqualToString("documentWithoutAView.querySelector('base').href", 'http:/
/webkit.org/'); |
38 | 37 |
39 // Make sure that we use the parent document as the base. | 38 // Make sure that we use the parent document as the base. |
40 var iframe = document.body.appendChild(document.createElement('iframe')); | 39 var iframe = document.body.appendChild(document.createElement('iframe')); |
41 base = iframe.contentDocument.head.appendChild(iframe.contentDocument.createElem
ent('base')); | 40 base = iframe.contentDocument.head.appendChild(iframe.contentDocument.createElem
ent('base')); |
42 base.setAttribute('href', 'foo/bar/'); | 41 base.setAttribute('href', 'foo/bar/'); |
43 shouldBeEqualToString("iframe.contentDocument.querySelector('base').href", ''); | 42 shouldBeEqualToString("iframe.contentDocument.querySelector('base').href", ''); |
44 | 43 |
45 // Make sure that we don't use the opener document as the base. | 44 // Make sure that we don't use the opener document as the base. |
46 var newWindow = window.open('about:blank'); | 45 var newWindow = window.open('about:blank'); |
47 base = newWindow.document.head.appendChild(newWindow.document.createElement('bas
e')); | 46 base = newWindow.document.head.appendChild(newWindow.document.createElement('bas
e')); |
48 base.setAttribute('href', 'foo/bar/'); | 47 base.setAttribute('href', 'foo/bar/'); |
49 shouldBeEqualToString("newWindow.document.querySelector('base').href", ''); | 48 shouldBeEqualToString("newWindow.document.querySelector('base').href", ''); |
50 newWindow.close(); | 49 newWindow.close(); |
51 | 50 |
52 </script> | 51 </script> |
53 <script> | 52 <script> |
54 | 53 |
55 finishJSTest(); | 54 finishJSTest(); |
56 | 55 |
57 </script> | 56 </script> |
OLD | NEW |