Diff
Copied: branches/chromium/1364/LayoutTests/fast/dom/shadow/getelementbyid-shadow-expected.txt (from rev 138131, trunk/LayoutTests/fast/dom/shadow/getelementbyid-shadow-expected.txt) (0 => 139388)
--- branches/chromium/1364/LayoutTests/fast/dom/shadow/getelementbyid-shadow-expected.txt (rev 0)
+++ branches/chromium/1364/LayoutTests/fast/dom/shadow/getelementbyid-shadow-expected.txt 2013-01-11 01:27:52 UTC (rev 139388)
@@ -0,0 +1,37 @@
+Tests to ensure ShadowRoot.getElementById works after complex DOM manipulation.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.getElementById("A") is A
+PASS shadowRootA.getElementById("B") is B
+PASS shadowRootB.getElementById("C") is C
+PASS shadowRootC.getElementById("D") is D
+
+Remove C from shadowRootB
+PASS document.getElementById("A") is A
+PASS shadowRootA.getElementById("B") is B
+PASS shadowRootB.getElementById("C") is null
+PASS shadowRootC.getElementById("D") is D
+
+Append C to ShadowRootB, and remove A from document
+PASS document.getElementById("A") is null
+PASS shadowRootA.getElementById("B") is B
+PASS shadowRootB.getElementById("C") is C
+PASS shadowRootC.getElementById("D") is D
+
+Remove C from shadowRootB
+PASS document.getElementById("A") is null
+PASS shadowRootA.getElementById("B") is B
+PASS shadowRootB.getElementById("C") is null
+PASS shadowRootC.getElementById("D") is D
+
+Remove D from shadowRootC
+PASS document.getElementById("A") is null
+PASS shadowRootA.getElementById("B") is B
+PASS shadowRootB.getElementById("C") is null
+PASS shadowRootC.getElementById("D") is null
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Copied: branches/chromium/1364/LayoutTests/fast/dom/shadow/getelementbyid-shadow.html (from rev 138131, trunk/LayoutTests/fast/dom/shadow/getelementbyid-shadow.html) (0 => 139388)
--- branches/chromium/1364/LayoutTests/fast/dom/shadow/getelementbyid-shadow.html (rev 0)
+++ branches/chromium/1364/LayoutTests/fast/dom/shadow/getelementbyid-shadow.html 2013-01-11 01:27:52 UTC (rev 139388)
@@ -0,0 +1,78 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script src=""
+
+<div id="container"></div>
+<pre id="console"></pre>
+
+<script>
+description("Tests to ensure ShadowRoot.getElementById works after complex DOM manipulation.");
+
+function createDiv(id)
+{
+ var div = document.createElement('div');
+ div.id = id;
+ return div;
+}
+
+var A = createDiv('A');
+var B = createDiv('B');
+var C = createDiv('C');
+var D = createDiv('D');
+var shadowRootA = A.webkitCreateShadowRoot();
+var shadowRootB = B.webkitCreateShadowRoot();
+var shadowRootC = C.webkitCreateShadowRoot();
+
+shadowRootA.appendChild(B);
+shadowRootB.appendChild(C);
+shadowRootC.appendChild(D);
+
+container.appendChild(A);
+shouldBe('document.getElementById("A")', 'A');
+shouldBe('shadowRootA.getElementById("B")', 'B');
+shouldBe('shadowRootB.getElementById("C")', 'C');
+shouldBe('shadowRootC.getElementById("D")', 'D');
+
+debug('');
+debug('Remove C from shadowRootB');
+shadowRootB.removeChild(C);
+
+shouldBe('document.getElementById("A")', 'A');
+shouldBe('shadowRootA.getElementById("B")', 'B');
+shouldBe('shadowRootB.getElementById("C")', 'null');
+shouldBe('shadowRootC.getElementById("D")', 'D');
+
+debug('');
+debug('Append C to ShadowRootB, and remove A from document');
+shadowRootB.appendChild(C);
+container.removeChild(A);
+
+shouldBe('document.getElementById("A")', 'null');
+shouldBe('shadowRootA.getElementById("B")', 'B');
+shouldBe('shadowRootB.getElementById("C")', 'C');
+shouldBe('shadowRootC.getElementById("D")', 'D');
+
+debug('');
+debug('Remove C from shadowRootB');
+shadowRootB.removeChild(C);
+
+shouldBe('document.getElementById("A")', 'null');
+shouldBe('shadowRootA.getElementById("B")', 'B');
+shouldBe('shadowRootB.getElementById("C")', 'null');
+shouldBe('shadowRootC.getElementById("D")', 'D');
+
+debug('');
+debug('Remove D from shadowRootC');
+shadowRootC.removeChild(D);
+
+shouldBe('document.getElementById("A")', 'null');
+shouldBe('shadowRootA.getElementById("B")', 'B');
+shouldBe('shadowRootB.getElementById("C")', 'null');
+shouldBe('shadowRootC.getElementById("D")', 'null');
+
+</script>
+<script src=""
+</body>
+</html>
Modified: branches/chromium/1364/Source/WebCore/dom/Element.cpp (139387 => 139388)
--- branches/chromium/1364/Source/WebCore/dom/Element.cpp 2013-01-11 01:21:11 UTC (rev 139387)
+++ branches/chromium/1364/Source/WebCore/dom/Element.cpp 2013-01-11 01:27:52 UTC (rev 139388)
@@ -1101,16 +1101,19 @@
if (!insertionPoint->isInTreeScope())
return InsertionDone;
+ TreeScope* scope = insertionPoint->treeScope();
+ if (scope != treeScope())
+ return InsertionDone;
+
const AtomicString& idValue = getIdAttribute();
if (!idValue.isNull())
- updateId(nullAtom, idValue);
+ updateId(scope, nullAtom, idValue);
const AtomicString& nameValue = getNameAttribute();
if (!nameValue.isNull())
updateName(nullAtom, nameValue);
if (hasTagName(labelTag)) {
- TreeScope* scope = treeScope();
if (scope->shouldCacheLabelsByForAttribute())
updateLabel(scope, nullAtom, fastGetAttribute(forAttr));
}
@@ -1134,9 +1137,9 @@
setSavedLayerScrollOffset(IntSize());
- if (insertionPoint->inDocument()) {
+ if (insertionPoint->isInTreeScope() && treeScope() == document()) {
const AtomicString& idValue = getIdAttribute();
- if (!idValue.isNull() && inDocument())
+ if (!idValue.isNull())
updateId(insertionPoint->treeScope(), idValue, nullAtom);
const AtomicString& nameValue = getNameAttribute();
Modified: branches/chromium/1364/Source/WebCore/dom/Element.h (139387 => 139388)
--- branches/chromium/1364/Source/WebCore/dom/Element.h 2013-01-11 01:21:11 UTC (rev 139387)
+++ branches/chromium/1364/Source/WebCore/dom/Element.h 2013-01-11 01:27:52 UTC (rev 139388)
@@ -826,6 +826,25 @@
return isElementNode() && toElement(this)->hasClass();
}
+inline Node::InsertionNotificationRequest Node::insertedInto(ContainerNode* insertionPoint)
+{
+ ASSERT(insertionPoint->inDocument() || isContainerNode());
+ if (insertionPoint->inDocument())
+ setFlag(InDocumentFlag);
+ if (parentOrHostNode()->isInShadowTree())
+ setFlag(IsInShadowTreeFlag);
+ return InsertionDone;
+}
+
+inline void Node::removedFrom(ContainerNode* insertionPoint)
+{
+ ASSERT(insertionPoint->inDocument() || isContainerNode());
+ if (insertionPoint->inDocument())
+ clearFlag(InDocumentFlag);
+ if (isInShadowTree() && !treeScope()->rootNode()->isShadowRoot())
+ clearFlag(IsInShadowTreeFlag);
+}
+
inline bool isShadowHost(const Node* node)
{
return node && node->isElementNode() && toElement(node)->shadow();
Modified: branches/chromium/1364/Source/WebCore/dom/Node.cpp (139387 => 139388)
--- branches/chromium/1364/Source/WebCore/dom/Node.cpp 2013-01-11 01:21:11 UTC (rev 139387)
+++ branches/chromium/1364/Source/WebCore/dom/Node.cpp 2013-01-11 01:27:52 UTC (rev 139388)
@@ -2095,25 +2095,6 @@
return document();
}
-Node::InsertionNotificationRequest Node::insertedInto(ContainerNode* insertionPoint)
-{
- ASSERT(insertionPoint->inDocument() || isContainerNode());
- if (insertionPoint->inDocument())
- setFlag(InDocumentFlag);
- if (parentOrHostNode()->isInShadowTree())
- setFlag(IsInShadowTreeFlag);
- return InsertionDone;
-}
-
-void Node::removedFrom(ContainerNode* insertionPoint)
-{
- ASSERT(insertionPoint->inDocument() || isContainerNode());
- if (insertionPoint->inDocument())
- clearFlag(InDocumentFlag);
- if (isInShadowTree() && !treeScope()->rootNode()->isShadowRoot())
- clearFlag(IsInShadowTreeFlag);
-}
-
void Node::didMoveToNewDocument(Document* oldDocument)
{
TreeScopeAdopter::ensureDidMoveToNewDocumentWasCalled(oldDocument);