| OLD | NEW |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var source = | 5 var source = |
| 6 ` | 6 ` |
| 7 function fib(x) { | 7 function fib(x) { |
| 8 if (x < 2) return 1; | 8 if (x < 2) return 1; |
| 9 return fib(x-1) + fib(x-2); | 9 return fib(x-1) + fib(x-2); |
| 10 } | 10 } |
| 11 (function iife() { | 11 (function iife() { |
| 12 return 1; | 12 return 1; |
| 13 })(); | 13 })(); |
| 14 fib(5); | 14 fib(5); |
| 15 `; | 15 `; |
| 16 | 16 |
| 17 print("Test collecting code coverage data with Runtime.collectCoverage."); | 17 print("Test collecting code coverage data with Runtime.collectCoverage."); |
| 18 | 18 |
| 19 function ClearAndGC() { | 19 function ClearAndGC() { |
| 20 return Protocol.Runtime.evaluate({ expression: "fib = null;" }) | 20 return Protocol.Runtime.evaluate({ expression: "fib = null;" }) |
| 21 .then(() => Protocol.HeapProfiler.enable()) | 21 .then(() => Protocol.HeapProfiler.enable()) |
| 22 .then(() => Protocol.HeapProfiler.collectGarbage()) | 22 .then(() => Protocol.HeapProfiler.collectGarbage()) |
| 23 .then(() => Protocol.HeapProfiler.disable()); | 23 .then(() => Protocol.HeapProfiler.disable()); |
| 24 } | 24 } |
| 25 | 25 |
| 26 function LogSorted(message) { |
| 27 message.result.result.sort((a, b) => parseInt(a.scriptId) - parseInt(b.scriptI
d)); |
| 28 return InspectorTest.logMessage(message); |
| 29 } |
| 30 |
| 26 InspectorTest.runTestSuite([ | 31 InspectorTest.runTestSuite([ |
| 27 function testPreciseCoverage(next) | 32 function testPreciseCoverage(next) |
| 28 { | 33 { |
| 29 Protocol.Runtime.enable() | 34 Protocol.Runtime.enable() |
| 30 .then(Protocol.Runtime.startPreciseCoverage) | 35 .then(Protocol.Runtime.startPreciseCoverage) |
| 31 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL
: "1", persistScript: true })) | 36 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL
: "1", persistScript: true })) |
| 32 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId })) | 37 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId })) |
| 33 .then(ClearAndGC) | 38 .then(ClearAndGC) |
| 34 .then(InspectorTest.logMessage) | 39 .then(InspectorTest.logMessage) |
| 35 .then(Protocol.Runtime.takePreciseCoverage) | 40 .then(Protocol.Runtime.takePreciseCoverage) |
| 36 .then(InspectorTest.logMessage) | 41 .then(LogSorted) |
| 37 .then(Protocol.Runtime.takePreciseCoverage) | 42 .then(Protocol.Runtime.takePreciseCoverage) |
| 38 .then(InspectorTest.logMessage) | 43 .then(LogSorted) |
| 39 .then(ClearAndGC) | 44 .then(ClearAndGC) |
| 40 .then(Protocol.Runtime.stopPreciseCoverage) | 45 .then(Protocol.Runtime.stopPreciseCoverage) |
| 41 .then(Protocol.Runtime.disable) | 46 .then(Protocol.Runtime.disable) |
| 42 .then(next); | 47 .then(next); |
| 43 }, | 48 }, |
| 44 function testPreciseCoverageFail(next) | 49 function testPreciseCoverageFail(next) |
| 45 { | 50 { |
| 46 Protocol.Runtime.enable() | 51 Protocol.Runtime.enable() |
| 47 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL
: "2", persistScript: true })) | 52 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL
: "2", persistScript: true })) |
| 48 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId })) | 53 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId })) |
| 49 .then(InspectorTest.logMessage) | 54 .then(InspectorTest.logMessage) |
| 50 .then(ClearAndGC) | 55 .then(ClearAndGC) |
| 51 .then(Protocol.Runtime.takePreciseCoverage) | 56 .then(Protocol.Runtime.takePreciseCoverage) |
| 52 .then(InspectorTest.logMessage) | 57 .then(InspectorTest.logMessage) |
| 53 .then(ClearAndGC) | 58 .then(ClearAndGC) |
| 54 .then(Protocol.Runtime.disable) | 59 .then(Protocol.Runtime.disable) |
| 55 .then(next); | 60 .then(next); |
| 56 }, | 61 }, |
| 57 function testBestEffortCoverage(next) | 62 function testBestEffortCoverage(next) |
| 58 { | 63 { |
| 59 Protocol.Runtime.enable() | 64 Protocol.Runtime.enable() |
| 60 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL
: "3", persistScript: true })) | 65 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL
: "3", persistScript: true })) |
| 61 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId })) | 66 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId })) |
| 62 .then(InspectorTest.logMessage) | 67 .then(InspectorTest.logMessage) |
| 63 .then(ClearAndGC) | 68 .then(ClearAndGC) |
| 64 .then(Protocol.Runtime.getBestEffortCoverage) | 69 .then(Protocol.Runtime.getBestEffortCoverage) |
| 65 .then(InspectorTest.logMessage) | 70 .then(LogSorted) |
| 66 .then(Protocol.Runtime.getBestEffortCoverage) | 71 .then(Protocol.Runtime.getBestEffortCoverage) |
| 67 .then(InspectorTest.logMessage) | 72 .then(LogSorted) |
| 68 .then(ClearAndGC) | 73 .then(ClearAndGC) |
| 69 .then(Protocol.Runtime.disable) | 74 .then(Protocol.Runtime.disable) |
| 70 .then(next); | 75 .then(next); |
| 71 }, | 76 }, |
| 72 function testBestEffortCoveragePrecise(next) | 77 function testBestEffortCoveragePrecise(next) |
| 73 { | 78 { |
| 74 Protocol.Runtime.enable() | 79 Protocol.Runtime.enable() |
| 75 .then(Protocol.Runtime.startPreciseCoverage) | 80 .then(Protocol.Runtime.startPreciseCoverage) |
| 76 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL
: "4", persistScript: true })) | 81 .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL
: "4", persistScript: true })) |
| 77 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId })) | 82 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scr
iptId })) |
| 78 .then(InspectorTest.logMessage) | 83 .then(InspectorTest.logMessage) |
| 79 .then(ClearAndGC) | 84 .then(ClearAndGC) |
| 80 .then(Protocol.Runtime.getBestEffortCoverage) | 85 .then(Protocol.Runtime.getBestEffortCoverage) |
| 81 .then(InspectorTest.logMessage) | 86 .then(LogSorted) |
| 82 .then(Protocol.Runtime.getBestEffortCoverage) | 87 .then(Protocol.Runtime.getBestEffortCoverage) |
| 83 .then(InspectorTest.logMessage) | 88 .then(LogSorted) |
| 84 .then(ClearAndGC) | 89 .then(ClearAndGC) |
| 85 .then(Protocol.Runtime.stopPreciseCoverage) | 90 .then(Protocol.Runtime.stopPreciseCoverage) |
| 86 .then(Protocol.Runtime.disable) | 91 .then(Protocol.Runtime.disable) |
| 87 .then(next); | 92 .then(next); |
| 88 }, | 93 }, |
| 89 ]); | 94 ]); |
| OLD | NEW |