Commit e09741d1 authored by sergeyv@chromium.org's avatar sergeyv@chromium.org

DevTools: Add test multi-target-breakpoint-manager.html

BUG=

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

git-svn-id: svn://svn.chromium.org/blink/trunk@176204 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 09bb0b1e
......@@ -36,18 +36,10 @@ function test()
serializedBreakpoints.push(createBreakpoint("a.js", 20, "", false));
serializedBreakpoints.push(createBreakpoint("b.js", 3, "", true));
var mockTarget = {
id: function()
{
return 1;
}
};
var targetManager = new WebInspector.TargetManager();
var mockTarget = InspectorTest.createMockTarget(targetManager, 1);
targetManager._targets.push(mockTarget);
InspectorTest.setupLiveLocationSniffers();
InspectorTest.initializeDefaultMappingOnTarget(mockTarget);
var addUISourceCode = InspectorTest.addUISourceCode.bind(null, mockTarget);
var createBreakpointManager = InspectorTest.createBreakpointManager.bind(null, targetManager);
......
......@@ -2,6 +2,8 @@ var initialize_BreakpointManagerTest = function() {
InspectorTest.uiSourceCodes = {};
InspectorTest.dumpTargetIds = false;
InspectorTest.initializeDefaultMappingOnTarget = function (target) {
var defaultMapping = {
rawLocationToUILocation: function(rawLocation)
......@@ -25,6 +27,23 @@ InspectorTest.initializeDefaultMappingOnTarget = function (target) {
target.defaultMapping = defaultMapping;
}
InspectorTest.createMockTarget = function(targetManager, id)
{
var target = {
id: function()
{
return id;
}
};
InspectorTest.initializeDefaultMappingOnTarget(target);
return target;
}
InspectorTest.dumpTarget = function(targetAware)
{
return InspectorTest.dumpTargetIds ? "target " + targetAware.target().id() + " " : "";
}
InspectorTest.DebuggerModelMock = function (target, sourceMapping)
{
target.debuggerModel = this;
......@@ -79,7 +98,7 @@ InspectorTest.DebuggerModelMock.prototype = {
setBreakpointByURL: function(url, lineNumber, columnNumber, condition, callback)
{
InspectorTest.addResult(" debuggerModel.setBreakpoint(" + [url, lineNumber, condition].join(":") + ")");
InspectorTest.addResult(" " + InspectorTest.dumpTarget(this) + "debuggerModel.setBreakpoint(" + [url, lineNumber, condition].join(":") + ")");
var breakpointId = url + ":" + lineNumber;
if (this._breakpoints[breakpointId]) {
......@@ -100,7 +119,7 @@ InspectorTest.DebuggerModelMock.prototype = {
setBreakpointByScriptLocation: function(location, condition, callback)
{
InspectorTest.addResult(" debuggerModel.setBreakpoint(" + [location.scriptId, location.lineNumber, condition].join(":") + ")");
InspectorTest.addResult(" " + InspectorTest.dumpTarget(this) + "debuggerModel.setBreakpoint(" + [location.scriptId, location.lineNumber, condition].join(":") + ")");
var breakpointId = location.scriptId + ":" + location.lineNumber;
if (this._breakpoints[breakpointId]) {
......@@ -124,7 +143,7 @@ InspectorTest.DebuggerModelMock.prototype = {
removeBreakpoint: function(breakpointId, callback)
{
InspectorTest.addResult(" debuggerModel.removeBreakpoint(" + breakpointId + ")");
InspectorTest.addResult(" " + InspectorTest.dumpTarget(this) + "debuggerModel.removeBreakpoint(" + breakpointId + ")");
delete this._breakpoints[breakpointId];
if (callback)
callback();
......@@ -182,11 +201,11 @@ InspectorTest.setupLiveLocationSniffers = function()
{
InspectorTest.addSniffer(WebInspector.Script.prototype, "createLiveLocation", function(rawLocation)
{
InspectorTest.addResult(" Location created: " + rawLocation.scriptId + ":" + rawLocation.lineNumber);
InspectorTest.addResult(" Location created: " + InspectorTest.dumpTarget(rawLocation) + rawLocation.scriptId + ":" + rawLocation.lineNumber);
}, true);
InspectorTest.addSniffer(WebInspector.Script.Location.prototype, "dispose", function()
{
InspectorTest.addResult(" Location disposed: " + this._rawLocation.scriptId + ":" + this._rawLocation.lineNumber);
InspectorTest.addResult(" Location disposed: " + InspectorTest.dumpTarget(this._rawLocation) + this._rawLocation.scriptId + ":" + this._rawLocation.lineNumber);
}, true);
}
......
Tests BreakpointManager class.
Running: testResolvedBreakpointInBothTarget
Created breakpoints manager
Dumping Storage
Adding UISourceCode: a.js
Setting breakpoint at a.js:30:0 enabled:true condition:
breakpointAdded(a.js, 30, 0, , true)
target 1 debuggerModel.setBreakpoint(a.js:30:)
breakpointRemoved(a.js, 30, 0)
breakpointAdded(a.js, 30, 0, , true)
Location created: target 1 a.js:30
breakpointAdded(a.js, 131, 0, , true)
Location created: target 1 a.js:131
Dumping Breakpoint Locations
UISourceCode (url='a.js', uri='a.js')
Location: (30, 0)
Location: (131, 0)
Second target added
target 2 debuggerModel.setBreakpoint(a.js:30:)
Location created: target 2 a.js:30
Dumping Breakpoint Locations
UISourceCode (url='a.js', uri='a.js')
Location: (30, 0)
Location: (131, 0)
First target removed
breakpointRemoved(a.js, 131, 0)
Location disposed: target 1 a.js:30
Location disposed: target 1 a.js:131
Dumping Breakpoint Locations
UISourceCode (url='a.js', uri='a.js')
Location: (30, 0)
Second target removed
breakpointRemoved(a.js, 30, 0)
breakpointAdded(a.js, 30, 0, , true)
Location disposed: target 2 a.js:30
Dumping Breakpoint Locations
UISourceCode (url='a.js', uri='a.js')
Location: (30, 0)
Dumping Storage
a.js:30 enabled:true condition:
Resetting breakpoint manager
breakpointRemoved(a.js, 30, 0)
Dumping Breakpoint Locations
Running: testResolvedBreakpointInOneTarget
Created breakpoints manager
Dumping Storage
Adding UISourceCode: a.js
Setting breakpoint at a.js:30:0 enabled:true condition:
breakpointAdded(a.js, 30, 0, , true)
target 1 debuggerModel.setBreakpoint(a.js:30:)
target 2 debuggerModel.setBreakpoint(a.js:30:)
breakpointRemoved(a.js, 30, 0)
breakpointAdded(a.js, 30, 0, , true)
Location created: target 1 a.js:30
First target removed!
breakpointRemoved(a.js, 30, 0)
breakpointAdded(a.js, 30, 0, , true)
Location disposed: target 1 a.js:30
Dumping Breakpoint Locations
UISourceCode (url='a.js', uri='a.js')
Location: (30, 0)
Dumping Breakpoint Locations
UISourceCode (url='a.js', uri='a.js')
Location: (30, 0)
Dumping Storage
a.js:30 enabled:true condition:
Resetting breakpoint manager
breakpointRemoved(a.js, 30, 0)
target 2 debuggerModel.removeBreakpoint(a.js:30)
Dumping Breakpoint Locations
<html>
<head>
<script src="../../../http/tests/inspector/inspector-test.js"></script>
<script src="breakpoint-manager.js"></script>
<script>
function test()
{
InspectorTest.dumpTargetIds = true;
InspectorTest.setupLiveLocationSniffers();
InspectorTest.runTestSuite([
function testResolvedBreakpointInBothTarget(next)
{
var targetManager = new WebInspector.TargetManager();
var target1 = InspectorTest.createMockTarget(targetManager, 1);
targetManager._targets.push(target1);
var breakpointManager = InspectorTest.createBreakpointManager(targetManager);
var uiSourceCode = InspectorTest.addUISourceCode(target1, breakpointManager, "a.js");
var target2;
InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 30, 0, "", true, step1);
function step1()
{
target1.debuggerModel._breakpointResolved("a.js:30", new WebInspector.DebuggerModel.Location(target1, "a.js", 131, 5));
InspectorTest.dumpBreakpointLocations(breakpointManager);
InspectorTest.addResult(" Second target added");
target2 = InspectorTest.createMockTarget(targetManager, 2);
new InspectorTest.DebuggerModelMock(target2, target2.defaultMapping);
targetManager.addTarget(target2);
target2.debuggerModel._addScript("a.js", "a.js");
uiSourceCode.setSourceMappingForTarget(target2, target2.defaultMapping);
window.setBreakpointCallback = step2;
}
function step2()
{
target2.debuggerModel._breakpointResolved("a.js:30", new WebInspector.DebuggerModel.Location(target2, "a.js", 30, 5));
InspectorTest.dumpBreakpointLocations(breakpointManager);
InspectorTest.addResult(" First target removed")
targetManager.removeTarget(target1);
InspectorTest.dumpBreakpointLocations(breakpointManager);
InspectorTest.addResult(" Second target removed")
targetManager.removeTarget(target2);
InspectorTest.finishBreakpointTest(breakpointManager, next)
}
},
function testResolvedBreakpointInOneTarget(next)
{
var targetManager = new WebInspector.TargetManager();
var target1 = InspectorTest.createMockTarget(targetManager, 1);
var target2 = InspectorTest.createMockTarget(targetManager, 2);
targetManager._targets.push(target1);
targetManager._targets.push(target2);
var breakpointManager = InspectorTest.createBreakpointManager(targetManager);
var uiSourceCode = InspectorTest.addUISourceCode(target1, breakpointManager, "a.js");
InspectorTest.setBreakpoint(breakpointManager, uiSourceCode, 30, 0, "", true, step1);
function step1()
{
window.setBreakpointCallback = step2;
}
function step2()
{
InspectorTest.addResult(" First target removed!")
targetManager.removeTarget(target1);
InspectorTest.dumpBreakpointLocations(breakpointManager);
InspectorTest.finishBreakpointTest(breakpointManager, next);
}
},
]);
};
</script>
</head>
<body onload="runTest()">
<p>Tests BreakpointManager class.</p>
</body>
</html>
......@@ -256,15 +256,33 @@ WebInspector.TargetManager.prototype = {
* @param {!WebInspector.Target} newTarget
*/
function callbackWrapper(newTarget)
{
this.addTarget(newTarget);
if (callback)
callback(newTarget);
}
},
/**
* @param {!WebInspector.Target} newTarget
*/
addTarget: function(newTarget)
{
this._targets.push(newTarget);
var copy = this._observers;
for (var i = 0; i < copy.length; ++i)
copy[i].targetAdded(newTarget);
},
if (callback)
callback(newTarget);
}
/**
* @param {!WebInspector.Target} target
*/
removeTarget: function(target)
{
this._targets.remove(target);
var copy = this._observers;
for (var i = 0; i < copy.length; ++i)
copy[i].targetRemoved(target);
},
/**
......
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