1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
base.require('tracing.test_utils');
base.require('tracing.find_control');
base.unittest.testSuite('tracing.find_control', function() {
/*
* Just enough of the Timeline to support the tests below.
*/
var FakeTimeline = ui.define('div');
FakeTimeline.prototype = {
__proto__: HTMLDivElement.prototype,
decorate: function() {
this.addAllObjectsMatchingFilterToSelectionReturnValue = [];
this.selection = new tracing.Selection();
this.highlight = new tracing.Selection();
this.keyHelp = '<keyHelp>';
// Put some simple UI in for testing purposes.
var noteEl = document.createElement('div');
noteEl.textContent = 'FakeTimeline:';
this.appendChild(noteEl);
this.statusEl_ = document.createElement('div');
this.appendChild(this.statusEl_);
this.refresh_();
},
refresh_: function() {
var status;
if (this.model)
status = 'model=set';
else
status = 'model=undefined';
this.statusEl_.textContent = status;
},
addAllObjectsMatchingFilterToSelection: function(filter, selection) {
var n = this.addAllObjectsMatchingFilterToSelectionReturnValue.length;
for (var i = 0; i < n; i++) {
selection.push(
this.addAllObjectsMatchingFilterToSelectionReturnValue[i]);
}
},
setHighlightAndClearSelection: function(highlight) {
this.highlight = highlight;
}
};
test('instantiate', function() {
var ctl = new tracing.FindControl();
ctl.controller = {
findNext: function() {
},
findPrevious: function() {
},
reset: function() {},
filterHits: ['a', 'b'],
currentHitIndex: 0
};
this.addHTMLOutput(ctl);
});
test('findControllerNoTimeline', function() {
var controller = new tracing.FindController();
controller.findNext();
controller.findPrevious();
});
test('findControllerEmptyHit', function() {
var timeline = new FakeTimeline();
var controller = new tracing.FindController();
controller.timeline = timeline;
timeline.selection = new tracing.Selection();
timeline.highlight = new tracing.Selection();
controller.findNext();
assertArrayShallowEquals([], timeline.selection);
assertArrayShallowEquals([], timeline.highlight);
controller.findPrevious();
assertArrayShallowEquals([], timeline.selection);
assertArrayShallowEquals([], timeline.highlight);
});
test('findControllerOneHit', function() {
var timeline = new FakeTimeline();
var controller = new tracing.FindController();
controller.timeline = timeline;
timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1];
controller.filterText = 'asdf';
assertArrayShallowEquals([], timeline.selection);
assertArrayShallowEquals([1], timeline.highlight);
controller.findNext();
assertArrayShallowEquals([1], timeline.selection);
assertArrayShallowEquals([1], timeline.highlight);
controller.findNext();
assertArrayShallowEquals([1], timeline.selection);
assertArrayShallowEquals([1], timeline.highlight);
controller.findPrevious();
assertArrayShallowEquals([1], timeline.selection);
assertArrayShallowEquals([1], timeline.highlight);
});
test('findControllerMultipleHits', function() {
var timeline = new FakeTimeline();
var controller = new tracing.FindController();
controller.timeline = timeline;
timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1, 2, 3];
controller.filterText = 'asdf';
// Loop through hits then when we wrap, try moving backward.
assertArrayShallowEquals([], timeline.selection);
assertArrayShallowEquals([1, 2, 3], timeline.highlight);
controller.findNext();
assertArrayShallowEquals([1], timeline.selection);
controller.findNext();
assertArrayShallowEquals([2], timeline.selection);
controller.findNext();
assertArrayShallowEquals([3], timeline.selection);
controller.findNext();
assertArrayShallowEquals([1], timeline.selection);
controller.findPrevious();
assertArrayShallowEquals([3], timeline.selection);
controller.findPrevious();
assertArrayShallowEquals([2], timeline.selection);
assertArrayShallowEquals([1, 2, 3], timeline.highlight);
});
test('findControllerChangeFilterAfterNext', function() {
var timeline = new FakeTimeline();
var controller = new tracing.FindController();
controller.timeline = timeline;
timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1, 2, 3];
controller.filterText = 'asdf';
// Loop through hits then when we wrap, try moving backward.
controller.findNext();
timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [4];
controller.filterText = 'asdfsf';
controller.findNext();
assertArrayShallowEquals([4], timeline.selection);
});
test('findControllerSelectsAllItemsFirst', function() {
var timeline = new FakeTimeline();
var controller = new tracing.FindController();
controller.timeline = timeline;
timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1, 2, 3];
controller.filterText = 'asdfsf';
assertArrayShallowEquals([], timeline.selection);
assertArrayShallowEquals([1, 2, 3], timeline.highlight);
controller.findNext();
assertArrayShallowEquals([1], timeline.selection);
controller.findNext();
assertArrayShallowEquals([2], timeline.selection);
assertArrayShallowEquals([1, 2, 3], timeline.highlight);
});
test('findControllerWithRealTimeline', function() {
var model = new tracing.TraceModel();
var p1 = model.getOrCreateProcess(1);
var t1 = p1.getOrCreateThread(1);
t1.sliceGroup.pushSlice(new tracing.trace_model.ThreadSlice(
'', 'a', 0, 1, {}, 3));
var timeline = new tracing.TimelineTrackView();
timeline.model = model;
var controller = new tracing.FindController();
controller.timeline = timeline;
// Test find with no filterText.
controller.findNext();
// Test find with filter txt.
controller.filterText = 'a';
assertArrayEquals([], timeline.selection);
assertArrayEquals(t1.sliceGroup.slices, timeline.highlight);
controller.findNext();
assertEquals(1, timeline.selection.length);
assertEquals(t1.sliceGroup.slices[0], timeline.selection[0]);
controller.filterText = 'xxx';
assertEquals(0, timeline.highlight.length);
assertEquals(0, timeline.selection.length);
controller.findNext();
assertEquals(0, timeline.selection.length);
controller.findNext();
assertEquals(0, timeline.selection.length);
});
});
|