Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / find_controller_test.html
1 <!DOCTYPE html>
2 <!--
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.
6 -->
7
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">
11
12 <script>
13 'use strict';
14
15 tvcm.unittest.testSuite(function() {
16   /*
17    * Just enough of the Timeline to support the tests below.
18    */
19   var FakeTimeline = tvcm.ui.define('div');
20
21   FakeTimeline.prototype = {
22     __proto__: HTMLDivElement.prototype,
23
24     decorate: function() {
25       this.addAllObjectsMatchingFilterToSelectionReturnValue = [];
26
27       this.selection = new tracing.Selection();
28       this.highlight = new tracing.Selection();
29       this.keyHelp = '<keyHelp>';
30
31       // Put some simple UI in for testing purposes.
32       var noteEl = document.createElement('div');
33       noteEl.textContent = 'FakeTimeline:';
34       this.appendChild(noteEl);
35
36       this.statusEl_ = document.createElement('div');
37       this.appendChild(this.statusEl_);
38       this.refresh_();
39     },
40
41     refresh_: function() {
42       var status;
43       if (this.model)
44         status = 'model=set';
45       else
46         status = 'model=undefined';
47       this.statusEl_.textContent = status;
48     },
49
50     addAllObjectsMatchingFilterToSelection: function(filter, selection) {
51       var n = this.addAllObjectsMatchingFilterToSelectionReturnValue.length;
52       for (var i = 0; i < n; i++) {
53         selection.push(
54             this.addAllObjectsMatchingFilterToSelectionReturnValue[i]);
55       }
56     },
57
58     setHighlightAndClearSelection: function(highlight) {
59       this.highlight = highlight;
60     }
61   };
62
63   test('findControllerNoTimeline', function() {
64     var controller = new tracing.FindController();
65     controller.findNext();
66     controller.findPrevious();
67   });
68
69   test('findControllerEmptyHit', function() {
70     var timeline = new FakeTimeline();
71     var controller = new tracing.FindController();
72     controller.timeline = timeline;
73
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);
82   });
83
84   test('findControllerOneHit', function() {
85     var timeline = new FakeTimeline();
86     var controller = new tracing.FindController();
87     controller.timeline = timeline;
88
89     timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1];
90     controller.filterText = 'asdf';
91
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);
103   });
104
105   test('findControllerMultipleHits', function() {
106     var timeline = new FakeTimeline();
107     var controller = new tracing.FindController();
108     controller.timeline = timeline;
109
110     timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1, 2, 3];
111     controller.filterText = 'asdf';
112
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);
129   });
130
131   test('findControllerChangeFilterAfterNext', function() {
132     var timeline = new FakeTimeline();
133     var controller = new tracing.FindController();
134     controller.timeline = timeline;
135
136     timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1, 2, 3];
137     controller.filterText = 'asdf';
138
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);
145   });
146
147   test('findControllerSelectsAllItemsFirst', function() {
148     var timeline = new FakeTimeline();
149     var controller = new tracing.FindController();
150     controller.timeline = timeline;
151
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);
161   });
162
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));
169
170     var timeline = new tracing.TimelineTrackView();
171     timeline.model = model;
172
173     var controller = new tracing.FindController();
174     controller.timeline = timeline;
175
176     // Test find with no filterText.
177     controller.findNext();
178
179     // Test find with filter txt.
180     controller.filterText = 'a';
181     assertArrayEquals([], timeline.selection);
182     assertArrayEquals(t1.sliceGroup.slices, timeline.highlight);
183
184     controller.findNext();
185     assertEquals(1, timeline.selection.length);
186     assertEquals(t1.sliceGroup.slices[0], timeline.selection[0]);
187
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);
195   });
196 });
197 </script>