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 {assertDefined} from 'common/assert_utils'; 18import {HierarchyTreeBuilder} from 'test/unit/hierarchy_tree_builder'; 19import {TraceRect} from 'trace/trace_rect'; 20import {TraceRectBuilder} from 'trace/trace_rect_builder'; 21import {HierarchyTreeNode} from 'trace/tree_node/hierarchy_tree_node'; 22import {RectsComputation} from './rects_computation'; 23 24describe('RectsComputation', () => { 25 let hierarchyRoot: HierarchyTreeNode; 26 let computation: RectsComputation; 27 28 beforeEach(() => { 29 hierarchyRoot = new HierarchyTreeBuilder() 30 .setId('ViewNode') 31 .setName('test.package.name@123456789') 32 .setProperties({ 33 scaleX: 1, 34 scaleY: 1, 35 scrollX: 0, 36 scrollY: 0, 37 left: 0, 38 top: 0, 39 width: 1, 40 height: 1, 41 translationX: 0, 42 translationY: 0, 43 isComputedVisible: true, 44 alpha: 1, 45 }) 46 .setChildren([ 47 { 48 id: 'ViewNode', 49 name: 'test.package.name@234567891', 50 properties: { 51 scaleX: 1, 52 scaleY: 1, 53 scrollX: 0, 54 scrollY: 0, 55 left: 0, 56 top: 0, 57 width: 2, 58 height: 2, 59 translationX: 0, 60 translationY: 0, 61 alpha: 1, 62 }, 63 children: [ 64 { 65 id: 'ViewNode', 66 name: 'test.package.name@345678912', 67 properties: { 68 scaleX: 1, 69 scaleY: 1, 70 scrollX: 0, 71 scrollY: 0, 72 left: 0, 73 top: 0, 74 width: 3, 75 height: 3, 76 translationX: 0, 77 translationY: 0, 78 alpha: 1, 79 }, 80 children: [], 81 }, 82 ], 83 }, 84 ]) 85 .build(); 86 87 computation = new RectsComputation(); 88 }); 89 90 it('makes rects', () => { 91 const expectedRects: TraceRect[] = [ 92 new TraceRectBuilder() 93 .setX(0) 94 .setY(0) 95 .setWidth(1) 96 .setHeight(1) 97 .setId('ViewNode test.package.name@123456789') 98 .setName('test.package.name@123456789') 99 .setCornerRadius(0) 100 .setGroupId(0) 101 .setIsVisible(true) 102 .setIsDisplay(false) 103 .setIsVirtual(false) 104 .setDepth(0) 105 .setOpacity(1) 106 .build(), 107 108 new TraceRectBuilder() 109 .setX(0) 110 .setY(0) 111 .setWidth(2) 112 .setHeight(2) 113 .setId('ViewNode test.package.name@234567891') 114 .setName('test.package.name@234567891') 115 .setCornerRadius(0) 116 .setGroupId(0) 117 .setIsVisible(false) 118 .setIsDisplay(false) 119 .setIsVirtual(false) 120 .setDepth(4) 121 .setOpacity(1) 122 .build(), 123 124 new TraceRectBuilder() 125 .setX(0) 126 .setY(0) 127 .setWidth(3) 128 .setHeight(3) 129 .setId('ViewNode test.package.name@345678912') 130 .setName('test.package.name@345678912') 131 .setCornerRadius(0) 132 .setGroupId(0) 133 .setIsVisible(false) 134 .setIsDisplay(false) 135 .setIsVirtual(false) 136 .setDepth(8) 137 .setOpacity(1) 138 .build(), 139 ]; 140 141 computation.setRoot(hierarchyRoot).executeInPlace(); 142 143 const rects: TraceRect[] = []; 144 hierarchyRoot.forEachNodeDfs((node) => { 145 rects.push(...assertDefined(node.getRects())); 146 }); 147 148 expect(rects).toEqual(expectedRects); 149 }); 150}); 151