enable-disable.js 2.8 KB
Newer Older
1 2 3 4
// 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.

5
let {session, contextGroup, Protocol} = InspectorTest.start("Test that profiling can only be started when Profiler was enabled and that Profiler.disable command will stop recording all profiles.");
6

7
Protocol.Profiler.start().then(didFailToStartWhenDisabled);
8 9 10 11
disallowConsoleProfiles();

function disallowConsoleProfiles()
{
12
  Protocol.Profiler.onConsoleProfileStarted(function(messageObject)
13 14
  {
    InspectorTest.log("FAIL: console profile started " + JSON.stringify(messageObject, null, 4));
15 16
  });
  Protocol.Profiler.onConsoleProfileFinished(function(messageObject)
17 18
  {
    InspectorTest.log("FAIL: unexpected profile received " + JSON.stringify(messageObject, null, 4));
19
  });
20 21 22
}
function allowConsoleProfiles()
{
23
  Protocol.Profiler.onConsoleProfileStarted(function(messageObject)
24 25
  {
    InspectorTest.log("PASS: console initiated profile started");
26 27
  });
  Protocol.Profiler.onConsoleProfileFinished(function(messageObject)
28 29
  {
    InspectorTest.log("PASS: console initiated profile received");
30
  });
31 32 33
}
function didFailToStartWhenDisabled(messageObject)
{
34
  if (!expectedError("didFailToStartWhenDisabled", messageObject))
35 36
    return;
  allowConsoleProfiles();
37 38
  Protocol.Profiler.enable();
  Protocol.Profiler.start().then(didStartFrontendProfile);
39 40 41
}
function didStartFrontendProfile(messageObject)
{
42
  if (!expectedSuccess("didStartFrontendProfile", messageObject))
43
    return;
44
  Protocol.Runtime.evaluate({expression: "console.profile('p1');"}).then(didStartConsoleProfile);
45 46 47 48
}

function didStartConsoleProfile(messageObject)
{
49
  if (!expectedSuccess("didStartConsoleProfile", messageObject))
50
    return;
51
  Protocol.Profiler.disable().then(didDisableProfiler);
52 53 54 55
}

function didDisableProfiler(messageObject)
{
56
  if (!expectedSuccess("didDisableProfiler", messageObject))
57
    return;
58 59
  Protocol.Profiler.enable();
  Protocol.Profiler.stop().then(didStopFrontendProfile);
60 61 62 63
}

function didStopFrontendProfile(messageObject)
{
64
  if (!expectedError("no front-end initiated profiles found", messageObject))
65 66
    return;
  disallowConsoleProfiles();
67
  Protocol.Runtime.evaluate({expression: "console.profileEnd();"}).then(didStopConsoleProfile);
68 69 70 71
}

function didStopConsoleProfile(messageObject)
{
72
  if (!expectedSuccess("didStopConsoleProfile", messageObject))
73 74 75
    return;
  InspectorTest.completeTest();
}
76 77 78 79 80 81 82 83 84 85 86 87 88 89

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);