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;
89 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1];
90 controller.filterText = 'asdf';
92 assertArrayShallowEquals([], timeline.selection);
93 assertArrayShallowEquals([1], timeline.highlight);
94 controller.findNext();
95 assertArrayShallowEquals([1], timeline.selection);
96 assertArrayShallowEquals([1], timeline.highlight);
97 controller.findNext();
98 assertArrayShallowEquals([1], timeline.selection);
99 assertArrayShallowEquals([1], timeline.highlight);
100 controller.findPrevious();
101 assertArrayShallowEquals([1], timeline.selection);
102 assertArrayShallowEquals([1], timeline.highlight);
105 test('findControllerMultipleHits', function() {
106 var timeline = new FakeTimeline();
107 var controller = new tracing.FindController();
108 controller.timeline = timeline;
110 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1, 2, 3];
111 controller.filterText = 'asdf';
113 // Loop through hits then when we wrap, try moving backward.
114 assertArrayShallowEquals([], timeline.selection);
115 assertArrayShallowEquals([1, 2, 3], timeline.highlight);
116 controller.findNext();
117 assertArrayShallowEquals([1], timeline.selection);
118 controller.findNext();
119 assertArrayShallowEquals([2], timeline.selection);
120 controller.findNext();
121 assertArrayShallowEquals([3], timeline.selection);
122 controller.findNext();
123 assertArrayShallowEquals([1], timeline.selection);
124 controller.findPrevious();
125 assertArrayShallowEquals([3], timeline.selection);
126 controller.findPrevious();
127 assertArrayShallowEquals([2], timeline.selection);
128 assertArrayShallowEquals([1, 2, 3], timeline.highlight);
131 test('findControllerChangeFilterAfterNext', function() {
132 var timeline = new FakeTimeline();
133 var controller = new tracing.FindController();
134 controller.timeline = timeline;
136 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1, 2, 3];
137 controller.filterText = 'asdf';
139 // Loop through hits then when we wrap, try moving backward.
140 controller.findNext();
141 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [4];
142 controller.filterText = 'asdfsf';
143 controller.findNext();
144 assertArrayShallowEquals([4], timeline.selection);
147 test('findControllerSelectsAllItemsFirst', function() {
148 var timeline = new FakeTimeline();
149 var controller = new tracing.FindController();
150 controller.timeline = timeline;
152 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1, 2, 3];
153 controller.filterText = 'asdfsf';
154 assertArrayShallowEquals([], timeline.selection);
155 assertArrayShallowEquals([1, 2, 3], timeline.highlight);
156 controller.findNext();
157 assertArrayShallowEquals([1], timeline.selection);
158 controller.findNext();
159 assertArrayShallowEquals([2], timeline.selection);
160 assertArrayShallowEquals([1, 2, 3], timeline.highlight);
163 test('findControllerWithRealTimeline', function() {
164 var model = new tracing.TraceModel();
165 var p1 = model.getOrCreateProcess(1);
166 var t1 = p1.getOrCreateThread(1);
167 t1.sliceGroup.pushSlice(new tracing.trace_model.ThreadSlice(
168 '', 'a', 0, 1, {}, 3));
170 var timeline = new tracing.TimelineTrackView();
171 timeline.model = model;
173 var controller = new tracing.FindController();
174 controller.timeline = timeline;
176 // Test find with no filterText.
177 controller.findNext();
179 // Test find with filter txt.
180 controller.filterText = 'a';
181 assertArrayEquals([], timeline.selection);
182 assertArrayEquals(t1.sliceGroup.slices, timeline.highlight);
184 controller.findNext();
185 assertEquals(1, timeline.selection.length);
186 assertEquals(t1.sliceGroup.slices[0], timeline.selection[0]);
188 controller.filterText = 'xxx';
189 assertEquals(0, timeline.highlight.length);
190 assertEquals(0, timeline.selection.length);
191 controller.findNext();
192 assertEquals(0, timeline.selection.length);
193 controller.findNext();
194 assertEquals(0, timeline.selection.length);