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

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Aug 18, 2014
1 parent 014c080 commit 3bfcb96
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/HTMLImports.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ if (!useNative) {
if (!document.baseURI) {
var baseURIDescriptor = {
get: function() {
return window.location.href;
var base = document.querySelector('base');
return base ? base.href : window.location.href;
},
configurable: true
};
Expand Down
50 changes: 50 additions & 0 deletions test/html/base/load-base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!doctype html>
<html>
<head>
<title>base load test</title>
<base href="../../html/">
<script>
window.loadEvents = 0;
(function() {
function importLoaded(event) {
window.loadEvents++;
if (event.type === 'load' && event.target.import) {
var s = event.target.import.querySelector('script');
chai.assert.ok(s, 'load event target can be used to find element in import');
}
}

function importError(event) {
window.loadEvents++;
}

window.importLoaded = importLoaded;
window.importError = importError;
})();
</script>
<script src="../../../tools/test/htmltest.js"></script>
<script src="../../../tools/test/chai/chai.js"></script>
<script src="../../html-imports.js"></script>
<link rel="import" href="imports/load-1.html" onload="importLoaded(event)">
<link rel="import" href="imports/load-2.html" onload="importLoaded(event)">
<link rel="import" id="willError" href="imports/404.html" onerror="importError(event)">
</head>
<body>
<div id="test1" class="red">Test</div>
<div id="test2" class="blue">Test</div>
<div id="test3" class="image"></div>
<script>
document.addEventListener('HTMLImportsLoaded', function() {
var baseURI = location.href.replace('base/load-base.html', '').replace(location.search, '');
chai.assert.equal(document.baseURI, baseURI, 'document.baseURI is correctly modified by base element');
//
chai.assert.equal(loadEvents, 3, 'expected # of load events');
var test1 = getComputedStyle(document.querySelector('#test1')).backgroundColor;
chai.assert.equal(test1, 'rgb(255, 0, 0)');
var test2 = getComputedStyle(document.querySelector('#test2')).backgroundColor;
chai.assert.equal(test2, 'rgb(0, 0, 255)');
done();
});
</script>
</body>
</html>
1 change: 1 addition & 0 deletions test/js/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ htmlSuite('HTMLImports', function() {
htmlTest('html/style-paths.html');
htmlTest('html/load.html');
htmlTest('html/load-404.html');
htmlTest('html/base/load-base.html');
htmlTest('html/currentScript.html');
htmlTest('html/dedupe.html');
htmlTest('html/dynamic.html');
Expand Down

0 comments on commit 3bfcb96

Please sign in to comment.