2 <script src=
"../../../resources/js-test.js"></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/')");
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", '');