Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit 3bfcb96

Browse files
committed

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

src/HTMLImports.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ if (!useNative) {
152152
if (!document.baseURI) {
153153
var baseURIDescriptor = {
154154
get: function() {
155-
return window.location.href;
155+
var base = document.querySelector('base');
156+
return base ? base.href : window.location.href;
156157
},
157158
configurable: true
158159
};

test/html/base/load-base.html

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>base load test</title>
5+
<base href="../../html/">
6+
<script>
7+
window.loadEvents = 0;
8+
(function() {
9+
function importLoaded(event) {
10+
window.loadEvents++;
11+
if (event.type === 'load' && event.target.import) {
12+
var s = event.target.import.querySelector('script');
13+
chai.assert.ok(s, 'load event target can be used to find element in import');
14+
}
15+
}
16+
17+
function importError(event) {
18+
window.loadEvents++;
19+
}
20+
21+
window.importLoaded = importLoaded;
22+
window.importError = importError;
23+
})();
24+
</script>
25+
<script src="../../../tools/test/htmltest.js"></script>
26+
<script src="../../../tools/test/chai/chai.js"></script>
27+
<script src="../../html-imports.js"></script>
28+
<link rel="import" href="imports/load-1.html" onload="importLoaded(event)">
29+
<link rel="import" href="imports/load-2.html" onload="importLoaded(event)">
30+
<link rel="import" id="willError" href="imports/404.html" onerror="importError(event)">
31+
</head>
32+
<body>
33+
<div id="test1" class="red">Test</div>
34+
<div id="test2" class="blue">Test</div>
35+
<div id="test3" class="image"></div>
36+
<script>
37+
document.addEventListener('HTMLImportsLoaded', function() {
38+
var baseURI = location.href.replace('base/load-base.html', '').replace(location.search, '');
39+
chai.assert.equal(document.baseURI, baseURI, 'document.baseURI is correctly modified by base element');
40+
//
41+
chai.assert.equal(loadEvents, 3, 'expected # of load events');
42+
var test1 = getComputedStyle(document.querySelector('#test1')).backgroundColor;
43+
chai.assert.equal(test1, 'rgb(255, 0, 0)');
44+
var test2 = getComputedStyle(document.querySelector('#test2')).backgroundColor;
45+
chai.assert.equal(test2, 'rgb(0, 0, 255)');
46+
done();
47+
});
48+
</script>
49+
</body>
50+
</html>

test/js/tests.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ htmlSuite('HTMLImports', function() {
1111
htmlTest('html/style-paths.html');
1212
htmlTest('html/load.html');
1313
htmlTest('html/load-404.html');
14+
htmlTest('html/base/load-base.html');
1415
htmlTest('html/currentScript.html');
1516
htmlTest('html/dedupe.html');
1617
htmlTest('html/dynamic.html');

0 commit comments

Comments
 (0)