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