Index: test/inspector/runtime/coverage.js |
diff --git a/test/inspector/runtime/coverage.js b/test/inspector/runtime/coverage.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7415c3061654e52d9b987f2efc0eb178044b3d2e |
--- /dev/null |
+++ b/test/inspector/runtime/coverage.js |
@@ -0,0 +1,83 @@ |
+// 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. |
+ |
+var source = |
+` |
+function fib(x) { |
+ if (x < 2) return 1; |
+ return fib(x-1) + fib(x-2); |
+} |
+(function iife() { |
+ return 1; |
+})(); |
+fib(5); |
+`; |
+ |
+print("Test collecting code coverage data with Runtime.collectCoverage."); |
+ |
+function ClearAndGC() { |
+ return Protocol.Runtime.evaluate({ expression: "fib = null;" }) |
+ .then(() => Protocol.HeapProfiler.enable()) |
+ .then(() => Protocol.HeapProfiler.collectGarbage()) |
+ .then(() => Protocol.HeapProfiler.disable()); |
+} |
+ |
+InspectorTest.runTestSuite([ |
+ function testPreciseCoverage(next) |
+ { |
+ Protocol.Runtime.enable() |
+ .then(() => Protocol.Runtime.startPreciseCoverage()) |
+ .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: "1", persistScript: true })) |
+ .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId })) |
+ .then(ClearAndGC) |
+ .then((result) => InspectorTest.logMessage(result)) |
kozy
2017/02/21 17:57:29
.then(InspectorTest.logMessage)
|
+ .then(() => Protocol.Runtime.takePreciseCoverage()) |
+ .then((result) => InspectorTest.logMessage(result)) |
+ .then(ClearAndGC) |
+ .then(() => Protocol.Runtime.stopPreciseCoverage()) |
+ .then(() => Protocol.Runtime.disable()) |
+ .then(() => next()); |
+ }, |
+ function testPreciseCoverageFail(next) |
+ { |
+ Protocol.Runtime.enable() |
+ .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: "2", persistScript: true })) |
+ .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId })) |
+ .then((result) => InspectorTest.logMessage(result)) |
+ .then(ClearAndGC) |
+ .then(() => Protocol.Runtime.takePreciseCoverage()) |
+ .then((result) => InspectorTest.logMessage(result)) |
+ .then(ClearAndGC) |
+ .then(() => Protocol.Runtime.disable()) |
+ .then(() => next()); |
kozy
2017/02/21 17:57:30
.then(next)
|
+ }, |
+ function testBestEffortCoverage(next) |
+ { |
+ Protocol.Runtime.enable() |
+ .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: "3", persistScript: true })) |
+ .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId })) |
+ .then((result) => InspectorTest.logMessage(result)) |
+ .then(ClearAndGC) |
+ .then(() => Protocol.Runtime.takeBestEffortCoverage()) |
+ .then((result) => InspectorTest.logMessage(result)) |
+ .then(ClearAndGC) |
+ .then(() => Protocol.Runtime.disable()) |
+ .then(() => next()); |
+ }, |
+ function testBestEffortCoveragePrecise(next) |
+ { |
+ Protocol.Runtime.enable() |
+ .then(() => Protocol.Runtime.startPreciseCoverage()) |
+ .then(() => Protocol.Runtime.compileScript({ expression: source, sourceURL: "4", persistScript: true })) |
+ .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId })) |
+ .then((result) => InspectorTest.logMessage(result)) |
+ .then(ClearAndGC) |
+ .then(() => Protocol.Runtime.takeBestEffortCoverage()) |
+ .then((result) => InspectorTest.logMessage(result)) |
+ .then(ClearAndGC) |
+ .then(() => Protocol.Runtime.stopPreciseCoverage()) |
+ .then(() => Protocol.Runtime.disable()) |
+ .then(() => next()); |
+ }, |
+]); |