OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <script src="../../resources/js-test.js"></script> | |
3 <base href="foo/bar/"> | |
4 <body></body> | |
5 <script> | |
6 | |
7 if (window.testRunner) { | |
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 | |
10 window.jsTestIsAsync = true; | |
11 testRunner.waitUntilDone(); | |
12 testRunner.setCanOpenWindows(); | |
13 } | |
14 | |
15 function endsWith(string, substring) | |
16 { | |
17 var length = string.length - substring.length; | |
18 return length >= 0 && string.indexOf(substring, length) === length; | |
19 } | |
20 | |
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/')
"); | |
24 | |
25 base.href = null; | |
26 shouldBeTrue("endsWith(document.querySelector('base').href, '/null')"); | |
27 | |
28 // When a document does not have a URL, base cannot be resolved | |
29 | |
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/'); | |
37 | |
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.createElem
ent('base')); | |
41 base.setAttribute('href', 'foo/bar/'); | |
42 shouldBeEqualToString("iframe.contentDocument.querySelector('base').href", ''); | |
43 | |
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('bas
e')); | |
47 base.setAttribute('href', 'foo/bar/'); | |
48 shouldBeEqualToString("newWindow.document.querySelector('base').href", ''); | |
49 newWindow.close(); | |
50 | |
51 </script> | |
52 <script> | |
53 | |
54 finishJSTest(); | |
55 | |
56 </script> | |
OLD | NEW |