Skip to content
Permalink
Browse files
Web Inspector: rewrite inspector/console/command-line-api.html to use…
… AsyncTestSuite

https://bugs.webkit.org/show_bug.cgi?id=148637

Reviewed by Darin Adler.

Source/WebInspectorUI:

* UserInterface/Base/Object.js:
(WebInspector.Object.singleFireEventListener):
(WebInspector.Object.singleFireEventListener.let.wrappedCallback): Arrow.

LayoutTests:

* inspector/console/command-line-api-expected.txt:
* inspector/console/command-line-api.html:

Canonical link: https://commits.webkit.org/166804@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189226 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
burg committed Sep 1, 2015
1 parent d913d62 commit 22b10d3bc162f35495c662984af6a53e5ac887c5
Showing 5 changed files with 162 additions and 72 deletions.
@@ -1,3 +1,13 @@
2015-09-01 Brian Burg <bburg@apple.com>

Web Inspector: rewrite inspector/console/command-line-api.html to use AsyncTestSuite
https://bugs.webkit.org/show_bug.cgi?id=148637

Reviewed by Darin Adler.

* inspector/console/command-line-api-expected.txt:
* inspector/console/command-line-api.html:

2015-09-01 Chris Dumez <cdumez@apple.com>

Range.insersectsNode(node) is supposed to return true if node.parent is null
@@ -2,34 +2,44 @@ CONSOLE MESSAGE: line 27: The console function $() has changed from $=getElement
Tests that command line api works.


STEP: String(keys([3,4]))
0,1

STEP: String(values([3,4]))
3,4

STEP: String($0)
[object HTMLParagraphElement]

STEP: String($('foo'))
CONSOLE: The console function $() has changed from $=getElementById(id) to $=querySelector(selector). You might try $("#%s")
null

STEP: String($('#foo'))
[object HTMLParagraphElement]

STEP: String($('#foo', document.body))
[object HTMLParagraphElement]

STEP: String($('#foo', 'non-node'))
[object HTMLParagraphElement]

STEP: String($('#foo', $('#bar')))
null

STEP: String($$('p'))
[object HTMLParagraphElement],[object HTMLParagraphElement]

STEP: String($$('p', document.body))
[object HTMLParagraphElement],[object HTMLParagraphElement]
== Running test suite: Console.TestCommandLineAPI
-- Running test case: EvaluateArrayKeys
Input: keys([3,4])
Output: 0,1

-- Running test case: EvaluateArrayValues
Input: values([3,4])
Output: 3,4

-- Running test case: EvaluateDollarZero
Input: $0
Output: undefined

-- Running test case: EvaluateInvalidSelector
Input: $('foo')
Output: null

-- Running test case: EvaluateIdSelector
Input: $('#foo')
Output: [object HTMLParagraphElement]

-- Running test case: EvaluateIdSelectorWithContext
Input: $('#foo', document.body)
Output: [object HTMLParagraphElement]

-- Running test case: EvaluateIdSelectorWithInvalidContext
Input: $('#foo', 'non-node')
Output: [object HTMLParagraphElement]

-- Running test case: EvaluateIdSelectorDynamicContext
Input: $('#foo', $('#bar'))
Output: null

-- Running test case: EvaluateElementSelectorAll
Input: $$('p')
Output: [object HTMLParagraphElement],[object HTMLParagraphElement]

-- Running test case: EvaluateElementSelectorAllWithContext
Input: $$('p', document.body)
Output: [object HTMLParagraphElement],[object HTMLParagraphElement]

@@ -5,57 +5,116 @@
<script>
function test()
{
var currentStepIndex = 0;
var steps = [
"String(keys([3,4]))",
"String(values([3,4]))",
"String($0)",
"String($('foo'))",
"String($('#foo'))",
"String($('#foo', document.body))",
"String($('#foo', 'non-node'))",
"String($('#foo', $('#bar')))",
"String($$('p'))",
"String($$('p', document.body))",
// 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)",
},
];

var consoleMessage = null;
let suite = InspectorTest.createAsyncSuite("Console.TestCommandLineAPI");

function runSteps()
{
for (var step of steps) {
WebInspector.runtimeManager.evaluateInInspectedWindow(step, "test", true, true, false, false, false, function(result, wasThrown) {
InspectorTest.log("\nSTEP: " + steps[currentStepIndex]);
if (consoleMessage) {
InspectorTest.log("CONSOLE: " + consoleMessage.messageText);
consoleMessage = null;
function addAPITestCase(args) {
let {title, input, setup} = args;
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();
}
InspectorTest.log(result.description);

if (++currentStepIndex >= steps.length)
InspectorTest.completeTest();
});
}
const objectGroup = "test";
const includeCommandLineAPI = true;
const ignorePauseOnExceptionsAndMute = false;
const shouldReturnByValue = false;
const shouldGeneratePreview = false;
const shouldSaveResult = false;
WebInspector.runtimeManager.evaluateInInspectedWindow(`String(${input})`, objectGroup, includeCommandLineAPI, ignorePauseOnExceptionsAndMute, shouldReturnByValue, shouldGeneratePreview, shouldSaveResult, callback);
}
})
}

// Detect console warning for $('foo').
WebInspector.logManager.addEventListener(WebInspector.LogManager.Event.MessageAdded, function(event) {
consoleMessage = event.data.message;
InspectorTest.assert(consoleMessage instanceof WebInspector.ConsoleMessage);
});
for (let input of testInputs)
addAPITestCase(input);

// Select div#foo for $0.
WebInspector.domTreeManager.requestDocument(function(documentNode) {
WebInspector.domTreeManager.querySelector(documentNode.id, "#foo", function(contentNodeId) {
if (contentNodeId) {
ConsoleAgent.addInspectedNode(contentNodeId);
runSteps();
} else {
suite.runTestCasesAndFinish();

function listenForConsoleWarning(resolve, reject) {
// Detect console warning for $('foo').
WebInspector.logManager.singleFireEventListener(WebInspector.LogManager.Event.MessageAdded, (event) => {
let message = event.data.message;
InspectorTest.assert(message instanceof WebInspector.ConsoleMessage);
InspectorTest.log(`CONSOLE: ${message.messageText}`);
});

resolve();
}

function selectElementForDollarZero(resolve, reject) {
WebInspector.domTreeManager.requestDocument(function(documentNode) {
if (!documentNode) {
InspectorTest.log("FAIL: DOM node not found.");
InspectorTest.completeTest();
return reject();
}

// Select div#foo for $0.
WebInspector.domTreeManager.querySelector(documentNode.id, "#foo", function(contentNodeId) {
if (!contentNodeId) {
InspectorTest.log("FAIL: DOM node not found.");
return reject();
}

ConsoleAgent.addInspectedNode(contentNodeId);
resolve();
});
});
});
}
}
</script>
</head>
@@ -1,3 +1,14 @@
2015-09-01 Brian Burg <bburg@apple.com>

Web Inspector: rewrite inspector/console/command-line-api.html to use AsyncTestSuite
https://bugs.webkit.org/show_bug.cgi?id=148637

Reviewed by Darin Adler.

* UserInterface/Base/Object.js:
(WebInspector.Object.singleFireEventListener):
(WebInspector.Object.singleFireEventListener.let.wrappedCallback): Arrow.

2015-09-01 Devin Rousso <drousso@apple.com>

Web Inspector: New rule button in the style sidebar is blurry and too dark
@@ -57,10 +57,10 @@ WebInspector.Object = class Object

static singleFireEventListener(eventType, listener, thisObject)
{
let wrappedCallback = function() {
let wrappedCallback = () => {
this.removeEventListener(eventType, wrappedCallback, null);
listener.apply(thisObject, arguments);
}.bind(this);
};

this.addEventListener(eventType, wrappedCallback, null);
return wrappedCallback;

0 comments on commit 22b10d3

Please sign in to comment.