-
Notifications
You must be signed in to change notification settings - Fork 2k
/
resolveurl.html
87 lines (79 loc) · 3.81 KB
/
resolveurl.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<meta charset="UTF-8">
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../../web-component-tester/browser.js"></script>
<link rel="import" href="../../polymer.html">
<link id="elements" rel="import" href="sub/resolveurl-elements.html">
</head>
<body>
<x-resolve></x-resolve>
<dom-module id="x-resolve">
</dom-module>
<script>
addEventListener('HTMLImportsLoaded', function() {
Polymer({is: 'x-resolve'});
});
</script>
<script>
suite('ResolveUrl', function() {
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');
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.$.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');
});
test('resolveUrl api', function() {
var el = document.createElement('p-r');
var expected = document.baseURI.replace(/[?#].*$/, '');
var actual = el.resolveUrl('../resolveurl.html');
assert.equal(actual, expected);
});
test('resolveUrl api, when defined in main doc', function() {
var el = document.querySelector('x-resolve');
var expected = document.baseURI.replace(/[?#].*$/, '');
expected = expected.split('/');
expected.pop();
expected = expected.join('/') + '/foo/bar.png';
var actual = el.resolveUrl('foo/../foo/bar.png');
assert.equal(actual, expected);
});
test('resolveUrl api with assetpath', function() {
var el = document.createElement('p-r-ap');
// Manually calculate expected URL, to avoid dependence on
// URL object for this test for IE! Otherwise, would do this:
// var importPath = document.querySelector('#elements').href;
// var expected = new URL('../../assets/Beaker2.jpg', importPath);
var expected = document.baseURI.replace(/[?#].*$/, '');
expected = expected.split('/');
expected.pop();
expected.pop();
expected = expected.join('/');
expected = expected + '/assets/Beaker2.jpg';
var actual = el.resolveUrl('Beaker2.jpg');
assert.equal(actual, expected);
});
});
</script>
</body>
</html>