From 36eaae88e0a651f800f361245c4e8daec065f5d1 Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Wed, 31 Aug 2016 08:02:39 -0700 Subject: [PATCH] Add tests for dirty propagation Summary: Previous test for dirty propagation (last test in CSSLayoutTest.cpp) only tested one specific case. This tests much more of the bahavior to ensure that a vital optimization in css-layout is applied correctly. Reviewed By: lucasr Differential Revision: D3790968 fbshipit-source-id: af11a5924640cd1d497920cd97549603a9f147cc --- tests/CSSLayoutDirtyMarkingTest.cpp | 67 +++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/CSSLayoutDirtyMarkingTest.cpp diff --git a/tests/CSSLayoutDirtyMarkingTest.cpp b/tests/CSSLayoutDirtyMarkingTest.cpp new file mode 100644 index 00000000..d460718a --- /dev/null +++ b/tests/CSSLayoutDirtyMarkingTest.cpp @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#include +#include + +TEST(CSSLayoutTest, dirty_propagation) { + const CSSNodeRef root = CSSNodeNew(); + CSSNodeStyleSetAlignItems(root, CSSAlignFlexStart); + CSSNodeStyleSetWidth(root, 100); + CSSNodeStyleSetHeight(root, 100); + + const CSSNodeRef root_child0 = CSSNodeNew(); + CSSNodeStyleSetWidth(root_child0, 50); + CSSNodeStyleSetHeight(root_child0, 20); + CSSNodeInsertChild(root, root_child0, 0); + + const CSSNodeRef root_child1 = CSSNodeNew(); + CSSNodeStyleSetWidth(root_child1, 50); + CSSNodeStyleSetHeight(root_child1, 20); + CSSNodeInsertChild(root, root_child1, 1); + + CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); + + CSSNodeStyleSetWidth(root_child0, 20); + + EXPECT_TRUE(CSSNodeIsDirty(root_child0)); + EXPECT_FALSE(CSSNodeIsDirty(root_child1)); + EXPECT_TRUE(CSSNodeIsDirty(root)); + + CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); + + EXPECT_FALSE(CSSNodeIsDirty(root_child0)); + EXPECT_FALSE(CSSNodeIsDirty(root_child1)); + EXPECT_FALSE(CSSNodeIsDirty(root)); +} + +TEST(CSSLayoutTest, dirty_propagation_only_if_prop_changed) { + const CSSNodeRef root = CSSNodeNew(); + CSSNodeStyleSetAlignItems(root, CSSAlignFlexStart); + CSSNodeStyleSetWidth(root, 100); + CSSNodeStyleSetHeight(root, 100); + + const CSSNodeRef root_child0 = CSSNodeNew(); + CSSNodeStyleSetWidth(root_child0, 50); + CSSNodeStyleSetHeight(root_child0, 20); + CSSNodeInsertChild(root, root_child0, 0); + + const CSSNodeRef root_child1 = CSSNodeNew(); + CSSNodeStyleSetWidth(root_child1, 50); + CSSNodeStyleSetHeight(root_child1, 20); + CSSNodeInsertChild(root, root_child1, 1); + + CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); + + CSSNodeStyleSetWidth(root_child0, 50); + + EXPECT_FALSE(CSSNodeIsDirty(root_child0)); + EXPECT_FALSE(CSSNodeIsDirty(root_child1)); + EXPECT_FALSE(CSSNodeIsDirty(root)); +}