set-instrumentation-breakpoint.js 5.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
// Copyright 2019 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.

const { session, contextGroup, Protocol } = InspectorTest.start(
    'Debugger.setInstrumentationBreakpoint');

InspectorTest.runAsyncTestSuite([
  async function testSetTwice() {
    await Protocol.Debugger.enable();
    const { result : firstResult } = await Protocol.Debugger.setInstrumentationBreakpoint({
      instrumentation: 'beforeScriptExecution'
    });
    InspectorTest.log('set breakpoint..');
    InspectorTest.logMessage(firstResult);
    InspectorTest.log('set breakpoint again..');
    InspectorTest.logMessage(await Protocol.Debugger.setInstrumentationBreakpoint({
      instrumentation: 'beforeScriptExecution'
    }));
    InspectorTest.log('remove breakpoint..');
    InspectorTest.logMessage(await Protocol.Debugger.removeBreakpoint({
      breakpointId: firstResult.breakpointId
    }));
    await Protocol.Debugger.disable();
  },

  async function testScriptParsed() {
    await Protocol.Debugger.enable();
    InspectorTest.log('set breakpoint and evaluate script..');
    const { result : firstResult } = await Protocol.Debugger.setInstrumentationBreakpoint({
      instrumentation: 'beforeScriptExecution'
    });
    Protocol.Runtime.evaluate({expression: '//# sourceURL=foo.js'});
    {
      const { params: { reason, data } } = await Protocol.Debugger.oncePaused();
      InspectorTest.log(`paused with reason: ${reason}`);
      InspectorTest.logMessage(data);
    }
    await Protocol.Debugger.resume();
    InspectorTest.log('set breakpoint and evaluate script with sourceMappingURL..');
    Protocol.Runtime.evaluate({expression: '//# sourceURL=foo.js\n//# sourceMappingURL=map.js'});
    {
      const { params: { reason, data } } = await Protocol.Debugger.oncePaused();
      InspectorTest.log(`paused with reason: ${reason}`);
      InspectorTest.logMessage(data);
    }
    InspectorTest.log('remove breakpoint..');
    InspectorTest.logMessage(await Protocol.Debugger.removeBreakpoint({
      breakpointId: firstResult.breakpointId
    }));
    InspectorTest.log('evaluate script again..');
    await Protocol.Runtime.evaluate({expression: '//# sourceURL=foo.js'});
    await Protocol.Debugger.disable();
  },

  async function testScriptWithSourceMapParsed() {
    await Protocol.Debugger.enable();
    InspectorTest.log('set breakpoint for scriptWithSourceMapParsed..');
    const { result : firstResult } = await Protocol.Debugger.setInstrumentationBreakpoint({
      instrumentation: 'beforeScriptWithSourceMapExecution'
    });
    InspectorTest.log('evaluate script without sourceMappingURL..')
    await Protocol.Runtime.evaluate({expression: '//# sourceURL=foo.js'});
    InspectorTest.log('evaluate script with sourceMappingURL..')
    Protocol.Runtime.evaluate({expression: '//# sourceURL=foo.js\n//# sourceMappingURL=map.js'});
    {
      const { params: { reason, data } } = await Protocol.Debugger.oncePaused();
      InspectorTest.log(`paused with reason: ${reason}`);
      InspectorTest.logMessage(data);
    }
    InspectorTest.log('remove breakpoint..')
    InspectorTest.logMessage(await Protocol.Debugger.removeBreakpoint({
      breakpointId: firstResult.breakpointId
    }));
    InspectorTest.log('evaluate script without sourceMappingURL..')
    await Protocol.Runtime.evaluate({expression: '//# sourceURL=foo.js'});
    InspectorTest.log('evaluate script with sourceMappingURL..')
    await Protocol.Runtime.evaluate({expression: '//# sourceURL=foo.js\n//# sourceMappingURL=map.js'});
    await Protocol.Debugger.disable();
  },

  async function testBlackboxing() {
    await Protocol.Debugger.enable();
    await Protocol.Debugger.setBlackboxPatterns({patterns: ['foo\.js']});
    InspectorTest.log('set breakpoint and evaluate blackboxed script..');
    const { result : firstResult } = await Protocol.Debugger.setInstrumentationBreakpoint({
      instrumentation: 'beforeScriptExecution'
    });
    await Protocol.Runtime.evaluate({expression: '//# sourceURL=foo.js'});
    InspectorTest.log('evaluate not blackboxed script..');
    Protocol.Runtime.evaluate({expression: '//# sourceURL=bar.js'});
    {
      const { params: { reason, data } } = await Protocol.Debugger.oncePaused();
      InspectorTest.log(`paused with reason: ${reason}`);
      InspectorTest.logMessage(data);
    }
    await Protocol.Debugger.resume();
    InspectorTest.log('evaluate blackboxed script that contains not blackboxed one..');
    Protocol.Runtime.evaluate({expression: `eval('//# sourceURL=bar.js')//# sourceURL=foo.js`});
    {
      const { params: { reason, data } } = await Protocol.Debugger.oncePaused();
      InspectorTest.log(`paused with reason: ${reason}`);
      InspectorTest.logMessage(data);
    }
    await Protocol.Debugger.resume();
    await Protocol.Debugger.disable();
  },

  async function testCompileFirstRunLater() {
    await Protocol.Runtime.enable();
    await Protocol.Debugger.enable();
    InspectorTest.log('set breakpoint for scriptWithSourceMapParsed..');
    const { result : firstResult } = await Protocol.Debugger.setInstrumentationBreakpoint({
      instrumentation: 'beforeScriptWithSourceMapExecution'
    });
    InspectorTest.log('compile script with sourceMappingURL..');
    const { result: { scriptId } } = await Protocol.Runtime.compileScript({
      expression: '//# sourceMappingURL=boo.js', sourceURL: 'foo.js', persistScript: true });
    InspectorTest.log('evaluate script without sourceMappingURL..');
    await Protocol.Runtime.evaluate({ expression: '' });
    InspectorTest.log('run previously compiled script with sourceMappingURL..');
    Protocol.Runtime.runScript({ scriptId });
    {
      const { params: { reason, data } } = await Protocol.Debugger.oncePaused();
      InspectorTest.log(`paused with reason: ${reason}`);
      InspectorTest.logMessage(data);
    }
    await Protocol.Debugger.disable();
    await Protocol.Runtime.disable();
  }
]);