Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Enabling the Console panel needs to wait for backend connection (to t…
…he thread actor)
  • Loading branch information
janodvarko committed Jun 25, 2013
1 parent b51e916 commit a7725b9
Showing 1 changed file with 79 additions and 66 deletions.
145 changes: 79 additions & 66 deletions tests/FBTest/content/FBTestFirebug.js
Expand Up @@ -998,73 +998,9 @@ this.disableScriptPanel = function(callback)
*/
this.enableScriptPanel = function(callback)
{
// Wait till the debugger is attached to the current thread (async)
function onCallback(win)
{
var context = FW.Firebug.currentContext;
if (!context)
{
FBTest.ok(context, "There is no current context!" + context);
return;
}

FBTest.sysout("enableScriptPanel.window loaded: " + win.location.href);

var listener;

// If the thread is already attached just execute the callback.
if (context.activeThread)
{
FBTest.sysout("enableScriptPanel.thread-actor already attached " +
context.activeThread.paused, context.activeThread);

// xxxHonza: hack, why the ThreadClient isn't paused too?
var actor = FW.Firebug.DebuggerLib.getThreadActor(context.browser);
var state = actor ? actor._state : "no tab actor";
FBTest.sysout("enableScriptPanel; actor: " + state);

if (state == "paused")
{
listener =
{
onResumed: function()
{
FBTest.sysout("enableScriptPanel.onResumed;");
DebuggerController.removeListener(listener);

if (callback)
callback(win);
}
};
}
else
{
if (callback)
callback(win);
return;
}
}
else
{
// Listener for 'onThreadAttached' event
listener =
{
onThreadAttached: function()
{
FBTest.sysout("enableScriptPanel.onThreadAttached;");
DebuggerController.removeListener(listener);

if (callback)
callback(win);
}
};
}

// Wait till the context is attached to the thread.
if (listener)
DebuggerController.addListener(listener);

FBTest.sysout("enableScriptPanel.add debugger listener; " + listener);
waitForDebuggerAttach(win, callback);
}

var cb = callback ? onCallback : null;
Expand All @@ -1086,7 +1022,13 @@ this.disableConsolePanel = function(callback)
*/
this.enableConsolePanel = function(callback)
{
this.setPanelState(FW.Firebug.Console, "console", callback, true);
function onCallback(win)
{
waitForDebuggerAttach(win, callback);
}

var cb = callback ? onCallback : null;
this.setPanelState(FW.Firebug.Console, "console", cb, true);
};

/**
Expand Down Expand Up @@ -3082,5 +3024,76 @@ this.isMac = function()
return (hiddenWindow.navigator.platform.indexOf("Mac") >= 0);
}

// ********************************************************************************************* //
// JSD2

function waitForDebuggerAttach(win, callback)
{
var context = FW.Firebug.currentContext;
if (!context)
{
FBTest.ok(context, "There is no current context!" + context);
return;
}

FBTest.sysout("waitForDebuggerAttach.window loaded: " + win.location.href);

var listener;

// If the thread is already attached just execute the callback.
if (context.activeThread)
{
FBTest.sysout("waitForDebuggerAttach.thread-actor already attached " +
context.activeThread.paused, context.activeThread);

// xxxHonza: hack, why the ThreadClient isn't paused too?
var actor = FW.Firebug.DebuggerLib.getThreadActor(context.browser);
var state = actor ? actor._state : "no tab actor";
FBTest.sysout("waitForDebuggerAttach; actor: " + state);

if (state == "paused")
{
listener =
{

This comment has been minimized.

Copy link
@fflorent

fflorent Dec 28, 2013

Member

Are you sure about onResume? DebuggerClient doesn't seem to raise such an event.

Florent

This comment has been minimized.

Copy link
@janodvarko

janodvarko Jan 2, 2014

Author Member

Yep, this is wrong. The "resumed" event is sent by ThreadClient object (context.activeThread).

So, the logic should be something like as follows:

  1. If the thread is attached and not paused, just execute the callback.
  2. If the thread is attached and paused, register "resumed" listener to context.activeThread object
  3. If the thread is not attached yet, register "onThreadAttached" listener to DebuggerController object
  4. When "onThreadAttached" is sent, check if it's for the right context and register "resumed" listener to context.activeThread object.

Do you want to take a look at this?
(in any case, It would be useful to have an issue report + a test scenario for this)

Honza

onResumed: function()
{
FBTest.sysout("waitForDebuggerAttach.onResumed;");
DebuggerController.removeListener(listener);

if (callback)
callback(win);
}
};
}
else
{
if (callback)
callback(win);
return;
}
}
else
{
// Listener for 'onThreadAttached' event
listener =
{
onThreadAttached: function()
{
FBTest.sysout("waitForDebuggerAttach.onThreadAttached;");
DebuggerController.removeListener(listener);

if (callback)
callback(win);
}
};
}

// Wait till the context is attached to the thread.
if (listener)
DebuggerController.addListener(listener);

FBTest.sysout("waitForDebuggerAttach.add debugger listener; " + listener);
}

// ********************************************************************************************* //
}).apply(FBTest);

0 comments on commit a7725b9

Please sign in to comment.