Index: third_party/WebKit/LayoutTests/inspector-protocol/runtime/runtime-command-line-api-can-be-overriden.html |
diff --git a/third_party/WebKit/LayoutTests/inspector-protocol/runtime/runtime-command-line-api-can-be-overriden.html b/third_party/WebKit/LayoutTests/inspector-protocol/runtime/runtime-command-line-api-can-be-overriden.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c74afd74269f4f5edf7f55e255e61780051de343 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/inspector-protocol/runtime/runtime-command-line-api-can-be-overriden.html |
@@ -0,0 +1,78 @@ |
+<html> |
+<head> |
+<script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script> |
+<script> |
+ |
+function overrideDir() |
+{ |
+ var v = "" + dir; |
+ dir = 239; |
+ return v + " -> " + dir; |
+} |
+ |
+function override$_() |
+{ |
+ var v = "" + $_; |
+ $_ = 239; |
+ return v + " -> " + $_; |
+} |
+ |
+function doesCommandLineAPIEnumerable() |
+{ |
+ for (var v in window) { |
+ if (v === "dir" || v === "$_") |
+ return "enumerable"; |
+ } |
+ return "non enumerable"; |
+} |
+ |
+function test() |
+{ |
+ function evaluatePromise(expression) |
+ { |
+ var cb; |
+ var p = new Promise(resolver => cb = resolver); |
+ InspectorTest.sendCommandOrDie("Runtime.evaluate", { "expression": expression, objectGroup: "console", includeCommandLineAPI: true }, cb); |
+ return p; |
+ } |
+ |
+ evaluatePromise("doesCommandLineAPIEnumerable()") |
+ .then(dumpResult.bind(null, "Check that CommandLineAPI isn't enumerable on window object:")) |
+ .then(() => evaluatePromise("overrideDir()")) |
+ .then(dumpResult.bind(null, "Override dir:")) |
+ .then(() => evaluatePromise("\"\" + dir")) |
+ .then(dumpResult.bind(null, "CommandLineAPI doesn't override dir:")) |
+ .then(() => evaluatePromise("delete dir")) |
+ .then(() => evaluatePromise("overrideDir()")) |
+ .then(dumpResult.bind(null, "CommandLineAPI is presented after removing override variable:")) |
+ // set $_ to 42 |
+ .then(() => evaluatePromise("42")) |
+ .then(() => evaluatePromise("override$_()")) |
+ .then(dumpResult.bind(null, "Override $_:")) |
+ .then(() => evaluatePromise("\"\" + $_")) |
+ .then(dumpResult.bind(null, "CommandLineAPI doesn't override $_:")) |
+ .then(() => evaluatePromise("delete $_")) |
+ .then(() => evaluatePromise("override$_()")) |
+ .then(dumpResult.bind(null, "CommandLineAPI is presented after removing override variable:")) |
+ .then(() => evaluatePromise("var dir = 1; \"\" + dir")) |
+ .then(dumpResult.bind(null, "CommandLineAPI can be overridden by var dir = 1:")) |
+ .then(() => evaluatePromise("\"\" + dir")) |
+ .then(dumpResult.bind(null, "CommandLineAPI doesn't override var dir = 1:")) |
+ .then(() => evaluatePromise("Object.defineProperty(window, \"copy\", { get: () => 239 }); \"\" + copy")) |
+ .then(dumpResult.bind(null, "CommandLineAPI can be overridden by Object.defineProperty:")) |
+ .then(() => evaluatePromise("\"\" + copy")) |
+ .then(dumpResult.bind(null, "CommandLineAPI doesn't override Object.defineProperty:")) |
+ .then(() => InspectorTest.completeTest()); |
+ |
+ function dumpResult(title, message) |
+ { |
+ InspectorTest.log(title); |
+ InspectorTest.log(message.result.value); |
+ } |
+} |
+</script> |
+</head> |
+<body onLoad="runTest();"> |
+Tests that Command Line API doesn't override defined on window methods and can be overridden during evaluation. |
+</body> |
+</html> |