Skip to content

Commit

Permalink
Add hash/abs URL resolution tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Feb 1, 2018
1 parent 892df3f commit d97373d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
26 changes: 16 additions & 10 deletions test/unit/resolveurl.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,25 @@
test('Urls in styles and attributes', function() {
var el = document.createElement('p-r');
document.body.appendChild(el);
var rx = /sub\/foo\.z/;
var resolvedUrl = /sub\/foo\.z/;
var styleHashUrl = /url\('#bar'\)/;
var styleAbsUrl = /url\('\/zot'\)/;
var style = el.shadowRoot.querySelector('style') || document.querySelector('style[scope=p-r]');
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(style.textContent, resolvedUrl, 'url not relative to main document');
assert.match(style.textContent, styleHashUrl, 'hash url incorrectly resolved');
assert.match(style.textContent, styleAbsUrl, 'absolute url incorrectly resolved');
assert.match(el.$.div.getAttribute('style'), resolvedUrl, 'style url not relative to main document');
assert.match(el.$.img.src, resolvedUrl, 'src url not relative to main document');
assert.match(el.$.a.href, resolvedUrl, 'href url not relative to main document');
assert.match(el.$.import.getAttribute('url'), resolvedUrl, 'url url not relative to main document');
assert.match(el.$.resolveUrl.getAttribute('url'), resolvedUrl, 'url url not relative to main document');
assert.equal(el.$.resolveUrlHash.getAttribute('url'), '#foo', 'url url not relative to main document');
assert.equal(el.$.resolveUrlAbs.getAttribute('url'), '/foo', 'url url not relative to main document');
assert.notMatch(el.$.root.getAttribute('url'), resolvedUrl, 'url url not relative to main document');
assert.notMatch(el.$.rel.href, resolvedUrl, 'relative href url not relative to main document');
assert.match(el.$.rel.href, /\?123$/, 'relative href does not preserve query string');
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.match(el.$.formAction.action, resolvedUrl, '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');
Expand Down
4 changes: 4 additions & 0 deletions test/unit/sub/resolveurl-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
<style>
.logo {
background-image: url(foo.z);
clip-path: url('#bar');
mask-image: url('/zot');
}
</style>
<div id="div" class="logo" style$="background-image: url('[[importPath]]foo.z');"></div>
<img id="img" src$="[[importPath]]foo.z">
<a id="a" href$="[[importPath]]foo.z">Foo</a>
<zonk id="import" url$="[[importPath]]foo.z"></zonk>
<zonk id="resolveUrl" url$="[[resolveUrl('foo.z')]]"></zonk>
<zonk id="resolveUrlHash" url$="[[resolveUrl('#foo')]]"></zonk>
<zonk id="resolveUrlAbs" url$="[[resolveUrl('/foo')]]"></zonk>
<zonk id="root" url$="[[rootPath]]foo.z"></zonk>
<a id="rel" href$="[[importPath]]../foo.z?123">Foo</a>
<a id="action" action="foo.z">Foo</a>
Expand Down

0 comments on commit d97373d

Please sign in to comment.