mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-30 07:31:47 +00:00
migrate more tests to htmlRunner
This commit is contained in:
13
src/tests/dom/implementation.html
Normal file
13
src/tests/dom/implementation.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<script src="../testing.js"></script>
|
||||
<script id=implementation>
|
||||
let impl = document.implementation;
|
||||
testing.expectEqual("[object HTMLDocument]", impl.createHTMLDocument().toString());;
|
||||
|
||||
const doc = impl.createHTMLDocument('foo');
|
||||
testing.expectEqual("[object HTMLDocument]", doc.toString());
|
||||
testing.expectEqual("foo", doc.title);
|
||||
testing.expectEqual("[object HTMLBodyElement]", doc.body.toString());
|
||||
testing.expectEqual("[object Document]", impl.createDocument(null, 'foo').toString());
|
||||
testing.expectEqual("[object DocumentType]", impl.createDocumentType('foo', 'bar', 'baz').toString());
|
||||
testing.expectEqual(true, impl.hasFeature());
|
||||
</script>
|
||||
95
src/tests/dom/intersection_observer.html
Normal file
95
src/tests/dom/intersection_observer.html
Normal file
@@ -0,0 +1,95 @@
|
||||
<body></body>
|
||||
<script src="../testing.js"></script>
|
||||
<script id=intersectionObserver>
|
||||
// doesn't crash (I guess)
|
||||
new IntersectionObserver(() => {}).observe(document.documentElement);
|
||||
|
||||
let count_a = 0;
|
||||
const a1 = document.createElement('div');
|
||||
new IntersectionObserver(entries => {count_a += 1;}).observe(a1);
|
||||
testing.expectEqual(1, count_a);
|
||||
|
||||
// This test is documenting current behavior, not correct behavior.
|
||||
// Currently every time observe is called, the callback is called with all entries.
|
||||
let count_b = 0;
|
||||
let observer_b = new IntersectionObserver(entries => {count_b = entries.length;});
|
||||
const b1 = document.createElement('div');
|
||||
observer_b.observe(b1);
|
||||
testing.expectEqual(1, count_b);
|
||||
const b2 = document.createElement('div');
|
||||
observer_b.observe(b2);
|
||||
testing.expectEqual(2, count_b);
|
||||
</script>
|
||||
|
||||
<script id=reobserve>
|
||||
let count_bb = 0;
|
||||
let observer_bb = new IntersectionObserver(entries => {count_bb = entries.length;});
|
||||
const bb1 = document.createElement('div');
|
||||
observer_bb.observe(bb1);
|
||||
testing.expectEqual(1, count_bb)
|
||||
observer_bb.observe(bb1);
|
||||
testing.expectEqual(1, count_bb) // Still 1, not 2
|
||||
</script>
|
||||
|
||||
<script id=unobserve>
|
||||
let count_c = 0;
|
||||
let observer_c = new IntersectionObserver(entries => { count_c = entries.length;});
|
||||
const c1 = document.createElement('div');
|
||||
observer_c.observe(c1);
|
||||
testing.expectEqual(1, count_c);
|
||||
observer_c.unobserve(c1);
|
||||
const c2 = document.createElement('div');
|
||||
observer_c.observe(c2);
|
||||
testing.expectEqual(1, count_c);
|
||||
</script>
|
||||
|
||||
<script id=takeRecords>
|
||||
let observer_e = new IntersectionObserver(entries => {});
|
||||
let e1 = document.createElement('div');
|
||||
observer_e.observe(e1);
|
||||
const e2 = document.createElement('div');
|
||||
observer_e.observe(e2);
|
||||
testing.expectEqual(2, observer_e.takeRecords().length);
|
||||
</script>
|
||||
|
||||
<script id=disconnect>
|
||||
let observer_d = new IntersectionObserver(entries => {});
|
||||
let d1 = document.createElement('div');
|
||||
observer_d.observe(d1);
|
||||
observer_d.disconnect();
|
||||
testing.expectEqual(0, observer_d.takeRecords().length);
|
||||
</script>
|
||||
|
||||
<script id=entry>
|
||||
let entry;
|
||||
let div1 = document.createElement('div');
|
||||
document.body.appendChild(div1);
|
||||
new IntersectionObserver(entries => { entry = entries[0]; }).observe(div1);
|
||||
|
||||
testing.expectEqual(0, entry.boundingClientRect.x);
|
||||
testing.expectEqual(1, entry.intersectionRatio);
|
||||
testing.expectEqual(0, entry.intersectionRect.x);
|
||||
testing.expectEqual(0, entry.intersectionRect.y);
|
||||
testing.expectEqual(1, entry.intersectionRect.width);
|
||||
testing.expectEqual(1, entry.intersectionRect.height);
|
||||
testing.expectEqual(true, entry.isIntersecting);
|
||||
testing.expectEqual(0, entry.rootBounds.x);
|
||||
testing.expectEqual(0, entry.rootBounds.y);
|
||||
testing.expectEqual(1, entry.rootBounds.width);
|
||||
testing.expectEqual(1, entry.rootBounds.height);
|
||||
testing.expectEqual('[object HTMLDivElement]', entry.target.toString());
|
||||
</script>
|
||||
|
||||
<script id=options>
|
||||
const new_root = document.createElement('span');
|
||||
document.body.appendChild(new_root);
|
||||
|
||||
let new_entry;
|
||||
const new_observer = new IntersectionObserver(
|
||||
(entries) => { new_entry = entries[0]; },
|
||||
{root: new_root, rootMargin: '0px 0px 0px 0px', threshold: [0]}
|
||||
);
|
||||
|
||||
new_observer.observe(document.createElement('div'));
|
||||
testing.expectEqual(1, new_entry.rootBounds.x);
|
||||
</script>
|
||||
59
src/tests/dom/message_channel.html
Normal file
59
src/tests/dom/message_channel.html
Normal file
@@ -0,0 +1,59 @@
|
||||
<script src="../testing.js"></script>
|
||||
<script id=messageChannel>
|
||||
const mc1 = new MessageChannel();
|
||||
testing.expectEqual(mc1.port1, mc1.port1);
|
||||
testing.expectEqual(mc1.port2, mc1.port2);
|
||||
testing.expectEqual(true, mc1.port1 != mc1.port2);
|
||||
mc1.port1.postMessage('msg1');
|
||||
|
||||
let message = null;
|
||||
let target = null;
|
||||
let currentTarget = null;
|
||||
mc1.port2.onmessage = (e) => {
|
||||
message = e.data;
|
||||
target = e.target;
|
||||
currentTarget = e.currentTarget;
|
||||
};
|
||||
|
||||
// as soon as onmessage is called, queued messages are delivered
|
||||
testing.expectEqual('msg1', message);
|
||||
testing.expectEqual(mc1.port2, target);
|
||||
testing.expectEqual(mc1.port2, currentTarget);
|
||||
|
||||
mc1.port1.postMessage('msg2');
|
||||
testing.expectEqual('msg2', message);
|
||||
testing.expectEqual(mc1.port2, target);
|
||||
testing.expectEqual(mc1.port2, currentTarget);
|
||||
|
||||
message = null;
|
||||
mc1.port1.close();
|
||||
mc1.port1.postMessage('msg3');
|
||||
testing.expectEqual(null, message);
|
||||
|
||||
const mc2 = new MessageChannel();
|
||||
mc2.port2.postMessage('msg1');
|
||||
mc2.port1.postMessage('msg2');
|
||||
|
||||
let message1 = null;
|
||||
mc2.port1.addEventListener('message', (e) => {
|
||||
message1 = e.data;
|
||||
});
|
||||
|
||||
let message2 = null;
|
||||
mc2.port2.addEventListener('message', (e) => {
|
||||
message2 = e.data;
|
||||
});
|
||||
|
||||
testing.expectEqual(null, message1);
|
||||
testing.expectEqual(null, message2);
|
||||
|
||||
mc2.port2.start();
|
||||
|
||||
testing.expectEqual(null, message1);
|
||||
testing.expectEqual('msg2', message2);
|
||||
message2 = null;
|
||||
|
||||
mc2.port1.start();
|
||||
testing.expectEqual('msg1', message1);
|
||||
testing.expectEqual(null, message2);
|
||||
</script>
|
||||
68
src/tests/dom/mutation_observer.html
Normal file
68
src/tests/dom/mutation_observer.html
Normal file
@@ -0,0 +1,68 @@
|
||||
<div></div>
|
||||
<div id=d1><p id=p1> And</p></div>
|
||||
<div id=d2><p id=p2> And</p></div>
|
||||
<div id=d3><p id=p3> And</p></div>
|
||||
|
||||
<script src="../testing.js"></script>
|
||||
<script id=mutationObserver>
|
||||
// doesn't crash, yay.
|
||||
new MutationObserver(() => {}).observe(document, { childList: true });
|
||||
|
||||
var nb = 0;
|
||||
var mrs;
|
||||
new MutationObserver((mu) => {
|
||||
mrs = mu;
|
||||
nb++;
|
||||
}).observe(document.firstElementChild, { attributes: true, attributeOldValue: true });
|
||||
document.firstElementChild.setAttribute("foo", "bar");
|
||||
document.firstElementChild.firstChild.setAttribute("foo", "bar");
|
||||
|
||||
testing.eventually(() => {
|
||||
testing.expectEqual(1, nb);
|
||||
testing.expectEqual('attributes', mrs[0].type);
|
||||
testing.expectEqual(document.firstElementChild, mrs[0].target);
|
||||
testing.expectEqual('bar', mrs[0].target.getAttribute('foo'));
|
||||
testing.expectEqual('foo', mrs[0].attributeName);
|
||||
testing.expectEqual(null, mrs[0].oldValue);
|
||||
});
|
||||
|
||||
var nb2 = 0;
|
||||
var mrs2;
|
||||
var node1 = $('#p1').firstChild;
|
||||
new MutationObserver((mu) => {
|
||||
mrs2 = mu;
|
||||
nb2++;
|
||||
}).observe(node1, { characterData: true, characterDataOldValue: true });
|
||||
node1.data = "foo";
|
||||
|
||||
testing.eventually(() => {
|
||||
testing.expectEqual(1, nb2);
|
||||
testing.expectEqual('characterData', mrs2[0].type);
|
||||
testing.expectEqual(node1, mrs2[0].target);
|
||||
testing.expectEqual('foo', mrs2[0].target.data);
|
||||
testing.expectEqual(' And', mrs2[0].oldValue);
|
||||
});
|
||||
</script>
|
||||
|
||||
<script id=callback>
|
||||
// tests that mutation observers that have a callback which trigger the
|
||||
// mutation observer don't crash.
|
||||
// https://github.com/lightpanda-io/browser/issues/550
|
||||
var node2 = $("#p2");
|
||||
new MutationObserver(() => {
|
||||
node2.innerText = 'a';
|
||||
}).observe($('#d2'), { subtree:true, childList:true });
|
||||
node2.innerText = "2";
|
||||
testing.eventually(() => testing.expectEqual('a', node2.innerText));
|
||||
|
||||
var node3 = $("#p3");
|
||||
var attrWatch = 0;
|
||||
new MutationObserver(() => {
|
||||
attrWatch++;
|
||||
}).observe($('#d3'), { attributeFilter: ["name"], subtree: true });
|
||||
node3.setAttribute("id", "1");
|
||||
|
||||
testing.expectEqual(0, attrWatch);
|
||||
node3.setAttribute('name', 'other');
|
||||
testing.eventually(() => testing.expectEqual(1, attrWatch));
|
||||
</script>
|
||||
18
src/tests/dom/named_node_map.html
Normal file
18
src/tests/dom/named_node_map.html
Normal file
@@ -0,0 +1,18 @@
|
||||
<div id="content"></div>
|
||||
|
||||
<script src="../testing.js"></script>
|
||||
<script id=namedNodeMap>
|
||||
let a = document.getElementById('content').attributes;
|
||||
testing.expectEqual(1, a.length);
|
||||
testing.expectEqual('[object Attr]', a.item(0).toString());
|
||||
testing.expectEqual(null, a.item(1));
|
||||
testing.expectEqual('[object Attr]', a.getNamedItem('id').toString());
|
||||
testing.expectEqual(null, a.getNamedItem('foo'));
|
||||
testing.expectEqual('[object Attr]', a.setNamedItem(a.getNamedItem('id')).toString());
|
||||
|
||||
testing.expectEqual('id', a['id'].name);
|
||||
testing.expectEqual('content', a['id'].value);
|
||||
testing.expectEqual(undefined, a['other']);
|
||||
a[0].value = 'abc123';
|
||||
testing.expectEqual('abc123', a[0].value);
|
||||
</script>
|
||||
Reference in New Issue
Block a user