Fix issue 5958 #48

Merged
merged 1 commit into from Oct 8, 2012
+23 −11
Split
@@ -32,20 +32,32 @@ function testDeleteAllWatches(callback, panelNode, targetSelector, watchExpressi
{
addWatches(watchExpressions.slice(0), function()
{
- FBTest.compare(watchExpressions.length, countWatches(panelNode), "all the watches must be added");
+ FBTest.compare(watchExpressions.length, countWatches(panelNode),
+ "all the watches must be added");
var target = panelNode.querySelector(targetSelector);
- FBTest.executeContextMenuCommand(target, "fbDeleteAllWatches", function()
+
+ var timeout, compareAndCallback, observer;
+ compareAndCallback = function()
{
- // xxxHonza: needs to be done properly.
- // The code should handle a mutation event or periodically check (for
- // limited amount of time) if the watch window is empty.
- // See: http://code.google.com/p/fbug/issues/detail?id=5958
- setTimeout(function()
- {
- FBTest.compare(0, countWatches(panelNode), "There should not be any watch");
- callback();
- }, 1000);
+ FBTest.compare(0, countWatches(panelNode), "There should not be any watch");
+ clearTimeout(timeout);
+ observer.disconnect();
+ callback();
+ };
+ // the timeout is triggered if the MutationObserver has not detected
+ // the deletion of the watch expressions
+ timeout = setTimeout(compareAndCallback, 1000);
+
+ observer = new MutationObserver(function(mutations)
+ {
+ // if there is no watch any more, we run compareAndCallback now
+ // otherwise, we wait for another mutation or for the timeout
+ if (countWatches(panelNode) === 0)
+ compareAndCallback();
});
+ observer.observe(panelNode, {childList: true});
+
+ FBTest.executeContextMenuCommand(target, "fbDeleteAllWatches");
});
}