blob: da105ebe022385be3d798738eb28fcc0a9336b9a [file] [log] [blame]
<!doctype html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script>
function test()
{
// Each input is wrapped in the String constructor to force stringification.
let testInputs = [
{
title: "ArrayKeys",
input: "keys([3,4])",
},
{
title: "ArrayValues",
input: "values([3,4])",
},
{
title: "DollarZero",
input: "$0",
setup: selectElementForDollarZero,
},
{
title: "InvalidSelector",
input: "$('foo')",
setup: listenForConsoleWarning,
},
{
title: "IdSelector",
input: "$('#foo')",
},
{
title: "IdSelectorWithContext",
input: "$('#foo', document.body)",
},
{
title: "IdSelectorWithInvalidContext",
input: "$('#foo', 'non-node')",
},
{
title: "IdSelectorDynamicContext",
input: "$('#foo', $('#bar'))",
},
{
title: "ElementSelectorAll",
input: "$$('p')",
},
{
title: "ElementSelectorAllWithContext",
input: "$$('p', document.body)",
},
];
let suite = InspectorTest.createAsyncSuite("Console.TestCommandLineAPI");
function addAPITestCase({title, input, setup}) {
suite.addTestCase({
name: `Evaluate${title}`,
setup,
test(resolve, reject) {
InspectorTest.log(`Input: ${input}`);
function callback(result, wasThrown) {
if (result) {
InspectorTest.log(`Output: ${result.description}`);
resolve();
} else
reject();
}
WI.runtimeManager.evaluateInInspectedWindow(`String(${input})`, {objectGroup: "test", includeCommandLineAPI: true}, callback);
}
})
}
for (let input of testInputs)
addAPITestCase(input);
suite.runTestCasesAndFinish();
function listenForConsoleWarning(resolve, reject) {
// Detect console warning for $('foo').
WI.consoleManager.singleFireEventListener(WI.ConsoleManager.Event.MessageAdded, (event) => {
let message = event.data.message;
InspectorTest.assert(message instanceof WI.ConsoleMessage);
InspectorTest.log(`CONSOLE: ${message.messageText}`);
});
resolve();
}
function selectElementForDollarZero(resolve, reject) {
WI.domManager.requestDocument((documentNode) => {
if (!documentNode) {
InspectorTest.log("FAIL: DOM node not found.");
return reject();
}
// Select div#foo for $0.
WI.domManager.querySelector(documentNode.id, "#foo", (contentNodeId) => {
if (!contentNodeId) {
InspectorTest.log("FAIL: DOM node not found.");
return reject();
}
DOMAgent.setInspectedNode(contentNodeId);
resolve();
});
});
}
}
</script>
</head>
<body onload="runTest();">
<p id="foo">Tests that command line api works.</p>
<p id="bar"></p>
</body>
</html>