Bug 663714 - Subscribable API doesn't seem sane; r=dao

This commit is contained in:
Tim Taubert 2011-07-14 10:54:25 -07:00
parent a5d99a818a
commit 7551d43e58
33 changed files with 158 additions and 245 deletions

View File

@ -86,6 +86,8 @@ function GroupItem(listOfEls, options) {
this.keepProportional = false;
this._frozenItemSizeData = {};
this._onChildClose = this._onChildClose.bind(this);
// Variable: _activeTab
// The <TabItem> for the groupItem's active tab.
this._activeTab = null;
@ -818,7 +820,7 @@ GroupItem.prototype = Utils.extend(new Item(), new Subscribable(), {
let shouldRemoveTabItems = [];
let toClose = this._children.concat();
toClose.forEach(function(child) {
child.removeSubscriber(self, "close");
child.removeSubscriber("close", self._onChildClose);
let removed = child.close(true);
if (removed) {
@ -826,7 +828,7 @@ GroupItem.prototype = Utils.extend(new Item(), new Subscribable(), {
} else {
// child.removeSubscriber() must be called before child.close(),
// therefore we call child.addSubscriber() if the tab is not removed.
child.addSubscriber(self, "close", self._onChildClose.bind(self));
child.addSubscriber("close", self._onChildClose);
}
});
@ -1009,7 +1011,7 @@ GroupItem.prototype = Utils.extend(new Item(), new Subscribable(), {
item.droppable(false);
item.groupItemData = {};
item.addSubscriber(this, "close", this._onChildClose.bind(this));
item.addSubscriber("close", this._onChildClose);
item.setParent(this);
if (typeof item.setResizable == 'function')
@ -1110,7 +1112,7 @@ GroupItem.prototype = Utils.extend(new Item(), new Subscribable(), {
item.setBounds(item.getBounds(), true, {force: true});
item.droppable(true);
item.removeSubscriber(this, "close");
item.removeSubscriber("close", this._onChildClose);
if (typeof item.setResizable == 'function')
item.setResizable(true, options.immediately);

View File

@ -405,10 +405,8 @@ Subscribable.prototype = {
// ----------
// Function: addSubscriber
// The given callback will be called when the Subscribable fires the given event.
// The refObject is used to facilitate removal if necessary.
addSubscriber: function Subscribable_addSubscriber(refObject, eventName, callback) {
addSubscriber: function Subscribable_addSubscriber(eventName, callback) {
try {
Utils.assertThrow(refObject, "refObject");
Utils.assertThrow(typeof callback == "function", "callback must be a function");
Utils.assertThrow(eventName && typeof eventName == "string",
"eventName must be a non-empty string");
@ -423,28 +421,17 @@ Subscribable.prototype = {
if (!this.subscribers[eventName])
this.subscribers[eventName] = [];
var subs = this.subscribers[eventName];
var existing = subs.filter(function(element) {
return element.refObject == refObject;
});
if (existing.length) {
Utils.assert(existing.length == 1, 'should only ever be one');
existing[0].callback = callback;
} else {
subs.push({
refObject: refObject,
callback: callback
});
}
let subscribers = this.subscribers[eventName];
if (subscribers.indexOf(callback) == -1)
subscribers.push(callback);
},
// ----------
// Function: removeSubscriber
// Removes the callback associated with refObject for the given event.
removeSubscriber: function Subscribable_removeSubscriber(refObject, eventName) {
// Removes the subscriber associated with the event for the given callback.
removeSubscriber: function Subscribable_removeSubscriber(eventName, callback) {
try {
Utils.assertThrow(refObject, "refObject");
Utils.assertThrow(typeof callback == "function", "callback must be a function");
Utils.assertThrow(eventName && typeof eventName == "string",
"eventName must be a non-empty string");
} catch(e) {
@ -455,9 +442,11 @@ Subscribable.prototype = {
if (!this.subscribers || !this.subscribers[eventName])
return;
this.subscribers[eventName] = this.subscribers[eventName].filter(function(element) {
return element.refObject != refObject;
});
let subscribers = this.subscribers[eventName];
let index = subscribers.indexOf(callback);
if (index > -1)
subscribers.splice(index, 1);
},
// ----------
@ -475,10 +464,10 @@ Subscribable.prototype = {
if (!this.subscribers || !this.subscribers[eventName])
return;
var subsCopy = this.subscribers[eventName].concat();
subsCopy.forEach(function(object) {
let subsCopy = this.subscribers[eventName].concat();
subsCopy.forEach(function (callback) {
try {
object.callback(this, eventInfo);
callback(this, eventInfo);
} catch(e) {
Utils.log(e);
}

View File

@ -400,21 +400,28 @@ let UI = {
if (this._activeTab) {
this._activeTab.makeDeactive();
this._activeTab.removeSubscriber(this, "close");
this._activeTab.removeSubscriber("close", this._onActiveTabClosed);
}
this._activeTab = tabItem;
if (this._activeTab) {
let self = this;
this._activeTab.addSubscriber(this, "close", function(closedTabItem) {
if (self._activeTab == closedTabItem)
self._setActiveTab(null);
});
this._activeTab.addSubscriber("close", this._onActiveTabClosed);
this._activeTab.makeActive();
}
},
// ----------
// Function: _onActiveTabClosed
// Handles when the currently active tab gets closed.
//
// Parameters:
// - the <TabItem> that is closed
_onActiveTabClosed: function UI__onActiveTabClosed(tabItem){
if (UI._activeTab == tabItem)
UI._setActiveTab(null);
},
// ----------
// Function: setActive
// Sets the active tab item or group item

View File

@ -58,8 +58,8 @@ function testGroups(groupItemOne, groupItemTwo, contentWindow) {
"The first tab item in group two is active");
let tabItem = groupItemOne.getChild(1);
tabItem.addSubscriber(tabItem, "tabRemoved", function() {
tabItem.removeSubscriber(tabItem, "tabRemoved");
tabItem.addSubscriber("tabRemoved", function onTabRemoved() {
tabItem.removeSubscriber("tabRemoved", onTabRemoved);
is(groupItemOne.getChildren().length, 1,
"The num of childen in group one is 1");
@ -76,8 +76,8 @@ function testGroups(groupItemOne, groupItemTwo, contentWindow) {
"The num of childen in group one is 2");
// clean up and finish
groupItemTwo.addSubscriber(groupItemTwo, "close", function() {
groupItemTwo.removeSubscriber(groupItemTwo, "close");
groupItemTwo.addSubscriber("close", function onClose() {
groupItemTwo.removeSubscriber("close", onClose);
gBrowser.removeTab(groupItemOne.getChild(1).tab);
is(contentWindow.GroupItems.groupItems.length, 1, "Has only one group");

View File

@ -46,8 +46,8 @@ function onTabViewWindowLoaded() {
is(group.getChildren()[0].tab.linkedBrowser.contentWindow.location, secondTab.linkedBrowser.contentWindow.location, "The second tab was there first");
is(group.getChildren()[1].tab.linkedBrowser.contentWindow.location, firstTab.linkedBrowser.contentWindow.location, "The first tab was just added and went to the end of the line");
group.addSubscriber(group, "close", function() {
group.removeSubscriber(group, "close");
group.addSubscriber("close", function onClose() {
group.removeSubscriber("close", onClose);
ok(group.isEmpty(), "The group is empty again");

View File

@ -29,14 +29,14 @@ function testCloseLastGroup() {
{ type: "click" }, groupItem.$undoContainer[0], contentWindow);
};
groupItem.addSubscriber(groupItem, "groupHidden", function() {
groupItem.removeSubscriber(groupItem, "groupHidden");
groupItem.addSubscriber("groupHidden", function onHidden() {
groupItem.removeSubscriber("groupHidden", onHidden);
// it should still stay after 3 ms.
setTimeout(checkExistence, 3);
});
groupItem.addSubscriber(groupItem, "groupShown", function() {
groupItem.removeSubscriber(groupItem, "groupShown");
groupItem.addSubscriber("groupShown", function onShown() {
groupItem.removeSubscriber("groupShown", onShown);
let endGame = function() {
window.removeEventListener("tabviewhidden", endGame, false);

View File

@ -26,8 +26,8 @@ function onTabViewWindowLoaded() {
ok(group1.getChildren().some(function(child) child == tab1Item), "The tab was made in our new group");
is(group1.getChildren().length, 1, "Only one tab in the first group");
group1.addSubscriber(group1, "close", function() {
group1.removeSubscriber(group1, "close");
group1.addSubscriber("close", function onClose() {
group1.removeSubscriber("close", onClose);
let onTabViewHidden = function() {
window.removeEventListener("tabviewhidden", onTabViewHidden, false);
@ -45,16 +45,11 @@ function onTabViewWindowLoaded() {
});
});
group1.addSubscriber(group1, "groupHidden", function() {
group1.removeSubscriber(group1, "groupHidden");
hideGroupItem(group1, function () {
// close undo group
let closeButton = group1.$undoContainer.find(".close");
EventUtils.sendMouseEvent(
{ type: "click" }, closeButton[0], contentWindow);
});
// Get rid of the group and its children
group1.closeAll();
}

View File

@ -35,8 +35,8 @@ function setupTwo(win) {
// force all canvases to update, and hook in imageData save detection
tabItems.forEach(function(tabItem) {
contentWindow.TabItems.update(tabItem.tab);
tabItem.addSubscriber(tabItem, "savedCachedImageData", function(item) {
item.removeSubscriber(item, "savedCachedImageData");
tabItem.addSubscriber("savedCachedImageData", function onSaved(item) {
item.removeSubscriber("savedCachedImageData", onSaved);
--numTabsToSave;
});
});
@ -87,8 +87,8 @@ function setupTwo(win) {
let count = tabItems.length;
tabItems.forEach(function(tabItem) {
tabItem.addSubscriber(tabItem, "loadedCachedImageData", function() {
tabItem.removeSubscriber(tabItem, "loadedCachedImageData");
tabItem.addSubscriber("loadedCachedImageData", function onLoaded() {
tabItem.removeSubscriber("loadedCachedImageData", onLoaded);
ok(tabItem.isShowingCachedData(),
"Tab item is showing cached data and is just connected. " +
tabItem.tab.linkedBrowser.currentURI.spec);

View File

@ -36,8 +36,8 @@ function onTabViewWindowLoaded() {
function testStayOnPage(contentWindow, groupItemOne, groupItemTwo) {
setupAndRun(contentWindow, groupItemOne, groupItemTwo, function(doc) {
groupItemTwo.addSubscriber(groupItemTwo, "groupShown", function() {
groupItemTwo.removeSubscriber(groupItemTwo, "groupShown");
groupItemTwo.addSubscriber("groupShown", function onShown() {
groupItemTwo.removeSubscriber("groupShown", onShown);
is(gBrowser.tabs.length, 2,
"The total number of tab is 2 when staying on the page");
@ -61,8 +61,8 @@ function testStayOnPage(contentWindow, groupItemOne, groupItemTwo) {
function testLeavePage(contentWindow, groupItemOne, groupItemTwo) {
setupAndRun(contentWindow, groupItemOne, groupItemTwo, function(doc) {
// clean up and finish the test
groupItemTwo.addSubscriber(groupItemTwo, "close", function() {
groupItemTwo.removeSubscriber(groupItemTwo, "close");
groupItemTwo.addSubscriber("close", function onClose() {
groupItemTwo.removeSubscriber("close", onClose);
is(gBrowser.tabs.length, 1,
"The total number of tab is 1 after leaving the page");

View File

@ -26,8 +26,8 @@ function test() {
cw.TabItems.pausePainting();
groupItem.getChildren().forEach(function (tabItem) {
tabItem.addSubscriber(tabItem, "updated", function () {
tabItem.removeSubscriber(tabItem, "updated");
tabItem.addSubscriber("updated", function onUpdated() {
tabItem.removeSubscriber("updated", onUpdated);
tabItem._testLastTabUpdateTime = tabItem._lastTabUpdateTime;
if (--numTabsToUpdate)

View File

@ -36,12 +36,7 @@ function test() {
let groupItem = cw.GroupItems.groupItems[1];
is(groupItem.getTitle(), "t", "new groupItem's title is correct");
groupItem.addSubscriber(groupItem, "close", function () {
groupItem.removeSubscriber(groupItem, "close");
executeSoon(callback);
});
groupItem.closeAll();
closeGroupItem(groupItem, callback);
};
let testDragOutOfGroup = function (callback) {

View File

@ -28,8 +28,7 @@ function onTabViewWindowLoaded() {
ok(TabView.isVisible(), "Tab View is still visible after removing a tab");
is(groupItems[0].getChildren().length, 2, "The group has two tab items");
tabTwo = undoCloseTab(0);
whenTabIsReconnected(tabTwo, function() {
restoreTab(function (tabTwo) {
ok(TabView.isVisible(), "Tab View is still visible after restoring a tab");
is(groupItems[0].getChildren().length, 3, "The group still has three tab items");
@ -41,18 +40,3 @@ function onTabViewWindowLoaded() {
});
});
}
// ----------
function whenTabIsReconnected(tab, callback) {
let tabItem = tab._tabViewTabItem;
if (tabItem._reconnected) {
callback();
return;
}
tabItem.addSubscriber(tabItem, "reconnected", function () {
tabItem.removeSubscriber(tabItem, "reconnected");
callback();
});
}

View File

@ -18,9 +18,7 @@ function onTabViewWindowLoaded() {
is(gBrowser.tabs.length, 1, "There is one tab on startup");
let groupItem = contentWindow.GroupItems.groupItems[0];
groupItem.addSubscriber(groupItem, "groupHidden", function() {
groupItem.removeSubscriber(groupItem, "groupHidden");
hideGroupItem(groupItem, function () {
let onTabViewHidden = function() {
window.removeEventListener("tabviewhidden", onTabViewHidden, false);
is(contentWindow.GroupItems.groupItems.length, 1,
@ -35,5 +33,4 @@ function onTabViewWindowLoaded() {
TabView.hide();
});
groupItem.closeAll();
}

View File

@ -160,13 +160,13 @@ function test() {
ok(groupItem.isStacked(), 'testExpandedMode: group is stacked');
groupItem.addSubscriber(groupItem, 'expanded', function () {
groupItem.removeSubscriber(groupItem, 'expanded');
groupItem.addSubscriber('expanded', function onGroupExpanded() {
groupItem.removeSubscriber('expanded', onGroupExpanded);
onExpanded();
});
groupItem.addSubscriber(groupItem, 'collapsed', function () {
groupItem.removeSubscriber(groupItem, 'collapsed');
groupItem.addSubscriber('collapsed', function onGroupCollapsed() {
groupItem.removeSubscriber('collapsed', onGroupCollapsed);
onCollapsed();
});

View File

@ -36,8 +36,8 @@ function onTabViewWindowLoaded(win) {
ok(!group.shouldStack(group._children.length), "Group should not stack.");
// PREPARE FINISH:
group.addSubscriber(group, "close", function() {
group.removeSubscriber(group, "close");
group.addSubscriber("close", function onClose() {
group.removeSubscriber("close", onClose);
ok(group.isEmpty(), "The group is empty again");
@ -78,11 +78,7 @@ function onTabViewWindowLoaded(win) {
// Get rid of the group and its children
// The group close will trigger a finish().
group.addSubscriber(group, "groupHidden", function() {
group.removeSubscriber(group, "groupHidden");
group.closeHidden();
});
group.closeAll();
closeGroupItem(group);
}, win);
}, win);
}

View File

@ -20,23 +20,6 @@ function test() {
return groupItem;
}
let hideGroupItem = function (groupItem, callback) {
groupItem.addSubscriber(groupItem, 'groupHidden', function () {
groupItem.removeSubscriber(groupItem, 'groupHidden');
callback();
});
groupItem.closeAll();
}
let closeGroupItem = function (groupItem, callback) {
afterAllTabsLoaded(function () {
hideGroupItem(groupItem, function () {
groupItem.closeHidden();
callback();
});
});
}
let tests = [];
let next = function () {

View File

@ -41,20 +41,6 @@ function test() {
return createTab('about:blank');
}
let restoreTab = function (callback) {
let tab = undoCloseTab(0);
if (tab._tabViewTabItem._reconnected) {
afterAllTabsLoaded(callback);
return;
}
tab._tabViewTabItem.addSubscriber(tab, 'reconnected', function () {
tab._tabViewTabItem.removeSubscriber(tab, 'reconnected');
afterAllTabsLoaded(callback);
});
}
let finishTest = function () {
prefix = 'finish';
assertValidPrerequisites();

View File

@ -39,10 +39,7 @@ function test1() {
ok(!contentWindow.ThumbnailStorage._shouldSaveThumbnail(newTab),
"Should not save the thumbnail for tab");
tabItem.addSubscriber(tabItem, "deniedToCacheImageData", function() {
tabItem.removeSubscriber(tabItem, "deniedToCacheImageData");
test2();
});
whenDeniedToCacheImageData(tabItem, test2);
tabItem.save(true);
HttpRequestObserver.cacheControlValue = null;
});
@ -59,10 +56,7 @@ function test2() {
ok(contentWindow.ThumbnailStorage._shouldSaveThumbnail(newTab),
"Should save the thumbnail for tab");
tabItem.addSubscriber(tabItem, "savedCachedImageData", function() {
tabItem.removeSubscriber(tabItem, "savedCachedImageData");
test3();
});
whenSavedCachedImageData(tabItem, test3);
tabItem.save(true);
});
}
@ -82,11 +76,7 @@ function test3() {
ok(contentWindow.ThumbnailStorage._shouldSaveThumbnail(newTab),
"Should save the thumbnail for tab");
tabItem.addSubscriber(tabItem, "savedCachedImageData", function() {
tabItem.removeSubscriber(tabItem, "savedCachedImageData");
test4();
});
whenSavedCachedImageData(tabItem, test4);
tabItem.save(true);
});
}
@ -104,11 +94,7 @@ function test4() {
ok(contentWindow.ThumbnailStorage._shouldSaveThumbnail(newTab),
"Should save the thumbnail for tab");
tabItem.addSubscriber(tabItem, "savedCachedImageData", function() {
tabItem.removeSubscriber(tabItem, "savedCachedImageData");
test5();
});
whenSavedCachedImageData(tabItem, test5);
tabItem.save(true);
});
}
@ -124,9 +110,7 @@ function test5() {
ok(!contentWindow.ThumbnailStorage._shouldSaveThumbnail(newTab),
"Should not the thumbnail for tab");
tabItem.addSubscriber(tabItem, "deniedToCacheImageData", function() {
tabItem.removeSubscriber(tabItem, "deniedToCacheImageData");
whenDeniedToCacheImageData(tabItem, function () {
hideTabView(function () {
gBrowser.removeTab(gBrowser.tabs[1]);
finish();
@ -154,3 +138,17 @@ let HttpRequestObserver = {
Services.obs.removeObserver(this, "http-on-examine-response");
}
};
function whenSavedCachedImageData(tabItem, callback) {
tabItem.addSubscriber("savedCachedImageData", function onSaved() {
tabItem.removeSubscriber("savedCachedImageData", onSaved);
callback();
});
}
function whenDeniedToCacheImageData(tabItem, callback) {
tabItem.addSubscriber("deniedToCacheImageData", function onDenied() {
tabItem.removeSubscriber("deniedToCacheImageData", onDenied);
callback();
});
}

View File

@ -19,11 +19,11 @@ function test() {
afterAllTabsLoaded(function () {
tabItem = tab._tabViewTabItem;
tabItem.addSubscriber(tabItem, "savedCachedImageData", function () {
tabItem.removeSubscriber(tabItem, "savedCachedImageData");
tabItem.addSubscriber("savedCachedImageData", function onSaved() {
tabItem.removeSubscriber("savedCachedImageData", onSaved);
tabItem.addSubscriber(tabItem, "loadedCachedImageData", function () {
tabItem.removeSubscriber(tabItem, "loadedCachedImageData");
tabItem.addSubscriber("loadedCachedImageData", function onLoaded() {
tabItem.removeSubscriber("loadedCachedImageData", onLoaded);
ok(tabItem.isShowingCachedData(), 'tabItem shows cached data');
testChangeUrlAfterReconnect();

View File

@ -28,10 +28,10 @@ function onTabViewWindowLoaded(win) {
function check() {
if (groupOrTab == 'group') {
group.removeSubscriber(group, "groupHidden", check);
group.removeSubscriber("groupHidden", check);
group.closeHidden();
} else
tab.removeSubscriber(tab, "tabRemoved", check);
tab.removeSubscriber("tabRemoved", check);
is(contentWindow.GroupItems.getActiveGroupItem(), originalGroup,
"The original group is active.");
@ -42,10 +42,10 @@ function onTabViewWindowLoaded(win) {
}
if (groupOrTab == 'group') {
group.addSubscriber(group, "groupHidden", check);
group.addSubscriber("groupHidden", check);
group.closeAll();
} else {
tab.addSubscriber(tab, "tabRemoved", check);
tab.addSubscriber("tabRemoved", check);
tab.close();
}
}
@ -58,4 +58,4 @@ function onTabViewWindowLoaded(win) {
finish();
});
});
}
}

View File

@ -25,20 +25,6 @@ function test() {
return cw.GroupItems.groupItems[index];
}
let restoreTab = function (callback) {
let tab = undoCloseTab(0);
if (tab._tabViewTabItem._reconnected) {
callback();
return;
}
tab._tabViewTabItem.addSubscriber(tab, 'reconnected', function () {
tab._tabViewTabItem.removeSubscriber(tab, 'reconnected');
afterAllTabsLoaded(callback);
});
}
let activateFirstGroupItem = function () {
let activeTabItem = getGroupItem(0).getChild(0);
cw.GroupItems.updateActiveGroupItemAndTabBar(activeTabItem);

View File

@ -19,12 +19,7 @@ function test() {
// show the undo close group button
let group = contentWindow.GroupItems.groupItems[0];
group.closeAll();
group.addSubscriber(group, "groupHidden", function() {
group.removeSubscriber(group, "groupHidden");
restore(group.id);
});
hideGroupItem(group, function () restore(group.id));
},
function(newWin) {
win = newWin;

View File

@ -43,13 +43,13 @@ function test() {
}
let testDragOutOfExpandedStackedGroup = function () {
groupItem.addSubscriber(groupItem, "expanded", function () {
groupItem.removeSubscriber(groupItem, "expanded");
groupItem.addSubscriber("expanded", function onExpanded() {
groupItem.removeSubscriber("expanded", onExpanded);
dragTabItem();
});
groupItem.addSubscriber(groupItem, "collapsed", function () {
groupItem.removeSubscriber(groupItem, "collapsed");
groupItem.addSubscriber("collapsed", function onCollapsed() {
groupItem.removeSubscriber("collapsed", onCollapsed);
let secondGroup = cw.GroupItems.groupItems[1];
closeGroupItem(secondGroup, function () hideTabView(finishTest));

View File

@ -71,8 +71,8 @@ function testCreateTabAndThen(callback) {
registerCleanupFunction(function () gBrowser.removeTab(tab))
tabItem.addSubscriber(tabItem, "zoomedIn", function() {
tabItem.removeSubscriber(tabItem, "zoomedIn");
tabItem.addSubscriber("zoomedIn", function onZoomedIn() {
tabItem.removeSubscriber("zoomedIn", onZoomedIn);
is(gBrowser.selectedTab, tab,
"The selected tab is the same as the newly opened tab");

View File

@ -21,8 +21,8 @@ function test() {
cw.TabItems.pausePainting();
tabItem.addSubscriber(tabItem, "updated", function () {
tabItem.removeSubscriber(tabItem, "updated");
tabItem.addSubscriber("updated", function onUpdated() {
tabItem.removeSubscriber("updated", onUpdated);
ok(isIdle, "tabItem is updated only when UI is idle");
finish();
});

View File

@ -8,8 +8,8 @@ function test() {
let cw = win.TabView.getContentWindow();
let tabItem = win.gBrowser.tabs[0]._tabViewTabItem;
tabItem.addSubscriber(tabItem, "savedCachedImageData", function () {
tabItem.removeSubscriber(tabItem, "savedCachedImageData");
tabItem.addSubscriber("savedCachedImageData", function onSaved() {
tabItem.removeSubscriber("savedCachedImageData", onSaved);
ok(cw.UI.isDOMWindowClosing, "dom window is closing");
waitForFocus(finish);

View File

@ -18,8 +18,8 @@ function test() {
ok(groupItem.isStacked(), "groupItem is now stacked");
is(win.gBrowser.tabs.length, 5, "we have five tabs");
groupItem.addSubscriber(groupItem, "expanded", function onExpanded() {
groupItem.removeSubscriber(groupItem, "expanded");
groupItem.addSubscriber("expanded", function onExpanded() {
groupItem.removeSubscriber("expanded", onExpanded);
ok(groupItem.expanded, "groupItem is expanded");
let bounds = children[1].getBounds();

View File

@ -24,8 +24,8 @@ function onTabViewWindowLoaded() {
let boxTwo = new contentWindow.Rect(20, 400, 300, 300);
let groupTwo = new contentWindow.GroupItem([], { bounds: boxTwo });
groupOne.addSubscriber(groupOne, "childAdded", function() {
groupOne.removeSubscriber(groupOne, "childAdded");
groupOne.addSubscriber("childAdded", function onChildAdded() {
groupOne.removeSubscriber("childAdded", onChildAdded);
groupTwo.newTab();
});
@ -68,7 +68,7 @@ function addTest(contentWindow, groupOneId, groupTwoId, originalTab) {
Math.round(groupTwoRectCenter.y - tabItemRectCenter.y);
function endGame() {
groupTwo.removeSubscriber(groupTwo, "childAdded");
groupTwo.removeSubscriber("childAdded", endGame);
is(groupOne.getChildren().length, --groupOneTabItemCount,
"The number of children in group one is decreased by 1");
@ -83,14 +83,14 @@ function addTest(contentWindow, groupOneId, groupTwoId, originalTab) {
EventUtils.sendMouseEvent(
{ type: "click" }, closeButton[0], contentWindow);
};
groupTwo.addSubscriber(groupTwo, "close", function() {
groupTwo.removeSubscriber(groupTwo, "close");
finish();
groupTwo.addSubscriber("close", function onClose() {
groupTwo.removeSubscriber("close", onClose);
finish();
});
window.addEventListener("tabviewhidden", onTabViewHidden, false);
gBrowser.selectedTab = originalTab;
}
groupTwo.addSubscriber(groupTwo, "childAdded", endGame);
groupTwo.addSubscriber("childAdded", endGame);
simulateDragDrop(tabItem.container, offsetX, offsetY, contentWindow);
}

View File

@ -51,7 +51,7 @@ function onTabViewWindowLoaded(win) {
// Here, we just expand the group, click elsewhere, and make sure
// it collapsed.
let stage1expanded = function() {
group.removeSubscriber("test stage 1", "expanded", stage1expanded);
group.removeSubscriber("expanded", stage1expanded);
ok(group.expanded, "The group is now expanded.");
is(expander[0].style.display, "none", "The expander is hidden!");
@ -60,14 +60,14 @@ function onTabViewWindowLoaded(win) {
ok(overlay, "The expanded tray exists.");
let $overlay = contentWindow.iQ(overlay);
group.addSubscriber("test stage 1", "collapsed", stage1collapsed);
group.addSubscriber("collapsed", stage1collapsed);
// null type means "click", for some reason...
EventUtils.synthesizeMouse(contentWindow.document.body, 10, $overlay.bounds().bottom + 5,
{type: null}, contentWindow);
};
let stage1collapsed = function() {
group.removeSubscriber("test stage 1", "collapsed", stage1collapsed);
group.removeSubscriber("collapsed", stage1collapsed);
ok(!group.expanded, "The group is no longer expanded.");
isnot(expander[0].style.display, "none", "The expander is visible!");
let expanderBounds = expander.bounds();
@ -76,7 +76,7 @@ function onTabViewWindowLoaded(win) {
ok(stackCenter.y < expanderBounds.center().y, "The expander is below the stack.");
// now, try opening it up again.
group.addSubscriber("test stage 2", "expanded", stage2expanded);
group.addSubscriber("expanded", stage2expanded);
EventUtils.sendMouseEvent({ type: "click" }, expander[0], contentWindow);
};
@ -84,7 +84,7 @@ function onTabViewWindowLoaded(win) {
// Now make sure every child of the group shows up within this "tray", and
// click on one of them and make sure we go into the tab and the tray collapses.
let stage2expanded = function() {
group.removeSubscriber("test stage 2", "expanded", stage2expanded);
group.removeSubscriber("expanded", stage2expanded);
ok(group.expanded, "The group is now expanded.");
is(expander[0].style.display, "none", "The expander is hidden!");
@ -132,27 +132,27 @@ function onTabViewWindowLoaded(win) {
}
// okay, expand this group one last time
group.addSubscriber("test stage 3", "expanded", stage3expanded);
group.addSubscriber("expanded", stage3expanded);
EventUtils.sendMouseEvent({ type: "click" }, expander[0], contentWindow);
}
// STAGE 3:
// Ensure that stack still shows the same top item after a expand and a collapse.
let stage3expanded = function() {
group.removeSubscriber("test stage 3", "expanded", stage3expanded);
group.removeSubscriber("expanded", stage3expanded);
ok(group.expanded, "The group is now expanded.");
let overlay = contentWindow.document.getElementById("expandedTray");
let $overlay = contentWindow.iQ(overlay);
group.addSubscriber("test stage 3", "collapsed", stage3collapsed);
group.addSubscriber("collapsed", stage3collapsed);
// null type means "click", for some reason...
EventUtils.synthesizeMouse(contentWindow.document.body, 10, $overlay.bounds().bottom + 5,
{type: null}, contentWindow);
};
let stage3collapsed = function() {
group.removeSubscriber("test stage 3", "collapsed", stage3collapsed);
group.removeSubscriber("collapsed", stage3collapsed);
ok(!group.expanded, "The group is no longer expanded.");
isnot(expander[0].style.display, "none", "The expander is visible!");
@ -176,7 +176,7 @@ function onTabViewWindowLoaded(win) {
contentWindow.UI.setActive(originalTabItem);
// now, try opening it up again.
group.addSubscriber("test stage 4", "expanded", stage4expanded);
group.addSubscriber("expanded", stage4expanded);
EventUtils.sendMouseEvent({ type: "click" }, expander[0], contentWindow);
};
@ -185,7 +185,7 @@ function onTabViewWindowLoaded(win) {
// enter Panorama (i.e., zoom into this other group), and make sure we can go to
// it and that the tray gets collapsed.
let stage4expanded = function() {
group.removeSubscriber("test stage 4", "expanded", stage4expanded);
group.removeSubscriber("expanded", stage4expanded);
ok(group.expanded, "The group is now expanded.");
is(expander[0].style.display, "none", "The expander is hidden!");
@ -231,7 +231,7 @@ function onTabViewWindowLoaded(win) {
}
// get the ball rolling
group.addSubscriber("test stage 1", "expanded", stage1expanded);
group.addSubscriber("expanded", stage1expanded);
EventUtils.sendMouseEvent({ type: "click" }, expander[0], contentWindow);
}, win);
}

View File

@ -37,8 +37,8 @@ function testEmptyGroupItem(contentWindow) {
is(contentWindow.GroupItems.groupItems.length, ++groupItemCount,
"The number of groups is increased by 1");
emptyGroupItem.addSubscriber(emptyGroupItem, "close", function() {
emptyGroupItem.removeSubscriber(emptyGroupItem, "close");
emptyGroupItem.addSubscriber("close", function onClose() {
emptyGroupItem.removeSubscriber("close", onClose);
// check the number of groups.
is(contentWindow.GroupItems.groupItems.length, --groupItemCount,
@ -75,12 +75,12 @@ function testGroupItemWithTabItem(contentWindow) {
ok(tabItem, "Tab item exists");
let tabItemClosed = false;
tabItem.addSubscriber(tabItem, "close", function() {
tabItem.removeSubscriber(tabItem, "close");
tabItem.addSubscriber("close", function onClose() {
tabItem.removeSubscriber("close", onClose);
tabItemClosed = true;
});
tabItem.addSubscriber(tabItem, "tabRemoved", function() {
tabItem.removeSubscriber(tabItem, "tabRemoved");
tabItem.addSubscriber("tabRemoved", function onTabRemoved() {
tabItem.removeSubscriber("tabRemoved", onTabRemoved);
ok(tabItemClosed, "The tab item is closed");
is(groupItem.getChildren().length, --tabItemCount,

View File

@ -82,8 +82,8 @@ function testEmptyGroupItem(contentWindow) {
}
// Shut down
emptyGroupItem.addSubscriber(emptyGroupItem, "close", function() {
emptyGroupItem.removeSubscriber(emptyGroupItem, "close");
emptyGroupItem.addSubscriber("close", function onClose() {
emptyGroupItem.removeSubscriber("close", onClose);
// check the number of groups.
is(contentWindow.GroupItems.groupItems.length, --groupItemCount,

View File

@ -46,8 +46,8 @@ function onTabViewWindowLoaded() {
}
function testUndoGroup(contentWindow, groupItem) {
groupItem.addSubscriber(groupItem, "groupHidden", function() {
groupItem.removeSubscriber(groupItem, "groupHidden");
groupItem.addSubscriber("groupHidden", function onHidden() {
groupItem.removeSubscriber("groupHidden", onHidden);
// check the data of the group
let theGroupItem = contentWindow.GroupItems.groupItem(groupItem.id);
@ -64,8 +64,8 @@ function testUndoGroup(contentWindow, groupItem) {
{ type: "click" }, theGroupItem.$undoContainer[0], contentWindow);
});
groupItem.addSubscriber(groupItem, "groupShown", function() {
groupItem.removeSubscriber(groupItem, "groupShown");
groupItem.addSubscriber("groupShown", function onShown() {
groupItem.removeSubscriber("groupShown", onShown);
// check the data of the group
let theGroupItem = contentWindow.GroupItems.groupItem(groupItem.id);
@ -87,8 +87,8 @@ function testUndoGroup(contentWindow, groupItem) {
}
function testCloseUndoGroup(contentWindow, groupItem) {
groupItem.addSubscriber(groupItem, "groupHidden", function() {
groupItem.removeSubscriber(groupItem, "groupHidden");
groupItem.addSubscriber("groupHidden", function onHidden() {
groupItem.removeSubscriber("groupHidden", onHidden);
// check the data of the group
let theGroupItem = contentWindow.GroupItems.groupItem(groupItem.id);
@ -107,8 +107,8 @@ function testCloseUndoGroup(contentWindow, groupItem) {
{ type: "click" }, closeButton[0], contentWindow);
});
groupItem.addSubscriber(groupItem, "close", function() {
groupItem.removeSubscriber(groupItem, "close");
groupItem.addSubscriber("close", function onClose() {
groupItem.removeSubscriber("close", onClose);
let theGroupItem = contentWindow.GroupItems.groupItem(groupItem.id);
ok(!theGroupItem, "The group item doesn't exists");

View File

@ -45,15 +45,15 @@ function createGroupItemWithBlankTabs(win, width, height, padding, numNewTabs, a
// ----------
function closeGroupItem(groupItem, callback) {
groupItem.addSubscriber(groupItem, "close", function () {
groupItem.removeSubscriber(groupItem, "close");
groupItem.addSubscriber("close", function onClose() {
groupItem.removeSubscriber("close", onClose);
if ("function" == typeof callback)
executeSoon(callback);
});
if (groupItem.getChildren().length) {
groupItem.addSubscriber(groupItem, "groupHidden", function () {
groupItem.removeSubscriber(groupItem, "groupHidden");
groupItem.addSubscriber("groupHidden", function onHide() {
groupItem.removeSubscriber("groupHidden", onHide);
groupItem.closeHidden();
});
}
@ -222,8 +222,8 @@ function whenSearchIsEnabled(callback, win) {
return;
}
contentWindow.addEventListener("tabviewsearchenabled", function () {
contentWindow.removeEventListener("tabviewsearchenabled", arguments.callee, false);
contentWindow.addEventListener("tabviewsearchenabled", function onSearchEnabled() {
contentWindow.removeEventListener("tabviewsearchenabled", onSearchEnabled, false);
callback();
}, false);
}
@ -238,8 +238,8 @@ function whenSearchIsDisabled(callback, win) {
return;
}
contentWindow.addEventListener("tabviewsearchdisabled", function () {
contentWindow.removeEventListener("tabviewsearchdisabled", arguments.callee, false);
contentWindow.addEventListener("tabviewsearchdisabled", function onSearchDisabled() {
contentWindow.removeEventListener("tabviewsearchdisabled", onSearchDisabled, false);
callback();
}, false);
}
@ -252,8 +252,8 @@ function hideGroupItem(groupItem, callback) {
return;
}
groupItem.addSubscriber(groupItem, "groupHidden", function () {
groupItem.removeSubscriber(groupItem, "groupHidden");
groupItem.addSubscriber("groupHidden", function onHide() {
groupItem.removeSubscriber("groupHidden", onHide);
callback();
});
groupItem.closeAll();
@ -266,8 +266,8 @@ function unhideGroupItem(groupItem, callback) {
return;
}
groupItem.addSubscriber(groupItem, "groupShown", function () {
groupItem.removeSubscriber(groupItem, "groupShown");
groupItem.addSubscriber("groupShown", function onShown() {
groupItem.removeSubscriber("groupShown", onShown);
callback();
});
groupItem._unhide();
@ -342,8 +342,8 @@ function restoreTab(callback, index, win) {
return;
}
tab._tabViewTabItem.addSubscriber(tab, "reconnected", function onReconnected() {
tab._tabViewTabItem.removeSubscriber(tab, "reconnected");
tab._tabViewTabItem.addSubscriber("reconnected", function onReconnected() {
tab._tabViewTabItem.removeSubscriber("reconnected", onReconnected);
finalize();
});
}