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-05-19 00:35:45 +00:00
let { session , contextGroup , Protocol } = InspectorTest . start ( "Test that profiler is able to record a profile. Also it tests that profiler returns an error when it unable to find the profile." ) ;
2016-10-02 21:22:49 +00:00
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 )
{
2017-05-19 00:35:45 +00:00
if ( ! expectedSuccess ( "startFrontendProfile" , messageObject ) )
2016-10-02 21:22:49 +00:00
return ;
2016-10-03 23:32:52 +00:00
Protocol . Runtime . evaluate ( { expression : "console.profile('Profile 1');" } ) . then ( didStartConsoleProfile ) ;
2016-10-02 21:22:49 +00:00
}
function didStartConsoleProfile ( messageObject )
{
2017-05-19 00:35:45 +00:00
if ( ! expectedSuccess ( "startConsoleProfile" , messageObject ) )
2016-10-02 21:22:49 +00:00
return ;
2016-10-03 23:32:52 +00:00
Protocol . Runtime . evaluate ( { expression : "console.profileEnd('Profile 1');" } ) . then ( didStopConsoleProfile ) ;
2016-10-02 21:22:49 +00:00
}
function didStopConsoleProfile ( messageObject )
{
2017-05-19 00:35:45 +00:00
if ( ! expectedSuccess ( "stopConsoleProfile" , messageObject ) )
2016-10-02 21:22:49 +00:00
return ;
2016-10-03 23:32:52 +00:00
Protocol . Profiler . stop ( ) . then ( didStopFrontendProfile ) ;
2016-10-02 21:22:49 +00:00
}
function didStopFrontendProfile ( messageObject )
{
2017-05-19 00:35:45 +00:00
if ( ! expectedSuccess ( "stoppedFrontendProfile" , messageObject ) )
2016-10-02 21:22:49 +00:00
return ;
2016-10-03 23:32:52 +00:00
Protocol . Profiler . start ( ) . then ( didStartFrontendProfile2 ) ;
2016-10-02 21:22:49 +00:00
}
function didStartFrontendProfile2 ( messageObject )
{
2017-05-19 00:35:45 +00:00
if ( ! expectedSuccess ( "startFrontendProfileSecondTime" , messageObject ) )
2016-10-02 21:22:49 +00:00
return ;
2016-10-03 23:32:52 +00:00
Protocol . Profiler . stop ( ) . then ( didStopFrontendProfile2 ) ;
2016-10-02 21:22:49 +00:00
}
function didStopFrontendProfile2 ( messageObject )
{
2017-05-19 00:35:45 +00:00
expectedSuccess ( "stopFrontendProfileSecondTime" , messageObject )
2016-10-02 21:22:49 +00:00
InspectorTest . completeTest ( ) ;
}
2017-05-19 00:35:45 +00:00
function checkExpectation ( fail , name , messageObject )
{
if ( fail === ! ! messageObject . error ) {
InspectorTest . log ( "PASS: " + name ) ;
return true ;
}
InspectorTest . log ( "FAIL: " + name + ": " + JSON . stringify ( messageObject ) ) ;
InspectorTest . completeTest ( ) ;
return false ;
}
var expectedSuccess = checkExpectation . bind ( null , false ) ;
var expectedError = checkExpectation . bind ( null , true ) ;