github.com/web-platform-tests/wpt.fyi@v0.0.0-20240530210107-70cf978996f1/webapp/components/test/path.html (about) 1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <script src="../../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script> 6 <script src="../../node_modules/wct-browser-legacy/browser.js"></script> 7 </head> 8 <body> 9 <dom-module id="path-info-concrete"> 10 <script type="module"> 11 import { PolymerElement } from '../../node_modules/@polymer/polymer/polymer-element.js'; 12 import { PathInfo } from '../path.js'; 13 14 class ConcreteType extends PathInfo(PolymerElement) {} 15 window.customElements.define('path-info-concrete', ConcreteType); 16 </script> 17 </dom-module> 18 19 <test-fixture id="path-info-fixture"> 20 <template> 21 <path-info-concrete></path-info-concrete> 22 </template> 23 </test-fixture> 24 25 <test-fixture id="path-part-dir-prefixed-fixture"> 26 <template> 27 <path-part path="/a/b" is-dir="true" prefix="/foo" navigate="navigate"></path-part> 28 </template> 29 </test-fixture> 30 31 <test-fixture id="path-part-dir-fixture"> 32 <template> 33 <path-part path="/a/b" is-dir="true" navigate="navigate"></path-part> 34 </template> 35 </test-fixture> 36 37 <test-fixture id="path-part-file-prefixed-fixture"> 38 <template> 39 <path-part path="/a/b/c.html" is-dir="false" prefix="/foo" navigate="navigate"></path-part> 40 </template> 41 </test-fixture> 42 43 <test-fixture id="path-part-file-fixture"> 44 <template> 45 <path-part path="/a/b/c.html" is-dir="false" navigate="navigate"></path-part> 46 </template> 47 </test-fixture> 48 49 <script type="module"> 50 import { PathPart } from '../path.js'; 51 import { PolymerElement } from '../../node_modules/@polymer/polymer/polymer-element.js'; 52 53 suite('PathInfo', () => { 54 let pathInfo; 55 56 setup(() => { 57 pathInfo = fixture('path-info-fixture'); 58 }); 59 60 test('pathIsATestPath', () => { 61 pathInfo.path = '/a/b.html'; 62 expect(pathInfo.pathIsATestFile).to.be.true; 63 pathInfo.path = '/a/b.html?x=1'; 64 expect(pathInfo.pathIsATestFile).to.be.true; 65 pathInfo.path = '/a/b.html#x=1'; 66 expect(pathInfo.pathIsATestFile).to.be.true; 67 pathInfo.path = '/a/b.html?x=1#y=2'; 68 expect(pathInfo.pathIsATestFile).to.be.true; 69 pathInfo.path = '/a/b.html?x=:a/b/:'; 70 expect(pathInfo.pathIsATestFile).to.be.true; 71 pathInfo.path = '/a/b/'; 72 expect(pathInfo.pathIsATestFile).to.be.false; 73 }); 74 75 test('encodeTestPath', () => { 76 expect(pathInfo.encodeTestPath('/a/b.html')).to.equal('/a/b.html'); 77 expect(pathInfo.encodeTestPath('/a/b/')).to.equal('/a/b/'); 78 expect(pathInfo.encodeTestPath('/a/b/?c=d')).to.equal('/a/b/%3Fc%3Dd'); 79 expect(pathInfo.encodeTestPath('/a/b/#c=d')).to.equal('/a/b/%23c%3Dd'); 80 expect(pathInfo.encodeTestPath('/a/b/?c=d#e=f')).to.equal('/a/b/%3Fc%3Dd%23e%3Df'); 81 82 // Specific example. 83 expect(pathInfo.encodeTestPath('/webgpu/cts.html?q=cts:command_buffer/basic:')) 84 .to.equal('/webgpu/cts.html%3Fq%3Dcts%3Acommand_buffer%2Fbasic%3A'); 85 }); 86 87 test('isParentDir', () => { 88 assert.isTrue(pathInfo.isParentDir('/', '/abc')); 89 assert.isTrue(pathInfo.isParentDir('/a', '/a/bc')); 90 assert.isTrue(pathInfo.isParentDir('/a', '/a/bc/')); 91 assert.isTrue(pathInfo.isParentDir('/a/', '/a/bc')); 92 assert.isTrue(pathInfo.isParentDir('/ab/bc', '/ab/bc/cd')); 93 assert.isFalse(pathInfo.isParentDir('/a', '/a')); 94 assert.isFalse(pathInfo.isParentDir('/ab', '/a')); 95 assert.isFalse(pathInfo.isParentDir('/ab', '/abc/d')); 96 assert.isFalse(pathInfo.isParentDir('/ab/', '/abc/d')); 97 assert.isFalse(pathInfo.isParentDir('/', '/a/b')); 98 assert.isFalse(pathInfo.isParentDir('/ab', '/ab/bc/cd')); 99 assert.isFalse(pathInfo.isParentDir('/ab/', '/ab/bc/cd')); 100 }); 101 102 test('getDirname', () => { 103 expect(pathInfo.getDirname('')).to.equal(''); 104 expect(pathInfo.getDirname('/')).to.equal(''); 105 expect(pathInfo.getDirname('/a.html')).to.equal(''); 106 expect(pathInfo.getDirname('/a/b.html')).to.equal('/a'); 107 expect(pathInfo.getDirname('/a/c/b.html')).to.equal('/a/c'); 108 expect(pathInfo.getDirname('/a/')).to.equal('/a'); 109 expect(pathInfo.getDirname('/a/b/c')).to.equal('/a/b'); 110 expect(pathInfo.getDirname('/a/c/b/')).to.equal('/a/c/b'); 111 }); 112 113 test('splitPathIntoLinkedParts', () => { 114 expect(pathInfo.splitPathIntoLinkedParts('/')).to.deep.equal([]); 115 116 expect(pathInfo.splitPathIntoLinkedParts('/a/b.html')).to.deep.equal([ 117 {name: 'a', path: '/a'}, 118 {name: 'b.html', path: '/a/b.html'}, 119 ]); 120 121 expect(pathInfo.splitPathIntoLinkedParts('/webgpu/cts.html?q=cts:command_buffer/basic:')) 122 .to.deep.equal([ 123 {name: 'webgpu', path: '/webgpu'}, 124 {name: 'cts.html?q=cts:command_buffer/basic:', path: '/webgpu/cts.html%3Fq%3Dcts%3Acommand_buffer%2Fbasic%3A'}, 125 ]); 126 127 expect(pathInfo.splitPathIntoLinkedParts('/a/b.html?x=1#y=2')) 128 .to.deep.equal([ 129 {name: 'a', path: '/a'}, 130 {name: 'b.html?x=1#y=2', path: '/a/b.html%3Fx%3D1%23y%3D2'}, 131 ]); 132 133 expect(pathInfo.splitPathIntoLinkedParts('/a.html#x=1')) 134 .to.deep.equal([ 135 {name: 'a.html#x=1', path: '/a.html%23x%3D1'}, 136 ]); 137 }); 138 }); 139 140 suite('PathPart', () => { 141 let sandbox, ppdir, ppfile, ppdirprefixed, ppfileprefixed; 142 143 setup(() => { 144 ppdir = fixture('path-part-dir-fixture'); 145 ppfile = fixture('path-part-file-fixture'); 146 ppdirprefixed = fixture('path-part-dir-prefixed-fixture'); 147 ppfileprefixed = fixture('path-part-file-prefixed-fixture'); 148 149 sandbox = sinon.sandbox.create(); 150 }); 151 152 teardown(() => { 153 sandbox.restore(); 154 }); 155 156 test('instanceof Polymer.Element', () => { 157 assert.isTrue(new PathPart() instanceof PolymerElement); 158 assert.isTrue(document.createElement('path-part') instanceof PolymerElement); 159 }); 160 161 suite('static get is()', () => { 162 test('path-part', () => { 163 assert.equal(PathPart.is, 'path-part'); 164 }); 165 }); 166 167 suite('PathPart.prototype.*', () => { 168 suite('href: computeHref(prefix, path)', () => { 169 test('computeHref()', () => { 170 assert.equal(typeof PathPart.prototype.computeHref, 'function'); 171 assert.equal(ppdir.computeHref('x', '/y').pathname, '/x/y'); 172 assert.equal(ppdir.computeHref('', '/y').pathname, '/y'); 173 assert.equal(ppdir.computeHref('x', '').pathname, '/x/'); 174 assert.equal(ppdir.computeHref(undefined, '').pathname, '/'); 175 }); 176 test('computeHref([default], path)', () => { 177 assert.equal(ppdir.href.pathname, '/a/b'); 178 assert.equal(ppfile.href.pathname, '/a/b/c.html'); 179 }); 180 test('computeHref([foo], path)', () => { 181 assert.equal(ppdirprefixed.href.pathname, '/foo/a/b'); 182 assert.equal(ppfileprefixed.href.pathname, '/foo/a/b/c.html'); 183 }); 184 test('computeHref(...) recomputes when prefix changed', () => { 185 assert.equal(ppdir.href.pathname, '/a/b'); 186 assert.equal(ppfile.href.pathname, '/a/b/c.html'); 187 188 ppdir.prefix = '/bar'; 189 ppfile.prefix = '/bar'; 190 191 assert.equal(ppdir.href.pathname, '/bar/a/b'); 192 assert.equal(ppfile.href.pathname, '/bar/a/b/c.html'); 193 }); 194 }); 195 suite('relativePath: computeDisplayableRelativePath(path)', () => { 196 test('computeDisplayableRelativePath()', () => { 197 assert.equal(typeof PathPart.prototype.computeDisplayableRelativePath, 'function'); 198 assert.equal(ppdir.computeDisplayableRelativePath(''), '/'); 199 assert.equal(ppdir.computeDisplayableRelativePath('foo'), 'foo/'); 200 }); 201 202 test('computeDisplayableRelativePath(...)', () => { 203 assert.equal(ppdir.relativePath, '/a/b/'); 204 }); 205 test('computeDisplayableRelativePath(...) (has prefix, is removed)', () => { 206 assert.equal(ppdirprefixed.relativePath, '/a/b/'); 207 }); 208 }); 209 suite('styleClass: computePathClass(isDir)', () => { 210 test('computePathClass()', () => { 211 assert.equal(typeof PathPart.prototype.computePathClass, 'function'); 212 assert.equal(ppfile.computePathClass(true), 'dir-path'); 213 assert.equal(ppfile.computePathClass(false), 'file-path'); 214 }); 215 test('computePathClass(true)', () => { 216 assert.equal(ppdir.styleClass, 'dir-path'); 217 }); 218 }); 219 }); 220 }); 221 </script> 222 </body> 223 </html>