Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/fast/dom/custom/svg-use-shadow-tree.html |
| diff --git a/third_party/WebKit/LayoutTests/fast/dom/custom/svg-use-shadow-tree.html b/third_party/WebKit/LayoutTests/fast/dom/custom/svg-use-shadow-tree.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9222cbdb48a7c73ed63a04eab060ccfbf8db999b |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/fast/dom/custom/svg-use-shadow-tree.html |
| @@ -0,0 +1,101 @@ |
| +<!DOCTYPE html> |
| +<script src="../../../resources/testharness.js"></script> |
| +<script src="../../../resources/testharnessreport.js"></script> |
| + |
| +<template id="template"> |
| +<svg> |
| + <defs> |
| + <g id="used-group"> |
| + <rect |
| + id="rect" |
| + is="x-rect" |
| + x="10" y="10" |
| + width="100" height="100" |
| + fill="red"/> |
| + </g> |
| + </defs> |
| + <use xlink:href="#used-group"/> |
| +</svg> |
| +</template> |
| + |
| +<div id="container"></div> |
| + |
| +<script> |
| +"use strict"; |
| + |
| +var instances = []; |
| + |
| +function createPrototype(superClass) { |
| + class ElementType extends superClass { |
|
dominicc (has gone to gerrit)
2015/10/30 02:42:39
This nested class definition w/ superClass is very
|
| + get ownerScope() { |
| + var scope = this.parentNode; |
| + while (scope && scope.parentNode) |
| + scope = scope.parentNode; |
| + return scope; |
| + } |
| + createdCallback() { |
| + this.instanceId = instances.length; |
| + instances[this.instanceId] = this; |
| + assert_false(this.ownerScope instanceof ShadowRoot, |
| + "Should not call createdCallback in UA ShadowRoot."); |
| + } |
| + attachedCallback() { |
| + assert_false(this.ownerScope instanceof ShadowRoot, |
| + "Should not call attachedCallback in UA ShadowRoot."); |
| + assert_equals(instances[this.instanceId], this); |
| + } |
| + detachedCallback() { |
| + assert_false(this.ownerScope instanceof ShadowRoot, |
| + "Should not call detachedCallback in UA ShadowRoot."); |
| + assert_equals(instances[this.instanceId], this); |
| + } |
| + attributeChangedCallback() { |
| + assert_unreached("attributeChangedCallback should never be called."); |
| + } |
| + }; |
| + return ElementType.prototype; |
| +} |
| + |
| +// <rect is=x-rect> |
| +var XRectElement = document.registerElement('x-rect', { |
| + extends: 'rect', |
| + prototype: createPrototype(SVGRectElement), |
| +}); |
| + |
| +// <x-test> |
| +var XTestElement = document.registerElement('x-test', { |
| + prototype: createPrototype(HTMLElement), |
| +}); |
| + |
| +test(function () { |
| + var template = document.getElementById("template"); |
| + var svg = document.importNode(template.content, true).firstElementChild; |
| + var usedGroup = svg.getElementById("used-group"); |
| + document.body.appendChild(svg); |
| + |
| + // Force a recreation of the use trees. |
| + document.body.offsetTop; |
| + assert_array_equals([usedGroup.firstElementChild], instances); |
| + |
| + var elements = [ |
| + usedGroup.firstElementChild, |
| + new XRectElement(), |
| + new XTestElement(), |
| + new XRectElement(), |
| + ]; |
| + |
| + // Add another <rect is=x-rect>, and a child <x-test> that also contains one. |
| + usedGroup.appendChild(elements[1]); |
| + var test = usedGroup.appendChild(elements[2]); |
| + test.appendChild(elements[3]); |
| + |
| + // Force a recreation of the use trees. |
| + document.body.offsetTop; |
| + assert_array_equals(elements, instances); |
| + |
| + for (var i = 0; i < instances.length; ++i) { |
| + assert_true(instances[i].ownerScope instanceof Document, |
| + "No instances should be inside a ShadowRoot."); |
| + } |
| +}, "SVG <use> shadow trees should not be exposed through custom elements."); |
| +</script> |