mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-30 07:31:47 +00:00
migrate to htmlRunner
This commit is contained in:
14
src/tests/dom/animation.html
Normal file
14
src/tests/dom/animation.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<script src="../testing.js"></script>
|
||||
|
||||
<script id=animation>
|
||||
let a1 = document.createElement('div').animate(null, null);
|
||||
testing.expectEqual('finished', a1.playState);
|
||||
|
||||
let cb = [];
|
||||
a1.ready.then(() => { cb.push('ready') });
|
||||
a1.finished.then((x) => {
|
||||
cb.push('finished');
|
||||
cb.push(x == a1);
|
||||
});
|
||||
testing.eventually(() => testing.expectEqual(['finished', true], cb));
|
||||
</script>
|
||||
32
src/tests/dom/attribute.html
Normal file
32
src/tests/dom/attribute.html
Normal file
@@ -0,0 +1,32 @@
|
||||
<script src="../testing.js"></script>
|
||||
|
||||
<a id="link" href="foo" class="ok">OK</a>
|
||||
|
||||
<script id=attribute>
|
||||
let a = document.createAttributeNS('foo', 'bar');
|
||||
testing.expectEqual('foo', a.namespaceURI);
|
||||
testing.expectEqual(null, a.prefix);
|
||||
testing.expectEqual('bar', a.localName);
|
||||
testing.expectEqual('bar', a.name);
|
||||
testing.expectEqual('', a.value);
|
||||
|
||||
// TODO: libdom has a bug here: the created attr has no parent, it
|
||||
// causes a panic w/ libdom when setting the value.
|
||||
//.{ "a.value = 'nok'", "nok" },
|
||||
testing.expectEqual(null, a.ownerElement);
|
||||
|
||||
let b = document.getElementById('link').getAttributeNode('class');
|
||||
testing.expectEqual('class', b.name);
|
||||
testing.expectEqual('ok', b.value);
|
||||
|
||||
b.value = 'nok';
|
||||
testing.expectEqual('nok', b.value)
|
||||
|
||||
b.value = null;
|
||||
testing.expectEqual('null', b.value);
|
||||
|
||||
b.value = 'ok';
|
||||
testing.expectEqual('ok', b.value);
|
||||
|
||||
testing.expectEqual('link', b.ownerElement.id);
|
||||
</script>
|
||||
47
src/tests/dom/character_data.html
Normal file
47
src/tests/dom/character_data.html
Normal file
@@ -0,0 +1,47 @@
|
||||
<script src="../testing.js"></script>
|
||||
|
||||
<a id="link" href="foo" class="ok">OK</a>
|
||||
|
||||
<script id=character_data>
|
||||
let link = document.getElementById('link');
|
||||
let cdata = link.firstChild;
|
||||
testing.expectEqual('OK', cdata.data);
|
||||
|
||||
cdata.data = 'OK modified';
|
||||
testing.expectEqual('OK modified', cdata.data);
|
||||
cdata.data = 'OK';
|
||||
|
||||
testing.expectEqual(2, cdata.length);
|
||||
|
||||
testing.expectEqual(true, cdata.nextElementSibling === null);
|
||||
|
||||
// create a next element
|
||||
let next = document.createElement('a');
|
||||
testing.expectEqual(true, link.appendChild(next, cdata) !== undefined);
|
||||
testing.expectEqual(true, cdata.nextElementSibling.localName === 'a');
|
||||
|
||||
testing.expectEqual(true, cdata.previousElementSibling === null);
|
||||
|
||||
// create a prev element
|
||||
let prev = document.createElement('div');
|
||||
testing.expectEqual(true, link.insertBefore(prev, cdata) !== undefined);
|
||||
testing.expectEqual('div', cdata.previousElementSibling.localName);
|
||||
|
||||
cdata.appendData(' modified');
|
||||
testing.expectEqual('OK modified', cdata.data);
|
||||
|
||||
cdata.deleteData('OK'.length, ' modified'.length);
|
||||
testing.expectEqual('OK', cdata.data)
|
||||
|
||||
cdata.insertData('OK'.length-1, 'modified');
|
||||
testing.expectEqual('OmodifiedK', cdata.data);
|
||||
|
||||
cdata.replaceData('OK'.length-1, 'modified'.length, 'replaced');
|
||||
testing.expectEqual('OreplacedK', cdata.data);
|
||||
|
||||
testing.expectEqual('replaced', cdata.substringData('OK'.length-1, 'replaced'.length));
|
||||
testing.expectEqual('', cdata.substringData('OK'.length-1, 0));
|
||||
|
||||
testing.expectEqual('replaced', cdata.substringData('OK'.length-1, 'replaced'.length));
|
||||
testing.expectEqual('', cdata.substringData('OK'.length-1, 0));
|
||||
</script>
|
||||
8
src/tests/dom/comment.html
Normal file
8
src/tests/dom/comment.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<script src="../testing.js"></script>
|
||||
<script id=comment>
|
||||
let comment = new Comment('foo');
|
||||
testing.expectEqual('foo', comment.data);
|
||||
|
||||
let empty = new Comment()
|
||||
testing.expectEqual('', empty.data);
|
||||
</script>
|
||||
169
src/tests/dom/document.html
Normal file
169
src/tests/dom/document.html
Normal file
@@ -0,0 +1,169 @@
|
||||
<script src="../testing.js"></script>
|
||||
|
||||
<div id="content">
|
||||
<a id="a1" href="foo" class="ok">OK</a>
|
||||
<p id="p1" class="ok empty">
|
||||
<span id="s1"></span>
|
||||
</p>
|
||||
<p id="p2"> And</p>
|
||||
</div>
|
||||
|
||||
<script id=document>
|
||||
testing.expectEqual('Document', document.__proto__.__proto__.constructor.name);
|
||||
testing.expectEqual('Node', document.__proto__.__proto__.__proto__.constructor.name);
|
||||
testing.expectEqual('EventTarget', document.__proto__.__proto__.__proto__.__proto__.constructor.name);
|
||||
|
||||
let newdoc = new Document();
|
||||
testing.expectEqual(null, newdoc.documentElement);
|
||||
testing.expectEqual(0, newdoc.children.length);
|
||||
testing.expectEqual(0, newdoc.getElementsByTagName('*').length);
|
||||
testing.expectEqual(null, newdoc.getElementsByTagName('*').item(0));
|
||||
testing.expectEqual(true, newdoc.inputEncoding === document.inputEncoding);
|
||||
testing.expectEqual(true, newdoc.documentURI === document.documentURI);
|
||||
testing.expectEqual(true, newdoc.URL === document.URL);
|
||||
testing.expectEqual(true, newdoc.compatMode === document.compatMode);
|
||||
testing.expectEqual(true, newdoc.characterSet === document.characterSet);
|
||||
testing.expectEqual(true, newdoc.charset === document.charset);
|
||||
testing.expectEqual(true, newdoc.contentType === document.contentType);
|
||||
|
||||
testing.expectEqual('HTML', document.documentElement.tagName);
|
||||
|
||||
testing.expectEqual('UTF-8', document.characterSet);
|
||||
testing.expectEqual('UTF-8', document.charset);
|
||||
testing.expectEqual('UTF-8', document.inputEncoding);
|
||||
testing.expectEqual('CSS1Compat', document.compatMode);
|
||||
testing.expectEqual('text/html', document.contentType);
|
||||
|
||||
testing.expectEqual('http://localhost:9582/src/tests/dom/document.html', document.documentURI);
|
||||
testing.expectEqual('http://localhost:9582/src/tests/dom/document.html', document.URL);
|
||||
|
||||
testing.expectEqual(document.body, document.activeElement);
|
||||
|
||||
$('#a1').focus();
|
||||
testing.expectEqual($('#a1'), document.activeElement);
|
||||
|
||||
testing.expectEqual(0, document.styleSheets.length);
|
||||
</script>
|
||||
|
||||
<script id=getElementById>
|
||||
let divById = document.getElementById('content');
|
||||
testing.expectEqual('HTMLDivElement', divById.constructor.name);
|
||||
testing.expectEqual('div', divById.localName);
|
||||
</script>
|
||||
|
||||
<script id=getElementsByTagName>
|
||||
let byTagName = document.getElementsByTagName('p');
|
||||
testing.expectEqual(2, byTagName.length)
|
||||
testing.expectEqual('p1', byTagName.item(0).id);
|
||||
testing.expectEqual('p2', byTagName.item(1).id);
|
||||
|
||||
let byTagNameAll = document.getElementsByTagName('*');
|
||||
// If you add a script block (or change the HTML in any other way on this
|
||||
// page), this test will break. Adjust it accordingly.
|
||||
testing.expectEqual(20, byTagNameAll.length);
|
||||
testing.expectEqual('html', byTagNameAll.item(0).localName);
|
||||
testing.expectEqual('SCRIPT', byTagNameAll.item(11).tagName);
|
||||
|
||||
testing.expectEqual('s1', byTagNameAll.namedItem('s1').id);
|
||||
</script>
|
||||
|
||||
<script id=getElementByClassName>
|
||||
let ok = document.getElementsByClassName('ok');
|
||||
testing.expectEqual(2, ok.length);
|
||||
|
||||
let empty = document.getElementsByClassName('empty');
|
||||
testing.expectEqual(1, empty.length);
|
||||
|
||||
let emptyok = document.getElementsByClassName('empty ok');
|
||||
testing.expectEqual(1, emptyok.length);
|
||||
</script>
|
||||
|
||||
<script id=createXYZ>
|
||||
var v = document.createDocumentFragment();
|
||||
testing.expectEqual('#document-fragment', v.nodeName);
|
||||
|
||||
v = document.createTextNode('foo');
|
||||
testing.expectEqual('#text', v.nodeName);
|
||||
|
||||
v = document.createCDATASection('foo');
|
||||
testing.expectEqual('#cdata-section', v.nodeName);
|
||||
|
||||
v = document.createAttribute('foo');
|
||||
testing.expectEqual('foo', v.nodeName);
|
||||
|
||||
v = document.createComment('foo');
|
||||
testing.expectEqual('#comment', v.nodeName);
|
||||
v.cloneNode(); // doesn't crash, (I guess that's the point??)
|
||||
|
||||
let pi = document.createProcessingInstruction('foo', 'bar')
|
||||
testing.expectEqual('foo', pi.target);
|
||||
pi.cloneNode(); // doesn't crash (I guess that's the point??)
|
||||
</script>
|
||||
|
||||
<script id=importNode>
|
||||
let nimp = document.getElementById('content');
|
||||
var v = document.importNode(nimp);
|
||||
testing.expectEqual('DIV', v.nodeName);
|
||||
</script>
|
||||
|
||||
<script id=children>
|
||||
testing.expectEqual(1, document.children.length);
|
||||
testing.expectEqual('HTML', document.children.item(0).nodeName);
|
||||
testing.expectEqual('HTML', document.firstElementChild.nodeName);
|
||||
testing.expectEqual('HTML', document.lastElementChild.nodeName);
|
||||
testing.expectEqual(1, document.childElementCount);
|
||||
|
||||
let nd = new Document();
|
||||
testing.expectEqual(0, nd.children.length);
|
||||
testing.expectEqual(null, nd.children.item(0));
|
||||
testing.expectEqual(null, nd.firstElementChild);
|
||||
testing.expectEqual(null, nd.lastElementChild);
|
||||
testing.expectEqual(0, nd.childElementCount);
|
||||
</script>
|
||||
|
||||
<script id=createElement>
|
||||
let emptydoc = document.createElement('html');
|
||||
emptydoc.prepend(document.createElement('html'));
|
||||
|
||||
let emptydoc2 = document.createElement('html');
|
||||
emptydoc2.append(document.createElement('html'));
|
||||
|
||||
// Not sure what the above are testing, I just copied and pasted them.
|
||||
// Maybe that something doesn't crash?
|
||||
// Adding this so that the test runner doesn't complain;
|
||||
testing.skip();
|
||||
</script>
|
||||
|
||||
<script id=querySelector>
|
||||
testing.expectEqual(null, document.querySelector(''));
|
||||
testing.expectEqual('HTML', document.querySelector('*').nodeName);
|
||||
testing.expectEqual('content', document.querySelector('#content').id);
|
||||
testing.expectEqual('p1', document.querySelector('#p1').id);
|
||||
testing.expectEqual('a1', document.querySelector('.ok').id);
|
||||
testing.expectEqual('p1', document.querySelector('a ~ p').id);
|
||||
testing.expectEqual('HTML', document.querySelector(':root').nodeName);
|
||||
|
||||
testing.expectEqual(2, document.querySelectorAll('p').length);
|
||||
|
||||
testing.expectEqual([''],
|
||||
Array.from(document.querySelectorAll('#content > p#p1'))
|
||||
.map(row => row.querySelector('span').textContent)
|
||||
);
|
||||
|
||||
testing.expectEqual(0, document.querySelectorAll('.\\:popover-open').length);
|
||||
testing.expectEqual(0, document.querySelectorAll('.foo\\:bar').length);
|
||||
</script>
|
||||
|
||||
<script id=adoptNode>
|
||||
// this test breaks the doc structure, keep it at the end
|
||||
let nadop = document.getElementById('content')
|
||||
var v = document.adoptNode(nadop);
|
||||
testing.expectEqual('DIV', v.nodeName);
|
||||
</script>
|
||||
|
||||
<script id=adoptedStyleSheets>
|
||||
const acss = document.adoptedStyleSheets;
|
||||
testing.expectEqual(0, acss.length);
|
||||
acss.push(new CSSStyleSheet());
|
||||
testing.expectEqual(1, acss.length);
|
||||
</script>
|
||||
Reference in New Issue
Block a user