Implement Node.ownerScope
The ownerScope property is equivalent to walking up the parentNode pointers until you hit the top and returning that node if it's a Document or ShadowRoot. This means that the ownerScope of ShadowRoot and Document is always itself, and the ownerScope of an Element that is not the descendant of a ShadowRoot, and is not in the document is null. R=eseidel@chromium.org Review URL: https://codereview.chromium.org/810793005
This commit is contained in:
9
engine/src/flutter/tests/dom/ownerScope-expected.txt
Normal file
9
engine/src/flutter/tests/dom/ownerScope-expected.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
Running 5 tests
|
||||
ok 1 ownerScope should return null for elements not a child of a scope
|
||||
ok 2 ownerScope should return the document for elements in the document scope
|
||||
ok 3 ownerScope should return the shadow root for elements in the shadow root scope
|
||||
ok 4 ownerScope should return self for a shadow root or document
|
||||
ok 5 ownerScope should dynamically update
|
||||
5 tests
|
||||
5 pass
|
||||
0 fail
|
||||
47
engine/src/flutter/tests/dom/ownerScope.sky
Normal file
47
engine/src/flutter/tests/dom/ownerScope.sky
Normal file
@@ -0,0 +1,47 @@
|
||||
<sky>
|
||||
<import src="../resources/chai.sky" />
|
||||
<import src="../resources/mocha.sky" />
|
||||
<script>
|
||||
describe("ownerScope", function() {
|
||||
it("should return null for elements not a child of a scope", function() {
|
||||
var doc = new Document();
|
||||
var element = doc.createElement("div");
|
||||
assert.isNull(element.ownerScope);
|
||||
});
|
||||
it("should return the document for elements in the document scope", function() {
|
||||
var doc = new Document();
|
||||
var element = doc.createElement("div");
|
||||
doc.appendChild(element);
|
||||
assert.equal(element.ownerScope, element.ownerDocument);
|
||||
assert.equal(element.ownerScope, doc);
|
||||
});
|
||||
it("should return the shadow root for elements in the shadow root scope", function() {
|
||||
var doc = new Document();
|
||||
var host = doc.createElement("div");
|
||||
var child = doc.createElement("div");
|
||||
var shadowRoot = host.ensureShadowRoot();
|
||||
shadowRoot.appendChild(child);
|
||||
assert.equal(child.ownerScope, shadowRoot);
|
||||
});
|
||||
it("should return self for a shadow root or document", function() {
|
||||
var doc = new Document();
|
||||
var host = doc.createElement("div");
|
||||
doc.appendChild(host);
|
||||
var shadowRoot = host.ensureShadowRoot();
|
||||
assert.equal(shadowRoot.ownerScope, shadowRoot);
|
||||
assert.equal(doc.ownerScope, doc);
|
||||
});
|
||||
it("should dynamically update", function() {
|
||||
var doc = new Document();
|
||||
var host = doc.createElement("div");
|
||||
var child = doc.createElement("div");
|
||||
var shadowRoot = host.ensureShadowRoot();
|
||||
assert.equal(child.ownerScope, null);
|
||||
shadowRoot.appendChild(child);
|
||||
assert.equal(child.ownerScope, shadowRoot);
|
||||
child.remove();
|
||||
assert.equal(child.ownerScope, null);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</sky>
|
||||
Reference in New Issue
Block a user