• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2024 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
17import {TreeNodeUtils} from 'test/unit/tree_node_utils';
18import {TreeNode} from 'trace/tree_node/tree_node';
19import {AddDiffsPropertiesTree} from './add_diffs_properties_tree';
20import {executeAddDiffsTests} from './add_diffs_test_utils';
21import {UiPropertyTreeNode} from './ui_property_tree_node';
22
23describe('AddDiffsPropertiesTree', () => {
24  let newRoot: UiPropertyTreeNode;
25  let oldRoot: UiPropertyTreeNode;
26  let expectedRoot: UiPropertyTreeNode;
27
28  const isModified = async (
29    newTree: TreeNode | undefined,
30    oldTree: TreeNode | undefined,
31    denylistProperties: string[],
32  ) => {
33    return (
34      (newTree as UiPropertyTreeNode)?.getValue() !==
35      (oldTree as UiPropertyTreeNode)?.getValue()
36    );
37  };
38  const addDiffs = new AddDiffsPropertiesTree(isModified, []);
39
40  describe('AddDiffs tests', () => {
41    executeAddDiffsTests(
42      TreeNodeUtils.treeNodeEqualityTester,
43      makeRoot,
44      makeChildAndAddToRoot,
45      addDiffs,
46    );
47  });
48
49  describe('Property tree tests', () => {
50    beforeEach(() => {
51      jasmine.addCustomEqualityTester(TreeNodeUtils.treeNodeEqualityTester);
52      newRoot = makeRoot();
53      oldRoot = makeRoot();
54      expectedRoot = makeRoot();
55    });
56
57    it('does not add MODIFIED to property tree root', async () => {
58      oldRoot = makeRoot('oldValue');
59      await addDiffs.executeInPlace(newRoot, oldRoot);
60      expect(newRoot).toEqual(expectedRoot);
61    });
62
63    it('does not add any diffs to property tree that has no old tree', async () => {
64      await addDiffs.executeInPlace(newRoot, undefined);
65      expect(newRoot).toEqual(expectedRoot);
66    });
67  });
68
69  function makeRoot(value = 'value'): UiPropertyTreeNode {
70    const root = TreeNodeUtils.makeUiPropertyNode('test', 'root', value);
71    root.setIsRoot(true);
72    return root;
73  }
74
75  function makeChildAndAddToRoot(
76    rootNode: UiPropertyTreeNode,
77    value = 'value',
78  ): UiPropertyTreeNode {
79    const child = TreeNodeUtils.makeUiPropertyNode('test node', 'child', value);
80    rootNode.addOrReplaceChild(child);
81    return child;
82  }
83});
84