2016-10-02 21:22:49 +00:00
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
2017-02-28 20:22:24 +00:00
InspectorTest . log ( "Test that profiling can only be started when Profiler was enabled and that Profiler.disable command will stop recording all profiles." ) ;
2016-10-02 21:22:49 +00:00
2016-10-03 23:32:52 +00:00
Protocol . Profiler . start ( ) . then ( didFailToStartWhenDisabled ) ;
2016-10-02 21:22:49 +00:00
disallowConsoleProfiles ( ) ;
function disallowConsoleProfiles ( )
{
2016-10-03 23:32:52 +00:00
Protocol . Profiler . onConsoleProfileStarted ( function ( messageObject )
2016-10-02 21:22:49 +00:00
{
InspectorTest . log ( "FAIL: console profile started " + JSON . stringify ( messageObject , null , 4 ) ) ;
2016-10-03 23:32:52 +00:00
} ) ;
Protocol . Profiler . onConsoleProfileFinished ( function ( messageObject )
2016-10-02 21:22:49 +00:00
{
InspectorTest . log ( "FAIL: unexpected profile received " + JSON . stringify ( messageObject , null , 4 ) ) ;
2016-10-03 23:32:52 +00:00
} ) ;
2016-10-02 21:22:49 +00:00
}
function allowConsoleProfiles ( )
{
2016-10-03 23:32:52 +00:00
Protocol . Profiler . onConsoleProfileStarted ( function ( messageObject )
2016-10-02 21:22:49 +00:00
{
InspectorTest . log ( "PASS: console initiated profile started" ) ;
2016-10-03 23:32:52 +00:00
} ) ;
Protocol . Profiler . onConsoleProfileFinished ( function ( messageObject )
2016-10-02 21:22:49 +00:00
{
InspectorTest . log ( "PASS: console initiated profile received" ) ;
2016-10-03 23:32:52 +00:00
} ) ;
2016-10-02 21:22:49 +00:00
}
function didFailToStartWhenDisabled ( messageObject )
{
if ( ! InspectorTest . expectedError ( "didFailToStartWhenDisabled" , messageObject ) )
return ;
allowConsoleProfiles ( ) ;
2016-10-03 23:32:52 +00:00
Protocol . Profiler . enable ( ) ;
Protocol . Profiler . start ( ) . then ( didStartFrontendProfile ) ;
2016-10-02 21:22:49 +00:00
}
function didStartFrontendProfile ( messageObject )
{
if ( ! InspectorTest . expectedSuccess ( "didStartFrontendProfile" , messageObject ) )
return ;
2016-10-03 23:32:52 +00:00
Protocol . Runtime . evaluate ( { expression : "console.profile('p1');" } ) . then ( didStartConsoleProfile ) ;
2016-10-02 21:22:49 +00:00
}
function didStartConsoleProfile ( messageObject )
{
if ( ! InspectorTest . expectedSuccess ( "didStartConsoleProfile" , messageObject ) )
return ;
2016-10-03 23:32:52 +00:00
Protocol . Profiler . disable ( ) . then ( didDisableProfiler ) ;
2016-10-02 21:22:49 +00:00
}
function didDisableProfiler ( messageObject )
{
if ( ! InspectorTest . expectedSuccess ( "didDisableProfiler" , messageObject ) )
return ;
2016-10-03 23:32:52 +00:00
Protocol . Profiler . enable ( ) ;
Protocol . Profiler . stop ( ) . then ( didStopFrontendProfile ) ;
2016-10-02 21:22:49 +00:00
}
function didStopFrontendProfile ( messageObject )
{
if ( ! InspectorTest . expectedError ( "no front-end initiated profiles found" , messageObject ) )
return ;
disallowConsoleProfiles ( ) ;
2016-10-03 23:32:52 +00:00
Protocol . Runtime . evaluate ( { expression : "console.profileEnd();" } ) . then ( didStopConsoleProfile ) ;
2016-10-02 21:22:49 +00:00
}
function didStopConsoleProfile ( messageObject )
{
if ( ! InspectorTest . expectedSuccess ( "didStopConsoleProfile" , messageObject ) )
return ;
InspectorTest . completeTest ( ) ;
}