Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: runtime/observatory/tests/observatory_ui/virtual_tree/element_test.dart

Issue 2968813002: Avoid Stack Overflows during VirtualTree expansion (Closed)
Patch Set: Addressed comments Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:html';
6 import 'package:unittest/unittest.dart';
7 import 'package:observatory/src/elements/containers/virtual_collection.dart';
8 import 'package:observatory/src/elements/containers/virtual_tree.dart';
9
10 main() {
11 VirtualTreeElement.tag.ensureRegistration();
12
13 final cTag = VirtualCollectionElement.tag.name;
14
15 var container;
16 setUp(() {
17 container = document.body.getElementsByClassName('test_container').first;
18 });
19 group('instantiation', () {
20 test('default', () {
21 final e = new VirtualTreeElement((_) {}, (_1, _2, _3) {}, (_) {});
22 expect(e, isNotNull, reason: 'element correctly created');
23 expect(e.items, isNotNull, reason: 'items not null');
24 expect(e.items, isEmpty, reason: 'no items');
25 });
26 test('items: []', () {
27 final items = ["1", 2, {}];
28 final e =
29 new VirtualTreeElement((_) {}, (_1, _2, _3) {}, (_) {}, items: items);
30 expect(e, isNotNull, reason: 'element correctly created');
31 expect(e.items, isNot(same(items)), reason: 'avoid side effect');
32 expect(e.items, equals(items), reason: 'same items');
33 });
34 });
35 test('elements created after attachment', () async {
36 final create = (toggle) => new DivElement()..classes = ['test_item'];
37 final update = (HtmlElement el, item, depth) {
38 el.text = item.toString();
39 };
40 final children = (item) => [];
41 final items = ["1", 2, {}];
42 final e = new VirtualTreeElement(create, update, children);
43 container.append(e);
44 await e.onRendered.first;
45 expect(e.children.length, isNonZero, reason: 'has elements');
46 expect(e.querySelectorAll(cTag).length, same(1));
47 e.remove();
48 await e.onRendered.first;
49 expect(e.children.length, isZero, reason: 'is empty');
50 });
51 test('expand single child', () async {
52 const max_depth = 100000;
53 final create = (toggle) => new DivElement()..classes = ['test_item'];
54 final update = (HtmlElement el, item, depth) {
55 el.text = item.toString();
56 };
57 final children = (item) => item >= max_depth ? [] : [item + 1];
58 final items = [0];
59 final e = new VirtualTreeElement(create, update, children, items: items);
60 container.append(e);
61 await e.onRendered.first;
62 expect(e.children.length, isNonZero, reason: 'has elements');
63 final VirtualCollectionElement collection = e.querySelectorAll(cTag).first;
64 expect(collection.items.length, equals(1), reason: 'begin');
65 e.expand(0, autoExpandSingleChildNodes: true);
66 await e.onRendered.first;
67 expect(collection.items.length, equals(max_depth + 1), reason: 'expanded');
68 e.collapse(0, autoCollapseSingleChildNodes: true);
69 await e.onRendered.first;
70 expect(collection.items.length, equals(1), reason: 'collapsed');
71 e.remove();
72 await e.onRendered.first;
73 expect(e.children.length, isZero, reason: 'is empty');
74 });
75
76 test('expand whole tree', () async {
77 const max_depth = 100000;
78 final create = (toggle) => new DivElement()..classes = ['test_item'];
79 final update = (HtmlElement el, item, depth) {
80 el.text = item.toString();
81 };
82 // We want to generated a tree that doesn't collapse to a chain of items
83 // while avoiding to generate an exponential number of items
84 final children = (item) {
85 if (item < 2 * max_depth) {
86 if (item % 200 == 0) {
87 return [item + 1, item + 2];
88 } else if (item % 2 == 0) {
89 return [item + 2];
90 }
91 }
92 return [];
93 };
94 final items = [0];
95 final e = new VirtualTreeElement(create, update, children, items: items);
96 container.append(e);
97 await e.onRendered.first;
98 expect(e.children.length, isNonZero, reason: 'has elements');
99 final VirtualCollectionElement collection = e.querySelectorAll(cTag).first;
100 expect(collection.items.length, equals(1), reason: 'begin');
101 e.expand(0, autoExpandWholeTree: true);
102 await e.onRendered.first;
103 expect(collection.items.length, equals(max_depth + max_depth / 100 + 1),
104 reason: 'expanded');
105 e.collapse(0, autoCollapseWholeTree: true);
106 await e.onRendered.first;
107 expect(collection.items.length, equals(1), reason: 'collapsed');
108 e.remove();
109 await e.onRendered.first;
110 expect(e.children.length, isZero, reason: 'is empty');
111 });
112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698