Commit 06929038 authored by Will Chen's avatar Will Chen Committed by Commit Bot

Reland "DevTools: transform console tests (part 2)"

This is a reland of 9869d2f1

I've marked the tests as Slow in this CL (https://chromium-review.googlesource.com/c/600829)
which is why there were flaky before.

Original change's description:
> DevTools: transform console tests (part 2)
> 
> F/u from https://chromium-review.googlesource.com/c/595238
> 
> Bug: 667560
> Change-Id: I4e387fae79ab4de0965f84a045c4fd04631b9e7d
> Reviewed-on: https://chromium-review.googlesource.com/597312
> Commit-Queue: Will Chen <chenwilliam@chromium.org>
> Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#491501}

Bug: 667560
Change-Id: Ie2cc4dd1249b46b7ce784a516647acaee223c39f
Reviewed-on: https://chromium-review.googlesource.com/600814Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Will Chen <chenwilliam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491884}
parent 322a5469
...@@ -612,27 +612,11 @@ crbug.com/728378 virtual/layout_ng/overflow/overflow-position-004.html [ Failure ...@@ -612,27 +612,11 @@ crbug.com/728378 virtual/layout_ng/overflow/overflow-position-004.html [ Failure
# ====== DevTools test migration failures from here ====== # ====== DevTools test migration failures from here ======
# Temporary failures (these tests are moves from html to js) # Temporary failures (these tests are moves from html to js)
# See crbug.com/667560 for details # See crbug.com/667560 for details
crbug.com/667560 http/tests/devtools/console/console-bind-fake.js [ Skip ]
crbug.com/667560 http/tests/devtools/console/console-call-getter-on-proto.js [ Skip ]
crbug.com/667560 http/tests/devtools/console/console-command-clear.js [ Skip ]
crbug.com/667560 http/tests/devtools/console/console-control-characters.js [ Skip ]
crbug.com/667560 http/tests/devtools/console/console-correct-suggestions.js [ Skip ]
crbug.com/667560 http/tests/devtools/console/console-css-unterminated-comment.js [ Skip ]
crbug.com/667560 http/tests/devtools/console/console-dir-deprecated.js [ Skip ]
crbug.com/667560 http/tests/devtools/console/console-dir-global.js [ Skip ]
crbug.com/667560 http/tests/devtools/console/console-edit-property-value.js [ Skip ]
### virtual/mojo-loading/http/tests/devtools ### virtual/mojo-loading/http/tests/devtools
crbug.com/667560 virtual/mojo-loading/http/tests/devtools/console/console-bind-fake.js [ Skip ]
crbug.com/667560 virtual/mojo-loading/http/tests/devtools/console/console-call-getter-on-proto.js [ Skip ] ### Manually fix after migration
crbug.com/667560 virtual/mojo-loading/http/tests/devtools/console/console-command-clear.js [ Skip ] crbug.com/667560 virtual/mojo-loading/http/tests/devtools/console/console-dir.js [ NeedsManualRebaseline ]
crbug.com/667560 virtual/mojo-loading/http/tests/devtools/console/console-control-characters.js [ Skip ]
crbug.com/667560 virtual/mojo-loading/http/tests/devtools/console/console-correct-suggestions.js [ Skip ]
crbug.com/667560 virtual/mojo-loading/http/tests/devtools/console/console-css-unterminated-comment.js [ Skip ]
crbug.com/667560 virtual/mojo-loading/http/tests/devtools/console/console-dir-deprecated.js [ Skip ]
crbug.com/667560 virtual/mojo-loading/http/tests/devtools/console/console-dir-global.js [ Skip ]
crbug.com/667560 virtual/mojo-loading/http/tests/devtools/console/console-dir.js [ Skip ]
crbug.com/667560 virtual/mojo-loading/http/tests/devtools/console/console-edit-property-value.js [ Skip ]
# ====== DevTools test migration failures until here ====== # ====== DevTools test migration failures until here ======
......
<html> // Copyright 2017 The Chromium Authors. All rights reserved.
<head> // Use of this source code is governed by a BSD-style license that can be
<script src="../../http/tests/inspector/inspector-test.js"></script> // found in the LICENSE file.
<script src="../../http/tests/inspector/console-test.js"></script>
<script>
var foo = 'fooValue';
Function.prototype.bind = function () { throw ":P"; }; (async function() {
TestRunner.addResult(`Tests that overriding Function.prototype.bind does not break inspector.\n`);
function test() await TestRunner.loadModule('console_test_runner');
{ await TestRunner.showPanel('console');
InspectorTest.evaluateInConsole("foo", step1);
function step1() await TestRunner.evaluateInPagePromise(`
{ var foo = 'fooValue';
InspectorTest.dumpConsoleMessages(); Function.prototype.bind = function () { throw ":P"; };
InspectorTest.completeTest(); `);
}
}
</script>
</head>
<body onload="runTest()"> ConsoleTestRunner.evaluateInConsole('foo', step1);
<p>
Tests that overriding Function.prototype.bind does not break inspector.
</p>
</body> function step1() {
</html> ConsoleTestRunner.dumpConsoleMessages();
TestRunner.completeTest();
}
})();
CONSOLE MESSAGE: line 21: [object Object]
Tests that calling getter on prototype will call it on the object. Tests that calling getter on prototype will call it on the object.
console-call-getter-on-proto.html:21 B {value: 239} console-call-getter-on-proto.js:27 B {value: 239}
foo: 239 foo: 239
value: 239 value: 239
__proto__: A __proto__: A
......
<html> // Copyright 2017 The Chromium Authors. All rights reserved.
<head> // Use of this source code is governed by a BSD-style license that can be
<script src="../../http/tests/inspector/inspector-test.js"></script> // found in the LICENSE file.
<script src="../../http/tests/inspector/console-test.js"></script>
<script>
function logObject()
{
var A = function() { this.value = 239; }
A.prototype = {
constructor: A,
get foo()
{
return this.value;
}
}
var B = function() { A.call(this); }
B.prototype = {
constructor: B,
__proto__: A.prototype
}
console.log(new B());
}
function test() (async function() {
{ TestRunner.addResult(`Tests that calling getter on prototype will call it on the object.\n`);
InspectorTest.evaluateInPage("logObject()", step2);
function step2() await TestRunner.loadModule('console_test_runner');
{ await TestRunner.showPanel('console');
InspectorTest.expandConsoleMessages(step3);
} await TestRunner.evaluateInPagePromise(`
function expandTreeElementFilter(treeElement) function logObject()
{
var name = treeElement.nameElement && treeElement.nameElement.textContent;
return name === "__proto__";
}
function step3()
{
InspectorTest.expandConsoleMessages(step4, expandTreeElementFilter);
}
function step4()
{
InspectorTest.expandGettersInConsoleMessages(step5);
}
function step5()
{ {
InspectorTest.dumpConsoleMessages(false, false, InspectorTest.textContentWithLineBreaks); var A = function() { this.value = 239; }
InspectorTest.completeTest(); A.prototype = {
constructor: A,
get foo()
{
return this.value;
}
}
var B = function() { A.call(this); }
B.prototype = {
constructor: B,
__proto__: A.prototype
}
console.log(new B());
} }
} `);
</script>
</head> TestRunner.evaluateInPage('logObject()', step2);
<body onload="runTest()"> function step2() {
<p> ConsoleTestRunner.expandConsoleMessages(step3);
Tests that calling getter on prototype will call it on the object. }
</p>
</body> function expandTreeElementFilter(treeElement) {
</html> var name = treeElement.nameElement && treeElement.nameElement.textContent;
return name === '__proto__';
}
function step3() {
ConsoleTestRunner.expandConsoleMessages(step4, expandTreeElementFilter);
}
function step4() {
ConsoleTestRunner.expandGettersInConsoleMessages(step5);
}
function step5() {
ConsoleTestRunner.dumpConsoleMessages(false, false, TestRunner.textContentWithLineBreaks);
TestRunner.completeTest();
}
})();
CONSOLE MESSAGE: line 9: one
CONSOLE MESSAGE: line 10: two
CONSOLE MESSAGE: line 11: three
Tests that console is cleared upon clear() eval in console. Tests that console is cleared upon clear() eval in console.
=== Before clear === === Before clear ===
console-command-clear.html:9 one console-command-clear.js:14 one
console-command-clear.html:10 two console-command-clear.js:15 two
console-command-clear.html:11 three console-command-clear.js:16 three
=== After clear === === After clear ===
VM:1 Console was cleared VM:1 Console was cleared
<html> // Copyright 2017 The Chromium Authors. All rights reserved.
<head> // Use of this source code is governed by a BSD-style license that can be
<script src="../../http/tests/inspector/inspector-test.js"></script> // found in the LICENSE file.
<script src="../../http/tests/inspector/console-test.js"></script>
<script> (async function() {
TestRunner.addResult(`Tests that console is cleared upon clear() eval in console.\n`);
function log() {
// Fill console. await TestRunner.loadModule('console_test_runner');
console.log("one"); await TestRunner.showPanel('console');
console.log("two");
console.log("three"); await TestRunner.evaluateInPagePromise(`
} function log() {
// Fill console.
log(); console.log("one");
console.log("two");
function test() console.log("three");
{
InspectorTest.addResult("=== Before clear ===");
InspectorTest.dumpConsoleMessages();
function callback()
{
InspectorTest.addResult("=== After clear ===");
InspectorTest.dumpConsoleMessages();
InspectorTest.completeTest();
} }
InspectorTest.evaluateInConsole("clear()", callback); log();
} `);
</script> TestRunner.addResult('=== Before clear ===');
</head> ConsoleTestRunner.dumpConsoleMessages();
<body onload="runTest()"> function callback() {
<p> TestRunner.addResult('=== After clear ===');
Tests that console is cleared upon clear() eval in console. ConsoleTestRunner.dumpConsoleMessages();
</p> TestRunner.completeTest();
}
</body> ConsoleTestRunner.evaluateInConsole('clear()', callback);
</html> })();
<html> // Copyright 2017 The Chromium Authors. All rights reserved.
<head> // Use of this source code is governed by a BSD-style license that can be
<script src="../../http/tests/inspector/inspector-test.js"></script> // found in the LICENSE file.
<script src="../../http/tests/inspector/console-test.js"></script>
<script>
function test() (async function() {
{ TestRunner.addResult(`Verify that control characters are substituted with printable characters.\n`);
// The following command has control character.
InspectorTest.evaluateInConsole("var\u001D i = 0;", onEvaluated);
function onEvaluated() await TestRunner.loadModule('console_test_runner');
{ await TestRunner.showPanel('console');
InspectorTest.dumpConsoleMessages();
InspectorTest.completeTest();
}
}
</script> ConsoleTestRunner.evaluateInConsole('var\u001d i = 0;', onEvaluated);
</head>
<body onload="runTest()"> function onEvaluated() {
<p> ConsoleTestRunner.dumpConsoleMessages();
Verify that control characters are substituted with printable characters. TestRunner.completeTest();
</p> }
})();
</body>
</html>
<html> // Copyright 2017 The Chromium Authors. All rights reserved.
<head> // Use of this source code is governed by a BSD-style license that can be
<script src="../../http/tests/inspector/inspector-test.js"></script> // found in the LICENSE file.
<script src="../../http/tests/inspector/console-test.js"></script>
<script> (async function() {
function templateString() TestRunner.addResult(`Tests that console correctly finds suggestions in complicated cases.\n`);
{
console.log("The template string should not run and you should not see this log"); await TestRunner.loadModule('console_test_runner');
return { await TestRunner.showPanel('console');
shouldNotFindThis:56
}; await TestRunner.evaluateInPagePromise(`
} function templateString()
function shouldNotFindThisFunction() { }
function shouldFindThisFunction() { }
window["should not find this"] = true;
var myMap = new Map([['first', 1], ['second', 2], ['third', 3], ['shouldNotFindThis', 4]]);
var complicatedObject = {
'foo-bar': true,
'"double-qouted"': true,
"'single-qouted'": true,
"notDangerous();": true
}
function test()
{
var consoleEditor;
function testCompletions(text, expected, force)
{ {
var cursorPosition = text.indexOf('|'); console.log("The template string should not run and you should not see this log");
if (cursorPosition < 0) return {
cursorPosition = Infinity; shouldNotFindThis:56
consoleEditor.setText(text.replace('|', '')); };
consoleEditor.setSelection(TextUtils.TextRange.createFromLocation(0, cursorPosition));
consoleEditor._autocompleteController.autocomplete(force);
return InspectorTest.addSnifferPromise(consoleEditor._autocompleteController, "_onSuggestionsShownForTest").then(checkExpected);
function checkExpected(suggestions)
{
var completions = new Map(suggestions.map(suggestion => [suggestion.text, suggestion]));
var message = "Checking '" + text.replace('\n', '\\n').replace('\r', '\\r') + "'";
if (force)
message += " forcefully";
InspectorTest.addResult(message);
for (var i = 0; i < expected.length; i++) {
if (completions.has(expected[i])) {
if (completions.get(expected[i]).title)
InspectorTest.addResult("Found: " + expected[i] + ", displayed as " + completions.get(expected[i]).title);
else
InspectorTest.addResult("Found: " + expected[i]);
} else {
InspectorTest.addResult("Not Found: " + expected[i]);
}
}
InspectorTest.addResult("");
}
} }
function sequential(tests) function shouldNotFindThisFunction() { }
{ function shouldFindThisFunction() { }
var promise = Promise.resolve(); window["should not find this"] = true;
for (var i = 0; i < tests.length; i++) var myMap = new Map([['first', 1], ['second', 2], ['third', 3], ['shouldNotFindThis', 4]]);
promise = promise.then(tests[i]); var complicatedObject = {
return promise; 'foo-bar': true,
'"double-qouted"': true,
"'single-qouted'": true,
"notDangerous();": true
} }
`);
var consoleEditor;
function testCompletions(text, expected, force) {
var cursorPosition = text.indexOf('|');
if (cursorPosition < 0)
cursorPosition = Infinity;
consoleEditor.setText(text.replace('|', ''));
consoleEditor.setSelection(TextUtils.TextRange.createFromLocation(0, cursorPosition));
consoleEditor._autocompleteController.autocomplete(force);
return TestRunner.addSnifferPromise(consoleEditor._autocompleteController, '_onSuggestionsShownForTest').then(checkExpected);
function checkExpected(suggestions) {
var completions = new Map(suggestions.map(suggestion => [suggestion.text, suggestion]));
var message = 'Checking \'' + text.replace('\n', '\\n').replace('\r', '\\r') + '\'';
if (force)
message += ' forcefully';
TestRunner.addResult(message);
for (var i = 0; i < expected.length; i++) {
if (completions.has(expected[i])) {
if (completions.get(expected[i]).title)
TestRunner.addResult('Found: ' + expected[i] + ', displayed as ' + completions.get(expected[i]).title);
else
TestRunner.addResult('Found: ' + expected[i]);
} else {
TestRunner.addResult('Not Found: ' + expected[i]);
}
}
TestRunner.addResult('');
}
}
function sequential(tests) {
var promise = Promise.resolve();
for (var i = 0; i < tests.length; i++)
promise = promise.then(tests[i]);
return promise;
}
sequential([ sequential([
InspectorTest.waitUntilConsoleEditorLoaded().then(e => consoleEditor = e), () => ConsoleTestRunner.waitUntilConsoleEditorLoaded().then(e => consoleEditor = e),
() => testCompletions("window.do", ["document"]), () => testCompletions('window.do', ['document']),
() => testCompletions("win", ["window"]), () => testCompletions('win', ['window']),
() => testCompletions('window["doc', ['"document"]']), () => testCompletions('window["doc', ['"document"]']),
() => testCompletions('window["document"].bo', ["body"]), () => testCompletions('window["document"].bo', ['body']),
() => testCompletions('window["document"]["body"].textC', ["textContent"]), () => testCompletions('window["document"]["body"].textC', ['textContent']),
() => testCompletions('document.body.inner', ["innerText", "innerHTML"]), () => testCompletions('document.body.inner', ['innerText', 'innerHTML']),
() => testCompletions('document["body"][window.do', ["document"]), () => testCompletions('document["body"][window.do', ['document']),
() => testCompletions('document["body"][window["document"].body.childNodes[0].text', ["textContent"]), () => testCompletions('document["body"][window["document"].body.childNodes[0].text', ['textContent']),
() => testCompletions("templateString`asdf`should", ["shouldNotFindThis"]), () => testCompletions('templateString`asdf`should', ['shouldNotFindThis']),
() => testCompletions("window.document.BODY", ["body"]), () => testCompletions('window.document.BODY', ['body']),
() => testCompletions("window.dOcUmE", ["document"]), () => testCompletions('window.dOcUmE', ['document']),
() => testCompletions("window.node", ["NodeList", "AudioNode", "GainNode"]), () => testCompletions('window.node', ['NodeList', 'AudioNode', 'GainNode']),
() => testCompletions("32", ["Float32Array", "Int32Array"]), () => testCompletions('32', ['Float32Array', 'Int32Array']),
() => testCompletions("window.32", ["Float32Array", "Int32Array"]), () => testCompletions('window.32', ['Float32Array', 'Int32Array']),
() => testCompletions("", ["window"], false), () => testCompletions('', ['window'], false),
() => testCompletions("", ["window"], true), () => testCompletions('', ['window'], true),
() => testCompletions('"string g', ["getComputedStyle"], false), () => testCompletions('"string g', ['getComputedStyle'], false),
() => testCompletions("`template string docu", ["document"], false), () => testCompletions('`template string docu', ['document'], false),
() => testCompletions("`${do", ["document"], false), () => testCompletions('`${do', ['document'], false),
() => testCompletions("// do", ["document"], false), () => testCompletions('// do', ['document'], false),
() => testCompletions('["should', ["shouldNotFindThisFunction"]), () => testCompletions('["should', ['shouldNotFindThisFunction']),
() => testCompletions("shou", ["should not find this"]), () => testCompletions('shou', ['should not find this']),
() => testCompletions('myMap.get(', ['"first")', '"second")', '"third")']), () => testCompletions('myMap.get(', ['"first")', '"second")', '"third")']),
() => testCompletions('myMap.get(\'', ['\'first\')', '\'second\')', '\'third\')']), () => testCompletions('myMap.get(\'', ['\'first\')', '\'second\')', '\'third\')']),
() => testCompletions('myMap.set(\'firs', ['\'first\', ']), () => testCompletions('myMap.set(\'firs', ['\'first\', ']),
() => testCompletions('myMap.set(should', ['shouldFindThisFunction', 'shouldNotFindThis', '\"shouldNotFindThis\")']), () => testCompletions('myMap.set(should', ['shouldFindThisFunction', 'shouldNotFindThis', '"shouldNotFindThis")']),
() => testCompletions('myMap.delete(\'', ['\'first\')', '\'second\')', '\'third\')']), () => testCompletions('myMap.delete(\'', ['\'first\')', '\'second\')', '\'third\')']),
() => testCompletions("document. bo", ["body"]), () => testCompletions('document. bo', ['body']),
() => testCompletions("document.\tbo", ["body"]), () => testCompletions('document.\tbo', ['body']),
() => testCompletions("document.\nbo", ["body"]), () => testCompletions('document.\nbo', ['body']),
() => testCompletions("document.\r\nbo", ["body"]), () => testCompletions('document.\r\nbo', ['body']),
() => testCompletions("document [ 'bo", ["'body']"]), () => testCompletions('document [ \'bo', ['\'body\']']),
() => testCompletions("function hey(should", ["shouldNotFindThisFunction"]), () => testCompletions('function hey(should', ['shouldNotFindThisFunction']),
() => testCompletions("var should", ["shouldNotFindThisFunction"]), () => testCompletions('var should', ['shouldNotFindThisFunction']),
() => testCompletions("document[[win", ["window"]), () => testCompletions('document[[win', ['window']),
() => testCompletions("document[ [win", ["window"]), () => testCompletions('document[ [win', ['window']),
() => testCompletions("document[ [ win", ["window"]), () => testCompletions('document[ [ win', ['window']),
() => testCompletions('I|mag', ['Image', 'Infinity']), () => testCompletions('I|mag', ['Image', 'Infinity']),
() => testCompletions('var x = (do|);', ['document']), () => testCompletions('var x = (do|);', ['document']),
() => testCompletions('complicatedObject["foo', ['"foo-bar"]']), () => testCompletions('complicatedObject["foo', ['"foo-bar"]']),
() => testCompletions('complicatedObject["foo-', ['"foo-bar"]']), () => testCompletions('complicatedObject["foo-', ['"foo-bar"]']),
() => testCompletions('complicatedObject["foo-bar', ['"foo-bar"]']), () => testCompletions('complicatedObject["foo-bar', ['"foo-bar"]']),
() => testCompletions('complicatedObject["\'sing', ['"\'single-qouted\'"]']), () => testCompletions('complicatedObject["\'sing', ['"\'single-qouted\'"]']),
() => testCompletions('complicatedObject[\'\\\'sing', ['\'\\\'single-qouted\\\'\']']), () => testCompletions('complicatedObject[\'\\\'sing', ['\'\\\'single-qouted\\\'\']']),
() => testCompletions('complicatedObject["\'single-qou', ['"\'single-qouted\'"]']), () => testCompletions('complicatedObject["\'single-qou', ['"\'single-qouted\'"]']),
() => testCompletions('complicatedObject["\\"double-qouted\\"', ['"\\"double-qouted\\""]']), () => testCompletions('complicatedObject["\\"double-qouted\\"', ['"\\"double-qouted\\""]']),
() => testCompletions('complicatedObject["notDangerous();', ['"notDangerous();"]']), () => testCompletions('complicatedObject["notDangerous();', ['"notDangerous();"]'])
]).then(InspectorTest.completeTest); ]).then(TestRunner.completeTest);
})();
}
</script>
</head>
<body onload="runTest()">
<p>Tests that console correctly finds suggestions in complicated cases.</p>
</body>
</html>
<html>
<head>
<script src="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/console-test.js"></script>
<style>/* unterminated comment </style>
<style>/*</style>
<style>/* terminated comment */</style>
<style>/* terminated comment *//*</style>
<script>
function test()
{
InspectorTest.consoleModel.messages().forEach(function(message)
{
InspectorTest.addResult(message.message + " (line " + message.line + ")");
});
InspectorTest.completeTest();
}
</script>
</head>
<body onload="runTest()">
<p id="p">Tests that unterminated comment in CSS generates a warning.</p>
</body>
</html>
CONSOLE MESSAGE: line 9: [object Window]
CONSOLE MESSAGE: line 10: [object ShadowRoot]
Tests that console does not log deprecated warning messages while dir-dumping objects. Tests that console does not log deprecated warning messages while dir-dumping objects.
console-dir-deprecated.html:9 Window console-dir-deprecated.js:17 Window
console-dir-deprecated.html:10 #document-fragment console-dir-deprecated.js:18 #document-fragment
<html> // Copyright 2017 The Chromium Authors. All rights reserved.
<head> // Use of this source code is governed by a BSD-style license that can be
<script src="../../http/tests/inspector/inspector-test.js"></script> // found in the LICENSE file.
<script src="../../http/tests/inspector/console-test.js"></script>
<script>
function logObjects() (async function() {
{ TestRunner.addResult(`Tests that console does not log deprecated warning messages while dir-dumping objects.\n`);
console.dir(window);
console.dir(document.getElementById("foo").createShadowRoot());
}
function test() await TestRunner.loadModule('console_test_runner');
{ await TestRunner.showPanel('console');
InspectorTest.evaluateInPage("logObjects()", step2);
function step2() await TestRunner.loadHTML(`
<div id="foo"></div>
`);
await TestRunner.evaluateInPagePromise(`
function logObjects()
{ {
InspectorTest.dumpConsoleMessages(); console.dir(window);
InspectorTest.completeTest(); console.dir(document.getElementById("foo").createShadowRoot());
} }
} `);
</script>
</head>
<body onload="runTest()"> TestRunner.evaluateInPage('logObjects()', step2);
<div id="foo"></div>
<p>
Tests that console does not log deprecated warning messages while dir-dumping objects.
</p>
</body> function step2() {
</html> ConsoleTestRunner.dumpConsoleMessages();
TestRunner.completeTest();
}
})();
CONSOLE MESSAGE: line 9: [object Window]
Tests that console dumps global object with properties. Tests that console dumps global object with properties.
{ {
......
<html> // Copyright 2017 The Chromium Authors. All rights reserved.
<head> // Use of this source code is governed by a BSD-style license that can be
<script src="../../http/tests/inspector/inspector-test.js"></script> // found in the LICENSE file.
<script src="../../http/tests/inspector/console-test.js"></script>
<script> (async function() {
TestRunner.addResult(`Tests that console dumps global object with properties.\n`);
function doit()
{
console.dir(window);
runTest();
}
function test()
{
InspectorTest.RuntimeAgent.evaluate("window", "console", false).then(evalCallback);
function evalCallback(result)
{
if (!result) {
testController.notifyDone("Exception");
return;
}
if (result.type === "error")
testController.notifyDone("Exception:" + result);
var objectProxy = InspectorTest.runtimeModel.createRemoteObject(result);
objectProxy.getOwnProperties(false, getPropertiesCallback);
}
function getPropertiesCallback(properties) await TestRunner.loadModule('console_test_runner');
await TestRunner.showPanel('console');
await TestRunner.evaluateInPagePromise(`
function doit()
{ {
properties.sort(ObjectUI.ObjectPropertiesSection.CompareProperties); console.dir(window);
var golden = { "window": 1, "document": 1, "eval": 1, "console": 1, "frames": 1, "Array": 1, "doit": 1 }; };
var result = {}; `);
for (var i = 0; i < properties.length; ++i) {
var name = properties[i].name; TestRunner.RuntimeAgent.evaluate('window', 'console', false).then(evalCallback);
if (golden[name])
result[name] = 1; function evalCallback(result) {
} if (!result) {
InspectorTest.addObject(result); testController.notifyDone('Exception');
InspectorTest.completeTest(); return;
} }
}
</script> if (result.type === 'error')
</head> testController.notifyDone('Exception:' + result);
<body onload="doit()"> var objectProxy = TestRunner.runtimeModel.createRemoteObject(result);
<p> objectProxy.getOwnProperties(false, getPropertiesCallback);
Tests that console dumps global object with properties. }
</p>
function getPropertiesCallback(properties) {
properties.sort(ObjectUI.ObjectPropertiesSection.CompareProperties);
var golden = {
'window': 1,
'document': 1,
'eval': 1,
'console': 1,
'frames': 1,
'Array': 1,
'doit': 1
};
var result = {};
for (var i = 0; i < properties.length; ++i) {
var name = properties[i].name;
if (golden[name])
result[name] = 1;
}
</body> TestRunner.addObject(result);
</html> TestRunner.completeTest();
}
})();
<html> // Copyright 2017 The Chromium Authors. All rights reserved.
<head> // Use of this source code is governed by a BSD-style license that can be
<script src="../../http/tests/inspector/inspector-test.js"></script> // found in the LICENSE file.
<script src="../../http/tests/inspector/console-test.js"></script>
<script> (async function() {
function onload() TestRunner.addResult(`Tests that console logging dumps proper messages.\n`);
{
console.dir(["test1", "test2"]);
console.dir(document.childNodes);
console.dir(document.evaluate("//head", document, null, XPathResult.ANY_TYPE, null));
// Object with properties containing whitespaces await TestRunner.loadModule('console_test_runner');
var obj = { $foo5_: 0 }; await TestRunner.showPanel('console');
obj[" a b "] = " a b ";
obj["c d"] = "c d";
obj[""] = "";
obj[" "] = " ";
obj["a\n\nb\nc"] = "a\n\nb\nc";
obj["negZero"] = -0;
console.dir(obj);
// This should correctly display information about the function. await TestRunner.evaluateInPagePromise(`
console.dir(function() {}); function onload()
{
console.dir(["test1", "test2"]);
console.dir(document.childNodes);
console.dir(document.evaluate("//head", document, null, XPathResult.ANY_TYPE, null));
// Test function inferred name in prototype constructor. // Object with properties containing whitespaces
var outer = { inner: function() {} }; var obj = { $foo5_: 0 };
console.dir(new outer.inner()); obj[" a b "] = " a b ";
obj["c d"] = "c d";
obj[""] = "";
obj[" "] = " ";
obj["a\n\nb\nc"] = "a\n\nb\nc";
obj["negZero"] = -0;
console.dir(obj);
// Test "No Properties" placeholder. // This should correctly display information about the function.
console.dir({ __proto__: null }); console.dir(function() {});
console.dir({ foo: { __proto__: null }});
// Test "No Scopes" placeholder.
console.dir(Object.getOwnPropertyDescriptor(Object.prototype, "__proto__").get);
// Test big typed array: should be no crash or timeout. // Test function inferred name in prototype constructor.
var bigTypedArray = new Uint8Array(new ArrayBuffer(400 * 1000 * 1000)); var outer = { inner: function() {} };
bigTypedArray["FAIL"] = "FAIL: Object.getOwnPropertyNames() should not have been run"; console.dir(new outer.inner());
console.dir(bigTypedArray);
// document.createEvent("Event") has a special property "isTrusted" flagged "Unforgeable". // Test "No Properties" placeholder.
var event = document.createEvent("Event"); console.dir({ __proto__: null });
Object.defineProperty(event, "timeStamp", {value: 0}) console.dir({ foo: { __proto__: null }});
console.dir(event); // Test "No Scopes" placeholder.
console.dir(Object.getOwnPropertyDescriptor(Object.prototype, "__proto__").get);
runTest(); // Test big typed array: should be no crash or timeout.
} var bigTypedArray = new Uint8Array(new ArrayBuffer(400 * 1000 * 1000));
//# sourceURL=console-dir.html bigTypedArray["FAIL"] = "FAIL: Object.getOwnPropertyNames() should not have been run";
</script> console.dir(bigTypedArray);
<script> // document.createEvent("Event") has a special property "isTrusted" flagged "Unforgeable".
function test() var event = document.createEvent("Event");
{ Object.defineProperty(event, "timeStamp", {value: 0})
InspectorTest.expandConsoleMessages(step1, expandTreeElementFilter); console.dir(event);
function expandTreeElementFilter(treeElement) runTest();
{
var name = treeElement.nameElement && treeElement.nameElement.textContent;
return name === "foo" || treeElement.title === "<function scope>";
} }
//# sourceURL=console-dir.js
`);
function step1() ConsoleTestRunner.expandConsoleMessages(step1, expandTreeElementFilter);
{
InspectorTest.expandConsoleMessages(dumpConsoleMessages, expandTreeElementFilter);
}
function dumpConsoleMessages()
{
InspectorTest.dumpConsoleMessagesIgnoreErrorStackFrames();
InspectorTest.completeTest();
}
}
</script> function expandTreeElementFilter(treeElement) {
</head> var name = treeElement.nameElement && treeElement.nameElement.textContent;
return name === 'foo' || treeElement.title === '<function scope>';
}
<body onload="onload()"> function step1() {
<p> ConsoleTestRunner.expandConsoleMessages(dumpConsoleMessages, expandTreeElementFilter);
Tests that console logging dumps proper messages. }
</p>
</body> function dumpConsoleMessages() {
</html> ConsoleTestRunner.dumpConsoleMessagesIgnoreErrorStackFrames();
TestRunner.completeTest();
}
})();
CONSOLE MESSAGE: line 10: [object Object]
Tests that property values can be edited inline in the console via double click. Tests that property values can be edited inline in the console via double click.
Node was hidden after dblclick: true Node was hidden after dblclick: true
...@@ -6,7 +5,7 @@ Node was hidden after dblclick: true ...@@ -6,7 +5,7 @@ Node was hidden after dblclick: true
Node was hidden after dblclick: true Node was hidden after dblclick: true
Node was hidden after dblclick: true Node was hidden after dblclick: true
logToConsole() logToConsole()
console-edit-property-value.html:10 {a: 1, b: "foo", c: null, d: 2} console-edit-property-value.js:15 {a: 1, b: "foo", c: null, d: 2}
a: 3 a: 3
b: "foo" b: "foo"
c: (3) [1, 2, 3] c: (3) [1, 2, 3]
......
<html> // Copyright 2017 The Chromium Authors. All rights reserved.
<head> // Use of this source code is governed by a BSD-style license that can be
<script src="../../http/tests/inspector/inspector-test.js"></script> // found in the LICENSE file.
<script src="../../http/tests/inspector/console-test.js"></script>
<script>
function logToConsole() (async function() {
{ TestRunner.addResult(`Tests that property values can be edited inline in the console via double click.\n`);
var obj = {a: 1, b: "foo", c: null, d: 2};
console.log(obj);
}
var test = function() await TestRunner.loadModule('console_test_runner');
{ await TestRunner.showPanel('console');
InspectorTest.evaluateInConsole("logToConsole()", step1);
function step1() await TestRunner.evaluateInPagePromise(`
function logToConsole()
{ {
InspectorTest.expandConsoleMessages(step2); var obj = {a: 1, b: "foo", c: null, d: 2};
console.log(obj);
} }
`);
function step2() ConsoleTestRunner.evaluateInConsole('logToConsole()', step1);
{
var valueElements = getValueElements();
doubleClickTypeAndEnter(valueElements[0], "1 + 2");
InspectorTest.waitForRemoteObjectsConsoleMessages(step3);
}
function step3() function step1() {
{ ConsoleTestRunner.expandConsoleMessages(step2);
var valueElements = getValueElements(); }
doubleClickTypeAndEnter(valueElements[1], "nonExistingValue");
InspectorTest.waitForRemoteObjectsConsoleMessages(step4);
}
function step4() function step2() {
{ var valueElements = getValueElements();
var valueElements = getValueElements(); doubleClickTypeAndEnter(valueElements[0], '1 + 2');
doubleClickTypeAndEnter(valueElements[2], "[1, 2, 3]"); ConsoleTestRunner.waitForRemoteObjectsConsoleMessages(step3);
InspectorTest.waitForRemoteObjectsConsoleMessages(step5); }
}
function step5() function step3() {
{ var valueElements = getValueElements();
var valueElements = getValueElements(); doubleClickTypeAndEnter(valueElements[1], 'nonExistingValue');
doubleClickTypeAndEnter(valueElements[3], "{x: 2}"); ConsoleTestRunner.waitForRemoteObjectsConsoleMessages(step4);
InspectorTest.waitForRemoteObjectsConsoleMessages(step6); }
}
function step6() function step4() {
{ var valueElements = getValueElements();
InspectorTest.dumpConsoleMessagesIgnoreErrorStackFrames(); doubleClickTypeAndEnter(valueElements[2], '[1, 2, 3]');
InspectorTest.completeTest(); ConsoleTestRunner.waitForRemoteObjectsConsoleMessages(step5);
} }
function getValueElements()
{
var messageElement = Console.ConsoleView.instance()._visibleViewMessages[1].element();
return messageElement.querySelector(".console-message-text *").shadowRoot.querySelectorAll(".value");
}
function doubleClickTypeAndEnter(node, text) function step5() {
{ var valueElements = getValueElements();
var event = document.createEvent("MouseEvent"); doubleClickTypeAndEnter(valueElements[3], '{x: 2}');
event.initMouseEvent("dblclick", true, true, null, 2); ConsoleTestRunner.waitForRemoteObjectsConsoleMessages(step6);
node.dispatchEvent(event); }
InspectorTest.addResult("Node was hidden after dblclick: " + node.classList.contains("hidden"));
var messageElement = Console.ConsoleView.instance()._visibleViewMessages[1].element();
var editPrompt = messageElement.querySelector(".console-message-text *").shadowRoot.querySelector(".text-prompt");
editPrompt.textContent = text;
editPrompt.dispatchEvent(InspectorTest.createKeyEvent("Enter"));
}
}
</script> function step6() {
</head> ConsoleTestRunner.dumpConsoleMessagesIgnoreErrorStackFrames();
TestRunner.completeTest();
}
<body onload="runTest()"> function getValueElements() {
<p> var messageElement = Console.ConsoleView.instance()._visibleViewMessages[1].element();
Tests that property values can be edited inline in the console via double click. return messageElement.querySelector('.console-message-text *').shadowRoot.querySelectorAll('.value');
</p> }
</body> function doubleClickTypeAndEnter(node, text) {
</html> var event = document.createEvent('MouseEvent');
event.initMouseEvent('dblclick', true, true, null, 2);
node.dispatchEvent(event);
TestRunner.addResult('Node was hidden after dblclick: ' + node.classList.contains('hidden'));
var messageElement = Console.ConsoleView.instance()._visibleViewMessages[1].element();
var editPrompt = messageElement.querySelector('.console-message-text *').shadowRoot.querySelector('.text-prompt');
editPrompt.textContent = text;
editPrompt.dispatchEvent(TestRunner.createKeyEvent('Enter'));
}
})();
...@@ -217,7 +217,7 @@ ConsoleTestRunner.consoleMessagesCount = function() { ...@@ -217,7 +217,7 @@ ConsoleTestRunner.consoleMessagesCount = function() {
}; };
/** /**
* @param {function(!Element):string} messageFormatter * @param {function(!Element):string|undefined} messageFormatter
* @param {!Element} node * @param {!Element} node
* @return {string} * @return {string}
*/ */
...@@ -261,7 +261,7 @@ ConsoleTestRunner.dumpConsoleMessagesIgnoreErrorStackFrames = function( ...@@ -261,7 +261,7 @@ ConsoleTestRunner.dumpConsoleMessagesIgnoreErrorStackFrames = function(
printOriginatingCommand, dumpClassNames, messageFormatter) { printOriginatingCommand, dumpClassNames, messageFormatter) {
TestRunner.addResults(ConsoleTestRunner.dumpConsoleMessagesIntoArray( TestRunner.addResults(ConsoleTestRunner.dumpConsoleMessagesIntoArray(
printOriginatingCommand, dumpClassNames, printOriginatingCommand, dumpClassNames,
messageFormatter ? ConsoleTestRunner.formatterIgnoreStackFrameUrls.bind(this, messageFormatter) : undefined)); ConsoleTestRunner.formatterIgnoreStackFrameUrls.bind(this, messageFormatter)));
}; };
ConsoleTestRunner.dumpConsoleMessagesWithStyles = function() { ConsoleTestRunner.dumpConsoleMessagesWithStyles = function() {
...@@ -410,11 +410,11 @@ ConsoleTestRunner.waitForRemoteObjectsConsoleMessages = function(callback) { ...@@ -410,11 +410,11 @@ ConsoleTestRunner.waitForRemoteObjectsConsoleMessages = function(callback) {
ConsoleTestRunner.waitUntilConsoleEditorLoaded = function() { ConsoleTestRunner.waitUntilConsoleEditorLoaded = function() {
var fulfill; var fulfill;
var promise = new Promise(x => (fulfill = x)); var promise = new Promise(x => (fulfill = x));
var editor = Console.ConsoleView.instance()._prompt._editor; var prompt = Console.ConsoleView.instance()._prompt;
if (editor) if (prompt._editor)
fulfill(editor); fulfill(prompt._editor);
else else
TestRunner.addSniffer(Console.ConsolePrompt.prototype, '_editorSetForTest', _ => fulfill(editor)); TestRunner.addSniffer(Console.ConsolePrompt.prototype, '_editorSetForTest', _ => fulfill(prompt._editor));
return promise; return promise;
}; };
......
...@@ -56,9 +56,13 @@ function migrateTest(inputPath, identifierMap) { ...@@ -56,9 +56,13 @@ function migrateTest(inputPath, identifierMap) {
helperScripts.push(filename); helperScripts.push(filename);
}); });
const outPath = migrateUtils.getOutPath(inputPath); const testsPath = path.resolve(__dirname, 'tests.txt');
const srcResourcePaths = resourceScripts.map(s => path.resolve(path.dirname(inputPath), s)); const newToOldTests = new Map(fs.readFileSync(testsPath, 'utf-8').split('\n').map(line => line.split(' ').reverse()));
const destResourcePaths = resourceScripts.map(s => path.resolve(path.dirname(outPath), s)); const originalTestPath = path.resolve(
__dirname, '..', '..', '..', '..', 'LayoutTests', newToOldTests.get(inputPath.slice(inputPath.indexOf('http/'))));
const srcResourcePaths = resourceScripts.map(s => path.resolve(path.dirname(originalTestPath), s));
const destResourcePaths = resourceScripts.map(s => path.resolve(path.dirname(inputPath), s));
const relativeResourcePaths = destResourcePaths.map(p => p.slice(p.indexOf('/http/tests') + '/http/tests'.length)); const relativeResourcePaths = destResourcePaths.map(p => p.slice(p.indexOf('/http/tests') + '/http/tests'.length));
let outputCode; let outputCode;
...@@ -86,16 +90,9 @@ function migrateTest(inputPath, identifierMap) { ...@@ -86,16 +90,9 @@ function migrateTest(inputPath, identifierMap) {
console.log(outputCode); console.log(outputCode);
if (!DRY_RUN) { if (!DRY_RUN) {
mkdirp.sync(path.dirname(outPath)); fs.writeFileSync(inputPath, outputCode);
fs.writeFileSync(outPath, outputCode);
const expectationsPath = inputPath.replace('.html', '-expected.txt');
copyExpectations(expectationsPath, outPath);
copyResourceScripts(srcResourcePaths, destResourcePaths); copyResourceScripts(srcResourcePaths, destResourcePaths);
console.log('Migrated: ', inputPath);
fs.unlinkSync(inputPath);
fs.unlinkSync(expectationsPath);
console.log('Migrated to: ', outPath);
} }
} }
...@@ -179,12 +176,11 @@ function transformTestScript( ...@@ -179,12 +176,11 @@ function transformTestScript(
* Create test header based on extracted data * Create test header based on extracted data
*/ */
const headerLines = []; const headerLines = [];
headerLines.push(createExpressionNode(`TestRunner.addResult('${bodyText}\\n');`)); headerLines.push(createExpressionNode(`TestRunner.addResult(\`${bodyText}\\n\`);`));
headerLines.push(createNewLineNode()); headerLines.push(createNewLineNode());
for (const helper of allTestHelpers) { for (const helper of allTestHelpers) {
headerLines.push(createAwaitExpressionNode(`await TestRunner.loadModule('${helper}');`)); headerLines.push(createAwaitExpressionNode(`await TestRunner.loadModule('${helper}');`));
} }
headerLines.push(createAwaitExpressionNode(`await TestRunner.loadPanel('${panel}');`));
headerLines.push(createAwaitExpressionNode(`await TestRunner.showPanel('${panel}');`)); headerLines.push(createAwaitExpressionNode(`await TestRunner.showPanel('${panel}');`));
if (domFixture) { if (domFixture) {
......
inspector/console/alert-toString-exception.html inspector/console/alert-toString-exception.html
inspector/console/console-api-on-call-frame.html inspector/console/console-api-on-call-frame.html
inspector/console/console-bind-fake.html http/tests/devtools/console/console-bind-fake.js
inspector/console/console-call-getter-on-proto.html http/tests/devtools/console/console-call-getter-on-proto.js
inspector/console/console-clear-function.html inspector/console/console-clear-function.html
inspector/console/console-command-clear.html http/tests/devtools/console/console-command-clear.js
inspector/console/console-command-copy.html inspector/console/console-command-copy.html
inspector/console/console-context-selector.html inspector/console/console-context-selector.html
inspector/console/console-control-characters.html http/tests/devtools/console/console-control-characters.js
inspector/console/console-copy-treeoutline.html inspector/console/console-copy-treeoutline.html
inspector/console/console-copy-truncated-text.html inspector/console/console-copy-truncated-text.html
inspector/console/console-correct-suggestions.html http/tests/devtools/console/console-correct-suggestions.js
inspector/console/console-css-unterminated-comment.html http/tests/devtools/console/console-css-unterminated-comment.js
inspector/console/console-dir-deprecated.html http/tests/devtools/console/console-dir-deprecated.js
inspector/console/console-dir-global.html http/tests/devtools/console/console-dir-global.js
inspector/console/console-dir.html http/tests/devtools/console/console-dir.js
inspector/console/console-edit-property-value.html http/tests/devtools/console/console-edit-property-value.js
inspector/console/console-error-on-call-frame.html inspector/console/console-error-on-call-frame.html
\ No newline at end of file
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
const fs = require('fs');
const path = require('path');
const childProcess = require('child_process');
const utils = require('../utils');
const MIGRATE_SCRIPT_PATH = path.resolve(__dirname, 'migrate_test.js');
const TESTS_PATH = path.resolve(__dirname, 'tests.txt');
const TEST_EXPECTATIONS_PATH = path.resolve(__dirname, '..', '..', '..', '..', 'LayoutTests', 'TestExpectations');
const FLAG_EXPECTATIONS_PATH = path.resolve(__dirname, '..', '..', '..', '..', 'LayoutTests', 'FlagExpectations');
function main() {
const tests = fs.readFileSync(TESTS_PATH, 'utf-8').split('\n').map(line => line.split(' '));
const oldToNewTests = new Map(tests);
const testCount = oldToNewTests.size;
const migratedTests = new Set();
for (const [_, testPath] of tests) {
if (!testPath)
continue;
const fullTestPath = path.resolve(__dirname, '..', '..', '..', '..', 'LayoutTests', testPath);
try {
childProcess.execSync(`node ${MIGRATE_SCRIPT_PATH} ${fullTestPath}`)
} catch (err) {
console.log(err.stdout.toString());
continue;
}
for (const [oldTest, newTest] of oldToNewTests) {
if (testPath === newTest)
oldToNewTests.delete(oldTest);
}
migratedTests.add(testPath);
}
console.log(`Successfully migrated: ${migratedTests.size} of ${testCount}`);
const updatedTests = Array.from(oldToNewTests.entries()).map(line => line.join(' ')).join('\n');
console.log(updatedTests);
// Update TestExpectations
const testExpectations = fs.readFileSync(TEST_EXPECTATIONS_PATH, 'utf-8');
const updatedTestExpecationLines = [];
let seenStartSentinel = false;
let seenEndSentinel = false;
for (const line of testExpectations.split('\n')) {
if (line === '# ====== DevTools test migration failures from here ======') {
seenStartSentinel = true;
updatedTestExpecationLines.push(line);
continue;
}
if (line === '# ====== DevTools test migration failures until here ======') {
seenEndSentinel = true;
updatedTestExpecationLines.push(line);
continue;
}
if (seenEndSentinel) {
updatedTestExpecationLines.push(line);
continue;
}
if (!seenStartSentinel) {
updatedTestExpecationLines.push(line);
continue;
}
let skipLine = false;
for (const test of migratedTests) {
if (line.indexOf(test) !== -1) {
skipLine = true;
break;
}
}
if (!skipLine)
updatedTestExpecationLines.push(line);
}
fs.writeFileSync(TEST_EXPECTATIONS_PATH, updatedTestExpecationLines.join('\n'));
// Update tests.txt
fs.writeFileSync(TESTS_PATH, updatedTests);
}
main();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment