Skip to content

Commit

Permalink
Make tests more strict.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Apr 14, 2017
1 parent 1a7d3b1 commit ea65a6d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 27 deletions.
67 changes: 41 additions & 26 deletions test/unit/resolveurl.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,30 @@

test('Urls in styles and attributes', function() {
var el = document.createElement('p-r');
var rx = /sub\/foo\.z/;
assert.match(el._styles[0].textContent, rx, 'url not relative to main document');
assert.match(el.$.div.getAttribute('style'), rx, 'style url not relative to main document');
assert.match(el.$.img.src, rx, 'src url not relative to main document');
assert.match(el.$.a.href, rx, 'href url not relative to main document');
assert.match(el.$.zonk.getAttribute('url'), rx, 'url url not relative to main document');
assert.notMatch(el.$.rel.href, rx, 'relative href url not relative to main document');
assert.match(el.$.rel.href, /\?123$/, 'relative href does not preserve query string');
var expected = document.baseURI.replace(/[?#].*$/, '');
expected = expected.split('/');
expected.pop();
var expectedEarlyRoot = 'earlyRootPath/foo.z';
var expectedRoot = expected.join('/') + '/foo.z';
var expectedImport = expected.join('/') + '/sub/foo.z';
var style = el._styles[0];
assert.isTrue(style.textContent.indexOf(expectedImport) >= 0, 'url not relative to main document');
assert.isTrue(el.$.div.getAttribute('style').indexOf(expectedImport) >= 0, 'style url not relative to main document');
assert.equal(el.$.img.src, expectedImport, 'src url not relative to main document');
assert.equal(el.$.a.href, expectedImport, 'href url not relative to main document');
assert.equal(el.$.import.getAttribute('url'), expectedImport, 'url url not relative to main document');
assert.equal(el.$.resolveUrl.getAttribute('url'), expectedImport, 'url url not relative to main document');
assert.equal(el.$.rel.href, expectedRoot + '?123', 'relative href url not relative to main document');
assert.equal(el.$.action.getAttribute('action'), 'foo.z', 'action attribute relativized for incorrect element type');
assert.match(el.$.formAction.action, rx, 'action attribute relativized for incorrect element type');
assert.equal(el.$.formAction.action, expectedImport, 'action attribute relativized for incorrect element type');
assert.equal(el.$.hash.getAttribute('href'), '#foo.z', 'hash-only url should not be resolved');
assert.equal(el.$.absolute.getAttribute('href'), '/foo.z', 'absolute urls should not be resolved');
assert.equal(el.$.protocol.getAttribute('href'), 'data:foo.z', 'urls with other protocols should not be resolved');
el.$.if.render();
assert.equal(Polymer.dom(el.root).querySelector('#importIf')
.getAttribute('url'), expectedImport, 'url url not relative to main document');
assert.equal(Polymer.dom(el.root).querySelector('#resolveUrlIf')
.getAttribute('url'), expectedImport, 'url url not relative to main document');
});

test('resolveUrl api', function() {
Expand Down Expand Up @@ -131,29 +142,33 @@
test('Hybrid: Urls in styles and attributes', function() {
var el = document.createElement('p-r-hybrid');
document.body.appendChild(el);
var rx = /sub\/foo\.z/;
var expected = document.baseURI.replace(/[?#].*$/, '');
expected = expected.split('/');
expected.pop();
var expectedEarlyRoot = 'earlyRootPath/foo.z';
var expectedRoot = expected.join('/') + '/foo.z';
var expectedImport = expected.join('/') + '/sub/foo.z';
var style = el._styles[0];
assert.match(style.textContent, rx, 'url not relative to main document');
assert.match(el.$.div.getAttribute('style'), rx, 'style url not relative to main document');
assert.match(el.$.img.src, rx, 'src url not relative to main document');
assert.match(el.$.a.href, rx, 'href url not relative to main document');
assert.match(el.$.import.getAttribute('url'), rx, 'url url not relative to main document');
assert.match(el.$.resolveUrl.getAttribute('url'), rx, 'url url not relative to main document');
assert.notMatch(el.$.root.getAttribute('url'), rx, 'url url not relative to main document');
assert.notMatch(el.$.rel.href, rx, 'relative href url not relative to main document');
assert.match(el.$.rel.href, /\?123$/, 'relative href does not preserve query string');
assert.isTrue(style.textContent.indexOf(expectedImport) >= 0, 'url not relative to main document');
assert.isTrue(el.$.div.getAttribute('style').indexOf(expectedImport) >= 0, 'style url not relative to main document');
assert.equal(el.$.img.src, expectedImport, 'src url not relative to main document');
assert.equal(el.$.a.href, expectedImport, 'href url not relative to main document');
assert.equal(el.$.import.getAttribute('url'), expectedImport, 'url url not relative to main document');
assert.equal(el.$.resolveUrl.getAttribute('url'), expectedImport, 'url url not relative to main document');
assert.equal(el.$.root.getAttribute('url'), expectedEarlyRoot, 'url url not relative to main document');
assert.equal(el.$.rel.href, expectedRoot + '?123', 'relative href url not relative to main document');
assert.equal(el.$.action.getAttribute('action'), 'foo.z', 'action attribute relativized for incorrect element type');
assert.match(el.$.formAction.action, rx, 'action attribute relativized for incorrect element type');
assert.equal(el.$.formAction.action, expectedImport, 'action attribute relativized for incorrect element type');
assert.equal(el.$.hash.getAttribute('href'), '#foo.z', 'hash-only url should not be resolved');
assert.equal(el.$.absolute.getAttribute('href'), '/foo.z', 'absolute urls should not be resolved');
assert.equal(el.$.protocol.getAttribute('href'), 'data:foo.z', 'urls with other protocols should not be resolved');
el.$.if.render();
assert.match(Polymer.dom(el.root).querySelector('#importIf')
.getAttribute('url'), rx, 'url url not relative to main document');
assert.match(Polymer.dom(el.root).querySelector('#resolveUrlIf')
.getAttribute('url'), rx, 'url url not relative to main document');
assert.notMatch(Polymer.dom(el.root).querySelector('#rootIf')
.getAttribute('url'), rx, 'url url not relative to main document');
assert.equal(Polymer.dom(el.root).querySelector('#importIf')
.getAttribute('url'), expectedImport, 'url url not relative to main document');
assert.equal(Polymer.dom(el.root).querySelector('#resolveUrlIf')
.getAttribute('url'), expectedImport, 'url url not relative to main document');
assert.equal(Polymer.dom(el.root).querySelector('#rootIf')
.getAttribute('url'), expectedEarlyRoot, 'url url not relative to main document');
document.body.removeChild(el);
});

Expand Down
7 changes: 6 additions & 1 deletion test/unit/sub/resolveurl-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@
<div id="div" class="logo" style="background-image: url(foo.z);"></div>
<img id="img" src="foo.z">
<a id="a" href="foo.z">Foo</a>
<zonk id="zonk" url="foo.z"></zonk>
<zonk id="import" url="foo.z"></zonk>
<zonk id="resolveUrl" url$="[[resolveUrl('foo.z')]]"></zonk>
<a id="rel" href="../foo.z?123">Foo</a>
<a id="action" action="foo.z">Foo</a>
<form id="formAction" action="foo.z"></form>
<a id="hash" href="#foo.z">Foo</a>
<a id="absolute" href="/foo.z">Foo</a>
<a id="protocol" href="data:foo.z">Foo</a>
<template is="dom-if" if id="if">
<zonk id="importIf" url="foo.z"></zonk>
<zonk id="resolveUrlIf" url$="[[resolveUrl('foo.z')]]"></zonk>
</template>
</template>
</dom-module>
<script>
Expand Down

0 comments on commit ea65a6d

Please sign in to comment.