Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix issue 5958

  • Loading branch information...
commit 65a9c5bffcf89691c7fb1f689dbc14ea7f7df293 1 parent c76b381
@fflorent fflorent authored
Showing with 23 additions and 11 deletions.
  1. +23 −11 tests/content/script/watch/5639/issue5639.js
View
34 tests/content/script/watch/5639/issue5639.js
@@ -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");
});
}
Please sign in to comment.
Something went wrong with that request. Please try again.