blob: 7c57a50c951d3ef1d79736136daa113965eca26d [file] [log] [blame]
John Reck44b49f02016-03-25 14:29:48 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <gtest/gtest.h>
18
19#include "RenderNode.h"
20#include "TreeInfo.h"
21#include "tests/common/TestUtils.h"
22#include "utils/Color.h"
23
24using namespace android;
25using namespace android::uirenderer;
26
27TEST(RenderNode, hasParents) {
28 auto child = TestUtils::createNode(0, 0, 200, 400,
29 [](RenderProperties& props, TestCanvas& canvas) {
30 canvas.drawColor(Color::Red_500, SkXfermode::kSrcOver_Mode);
31 });
32 auto parent = TestUtils::createNode(0, 0, 200, 400,
33 [&child](RenderProperties& props, TestCanvas& canvas) {
34 canvas.drawRenderNode(child.get());
35 });
36
37 TestUtils::syncHierarchyPropertiesAndDisplayList(parent);
38
39 EXPECT_TRUE(child->hasParents()) << "Child node has no parent";
40 EXPECT_FALSE(parent->hasParents()) << "Root node shouldn't have any parents";
41
42 TestUtils::recordNode(*parent, [](TestCanvas& canvas) {
43 canvas.drawColor(Color::Amber_500, SkXfermode::kSrcOver_Mode);
44 });
45
46 EXPECT_TRUE(child->hasParents()) << "Child should still have a parent";
47 EXPECT_FALSE(parent->hasParents()) << "Root node shouldn't have any parents";
48
49 TestUtils::syncHierarchyPropertiesAndDisplayList(parent);
50
51 EXPECT_FALSE(child->hasParents()) << "Child should be removed";
52 EXPECT_FALSE(parent->hasParents()) << "Root node shouldn't have any parents";
53}