3 Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
8 <link rel="import" href="/tracing/find_controller.html">
9 <link rel="import" href="/tracing/test_utils.html">
10 <link rel="import" href="/tracing/timeline_track_view.html">
15 tvcm.unittest.testSuite(function() {
17 * Just enough of the Timeline to support the tests below.
19 var FakeTimeline = tvcm.ui.define('div');
21 FakeTimeline.prototype = {
22 __proto__: HTMLDivElement.prototype,
24 decorate: function() {
25 this.addAllObjectsMatchingFilterToSelectionReturnValue = [];
27 this.selection = new tracing.Selection();
28 this.highlight = new tracing.Selection();
29 this.keyHelp = '<keyHelp>';
31 // Put some simple UI in for testing purposes.
32 var noteEl = document.createElement('div');
33 noteEl.textContent = 'FakeTimeline:';
34 this.appendChild(noteEl);
36 this.statusEl_ = document.createElement('div');
37 this.appendChild(this.statusEl_);
41 refresh_: function() {
46 status = 'model=undefined';
47 this.statusEl_.textContent = status;
50 addAllObjectsMatchingFilterToSelection: function(filter, selection) {
51 var n = this.addAllObjectsMatchingFilterToSelectionReturnValue.length;
52 for (var i = 0; i < n; i++) {
54 this.addAllObjectsMatchingFilterToSelectionReturnValue[i]);
58 setHighlightAndClearSelection: function(highlight) {
59 this.highlight = highlight;
63 test('findControllerNoTimeline', function() {
64 var controller = new tracing.FindController();
65 controller.findNext();
66 controller.findPrevious();
69 test('findControllerEmptyHit', function() {
70 var timeline = new FakeTimeline();
71 var controller = new tracing.FindController();
72 controller.timeline = timeline;
74 timeline.selection = new tracing.Selection();
75 timeline.highlight = new tracing.Selection();
76 controller.findNext();
77 assertArrayShallowEquals([], timeline.selection);
78 assertArrayShallowEquals([], timeline.highlight);
79 controller.findPrevious();
80 assertArrayShallowEquals([], timeline.selection);
81 assertArrayShallowEquals([], timeline.highlight);
84 test('findControllerOneHit', function() {
85 var timeline = new FakeTimeline();
86 var controller = new tracing.FindController();
87 controller.timeline = timeline;
90 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [s1];
91 controller.filterText = 'asdf';
93 assertArrayShallowEquals([], timeline.selection);
94 assertArrayShallowEquals([s1], timeline.highlight);
95 controller.findNext();
96 assertArrayShallowEquals([s1], timeline.selection);
97 assertArrayShallowEquals([s1], timeline.highlight);
98 controller.findNext();
99 assertArrayShallowEquals([s1], timeline.selection);
100 assertArrayShallowEquals([s1], timeline.highlight);
101 controller.findPrevious();
102 assertArrayShallowEquals([s1], timeline.selection);
103 assertArrayShallowEquals([s1], timeline.highlight);
106 test('findControllerMultipleHits', function() {
107 var timeline = new FakeTimeline();
108 var controller = new tracing.FindController();
109 controller.timeline = timeline;
115 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [s1, s2, s3];
116 controller.filterText = 'asdf';
118 // Loop through hits then when we wrap, try moving backward.
119 assertArrayShallowEquals([], timeline.selection);
120 assertArrayShallowEquals([s1, s2, s3], timeline.highlight);
121 controller.findNext();
122 assertArrayShallowEquals([s1], timeline.selection);
123 controller.findNext();
124 assertArrayShallowEquals([s2], timeline.selection);
125 controller.findNext();
126 assertArrayShallowEquals([s3], timeline.selection);
127 controller.findNext();
128 assertArrayShallowEquals([s1], timeline.selection);
129 controller.findPrevious();
130 assertArrayShallowEquals([s3], timeline.selection);
131 controller.findPrevious();
132 assertArrayShallowEquals([s2], timeline.selection);
133 assertArrayShallowEquals([s1, s2, s3], timeline.highlight);
136 test('findControllerChangeFilterAfterNext', function() {
137 var timeline = new FakeTimeline();
138 var controller = new tracing.FindController();
139 controller.timeline = timeline;
146 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [s1, s2, s3];
147 controller.filterText = 'asdf';
149 // Loop through hits then when we wrap, try moving backward.
150 controller.findNext();
151 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [s4];
152 controller.filterText = 'asdfsf';
153 controller.findNext();
154 assertArrayShallowEquals([s4], timeline.selection);
157 test('findControllerSelectsAllItemsFirst', function() {
158 var timeline = new FakeTimeline();
159 var controller = new tracing.FindController();
160 controller.timeline = timeline;
165 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [s1, s2, s3];
166 controller.filterText = 'asdfsf';
167 assertArrayShallowEquals([], timeline.selection);
168 assertArrayShallowEquals([s1, s2, s3], timeline.highlight);
169 controller.findNext();
170 assertArrayShallowEquals([s1], timeline.selection);
171 controller.findNext();
172 assertArrayShallowEquals([s2], timeline.selection);
173 assertArrayShallowEquals([s1, s2, s3], timeline.highlight);
176 test('findControllerWithRealTimeline', function() {
177 var model = new tracing.TraceModel();
178 var p1 = model.getOrCreateProcess(1);
179 var t1 = p1.getOrCreateThread(1);
180 t1.sliceGroup.pushSlice(new tracing.trace_model.ThreadSlice(
181 '', 'a', 0, 1, {}, 3));
183 var timeline = new tracing.TimelineTrackView();
184 timeline.model = model;
186 var controller = new tracing.FindController();
187 controller.timeline = timeline;
189 // Test find with no filterText.
190 controller.findNext();
192 // Test find with filter txt.
193 controller.filterText = 'a';
194 assertArrayEquals([], timeline.selection);
195 assertArrayEquals(t1.sliceGroup.slices, timeline.highlight);
197 controller.findNext();
198 assertEquals(1, timeline.selection.length);
199 assertEquals(t1.sliceGroup.slices[0], timeline.selection[0]);
201 controller.filterText = 'xxx';
202 assertEquals(0, timeline.highlight.length);
203 assertEquals(0, timeline.selection.length);
204 controller.findNext();
205 assertEquals(0, timeline.selection.length);
206 controller.findNext();
207 assertEquals(0, timeline.selection.length);