9fc53e5eb2791734536716f67cbc38e1a55532cc
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / side_panel / timeline_view_test.html
1 <!DOCTYPE html>
2 <!--
3 Copyright (c) 2014 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/side_panel/timeline_view.html">
9 <link rel="import" href="/tracing/trace_model.html">
10
11 <script>
12 'use strict';
13
14 tv.unittest.testSuite(function() {
15   var TimelineViewSidePanel = tracing.TimelineViewSidePanel;
16   var TimelineViewSidePanelContainer = tracing.TimelineViewSidePanelContainer;
17
18   /**
19    * @constructor
20    */
21   var Panel1 = tv.ui.define('panel-1', TimelineViewSidePanel);
22   Panel1.textLabel = 'Panel 1';
23   Panel1.supportsModel = function(m) {
24     return {
25       supported: false,
26       reason: 'Explanation'
27     };
28   };
29
30   Panel1.prototype = {
31     __proto__: TimelineViewSidePanel.prototype,
32
33     decorate: function() {
34       this.textContent = 'I am panel 1';
35     }
36   };
37
38   /**
39    * @constructor
40    */
41   var Panel2 = tv.ui.define('panel-2', TimelineViewSidePanel);
42   Panel2.textLabel = 'Panel 2';
43   Panel2.supportsModel = function(m) {
44     return {
45       supported: true
46     };
47   };
48
49   Panel2.prototype = {
50     __proto__: TimelineViewSidePanel.prototype,
51
52     decorate: function() {
53       this.textContent = 'I am panel 1';
54       this.style.height = '300px';
55     }
56   };
57
58
59   function testBasic(name, fn) {
60     test(name, function() {
61       var registeredPanelConstructors =
62           TimelineViewSidePanel.getPanelConstructors();
63       var oldConstructors = registeredPanelConstructors.splice(
64           0, registeredPanelConstructors.length);
65       TimelineViewSidePanel.registerPanelSubtype(Panel1);
66       TimelineViewSidePanel.registerPanelSubtype(Panel2);
67       try {
68         fn.call(this);
69       } finally {
70         TimelineViewSidePanel.unregisterPanelSubtype(Panel1);
71         TimelineViewSidePanel.unregisterPanelSubtype(Panel2);
72         registeredPanelConstructors.push.apply(registeredPanelConstructors,
73                                                oldConstructors);
74       }
75     });
76   }
77
78   function createModel() {
79     var m = new tracing.TraceModel();
80     m.importTraces([], false, false, function() {
81       var browserProcess = m.getOrCreateProcess(1);
82       var browserMain = browserProcess.getOrCreateThread(2);
83       browserMain.sliceGroup.beginSlice('cat', 'Task', 0);
84       browserMain.sliceGroup.endSlice(10);
85       browserMain.sliceGroup.beginSlice('cat', 'Task', 20);
86       browserMain.sliceGroup.endSlice(30);
87     });
88     return m;
89   }
90
91   testBasic('instantiateCollapsed', function() {
92     var container = new TimelineViewSidePanelContainer();
93     container.model = createModel();
94     this.addHTMLOutput(container);
95   });
96
97   testBasic('instantiateExpanded', function() {
98     var container = new TimelineViewSidePanelContainer();
99     container.model = createModel();
100     container.activePanelConstructor = Panel2;
101     container.activePanelConstructor = undefined;
102     container.activePanelConstructor = Panel2;
103     this.addHTMLOutput(container);
104   });
105
106   return {
107   };
108 });
109 </script>