From d97373dd2532cc198ab63705528996cd6148e0af Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Wed, 31 Jan 2018 16:13:43 -0800 Subject: [PATCH] Add hash/abs URL resolution tests. --- test/unit/resolveurl.html | 26 ++++++++++++++++---------- test/unit/sub/resolveurl-elements.html | 4 ++++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/test/unit/resolveurl.html b/test/unit/resolveurl.html index 8b08f692d3..703e20c13d 100644 --- a/test/unit/resolveurl.html +++ b/test/unit/resolveurl.html @@ -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'); diff --git a/test/unit/sub/resolveurl-elements.html b/test/unit/sub/resolveurl-elements.html index b0dc0c7324..de5017d7b1 100644 --- a/test/unit/sub/resolveurl-elements.html +++ b/test/unit/sub/resolveurl-elements.html @@ -13,6 +13,8 @@ @@ -20,6 +22,8 @@ Foo + + Foo Foo