diff --git a/test/unit/resolveurl.html b/test/unit/resolveurl.html index aa2bc651e6..67614a5470 100644 --- a/test/unit/resolveurl.html +++ b/test/unit/resolveurl.html @@ -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() { @@ -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); }); diff --git a/test/unit/sub/resolveurl-elements.html b/test/unit/sub/resolveurl-elements.html index ddb1c04296..8c2b1a9557 100644 --- a/test/unit/sub/resolveurl-elements.html +++ b/test/unit/sub/resolveurl-elements.html @@ -18,13 +18,18 @@ Foo - + + Foo Foo
Foo Foo Foo +