| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| |
| <link rel="import" href="/tracing/base/base.html"> |
| <link rel="import" |
| href="/tracing/ui/extras/about_tracing/mock_tracing_controller_client.html"> |
| <link rel="import" href="/tracing/extras/importer/trace_event_importer.html"> |
| <link rel="import" href="/tracing/ui/extras/about_tracing/profiling_view.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tr.b.unittest.testSuite(function() { |
| var testData = [ |
| {name: 'a', args: {}, pid: 52, ts: 15000, cat: 'foo', tid: 53, ph: 'B'}, |
| {name: 'a', args: {}, pid: 52, ts: 19000, cat: 'foo', tid: 53, ph: 'E'}, |
| {name: 'b', args: {}, pid: 52, ts: 32000, cat: 'foo', tid: 53, ph: 'B'}, |
| {name: 'b', args: {}, pid: 52, ts: 54000, cat: 'foo', tid: 53, ph: 'E'} |
| ]; |
| |
| var monitoringOptions = { |
| isMonitoring: false, |
| categoryFilter: '*', |
| useSystemTracing: false, |
| useContinuousTracing: false, |
| useSampling: false |
| }; |
| |
| var ProfilingView = tr.ui.e.about_tracing.ProfilingView; |
| |
| test('recording', function() { |
| var mock = new tr.ui.e.about_tracing.MockTracingControllerClient(); |
| mock.allowLooping = true; |
| mock.expectRequest('getMonitoringStatus', function() { |
| return btoa(JSON.stringify(monitoringOptions)); |
| }); |
| mock.expectRequest('endRecording', function() { |
| return ''; |
| }); |
| mock.expectRequest('getCategories', function() { |
| return ['a', 'b', 'c']; |
| }); |
| mock.expectRequest('beginRecording', function(data) { |
| return ''; |
| }); |
| mock.expectRequest('endRecording', function(data) { |
| return JSON.stringify(testData); |
| }); |
| |
| var view = new ProfilingView(mock); |
| view.style.height = '400px'; |
| view.style.border = '1px solid black'; |
| this.addHTMLOutput(view); |
| |
| return new Promise(function(resolve, reject) { |
| var recordingPromise = view.beginRecording(); |
| |
| var didAbort = false; |
| function pressRecord() { |
| if (didAbort) |
| return; |
| recordingPromise.selectionDlg.clickRecordButton(); |
| setTimeout(pressStop, 60); |
| } |
| function pressStop() { |
| recordingPromise.progressDlg.clickStopButton(); |
| } |
| setTimeout(pressRecord, 60); |
| recordingPromise.then( |
| function() { |
| resolve(); |
| }, |
| function(err) { |
| didAbort = true; |
| reject(err); |
| }); |
| }); |
| }); |
| |
| test('monitoring', function() { |
| var mock = new tr.ui.e.about_tracing.MockTracingControllerClient(); |
| mock.allowLooping = true; |
| mock.expectRequest('getMonitoringStatus', function() { |
| return btoa(JSON.stringify(monitoringOptions)); |
| }); |
| mock.expectRequest('beginMonitoring', function(data) { |
| return ''; |
| }); |
| mock.expectRequest('captureMonitoring', function(data) { |
| return JSON.stringify(testData); |
| }); |
| mock.expectRequest('endMonitoring', function(data) { |
| return ''; |
| }); |
| |
| var view = new ProfilingView(mock); |
| view.style.height = '400px'; |
| view.style.border = '1px solid black'; |
| this.addHTMLOutput(view); |
| |
| return new Promise(function(resolve, reject) { |
| assert.isFalse(view.monitorCheckbox_.checked); |
| |
| function beginMonitoring() { |
| // Since we don't fall back to TracingController when testing, |
| // we cannot rely on TracingController to invoke a callback to change |
| // view.isMonitoring_. Thus we change view.isMonitoring_ manually. |
| view.onMonitoringStateChanged_(true); |
| assert.isTrue(view.monitorCheckbox_.checked); |
| setTimeout(captureMonitoring, 60); |
| } |
| |
| function captureMonitoring() { |
| assert.isTrue(view.monitorCheckbox_.checked); |
| view.captureButton_.click(); |
| setTimeout(endMonitoring, 60); |
| } |
| |
| function endMonitoring() { |
| assert.isTrue(view.monitorCheckbox_.checked); |
| view.monitorCheckbox_.click(); |
| assert.isFalse(view.monitorCheckbox_.checked); |
| } |
| |
| var monitoringPromise = view.beginMonitoring(); |
| setTimeout(beginMonitoring, 60); |
| |
| monitoringPromise.then(resolve, reject); |
| }); |
| }); |
| }); |
| </script> |
| |