Fabric: Using shallowSourceNode() inside ViewShadowNode::cloneAndReplaceChild()

Summary:
We have to call shallowSourceNode() in all cases of cloning which were not caused by UIManager instructions,
otherwise the diffing alogorith might produce incorrect mutation instructions.

Reviewed By: mdvacca

Differential Revision: D7503383

fbshipit-source-id: b33e5c39b7ba8cbd0f925fd29b3af379441a40a4
This commit is contained in:
Valentin Shergin
2018-04-10 12:46:12 -07:00
committed by Facebook Github Bot
parent 53837c4a4f
commit 47c0ab91a5
4 changed files with 52 additions and 2 deletions

View File

@@ -94,3 +94,27 @@ TEST(ShadowNodeTest, handleShadowNodeMutation) {
node5->clearSourceNode();
ASSERT_EQ(node5->getSourceNode(), nullptr);
}
TEST(ShadowNodeTest, handleSourceNode) {
auto nodeFirstGeneration = std::make_shared<TestShadowNode>(9, 1, (void *)NULL);
auto nodeSecondGeneration = std::make_shared<TestShadowNode>(nodeFirstGeneration);
auto nodeThirdGeneration = std::make_shared<TestShadowNode>(nodeSecondGeneration);
auto nodeForthGeneration = std::make_shared<TestShadowNode>(nodeThirdGeneration);
// Ensure established shource nodes structure.
ASSERT_EQ(nodeForthGeneration->getSourceNode(), nodeThirdGeneration);
ASSERT_EQ(nodeThirdGeneration->getSourceNode(), nodeSecondGeneration);
ASSERT_EQ(nodeSecondGeneration->getSourceNode(), nodeFirstGeneration);
// Shallow source node for the forth generation node.
nodeForthGeneration->shallowSourceNode();
ASSERT_EQ(nodeForthGeneration->getSourceNode(), nodeSecondGeneration);
// Shallow it one more time.
nodeForthGeneration->shallowSourceNode();
ASSERT_EQ(nodeForthGeneration->getSourceNode(), nodeFirstGeneration);
// Ensure that 3th and 2nd were not affected.
ASSERT_EQ(nodeThirdGeneration->getSourceNode(), nodeSecondGeneration);
ASSERT_EQ(nodeSecondGeneration->getSourceNode(), nodeFirstGeneration);
}