| OLD | NEW |
| 1 <!DOCTYPE HTML> | 1 <!DOCTYPE HTML> |
| 2 <html> | 2 <html> |
| 3 <!-- | 3 <!-- |
| 4 Copyright (c) 2012 The Chromium Authors. All rights reserved. | 4 Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 5 Use of this source code is governed by a BSD-style license that can be | 5 Use of this source code is governed by a BSD-style license that can be |
| 6 found in the LICENSE file. | 6 found in the LICENSE file. |
| 7 --> | 7 --> |
| 8 <head i18n-values="dir:textdirection;"> | 8 <head i18n-values="dir:textdirection;"> |
| 9 <title>Interactive Timeline Tests</title> | 9 <title>ProfilingView tests</title> |
| 10 <link rel="stylesheet" href="profiling_view.css"> | 10 <link rel="stylesheet" href="profiling_view.css"> |
| 11 <link rel="stylesheet" href="timeline_view.css"> |
| 12 <link rel="stylesheet" href="overlay.css"> |
| 13 <link rel="stylesheet" href="timeline.css"> |
| 11 <link rel="stylesheet" href="../shared/css/tabs.css"> | 14 <link rel="stylesheet" href="../shared/css/tabs.css"> |
| 12 <script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.j
s"></script> | 15 <script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.j
s"></script> |
| 13 <script src="../shared/js/cr.js"></script> | 16 <script src="../shared/js/cr.js"></script> |
| 14 <script src="../shared/js/cr/event_target.js"></script> | 17 <script src="../shared/js/cr/event_target.js"></script> |
| 15 <script src="../shared/js/cr/ui.js"></script> | 18 <script src="../shared/js/cr/ui.js"></script> |
| 16 <script src="../shared/js/cr/ui/tabs.js"></script> | 19 <script src="../shared/js/cr/ui/tabs.js"></script> |
| 20 <script src="overlay.js"></script> |
| 21 <script src="measuring_stick.js"></script> |
| 17 <script src="profiling_view.js"></script> | 22 <script src="profiling_view.js"></script> |
| 23 <script src="timeline_view.js"></script> |
| 24 <script src="timeline_model.js"></script> |
| 25 <script src="linux_perf_importer.js"></script> |
| 26 <script src="trace_event_importer.js"></script> |
| 27 <script src="timeline.js"></script> |
| 28 <script src="timeline_track.js"></script> |
| 29 <script src="sorted_array_utils.js"></script> |
| 30 <script src="fast_rect_renderer.js"></script> |
| 31 <script src="test_utils.js"></script> |
| 18 <script> | 32 <script> |
| 19 goog.require('goog.testing.jsunit'); | 33 goog.require('goog.testing.jsunit'); |
| 20 </script> | 34 </script> |
| 21 <style> | 35 <style> |
| 22 .profiling-view { | 36 .profiling-view { |
| 23 border: 1px solid black; | 37 border: 1px solid black; |
| 24 } | 38 } |
| 25 </style> | 39 </style> |
| 26 </head> | 40 </head> |
| 27 <body> | 41 <body> |
| 28 <script> | 42 <script> |
| 29 'use strict'; | 43 'use strict'; |
| 30 | 44 |
| 31 /* | 45 /* |
| 32 * Just enough of the TracingController to support the tests below. | 46 * Just enough of the TracingController to support the tests below. |
| 33 */ | 47 */ |
| 34 function FakeTracingController() { | 48 function FakeTracingController() { |
| 35 | |
| 36 } | 49 } |
| 50 |
| 37 FakeTracingController.prototype = { | 51 FakeTracingController.prototype = { |
| 38 __proto__: cr.EventTarget.prototype, | 52 __proto__: cr.EventTarget.prototype, |
| 39 | 53 |
| 40 beginTracing: function(opt_systemTracingEnabled) { | 54 beginTracing: function(opt_systemTracingEnabled) { |
| 41 this.wasBeginTracingCalled = true; | 55 this.wasBeginTracingCalled = true; |
| 42 this.wasBeginTracingCalledWithSystemTracingEnabled = opt_systemTracingEn
abled; | 56 this.wasBeginTracingCalledWithSystemTracingEnabled = opt_systemTracingEn
abled; |
| 43 }, | 57 }, |
| 44 | 58 |
| 45 get traceEvents() { | 59 get traceEvents() { |
| 46 if (!this.wasBeginTracingCalled) | 60 if (!this.wasBeginTracingCalled) |
| 47 return undefined; | 61 return undefined; |
| 48 return FakeTracingController.testData; | 62 return FakeTracingController.testData; |
| 49 }, | 63 }, |
| 50 | 64 |
| 51 get systemTraceEvents() { | 65 get systemTraceEvents() { |
| 52 if (!this.wasBeginTracingCalled) | 66 if (!this.wasBeginTracingCalled) |
| 53 return undefined; | 67 return []; |
| 54 if (!this.wasBeginTracingCalledWithSystemTracingEnabled) | 68 if (!this.wasBeginTracingCalledWithSystemTracingEnabled) |
| 55 return undefined; | 69 return []; |
| 56 return FakeTracingController.systemTraceTestData; | 70 return FakeTracingController.systemTraceTestData; |
| 57 } | 71 } |
| 58 | 72 |
| 59 }; | 73 }; |
| 60 FakeTracingController.testData = [ | 74 FakeTracingController.testData = [ |
| 61 "hello", | 75 {name: 'a', args: {}, pid: 52, ts: 520, cat: 'foo', tid: 53, ph: 'B'}, |
| 62 "world" | 76 {name: 'a', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'E'}, |
| 77 {name: 'b', args: {}, pid: 52, ts: 629, cat: 'foo', tid: 53, ph: 'B'}, |
| 78 {name: 'b', args: {}, pid: 52, ts: 631, cat: 'foo', tid: 53, ph: 'E'} |
| 63 ]; | 79 ]; |
| 64 FakeTracingController.systemTraceTestData = [ | 80 FakeTracingController.systemTraceTestData = [ |
| 65 "the kernel", | 81 'systrace.sh-8170 [001] 15180.978813: sched_switch: ' + |
| 66 "says it wants", | 82 'prev_comm=systrace.sh prev_pid=8170 prev_prio=120 ' + |
| 67 "its memory back" | 83 'prev_state=x ==> next_comm=kworker/1:0 next_pid=7873 ' + |
| 68 ]; | 84 'next_prio=120', |
| 69 | 85 ' kworker/1:0-7873 [001] 15180.978836: sched_switch: ' + |
| 70 /* | 86 'prev_comm=kworker/1:0 prev_pid=7873 prev_prio=120 ' + |
| 71 * Just enough of the TimelineModel to support the tests below. | 87 'prev_state=S ==> next_comm=debugd next_pid=4404 next_prio=120', |
| 72 */ | 88 ' debugd-4404 [001] 15180.979010: sched_switch: prev_comm=debugd ' + |
| 73 function FakeTimelineModel() { | 89 'prev_pid=4404 prev_prio=120 prev_state=S ==> ' + |
| 74 | 90 'next_comm=dbus-daemon next_pid=510 next_prio=120', |
| 75 } | 91 'systrace.sh-8182 [000] 15186.203900: tracing_mark_write: ' + |
| 76 FakeTimelineModel.prototype = { | 92 'trace_event_clock_sync: parent_ts=0.0' |
| 77 __proto__: Object.prototype, | 93 ].join('\n'); |
| 78 | |
| 79 importEvents: function(eventData, | |
| 80 opt_zeroAndBoost, opt_additionalEventData) { | |
| 81 assertEquals(eventData, FakeTracingController.testData); | |
| 82 if (cr.isChromeOS) { | |
| 83 assertEquals(1, opt_additionalEventData.length); | |
| 84 assertEquals(opt_additionalEventData[0], FakeTracingController.systemT
raceTestData) | |
| 85 } | |
| 86 }, | |
| 87 | |
| 88 something: function() { | |
| 89 }, | |
| 90 }; | |
| 91 | |
| 92 /* | |
| 93 * Just enough of the TimelineView to support the tests below. | |
| 94 */ | |
| 95 var FakeTimelineView = cr.ui.define('div'); | |
| 96 | |
| 97 FakeTimelineView.prototype = { | |
| 98 __proto__: HTMLDivElement.prototype, | |
| 99 | |
| 100 decorate: function() { | |
| 101 this.statusEl_ = document.createElement('span'); | |
| 102 this.appendChild(this.statusEl_); | |
| 103 this.refresh_(); | |
| 104 }, | |
| 105 | |
| 106 refresh_: function() { | |
| 107 var status; | |
| 108 if (this.timelineModel) | |
| 109 status = "timelineModel"; | |
| 110 else | |
| 111 status = "!timelineModel"; | |
| 112 this.statusEl_.textContent = status; | |
| 113 }, | |
| 114 }; | |
| 115 | |
| 116 /* Monkeypatch timeline model and view so ProfilingView | |
| 117 * instantiates them instead. | |
| 118 */ | |
| 119 tracing.TimelineModel = FakeTimelineModel; | |
| 120 tracing.TimelineView = FakeTimelineView; | |
| 121 | 94 |
| 122 /* This test just instantiates a ProflingView and adds it to the DOM | 95 /* This test just instantiates a ProflingView and adds it to the DOM |
| 123 * to help with non-unittest UI work. | 96 * to help with non-unittest UI work. |
| 124 */ | 97 */ |
| 125 function testInstantiate() { | 98 function testInstantiate() { |
| 126 var view = new tracing.ProfilingView(); | 99 var view = new tracing.ProfilingView(); |
| 127 view.tracingController = new FakeTracingController(); | 100 view.tracingController = new FakeTracingController(); |
| 101 view.focusElement = view; |
| 128 document.body.appendChild(view); | 102 document.body.appendChild(view); |
| 129 } | 103 } |
| 130 | 104 |
| 131 function recordTestCommon() { | 105 function recordTestCommon() { |
| 132 var view = new tracing.ProfilingView(); | 106 var view = new tracing.ProfilingView(); |
| 133 var tracingController = new FakeTracingController() | 107 var tracingController = new FakeTracingController() |
| 134 view.tracingController = tracingController; | 108 view.tracingController = tracingController; |
| 135 view.querySelector('button.record').click(); | 109 view.querySelector('button.record').click(); |
| 136 assertTrue(tracingController.wasBeginTracingCalled); | 110 assertTrue(tracingController.wasBeginTracingCalled); |
| 137 assertEquals(cr.isChromeOS, | 111 assertEquals(cr.isChromeOS, |
| 138 tracingController.wasBeginTracingCalledWithSystemTracingEnabl
ed); | 112 tracingController.wasBeginTracingCalledWithSystemTracingEnabl
ed); |
| 139 | 113 |
| 140 var e = new cr.Event('traceEnded'); | 114 var e = new cr.Event('traceEnded'); |
| 141 var didRefresh = false; | 115 var didRefresh = false; |
| 142 e.events = tracingController.traceEvents; | 116 e.events = tracingController.traceEvents; |
| 143 tracingController.dispatchEvent(e); | 117 tracingController.dispatchEvent(e); |
| 144 assertTrue(!!view.timelineView.model); | 118 assertTrue(!!view.timelineView.model); |
| 145 } | 119 } |
| 146 | 120 |
| 147 function testRecordNonCros() { | 121 function testRecordNonCros() { |
| 148 var old = cr.isChromeOS; | 122 var old = cr.isChromeOS; |
| 149 cr.isChromeOS = false; | 123 cr.isChromeOS = false; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 160 try { | 134 try { |
| 161 recordTestCommon(); | 135 recordTestCommon(); |
| 162 } finally { | 136 } finally { |
| 163 cr.isChromeOS = old; | 137 cr.isChromeOS = old; |
| 164 } | 138 } |
| 165 } | 139 } |
| 166 | 140 |
| 167 </script> | 141 </script> |
| 168 </body> | 142 </body> |
| 169 </html> | 143 </html> |
| OLD | NEW |