pause.js 4.69 KB
Newer Older
1 2 3 4 5
// Copyright 2017 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.

InspectorTest.log('Checks Debugger.pause');
6 7 8
let contextGroup1 = new InspectorTest.ContextGroup();
let session1 = contextGroup1.connect();
let Protocol1 = session1.Protocol;
9

10 11
session1.setupScriptMap();
Protocol1.Debugger.enable();
12 13
InspectorTest.runAsyncTestSuite([
  async function testPause() {
14 15 16 17
    Protocol1.Debugger.pause();
    Protocol1.Runtime.evaluate({expression: 'var a = 42;'});
    await waitPauseAndDumpLocation(session1);
    await Protocol1.Debugger.resume();
18 19 20
  },

  async function testSkipFrameworks() {
21 22 23 24 25 26
    Protocol1.Debugger.setBlackboxPatterns({patterns: ['framework\.js']});
    Protocol1.Debugger.pause();
    Protocol1.Runtime.evaluate({expression: 'var a = 42; //# sourceURL=framework.js'});
    Protocol1.Runtime.evaluate({expression: 'var a = 239;'});
    await waitPauseAndDumpLocation(session1);
    await Protocol1.Debugger.resume();
27 28 29
  },

  async function testSkipOtherContext1() {
30 31 32 33 34 35 36 37 38 39 40
    let contextGroup2 = new InspectorTest.ContextGroup();
    let session2 = contextGroup2.connect();
    let Protocol2 = session2.Protocol;
    Protocol2.Debugger.enable({});
    Protocol1.Debugger.pause();
    Protocol1.Runtime.evaluate({expression: 'var a = 42; //# sourceURL=framework.js'});
    Protocol2.Runtime.evaluate({expression: 'var a = 239;'});
    Protocol1.Runtime.evaluate({expression: 'var a = 1;'});
    await waitPauseAndDumpLocation(session1);
    await Protocol1.Debugger.resume();
    await Protocol2.Debugger.disable({});
41 42 43
  },

  async function testSkipOtherContext2() {
44 45 46 47 48 49 50 51 52 53
    let contextGroup2 = new InspectorTest.ContextGroup();
    let session2 = contextGroup2.connect();
    let Protocol2 = session2.Protocol;
    session2.setupScriptMap();
    Protocol2.Debugger.enable({});
    Protocol2.Debugger.pause({});
    Protocol1.Runtime.evaluate({expression: 'var a = 42; //# sourceURL=framework.js'});
    Protocol2.Runtime.evaluate({expression: 'var a = 239;'});
    Protocol1.Runtime.evaluate({expression: 'var a = 1;'});
    await waitPauseAndDumpLocation(session2);
54
    // should not resume pause from different context group id.
55 56 57 58 59
    Protocol1.Debugger.resume();
    Protocol2.Debugger.stepOver({});
    await waitPauseAndDumpLocation(session2);
    await Protocol2.Debugger.resume({});
    await Protocol2.Debugger.disable({});
60 61 62
  },

  async function testWithNativeBreakpoint() {
63 64 65 66 67 68
    contextGroup1.schedulePauseOnNextStatement('', '');
    await Protocol1.Debugger.pause();
    contextGroup1.cancelPauseOnNextStatement();
    Protocol1.Runtime.evaluate({expression: 'var a = 42;'});
    await waitPauseAndDumpLocation(session1);
    await Protocol1.Debugger.resume();
69

70 71 72 73 74 75
    await Protocol1.Debugger.pause();
    contextGroup1.schedulePauseOnNextStatement('', '');
    contextGroup1.cancelPauseOnNextStatement();
    Protocol1.Runtime.evaluate({expression: 'var a = 42;'});
    await waitPauseAndDumpLocation(session1);
    await Protocol1.Debugger.resume();
76

77 78 79 80 81 82
    contextGroup1.schedulePauseOnNextStatement('', '');
    contextGroup1.cancelPauseOnNextStatement();
    await Protocol1.Debugger.pause();
    Protocol1.Runtime.evaluate({expression: 'var a = 42;'});
    await waitPauseAndDumpLocation(session1);
    await Protocol1.Debugger.resume();
83 84
  },

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
  async function testResumeAnotherGroup() {
    let contextGroup2 = new InspectorTest.ContextGroup();
    let session2 = contextGroup2.connect();
    session2.setupScriptMap();
    let Protocol2 = session2.Protocol;
    Protocol2.Debugger.enable();
    Protocol1.Debugger.pause();
    Protocol1.Runtime.evaluate({expression: 'var a = 42;'});
    await waitPauseAndDumpLocation(session1);
    InspectorTest.logMessage(await Protocol2.Debugger.resume());
    InspectorTest.logMessage(await Protocol2.Debugger.stepOver());
    InspectorTest.logMessage(await Protocol2.Debugger.stepInto());
    InspectorTest.logMessage(await Protocol2.Debugger.stepOut());
    await Protocol1.Debugger.resume();
    await Protocol2.Debugger.disable();
  },

102
  async function testDisableBreaksShouldCancelPause() {
103 104 105 106 107 108 109
    await Protocol1.Debugger.pause();
    await Protocol1.Debugger.setBreakpointsActive({active: false});
    Protocol1.Runtime.evaluate({expression: 'var a = 42;'})
      .then(() => Protocol1.Debugger.setBreakpointsActive({active: true}))
      .then(() => Protocol1.Runtime.evaluate({expression: 'debugger'}));
    await waitPauseAndDumpLocation(session1);
    await Protocol1.Debugger.resume();
110 111 112
  }
]);

113 114
async function waitPauseAndDumpLocation(session) {
  var message = await session.Protocol.Debugger.oncePaused();
115
  InspectorTest.log('paused at:');
116
  await session.logSourceLocation(message.params.callFrames[0].location);
117 118
  return message;
}