Upstream version 10.39.225.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     var s1 = {guid: 1};
90     timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [s1];
91     controller.filterText = 'asdf';
92
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);
104   });
105
106   test('findControllerMultipleHits', function() {
107     var timeline = new FakeTimeline();
108     var controller = new tracing.FindController();
109     controller.timeline = timeline;
110
111     var s1 = {guid: 1};
112     var s2 = {guid: 2};
113     var s3 = {guid: 3};
114
115     timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [s1, s2, s3];
116     controller.filterText = 'asdf';
117
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);
134   });
135
136   test('findControllerChangeFilterAfterNext', function() {
137     var timeline = new FakeTimeline();
138     var controller = new tracing.FindController();
139     controller.timeline = timeline;
140
141     var s1 = {guid: 1};
142     var s2 = {guid: 2};
143     var s3 = {guid: 3};
144     var s4 = {guid: 4};
145
146     timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [s1, s2, s3];
147     controller.filterText = 'asdf';
148
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);
155   });
156
157   test('findControllerSelectsAllItemsFirst', function() {
158     var timeline = new FakeTimeline();
159     var controller = new tracing.FindController();
160     controller.timeline = timeline;
161
162     var s1 = {guid: 1};
163     var s2 = {guid: 2};
164     var s3 = {guid: 3};
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);
174   });
175
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));
182
183     var timeline = new tracing.TimelineTrackView();
184     timeline.model = model;
185
186     var controller = new tracing.FindController();
187     controller.timeline = timeline;
188
189     // Test find with no filterText.
190     controller.findNext();
191
192     // Test find with filter txt.
193     controller.filterText = 'a';
194     assertArrayEquals([], timeline.selection);
195     assertArrayEquals(t1.sliceGroup.slices, timeline.highlight);
196
197     controller.findNext();
198     assertEquals(1, timeline.selection.length);
199     assertEquals(t1.sliceGroup.slices[0], timeline.selection[0]);
200
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);
208   });
209 });
210 </script>