summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/shadow-dom/leaktests
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /testing/web-platform/tests/shadow-dom/leaktests
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/tests/shadow-dom/leaktests')
-rw-r--r--testing/web-platform/tests/shadow-dom/leaktests/get-elements.html174
-rw-r--r--testing/web-platform/tests/shadow-dom/leaktests/html-collection.html76
-rw-r--r--testing/web-platform/tests/shadow-dom/leaktests/window-frames.html36
3 files changed, 286 insertions, 0 deletions
diff --git a/testing/web-platform/tests/shadow-dom/leaktests/get-elements.html b/testing/web-platform/tests/shadow-dom/leaktests/get-elements.html
new file mode 100644
index 000000000..2ce916a65
--- /dev/null
+++ b/testing/web-platform/tests/shadow-dom/leaktests/get-elements.html
@@ -0,0 +1,174 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='author' title='Google' href='http://www.google.com'>
+<meta name='assert' content='getElement* API in document should not leak any node in shadow tree.'>
+<link rel='help' href='https://w3c.github.io/webcomponents/spec/shadow/'>
+<script src='/resources/testharness.js'></script>
+<script src='/resources/testharnessreport.js'></script>
+</head>
+<body>
+
+<!-- This template will be filled in '#doc', '#host-open', and '#host-closed' below -->
+<template id='domtree-template'>
+ <span id='foo'></span>
+ <div class='bar'></div>
+ <form name='baz'></form>
+ <my-element></my-element>
+</template>
+
+<div id='doc'>
+ <div id='host-open'></div>
+ <div id='host-closed'></div>
+</div>
+
+</body>
+<script>
+'use strict';
+
+function fillTemplate(root, prefix) {
+ var tmpl = document.getElementById('domtree-template');
+ root.appendChild(document.importNode(tmpl.content, true));
+ for (var i = 0; i < root.childNodes.length; ++i) {
+ var el = root.childNodes[i];
+ if (el.nodeType != 1)
+ continue;
+ el.setAttribute('label', prefix + el.tagName.toLowerCase());
+ }
+
+ root.appendChild(document.createElementNS('http://www.w3.org/2000/svg', 'linearGradient'));
+}
+
+// Construct subtree with 'doc-*' ids.
+var doc = document.getElementById('doc');
+fillTemplate(doc, 'doc-');
+
+// Construct shadow subtree with 'shadow-*' ids.
+var hostOpen = document.getElementById('host-open');
+var shadowOpen = hostOpen.attachShadow({mode: 'open'});
+fillTemplate(shadowOpen, 'shadow-open-');
+
+var hostClosed = document.getElementById('host-closed');
+var shadowClosed = hostClosed.attachShadow({mode: 'closed'});
+fillTemplate(shadowClosed, 'shadow-closed-');
+
+test(function() {
+ // getElementById() (NonElementParentNode)
+ assert_equals(document.querySelectorAll('#foo').length, 1);
+ assert_equals(document.getElementById('foo').getAttribute('label'), 'doc-span');
+ assert_equals(document.querySelector('#foo').getAttribute('label'), 'doc-span');
+
+ assert_equals(doc.querySelectorAll('#foo').length, 1);
+ assert_equals(doc.querySelector('#foo').getAttribute('label'), 'doc-span');
+
+ assert_equals(hostOpen.querySelectorAll('#foo').length, 0);
+
+ assert_equals(shadowOpen.querySelectorAll('#foo').length, 1);
+ assert_equals(shadowOpen.getElementById('foo').getAttribute('label'), 'shadow-open-span');
+ assert_equals(shadowOpen.querySelector('#foo').getAttribute('label'), 'shadow-open-span');
+
+ assert_equals(hostClosed.querySelectorAll('#foo').length, 0);
+
+ assert_equals(shadowClosed.querySelectorAll('#foo').length, 1);
+ assert_equals(shadowClosed.getElementById('foo').getAttribute('label'), 'shadow-closed-span');
+ assert_equals(shadowClosed.querySelector('#foo').getAttribute('label'), 'shadow-closed-span');
+}, 'getElementsById() should not leak nodes in shadow tree');
+
+test(function() {
+ // getElementsByClassName() (Element, Document)
+ assert_equals(document.getElementsByClassName('bar').length, 1);
+ assert_equals(document.getElementsByClassName('bar')[0].getAttribute('label'), 'doc-div');
+ assert_equals(document.getElementsByClassName('bar').length, 1);
+ assert_equals(document.getElementsByClassName('bar')[0].getAttribute('label'), 'doc-div');
+ assert_equals(document.querySelectorAll('.bar').length, 1);
+
+ assert_equals(doc.querySelectorAll('.bar').length, 1);
+ assert_equals(doc.getElementsByClassName('bar')[0].getAttribute('label'), 'doc-div');
+
+ assert_array_equals(hostOpen.querySelectorAll('.bar').length, 0);
+
+ assert_equals(shadowOpen.querySelectorAll('.bar').length, 1);
+ assert_equals(shadowOpen.querySelectorAll('.bar')[0].getAttribute('label'), 'shadow-open-div');
+
+ assert_array_equals(hostClosed.querySelectorAll('.bar').length, 0);
+
+ assert_equals(shadowClosed.querySelectorAll('.bar').length, 1);
+ assert_equals(shadowClosed.querySelectorAll('.bar')[0].getAttribute('label'), 'shadow-closed-div');
+}, 'getElementsByClassName() should not leak nodes in shadow tree');
+
+test(function() {
+ // getElementsByName (Document)
+ assert_equals(document.getElementsByName('baz').length, 1);
+ assert_equals(document.getElementsByName('baz')[0].getAttribute('label'), 'doc-form');
+ assert_equals(document.getElementsByName('baz').length, 1);
+ assert_equals(document.getElementsByName('baz')[0].getAttribute('label'), 'doc-form');
+ assert_equals(document.querySelectorAll('[name=baz]').length, 1);
+
+ assert_equals(doc.querySelectorAll('[name=baz]').length, 1);
+
+ assert_array_equals(hostOpen.querySelectorAll('[name=baz]').length, 0);
+ assert_equals(shadowOpen.querySelectorAll('[name=baz]').length, 1);
+ assert_equals(shadowOpen.querySelectorAll('[name=baz]')[0].getAttribute('label'), 'shadow-open-form');
+
+ assert_array_equals(hostClosed.querySelectorAll('[name=baz]').length, 0);
+ assert_equals(shadowClosed.querySelectorAll('[name=baz]').length, 1);
+ assert_equals(shadowClosed.querySelectorAll('[name=baz]')[0].getAttribute('label'), 'shadow-closed-form');
+}, 'getElementsByName() should not leak nodes in shadow tree');
+
+test(function() {
+ // getElementsByTagName (Element, Document)
+ assert_equals(document.getElementsByTagName('my-element').length, 1);
+ assert_equals(document.getElementsByTagName('my-element')[0].getAttribute('label'), 'doc-my-element');
+ assert_equals(document.getElementsByTagName('my-element').length, 1);
+ assert_equals(document.getElementsByTagName('my-element')[0].getAttribute('label'), 'doc-my-element');
+ assert_equals(document.querySelectorAll('my-element').length, 1);
+
+ assert_equals(doc.querySelectorAll('my-element').length, 1);
+ assert_equals(doc.getElementsByTagName('my-element')[0].getAttribute('label'), 'doc-my-element');
+
+ assert_array_equals(hostOpen.querySelectorAll('my-element').length, 0);
+ // ShadowRoot isn't an Element, does not have getElementsByTagName().
+ assert_equals(shadowOpen.querySelectorAll('my-element').length, 1);
+ assert_equals(shadowOpen.querySelectorAll('my-element')[0].getAttribute('label'), 'shadow-open-my-element');
+
+ assert_array_equals(hostClosed.querySelectorAll('my-element').length, 0);
+ assert_equals(shadowClosed.querySelectorAll('my-element').length, 1);
+ assert_equals(shadowClosed.querySelectorAll('my-element')[0].getAttribute('label'), 'shadow-closed-my-element');
+}, 'getElementsByTagName() should not leak nodes in shadow tree');
+
+test(function() {
+ // getElementsByTagNameNS (Element, Document)
+ assert_equals(document.getElementsByTagName('lineargradient').length, 0);
+ assert_equals(document.getElementsByTagNameNS('*', 'lineargradient').length, 0);
+ assert_equals(document.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'lineargradient').length, 0);
+ assert_equals(document.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'lineargradient').length, 0);
+
+ assert_equals(document.getElementsByTagName('linearGradient').length, 1);
+ assert_equals(document.getElementsByTagNameNS('*', 'linearGradient').length, 1);
+ assert_equals(document.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'linearGradient').length, 1);
+ assert_equals(document.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'linearGradient').length, 0);
+
+ assert_equals(doc.getElementsByTagName('lineargradient').length, 0);
+ assert_equals(doc.getElementsByTagNameNS('*', 'lineargradient').length, 0);
+ assert_equals(doc.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'lineargradient').length, 0);
+ assert_equals(doc.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'lineargradient').length, 0);
+
+ assert_equals(doc.getElementsByTagName('linearGradient').length, 1);
+ assert_equals(doc.getElementsByTagNameNS('*', 'linearGradient').length, 1);
+ assert_equals(doc.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'linearGradient').length, 1);
+ assert_equals(doc.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'linearGradient').length, 0);
+
+ assert_equals(hostOpen.getElementsByTagName('linearGradient').length, 0);
+ assert_equals(hostOpen.getElementsByTagNameNS('*', 'linearGradient').length, 0);
+ assert_equals(hostOpen.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'linearGradient').length, 0);
+ assert_equals(hostOpen.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'linearGradient').length, 0);
+
+ assert_equals(hostClosed.getElementsByTagName('linearGradient').length, 0);
+ assert_equals(hostClosed.getElementsByTagNameNS('*', 'linearGradient').length, 0);
+ assert_equals(hostClosed.getElementsByTagNameNS('http://www.w3.org/2000/svg', 'linearGradient').length, 0);
+ assert_equals(hostClosed.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'linearGradient').length, 0);
+
+ // ShadowRoot isn't an Element, does not have getElementsByTagNameNS().
+}, 'getElementsByTagNameNS() should not leak nodes in shadow tree');
+</script>
+</html>
diff --git a/testing/web-platform/tests/shadow-dom/leaktests/html-collection.html b/testing/web-platform/tests/shadow-dom/leaktests/html-collection.html
new file mode 100644
index 000000000..d15656971
--- /dev/null
+++ b/testing/web-platform/tests/shadow-dom/leaktests/html-collection.html
@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='author' title='Google' href='http://www.google.com'>
+<meta name='assert' content='document attributes that returns HTMLCollection should not expose nodes in shadow tree.'>
+<link rel='help' href='https://w3c.github.io/webcomponents/spec/shadow/'>
+<script src='/resources/testharness.js'></script>
+<script src='/resources/testharnessreport.js'></script>
+</head>
+<body>
+<template id='collection-template'>
+ <img>
+ <embed></embed>
+ <applet></applet>
+ <object type='application/x-java-applet'></object>
+ <a href='http://example.com'></a>
+ <a name='test'></a>
+ <form name='test'></form>
+ <script></script>
+</template>
+<div id='doc'></div>
+<div id='host-open'></div>
+<div id='host-closed'></div>
+</body>
+<script>
+'use strict';
+
+function fillTemplate(root, prefix) {
+ var tmpl = document.getElementById('collection-template');
+ root.appendChild(document.importNode(tmpl.content, true));
+ for (var i = 0; i < root.childNodes.length; ++i) {
+ var el = root.childNodes[i];
+ if (el.nodeType != 1)
+ continue;
+ el.id = prefix + el.tagName.toLowerCase();
+ }
+}
+
+// Construct subtree with 'doc-*' ids.
+var doc = document.getElementById('doc');
+fillTemplate(doc, 'doc-');
+
+// Construct shadow subtree with 'shadow-*' ids.
+var host = document.getElementById('host-open');
+var shadow = host.attachShadow({mode: 'open'});
+fillTemplate(shadow, 'shadow-open-');
+
+host = document.getElementById('host-closed');
+shadow = host.attachShadow({mode: 'closed'});
+fillTemplate(shadow, 'shadow-closed-');
+
+function testCollection(collection) {
+ var elements = document[collection];
+ assert_greater_than(elements.length, 0, 'document.' + collection + ' should have at least 1 element.');
+ for (var i = 0; i < elements.length; ++i) {
+ if (elements[i].id) {
+ assert_equals(elements[i].id.indexOf('shadow-'), -1, 'document.' + collection + ' should not contain elements in shadow tree.');
+ }
+ }
+}
+
+var testParams = [
+ ['document.scripts should not contain shadow nodes', 'scripts'],
+ ['document.all should not contain shadow nodes', 'all'],
+ ['document.forms should not contain shadow nodes', 'forms'],
+ ['document.images should not contain shadow nodes', 'images'],
+ ['document.links should not contain shadow nodes', 'links'],
+ ['document.anchors should not contain shadow nodes', 'anchors'],
+ ['document.embeds should not contain shadow nodes', 'embeds'],
+ ['document.plugins should not contain shadow nodes', 'plugins'],
+ ['document.applets should not contain shadow nodes', 'applets']];
+
+generate_tests(testCollection, testParams);
+
+</script>
+</html>
diff --git a/testing/web-platform/tests/shadow-dom/leaktests/window-frames.html b/testing/web-platform/tests/shadow-dom/leaktests/window-frames.html
new file mode 100644
index 000000000..5ba2531ff
--- /dev/null
+++ b/testing/web-platform/tests/shadow-dom/leaktests/window-frames.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='author' title='Google' href='http://www.google.com'>
+<meta name='assert' content='Shadow DOM should not leak via window.frames.'>
+<link rel='help' href='https://w3c.github.io/webcomponents/spec/shadow/'>
+<script src='/resources/testharness.js'></script>
+<script src='/resources/testharnessreport.js'></script>
+</head>
+<body>
+<div id='log'></div>
+<iframe src='about:blank' name='mainFrame1'></iframe>
+<div id='host-open'></div>
+<div id='host-closed'></div>
+</body>
+<script>
+'use strict';
+
+var host_open = document.getElementById('host-open');
+var root_open = host_open.attachShadow({mode: 'open'});
+root_open.innerHTML = '<iframe src="about:blank" name="shadowFrame1"></iframe>';
+
+var host_closed = document.getElementById('host-closed');
+var root_closed = host_closed.attachShadow({mode: 'closed'});
+root_closed.innerHTML = '<iframe src="about:blank" name="shadowFrame2"></iframe>';
+
+test(() => {
+ assert_equals(window.frames.length, 1, 'window.frames should return only frames in document.');
+ assert_equals(window.frames[0].name, 'mainFrame1', 'window.frames[0] should be mainFrame1.');
+ assert_equals(window.frames['mainFrame1'], window.frames[0], 'window.frames[\'mainFrame1\'] should be equal to mainFrame1.');
+ assert_equals(window.frames['shadowFrame1'], undefined, 'shadowFrame1 should not leak.');
+ assert_equals(window.frames['shadowFrame2'], undefined, 'shadowFrame2 should not leak.');
+
+}, 'window.frames should not leak frames in Shadow DOM.');
+</script>
+</html>