Commit a173c09b authored by aandrey@chromium.org's avatar aandrey@chromium.org

DevTools: Expand protocol to allow setting DOM event breakpoints on a given event target.

This will allow debugger to pause on "load", "error" and etc. event breakpoints only
when they happen on XHR event targets.

BUG=381470
R=yurys, pfeldman@chromium.org

Review URL: https://codereview.chromium.org/320933003

git-svn-id: svn://svn.chromium.org/blink/trunk@175882 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent fdffd81c
......@@ -223,7 +223,7 @@ InspectorTest._pausedScript = function(callFrames, reason, auxData, breakpointId
{
if (!InspectorTest._quiet)
InspectorTest.addResult("Script execution paused.");
InspectorTest._pausedScriptArguments = [WebInspector.DebuggerModel.CallFrame.fromPayloadArray(WebInspector.targetManager.activeTarget(), callFrames), reason, breakpointIds, asyncStackTrace];
InspectorTest._pausedScriptArguments = [WebInspector.DebuggerModel.CallFrame.fromPayloadArray(WebInspector.targetManager.activeTarget(), callFrames), reason, breakpointIds, asyncStackTrace, auxData];
if (InspectorTest._waitUntilPausedCallback) {
var callback = InspectorTest._waitUntilPausedCallback;
delete InspectorTest._waitUntilPausedCallback;
......
......@@ -8,6 +8,7 @@ Call stack:
0) testElementClicked (event-listener-breakpoints.html:7)
1) addListenerAndClick (event-listener-breakpoints.html:16)
2) (:1)
Event target: Node
Script execution resumed.
Running: testTimerFiredBreakpoint
......@@ -16,3 +17,10 @@ Call stack:
0) timerFired (event-listener-breakpoints.html:19)
Script execution resumed.
Running: testLoadBreakpointOnXHR
Script execution paused.
Call stack:
0) loadCallback (event-listener-breakpoints.html:42)
Event target: XMLHttpRequest
Script execution resumed.
......@@ -21,6 +21,29 @@ function timerFired()
return 0;
}
function addLoadListeners()
{
var xhr = new XMLHttpRequest();
xhr.onload = loadCallback;
xhr.onerror = loadCallback;
xhr.open("GET", "http://localhost/", true);
var img = new Image();
img.onload = sendXHR;
img.onerror = sendXHR;
img.src = "foo/bar/dummy";
function sendXHR()
{
xhr.send();
}
}
function loadCallback()
{
return 0;
}
function test()
{
WebInspector.inspectorView.showPanel("sources");
......@@ -32,16 +55,17 @@ function test()
InspectorTest.waitUntilPaused(paused);
InspectorTest.evaluateInPageWithTimeout("addListenerAndClick()");
function paused(callFrames)
function paused(callFrames, reason, breakpointIds, asyncStackTrace, auxData)
{
InspectorTest.captureStackTrace(callFrames);
printEventTargetName(auxData);
pane._removeBreakpoint("listener:click");
InspectorTest.resumeExecution(resumed);
}
function resumed()
{
InspectorTest.evaluateInPage("addListenerAndClick())", next);
InspectorTest.evaluateInPage("addListenerAndClick()", next);
}
},
......@@ -57,8 +81,39 @@ function test()
pane._removeBreakpoint("instrumentation:timerFired");
InspectorTest.resumeExecution(next);
}
},
function testLoadBreakpointOnXHR(next)
{
DOMDebuggerAgent.setEventListenerBreakpoint("load", "xmlHTTPrequest"); // test case-insensitive match
DOMDebuggerAgent.setEventListenerBreakpoint("error", "XMLHttpRequest");
InspectorTest.waitUntilPaused(paused);
InspectorTest.evaluateInPageWithTimeout("addLoadListeners()");
function paused(callFrames, reason, breakpointIds, asyncStackTrace, auxData)
{
InspectorTest.captureStackTrace(callFrames);
printEventTargetName(auxData);
DOMDebuggerAgent.removeEventListenerBreakpoint("load", "XMLHttpRequest");
DOMDebuggerAgent.removeEventListenerBreakpoint("error", "xmlHTTPrequest");
InspectorTest.resumeExecution(resumed);
}
function resumed()
{
InspectorTest.evaluateInPage("addLoadListeners()", next);
}
}
]);
function printEventTargetName(auxData)
{
var targetName = auxData && auxData.targetName;
if (targetName)
InspectorTest.addResult("Event target: " + targetName);
else
InspectorTest.addResult("FAIL: No event target name received!");
}
}
</script>
......
......@@ -68,8 +68,8 @@ public:
// DOMDebugger API for InspectorFrontend
virtual void setXHRBreakpoint(ErrorString*, const String& url) OVERRIDE;
virtual void removeXHRBreakpoint(ErrorString*, const String& url) OVERRIDE;
virtual void setEventListenerBreakpoint(ErrorString*, const String& eventName) OVERRIDE;
virtual void removeEventListenerBreakpoint(ErrorString*, const String& eventName) OVERRIDE;
virtual void setEventListenerBreakpoint(ErrorString*, const String& eventName, const String* targetName) OVERRIDE;
virtual void removeEventListenerBreakpoint(ErrorString*, const String& eventName, const String* targetName) OVERRIDE;
virtual void setInstrumentationBreakpoint(ErrorString*, const String& eventName) OVERRIDE;
virtual void removeInstrumentationBreakpoint(ErrorString*, const String& eventName) OVERRIDE;
virtual void setDOMBreakpoint(ErrorString*, int nodeId, const String& type) OVERRIDE;
......@@ -104,7 +104,7 @@ private:
InspectorDOMDebuggerAgent(InspectorDOMAgent*, InspectorDebuggerAgent*);
void pauseOnNativeEventIfNeeded(PassRefPtr<JSONObject> eventData, bool synchronous);
PassRefPtr<JSONObject> preparePauseOnNativeEventData(bool isDOMEvent, const String& eventName);
PassRefPtr<JSONObject> preparePauseOnNativeEventData(const String& eventName, const AtomicString* targetName);
// InspectorDOMAgent::Listener implementation.
virtual void domAgentWasEnabled() OVERRIDE;
......@@ -120,8 +120,8 @@ private:
void descriptionForDOMEvent(Node* target, int breakpointType, bool insertion, JSONObject* description);
void updateSubtreeBreakpoints(Node*, uint32_t rootMask, bool set);
bool hasBreakpoint(Node*, int type);
void setBreakpoint(ErrorString*, const String& eventName);
void removeBreakpoint(ErrorString*, const String& eventName);
void setBreakpoint(ErrorString*, const String& eventName, const String* targetName);
void removeBreakpoint(ErrorString*, const String& eventName, const String* targetName);
void clear();
......
......@@ -3348,14 +3348,16 @@
{
"name": "setEventListenerBreakpoint",
"parameters": [
{ "name": "eventName", "type": "string", "description": "DOM Event name to stop on (any DOM event will do)." }
{ "name": "eventName", "type": "string", "description": "DOM Event name to stop on (any DOM event will do)." },
{ "name": "targetName", "type": "string", "optional": true, "description": "EventTarget interface name to stop on. If equal to <code>\"*\"</code> or not provided, will stop on any EventTarget.", "hidden": true }
],
"description": "Sets breakpoint on particular DOM event."
},
{
"name": "removeEventListenerBreakpoint",
"parameters": [
{ "name": "eventName", "type": "string", "description": "Event name." }
{ "name": "eventName", "type": "string", "description": "Event name." },
{ "name": "targetName", "type": "string", "optional": true, "description": "EventTarget interface name.", "hidden": true }
],
"description": "Removes breakpoint on particular DOM event."
},
......
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