migrate more tests to htmlRunner

This commit is contained in:
Karl Seguin
2025-09-08 18:40:59 +08:00
parent bc82023878
commit 15628d9b07
8 changed files with 224 additions and 226 deletions

View File

@@ -0,0 +1,115 @@
<script src="../testing.js"></script>
<div id="content"><p id=para></p></div>
<script id=eventTarget>
testing.expectEqual('[object EventTarget]', new EventTarget().toString());
let content = $('#content');
let para = $('#para');
var nb = 0;
var evt;
var phase;
var cur;
function reset() {
nb = 0;
evt = undefined;
phase = undefined;
cur = undefined;
}
function cbk(event) {
evt = event;
phase = event.eventPhase;
cur = event.currentTarget;
nb++;
}
content.addEventListener('basic', cbk);
content.dispatchEvent(new Event('basic'));
testing.expectEqual(1, nb);
testing.expectEqual(true, evt instanceof Event);
testing.expectEqual('basic', evt.type);
testing.expectEqual(2, phase);
testing.expectEqual('content', cur.getAttribute('id'));
reset();
para.dispatchEvent(new Event('basic'))
// handler is not called, no capture, not the targeno bubbling
testing.expectEqual(0, nb);
testing.expectEqual(undefined, evt);
reset();
content.addEventListener('basic', cbk);
content.dispatchEvent(new Event('basic'))
testing.expectEqual(1, nb);
reset();
content.addEventListener('basic', cbk, true);
content.dispatchEvent(new Event('basic'));
testing.expectEqual(2, nb);
reset()
content.removeEventListener('basic', cbk);
content.dispatchEvent(new Event('basic'));
testing.expectEqual(1, nb);
reset();
content.removeEventListener('basic', cbk, {capture: true});
content.dispatchEvent(new Event('basic'));
testing.expectEqual(0, nb);
reset();
content.addEventListener('capture', cbk, true);
content.dispatchEvent(new Event('capture'));
testing.expectEqual(1, nb);
testing.expectEqual(true, evt instanceof Event);
testing.expectEqual('capture', evt.type);
testing.expectEqual(2, phase);
testing.expectEqual('content', cur.getAttribute('id'));
reset();
para.dispatchEvent(new Event('capture'));
testing.expectEqual(1, nb);
testing.expectEqual(true, evt instanceof Event);
testing.expectEqual('capture', evt.type);
testing.expectEqual(1, phase);
testing.expectEqual('content', cur.getAttribute('id'));
reset();
content.addEventListener('bubbles', cbk);
content.dispatchEvent(new Event('bubbles', {bubbles: true}));
testing.expectEqual(1, nb);
testing.expectEqual(true, evt instanceof Event);
testing.expectEqual('bubbles', evt.type);
testing.expectEqual(2, phase);
testing.expectEqual('content', cur.getAttribute('id'));
reset();
para.dispatchEvent(new Event('bubbles', {bubbles: true}));
testing.expectEqual(1, nb);
testing.expectEqual(true, evt instanceof Event);
testing.expectEqual('bubbles', evt.type);
testing.expectEqual(3, phase);
testing.expectEqual('content', cur.getAttribute('id'));
const obj1 = {
calls: 0,
handleEvent: function() { this.calls += 1 }
};
content.addEventListener('he', obj1);
content.dispatchEvent(new Event('he'));
testing.expectEqual(1, obj1.calls);
content.removeEventListener('he', obj1);
content.dispatchEvent(new Event('he'));
testing.expectEqual(1, obj1.calls);
// doesn't crash on null receiver
content.addEventListener('he2', null);
content.dispatchEvent(new Event('he2'));
</script>

View File

@@ -0,0 +1,39 @@
<script src="../testing.js"></script>
<div id="content">
<a id="link" href="foo" class="ok">OK</a>
</div>
<script id=exceptions>
let content = $('#content');
let link = $('#link');
testing.withError((err) => {
const msg = "Failed to execute 'appendChild' on 'Node': The new child element contains the parent.";
testing.expectEqual(3, err.code);
testing.expectEqual(msg, err.message);
testing.expectEqual('HierarchyRequestError: ' + msg, err.toString());
testing.expectEqual(true, err instanceof DOMException);
testing.expectEqual(true, err instanceof Error);
}, () => link.appendChild(content));
</script>
<script id=constructor>
let exc0 = new DOMException();
testing.expectEqual('Error', exc0.name);
testing.expectEqual(0, exc0.code);
testing.expectEqual('', exc0.message);
testing.expectEqual('Error', exc0.toString());
let exc1 = new DOMException('Sandwich malfunction');
testing.expectEqual('Error', exc1.name);
testing.expectEqual(0, exc1.code);
testing.expectEqual('Sandwich malfunction', exc1.message);
testing.expectEqual('Error: Sandwich malfunction', exc1.toString());
let exc2 = new DOMException('Caterpillar turned into a butterfly', 'NoModificationAllowedError');
testing.expectEqual('NoModificationAllowedError', exc2.name);
testing.expectEqual(7, exc2.code);
testing.expectEqual('Caterpillar turned into a butterfly', exc2.message);
testing.expectEqual('NoModificationAllowedError: Caterpillar turned into a butterfly', exc2.toString());
</script>

View File

@@ -0,0 +1,59 @@
<body>
<div id="content">
<a id="link" href="foo" class="ok">OK</a>
<p id="para-empty" class="ok empty">
<span id="para-empty-child"></span>
</p>
<p id="para"> And</p>
<!--comment-->
</div>
</body>
<script src="../testing.js"></script>
<script id=exceptions>
let content = $('#content');
let pe = $('#para-empty');
let getElementsByTagName = document.getElementsByTagName('p');
testing.expectEqual(2, getElementsByTagName.length);
let getElementsByTagNameCI = document.getElementsByTagName('P');
testing.expectEqual(2, getElementsByTagNameCI.length);
testing.expectEqual('p', getElementsByTagName.item(0).localName);
testing.expectEqual('p', getElementsByTagName.item(1).localName);
let getElementsByTagNameAll = document.getElementsByTagName('*');
testing.expectEqual(10, getElementsByTagNameAll.length);
testing.expectEqual('html', getElementsByTagNameAll.item(0).localName);
testing.expectEqual('html', getElementsByTagNameAll.item(0).localName);
testing.expectEqual('head', getElementsByTagNameAll.item(1).localName);
testing.expectEqual('html', getElementsByTagNameAll.item(0).localName);
testing.expectEqual('body', getElementsByTagNameAll.item(2).localName);
testing.expectEqual('div', getElementsByTagNameAll.item(3).localName);
testing.expectEqual('p', getElementsByTagNameAll.item(7).localName);
testing.expectEqual('span', getElementsByTagNameAll.namedItem('para-empty-child').localName);
// array like
testing.expectEqual('html', getElementsByTagNameAll[0].localName);
testing.expectEqual('p', getElementsByTagNameAll[7].localName);
testing.expectEqual(undefined, getElementsByTagNameAll[11]);
testing.expectEqual('span', getElementsByTagNameAll['para-empty-child'].localName);
testing.expectEqual(undefined, getElementsByTagNameAll['foo']);
testing.expectEqual(4, content.getElementsByTagName('*').length);
testing.expectEqual(2, content.getElementsByTagName('p').length);
testing.expectEqual(0, content.getElementsByTagName('div').length);
testing.expectEqual(1, document.children.length);
testing.expectEqual(3, content.children.length);
// check liveness
let p = document.createElement('p');
testing.expectEqual('OK live', p.textContent = 'OK live');
testing.expectEqual(' And', getElementsByTagName.item(1).textContent);
testing.expectEqual(true, content.appendChild(p) != undefined);
testing.expectEqual(3, getElementsByTagName.length);
testing.expectEqual('OK live', getElementsByTagName.item(2).textContent);
testing.expectEqual(true, content.insertBefore(p, pe) != undefined);
testing.expectEqual('OK live', getElementsByTagName.item(0).textContent);
</script>