mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
bug 940820 fix status and mark buttons by using customization widgets, r=markh, r=Gijs
This commit is contained in:
parent
934952b38e
commit
4d2837276e
@ -49,8 +49,6 @@ SocialUI = {
|
||||
Services.obs.addObserver(this, "social:provider-set", false);
|
||||
Services.obs.addObserver(this, "social:providers-changed", false);
|
||||
Services.obs.addObserver(this, "social:provider-reload", false);
|
||||
Services.obs.addObserver(this, "social:provider-installed", false);
|
||||
Services.obs.addObserver(this, "social:provider-uninstalled", false);
|
||||
Services.obs.addObserver(this, "social:provider-enabled", false);
|
||||
Services.obs.addObserver(this, "social:provider-disabled", false);
|
||||
|
||||
@ -58,10 +56,6 @@ SocialUI = {
|
||||
Services.prefs.addObserver("social.toast-notifications.enabled", this, false);
|
||||
|
||||
gBrowser.addEventListener("ActivateSocialFeature", this._activationEventHandler.bind(this), true, true);
|
||||
window.addEventListener("aftercustomization", function() {
|
||||
if (SocialUI.enabled)
|
||||
SocialMarks.populateContextMenu(SocialMarks);
|
||||
}, false);
|
||||
|
||||
if (!Social.initialized) {
|
||||
Social.init();
|
||||
@ -81,8 +75,6 @@ SocialUI = {
|
||||
Services.obs.removeObserver(this, "social:provider-set");
|
||||
Services.obs.removeObserver(this, "social:providers-changed");
|
||||
Services.obs.removeObserver(this, "social:provider-reload");
|
||||
Services.obs.removeObserver(this, "social:provider-installed");
|
||||
Services.obs.removeObserver(this, "social:provider-uninstalled");
|
||||
Services.obs.removeObserver(this, "social:provider-enabled");
|
||||
Services.obs.removeObserver(this, "social:provider-disabled");
|
||||
|
||||
@ -99,14 +91,6 @@ SocialUI = {
|
||||
// manually :(
|
||||
try {
|
||||
switch (topic) {
|
||||
case "social:provider-installed":
|
||||
SocialMarks.setPosition(data);
|
||||
SocialStatus.setPosition(data);
|
||||
break;
|
||||
case "social:provider-uninstalled":
|
||||
SocialMarks.removePosition(data);
|
||||
SocialStatus.removePosition(data);
|
||||
break;
|
||||
case "social:provider-enabled":
|
||||
SocialMarks.populateToolbarPalette();
|
||||
SocialStatus.populateToolbarPalette();
|
||||
@ -1293,129 +1277,52 @@ SocialSidebar = {
|
||||
}
|
||||
|
||||
// this helper class is used by removable/customizable buttons to handle
|
||||
// location persistence and insertion into palette and/or toolbars
|
||||
// widget creation/destruction
|
||||
|
||||
// When a provider is installed we show all their UI so the user will see the
|
||||
// functionality of what they installed. The user can later customize the UI,
|
||||
// moving buttons around or off the toolbar.
|
||||
//
|
||||
// To make this happen, on install we add a button id to the navbar currentset.
|
||||
// On enabling the provider (happens just after install) we insert the button
|
||||
// into the toolbar as well. The button is then persisted on restart (assuming
|
||||
// it was not removed).
|
||||
//
|
||||
// When a provider is disabled, we do not remove the buttons from currentset.
|
||||
// That way, if the provider is re-enabled during the same session, the buttons
|
||||
// will reappear where they were before. When a provider is uninstalled, we make
|
||||
// sure that the id is removed from currentset.
|
||||
//
|
||||
// On startup, we insert the buttons of any enabled provider into either the
|
||||
// apropriate toolbar or the palette.
|
||||
// On startup, we create the button widgets of any enabled provider.
|
||||
// CustomizableUI handles placement and persistence of placement.
|
||||
function ToolbarHelper(type, createButtonFn) {
|
||||
this._createButton = createButtonFn;
|
||||
this._type = type;
|
||||
}
|
||||
|
||||
ToolbarHelper.prototype = {
|
||||
idFromOrgin: function(origin) {
|
||||
return this._type + "-" + origin;
|
||||
},
|
||||
|
||||
// find a button either in the document or the palette
|
||||
_getExistingButton: function(id) {
|
||||
let button = document.getElementById(id);
|
||||
if (button)
|
||||
return button;
|
||||
let palette = document.getElementById("navigator-toolbox").palette;
|
||||
let paletteItem = palette.firstChild;
|
||||
while (paletteItem) {
|
||||
if (paletteItem.id == id)
|
||||
return paletteItem;
|
||||
paletteItem = paletteItem.nextSibling;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
setPersistentPosition: function(id) {
|
||||
// called when a provider is installed. add provider buttons to nav-bar
|
||||
let toolbar = document.getElementById("nav-bar");
|
||||
// first startups will not have a currentset attribute, always rely on
|
||||
// currentSet since it will be derived from the defaultset in that case.
|
||||
let currentset = toolbar.currentSet;
|
||||
if (currentset == "__empty")
|
||||
currentset = []
|
||||
else
|
||||
currentset = currentset.split(",");
|
||||
if (currentset.indexOf(id) >= 0)
|
||||
return;
|
||||
// we do not set toolbar.currentSet since that will try to add the button,
|
||||
// and we have not added it yet (happens on provider being enabled)
|
||||
currentset.push(id);
|
||||
toolbar.setAttribute("currentset", currentset.join(","));
|
||||
document.persist(toolbar.id, "currentset");
|
||||
idFromOrigin: function(origin) {
|
||||
// this id needs to pass the checks in CustomizableUI, so remove characters
|
||||
// that wont pass.
|
||||
return this._type + "-" + Services.io.newURI(origin, null, null).hostPort.replace(/[\.:]/g,'-');
|
||||
},
|
||||
|
||||
// should be called on disable of a provider
|
||||
removeProviderButton: function(origin) {
|
||||
// this will remove the button from the palette or the toolbar
|
||||
let button = this._getExistingButton(this.idFromOrgin(origin));
|
||||
if (button)
|
||||
button.parentNode.removeChild(button);
|
||||
CustomizableUI.destroyWidget(this.idFromOrigin(origin));
|
||||
},
|
||||
|
||||
removePersistence: function(id) {
|
||||
let persisted = document.querySelectorAll("*[currentset]");
|
||||
for (let pent of persisted) {
|
||||
// the button will have been removed, but left in the currentset attribute
|
||||
// in case the user re-enables (e.g. undo in addon manager). So we only
|
||||
// check the attribute here.
|
||||
let currentset = pent.getAttribute("currentset").split(",");
|
||||
|
||||
let pos = currentset.indexOf(id);
|
||||
if (pos >= 0) {
|
||||
currentset.splice(pos, 1);
|
||||
pent.setAttribute("currentset", currentset.join(","));
|
||||
document.persist(pent.id, "currentset");
|
||||
return;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// if social is entirely disabled, we need to clear the palette, but leave
|
||||
// the persisted id's in place
|
||||
clearPalette: function() {
|
||||
[this.removeProviderButton(p.origin) for (p of Social.providers)];
|
||||
},
|
||||
|
||||
// should be called on startup of each window, otherwise the addon manager
|
||||
// listener will handle new activations, or enable/disabling of a provider
|
||||
// XXX we currently call more regularly, will fix during refactoring
|
||||
// should be called on enable of a provider
|
||||
populatePalette: function() {
|
||||
if (!Social.enabled) {
|
||||
this.clearPalette();
|
||||
return;
|
||||
}
|
||||
let persisted = document.querySelectorAll("*[currentset]");
|
||||
let persistedById = {};
|
||||
for (let pent of persisted) {
|
||||
let pset = pent.getAttribute("currentset").split(',');
|
||||
for (let id of pset)
|
||||
persistedById[id] = pent;
|
||||
}
|
||||
|
||||
// create any buttons that do not exist yet if they have been persisted
|
||||
// as a part of the UI (otherwise they belong in the palette).
|
||||
for (let provider of Social.providers) {
|
||||
let id = this.idFromOrgin(provider.origin);
|
||||
if (this._getExistingButton(id))
|
||||
continue;
|
||||
let button = this._createButton(provider);
|
||||
if (button && persistedById.hasOwnProperty(id)) {
|
||||
let parent = persistedById[id];
|
||||
let pset = persistedById[id].getAttribute("currentset").split(',');
|
||||
let pi = pset.indexOf(id) + 1;
|
||||
let next = document.getElementById(pset[pi]);
|
||||
parent.insertItem(id, next, null, false);
|
||||
}
|
||||
let id = this.idFromOrigin(provider.origin);
|
||||
let widget = CustomizableUI.getWidget(id);
|
||||
// The widget is only null if we've created then destroyed the widget.
|
||||
// Once we've actually called createWidget the provider will be set to
|
||||
// PROVIDER_API.
|
||||
if (!widget || widget.provider != CustomizableUI.PROVIDER_API)
|
||||
this._createButton(provider);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1427,25 +1334,6 @@ SocialStatus = {
|
||||
this._toolbarHelper.populatePalette();
|
||||
},
|
||||
|
||||
setPosition: function(origin) {
|
||||
if (!Social.allowMultipleWorkers)
|
||||
return;
|
||||
// this is called during install, before the provider is enabled so we have
|
||||
// to use the manifest rather than the provider instance as we do elsewhere.
|
||||
let manifest = Social.getManifestByOrigin(origin);
|
||||
if (!manifest.statusURL)
|
||||
return;
|
||||
let tbh = this._toolbarHelper;
|
||||
tbh.setPersistentPosition(tbh.idFromOrgin(origin));
|
||||
},
|
||||
|
||||
removePosition: function(origin) {
|
||||
if (!Social.allowMultipleWorkers)
|
||||
return;
|
||||
let tbh = this._toolbarHelper;
|
||||
tbh.removePersistence(tbh.idFromOrgin(origin));
|
||||
},
|
||||
|
||||
removeProvider: function(origin) {
|
||||
if (!Social.allowMultipleWorkers)
|
||||
return;
|
||||
@ -1476,20 +1364,30 @@ SocialStatus = {
|
||||
|
||||
_createButton: function(provider) {
|
||||
if (!provider.statusURL)
|
||||
return null;
|
||||
let palette = document.getElementById("navigator-toolbox").palette;
|
||||
let button = document.createElement("toolbarbutton");
|
||||
button.setAttribute("class", "toolbarbutton-1 chromeclass-toolbar-additional social-status-button");
|
||||
button.setAttribute("type", "badged");
|
||||
button.setAttribute("removable", "true");
|
||||
button.setAttribute("image", provider.iconURL);
|
||||
button.setAttribute("label", provider.name);
|
||||
button.setAttribute("tooltiptext", provider.name);
|
||||
button.setAttribute("origin", provider.origin);
|
||||
button.setAttribute("oncommand", "SocialStatus.showPopup(this);");
|
||||
button.setAttribute("id", this._toolbarHelper.idFromOrgin(provider.origin));
|
||||
palette.appendChild(button);
|
||||
return button;
|
||||
return;
|
||||
let aId = this._toolbarHelper.idFromOrigin(provider.origin);
|
||||
CustomizableUI.createWidget({
|
||||
id: aId,
|
||||
type: 'custom',
|
||||
removable: true,
|
||||
defaultArea: CustomizableUI.AREA_NAVBAR,
|
||||
onBuild: function(document) {
|
||||
let window = document.defaultView;
|
||||
|
||||
let node = document.createElement('toolbarbutton');
|
||||
|
||||
node.id = this.id;
|
||||
node.setAttribute('class', 'toolbarbutton-1 chromeclass-toolbar-additional social-status-button');
|
||||
node.setAttribute('type', "badged");
|
||||
node.style.listStyleImage = "url(" + provider.iconURL + ")";
|
||||
node.setAttribute("origin", provider.origin);
|
||||
|
||||
node.setAttribute("label", provider.name);
|
||||
node.setAttribute("tooltiptext", provider.name);
|
||||
node.setAttribute("oncommand", "SocialStatus.showPopup(this);");
|
||||
return node;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// status panels are one-per button per-process, we swap the docshells between
|
||||
@ -1538,7 +1436,7 @@ SocialStatus = {
|
||||
if (!Social.allowMultipleWorkers)
|
||||
return;
|
||||
let provider = Social._getProviderFromOrigin(origin);
|
||||
let button = document.getElementById(this._toolbarHelper.idFromOrgin(provider.origin));
|
||||
let button = document.getElementById(this._toolbarHelper.idFromOrigin(provider.origin));
|
||||
if (button) {
|
||||
// we only grab the first notification, ignore all others
|
||||
let icons = provider.ambientNotificationIcons;
|
||||
@ -1673,7 +1571,7 @@ SocialMarks = {
|
||||
// menu's, this is ok.
|
||||
let tbh = this._toolbarHelper;
|
||||
return [p for (p of Social.providers) if (p.markURL &&
|
||||
document.getElementById(tbh.idFromOrgin(p.origin)))];
|
||||
document.getElementById(tbh.idFromOrigin(p.origin)))];
|
||||
},
|
||||
|
||||
populateContextMenu: function() {
|
||||
@ -1732,21 +1630,6 @@ SocialMarks = {
|
||||
this.populateContextMenu();
|
||||
},
|
||||
|
||||
setPosition: function(origin) {
|
||||
// this is called during install, before the provider is enabled so we have
|
||||
// to use the manifest rather than the provider instance as we do elsewhere.
|
||||
let manifest = Social.getManifestByOrigin(origin);
|
||||
if (!manifest.markURL)
|
||||
return;
|
||||
let tbh = this._toolbarHelper;
|
||||
tbh.setPersistentPosition(tbh.idFromOrgin(origin));
|
||||
},
|
||||
|
||||
removePosition: function(origin) {
|
||||
let tbh = this._toolbarHelper;
|
||||
tbh.removePersistence(tbh.idFromOrgin(origin));
|
||||
},
|
||||
|
||||
removeProvider: function(origin) {
|
||||
this._toolbarHelper.removeProviderButton(origin);
|
||||
},
|
||||
@ -1759,21 +1642,32 @@ SocialMarks = {
|
||||
|
||||
_createButton: function(provider) {
|
||||
if (!provider.markURL)
|
||||
return null;
|
||||
let palette = document.getElementById("navigator-toolbox").palette;
|
||||
let button = document.createElement("toolbarbutton");
|
||||
button.setAttribute("type", "socialmark");
|
||||
button.setAttribute("class", "toolbarbutton-1 chromeclass-toolbar-additional social-mark-button");
|
||||
button.style.listStyleImage = "url(" + provider.iconURL + ")";
|
||||
button.setAttribute("origin", provider.origin);
|
||||
button.setAttribute("id", this._toolbarHelper.idFromOrgin(provider.origin));
|
||||
palette.appendChild(button);
|
||||
return button
|
||||
return;
|
||||
let aId = this._toolbarHelper.idFromOrigin(provider.origin);
|
||||
CustomizableUI.createWidget({
|
||||
id: aId,
|
||||
type: 'custom',
|
||||
removable: true,
|
||||
defaultArea: CustomizableUI.AREA_NAVBAR,
|
||||
onBuild: function(document) {
|
||||
let window = document.defaultView;
|
||||
|
||||
let node = document.createElement('toolbarbutton');
|
||||
|
||||
node.id = this.id;
|
||||
node.setAttribute('class', 'toolbarbutton-1 chromeclass-toolbar-additional social-mark-button');
|
||||
node.setAttribute('type', "socialmark");
|
||||
node.style.listStyleImage = "url(" + provider.iconURL + ")";
|
||||
node.setAttribute("origin", provider.origin);
|
||||
|
||||
return node;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
markLink: function(aOrigin, aUrl) {
|
||||
// find the button for this provider, and open it
|
||||
let id = this._toolbarHelper.idFromOrgin(aOrigin);
|
||||
let id = this._toolbarHelper.idFromOrigin(aOrigin);
|
||||
document.getElementById(id).markLink(aUrl);
|
||||
}
|
||||
};
|
||||
|
@ -64,51 +64,23 @@ function test() {
|
||||
// just in case the tests failed, clear these here as well
|
||||
Services.prefs.clearUserPref("social.allowMultipleWorkers");
|
||||
Services.prefs.clearUserPref("social.whitelist");
|
||||
|
||||
// This post-test test ensures that a new window maintains the same
|
||||
// toolbar button set as when we started. That means our insert/removal of
|
||||
// persistent id's is working correctly
|
||||
is(currentsetAtStart, toolbar.currentSet, "toolbar currentset unchanged");
|
||||
openWindowAndWaitForInit(function(w1) {
|
||||
checkSocialUI(w1);
|
||||
// Sometimes the new window adds other buttons to currentSet that are
|
||||
// outside the scope of what we're checking. So we verify that all
|
||||
// buttons from startup are in currentSet for a new window, and that the
|
||||
// provider buttons are properly removed. (e.g on try, window-controls
|
||||
// was not present in currentsetAtStart, but present on the second
|
||||
// window)
|
||||
let tb1 = w1.document.getElementById("nav-bar");
|
||||
let startupSet = Set(toolbar.currentSet.split(','));
|
||||
let newSet = Set(tb1.currentSet.split(','));
|
||||
let intersect = Set([x for (x of startupSet) if (newSet.has(x))]);
|
||||
let difference = Set([x for (x of newSet) if (!startupSet.has(x))]);
|
||||
is(startupSet.size, intersect.size, "new window toolbar same as old");
|
||||
// verify that our provider buttons are not in difference
|
||||
let id = SocialMarks._toolbarHelper.idFromOrgin(manifest2.origin);
|
||||
ok(!difference.has(id), "mark button not persisted at end");
|
||||
w1.close();
|
||||
finish();
|
||||
});
|
||||
ok(CustomizableUI.inDefaultState, "Should be in the default state when we finish");
|
||||
CustomizableUI.reset();
|
||||
finish();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var tests = {
|
||||
testNoButtonOnInstall: function(next) {
|
||||
testNoButtonOnEnable: function(next) {
|
||||
// we expect the addon install dialog to appear, we need to accept the
|
||||
// install from the dialog.
|
||||
info("Waiting for install dialog");
|
||||
let panel = document.getElementById("servicesInstall-notification");
|
||||
PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() {
|
||||
PopupNotifications.panel.removeEventListener("popupshown", onpopupshown);
|
||||
info("servicesInstall-notification panel opened");
|
||||
panel.button.click();
|
||||
})
|
||||
|
||||
let id = "social-mark-button-" + manifest3.origin;
|
||||
let toolbar = document.getElementById("nav-bar");
|
||||
let currentset = toolbar.getAttribute("currentset").split(',');
|
||||
ok(currentset.indexOf(id) < 0, "button is not part of currentset at start");
|
||||
});
|
||||
|
||||
let activationURL = manifest3.origin + "/browser/browser/base/content/test/social/social_activate.html"
|
||||
addTab(activationURL, function(tab) {
|
||||
@ -116,9 +88,10 @@ var tests = {
|
||||
Social.installProvider(doc, manifest3, function(addonManifest) {
|
||||
// enable the provider so we know the button would have appeared
|
||||
SocialService.addBuiltinProvider(manifest3.origin, function(provider) {
|
||||
ok(provider, "provider is installed");
|
||||
currentset = toolbar.getAttribute("currentset").split(',');
|
||||
ok(currentset.indexOf(id) < 0, "button was not added to currentset");
|
||||
is(provider.origin, manifest3.origin, "provider is installed");
|
||||
let id = SocialMarks._toolbarHelper.idFromOrigin(provider.origin);
|
||||
let widget = CustomizableUI.getWidget(id);
|
||||
ok(!widget || !widget.forWindow(window).node, "no button added to widget set");
|
||||
Social.uninstallProvider(manifest3.origin, function() {
|
||||
gBrowser.removeTab(tab);
|
||||
next();
|
||||
@ -128,57 +101,39 @@ var tests = {
|
||||
});
|
||||
},
|
||||
|
||||
testButtonOnInstall: function(next) {
|
||||
// we expect the addon install dialog to appear, we need to accept the
|
||||
// install from the dialog.
|
||||
info("Waiting for install dialog");
|
||||
testButtonOnEnable: function(next) {
|
||||
let panel = document.getElementById("servicesInstall-notification");
|
||||
PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() {
|
||||
PopupNotifications.panel.removeEventListener("popupshown", onpopupshown);
|
||||
info("servicesInstall-notification panel opened");
|
||||
panel.button.click();
|
||||
})
|
||||
});
|
||||
|
||||
// enable the provider now
|
||||
let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html"
|
||||
addTab(activationURL, function(tab) {
|
||||
let doc = tab.linkedBrowser.contentDocument;
|
||||
Social.installProvider(doc, manifest2, function(addonManifest) {
|
||||
// at this point, we should have a button id in the currentset for our provider
|
||||
let id = "social-mark-button-" + manifest2.origin;
|
||||
let toolbar = document.getElementById("nav-bar");
|
||||
|
||||
waitForCondition(function() {
|
||||
let currentset = toolbar.getAttribute("currentset").split(',');
|
||||
return currentset.indexOf(id) >= 0;
|
||||
},
|
||||
function() {
|
||||
// no longer need the tab
|
||||
gBrowser.removeTab(tab);
|
||||
next();
|
||||
}, "mark button added to currentset");
|
||||
SocialService.addBuiltinProvider(manifest2.origin, function(provider) {
|
||||
is(provider.origin, manifest2.origin, "provider is installed");
|
||||
let id = SocialMarks._toolbarHelper.idFromOrigin(manifest2.origin);
|
||||
let widget = CustomizableUI.getWidget(id).forWindow(window)
|
||||
ok(widget.node, "button added to widget set");
|
||||
checkSocialUI(window);
|
||||
gBrowser.removeTab(tab);
|
||||
next();
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
testButtonOnEnable: function(next) {
|
||||
// enable the provider now
|
||||
SocialService.addBuiltinProvider(manifest2.origin, function(provider) {
|
||||
ok(provider, "provider is installed");
|
||||
let id = "social-mark-button-" + manifest2.origin;
|
||||
waitForCondition(function() { return document.getElementById(id) },
|
||||
function() {
|
||||
checkSocialUI(window);
|
||||
next();
|
||||
}, "button exists after enabling social");
|
||||
});
|
||||
},
|
||||
|
||||
testMarkPanel: function(next) {
|
||||
// click on panel to open and wait for visibility
|
||||
let provider = Social._getProviderFromOrigin(manifest2.origin);
|
||||
ok(provider.enabled, "provider is enabled");
|
||||
let id = "social-mark-button-" + provider.origin;
|
||||
let btn = document.getElementById(id)
|
||||
let id = SocialMarks._toolbarHelper.idFromOrigin(manifest2.origin);
|
||||
let widget = CustomizableUI.getWidget(id);
|
||||
let btn = widget.forWindow(window).node;
|
||||
ok(btn, "got a mark button");
|
||||
let port = provider.getWorkerPort();
|
||||
ok(port, "got a port");
|
||||
@ -300,26 +255,18 @@ var tests = {
|
||||
let provider = Social._getProviderFromOrigin(manifest2.origin);
|
||||
ok(provider, "provider is installed");
|
||||
SocialService.removeProvider(manifest2.origin, function() {
|
||||
let id = "social-mark-button-" + manifest2.origin;
|
||||
waitForCondition(function() { return !document.getElementById(id) },
|
||||
let id = SocialMarks._toolbarHelper.idFromOrigin(manifest2.origin);
|
||||
waitForCondition(function() {
|
||||
// getWidget now returns null since we've destroyed the widget
|
||||
return !CustomizableUI.getWidget(id)
|
||||
},
|
||||
function() {
|
||||
checkSocialUI(window);
|
||||
next();
|
||||
Social.uninstallProvider(manifest2.origin, next);
|
||||
}, "button does not exist after disabling the provider");
|
||||
});
|
||||
},
|
||||
|
||||
testButtonOnUninstall: function(next) {
|
||||
Social.uninstallProvider(manifest2.origin, function() {
|
||||
// test that the button is no longer persisted
|
||||
let id = "social-mark-button-" + manifest2.origin;
|
||||
let toolbar = document.getElementById("nav-bar");
|
||||
let currentset = toolbar.getAttribute("currentset").split(',');
|
||||
is(currentset.indexOf(id), -1, "button no longer in currentset");
|
||||
next();
|
||||
});
|
||||
},
|
||||
|
||||
testContextSubmenu: function(next) {
|
||||
// install 4 providers to test that the menu's are added as submenus
|
||||
let manifests = [
|
||||
@ -348,31 +295,24 @@ var tests = {
|
||||
})
|
||||
|
||||
let activationURL = manifest.origin + "/browser/browser/base/content/test/social/social_activate.html"
|
||||
let id = "social-mark-button-" + manifest.origin;
|
||||
let id = SocialMarks._toolbarHelper.idFromOrigin(manifest.origin);
|
||||
let toolbar = document.getElementById("nav-bar");
|
||||
addTab(activationURL, function(tab) {
|
||||
let doc = tab.linkedBrowser.contentDocument;
|
||||
Social.installProvider(doc, manifest, function(addonManifest) {
|
||||
|
||||
waitForCondition(function() {
|
||||
let currentset = toolbar.getAttribute("currentset").split(',');
|
||||
return currentset.indexOf(id) >= 0;
|
||||
},
|
||||
function() {
|
||||
// enable the provider so we know the button would have appeared
|
||||
SocialService.addBuiltinProvider(manifest.origin, function(provider) {
|
||||
waitForCondition(function() { return document.getElementById(id) },
|
||||
function() {
|
||||
gBrowser.removeTab(tab);
|
||||
installed.push(manifest.origin);
|
||||
// checkSocialUI will properly check where the menus are located
|
||||
checkSocialUI(window);
|
||||
executeSoon(function() {
|
||||
addProviders(callback);
|
||||
});
|
||||
}, "button exists after enabling social");
|
||||
});
|
||||
}, "mark button added to currentset");
|
||||
// enable the provider so we know the button would have appeared
|
||||
SocialService.addBuiltinProvider(manifest.origin, function(provider) {
|
||||
waitForCondition(function() { return CustomizableUI.getWidget(id) },
|
||||
function() {
|
||||
gBrowser.removeTab(tab);
|
||||
installed.push(manifest.origin);
|
||||
// checkSocialUI will properly check where the menus are located
|
||||
checkSocialUI(window);
|
||||
executeSoon(function() {
|
||||
addProviders(callback);
|
||||
});
|
||||
}, "button exists after enabling social");
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -41,53 +41,23 @@ function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
Services.prefs.setBoolPref("social.allowMultipleWorkers", true);
|
||||
let toolbar = document.getElementById("nav-bar");
|
||||
let currentsetAtStart = toolbar.currentSet;
|
||||
info("tb0 "+currentsetAtStart);
|
||||
runSocialTestWithProvider(manifest, function () {
|
||||
runSocialTests(tests, undefined, undefined, function () {
|
||||
Services.prefs.clearUserPref("social.remote-install.enabled");
|
||||
// just in case the tests failed, clear these here as well
|
||||
Services.prefs.clearUserPref("social.allowMultipleWorkers");
|
||||
Services.prefs.clearUserPref("social.whitelist");
|
||||
|
||||
// This post-test test ensures that a new window maintains the same
|
||||
// toolbar button set as when we started. That means our insert/removal of
|
||||
// persistent id's is working correctly
|
||||
is(currentsetAtStart, toolbar.currentSet, "toolbar currentset unchanged");
|
||||
openWindowAndWaitForInit(function(w1) {
|
||||
checkSocialUI(w1);
|
||||
// Sometimes the new window adds other buttons to currentSet that are
|
||||
// outside the scope of what we're checking. So we verify that all
|
||||
// buttons from startup are in currentSet for a new window, and that the
|
||||
// provider buttons are properly removed. (e.g on try, window-controls
|
||||
// was not present in currentsetAtStart, but present on the second
|
||||
// window)
|
||||
let tb1 = w1.document.getElementById("nav-bar");
|
||||
info("tb0 "+toolbar.currentSet);
|
||||
info("tb1 "+tb1.currentSet);
|
||||
let startupSet = Set(toolbar.currentSet.split(','));
|
||||
let newSet = Set(tb1.currentSet.split(','));
|
||||
let intersect = Set([x for (x of startupSet) if (newSet.has(x))]);
|
||||
info("intersect "+intersect);
|
||||
let difference = Set([x for (x of newSet) if (!startupSet.has(x))]);
|
||||
info("difference "+difference);
|
||||
is(startupSet.size, intersect.size, "new window toolbar same as old");
|
||||
// verify that our provider buttons are not in difference
|
||||
let id = SocialStatus._toolbarHelper.idFromOrgin(manifest2.origin);
|
||||
ok(!difference.has(id), "status button not persisted at end");
|
||||
w1.close();
|
||||
finish();
|
||||
});
|
||||
ok(CustomizableUI.inDefaultState, "Should be in the default state when we finish");
|
||||
CustomizableUI.reset();
|
||||
finish();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var tests = {
|
||||
testNoButtonOnInstall: function(next) {
|
||||
testNoButtonOnEnable: function(next) {
|
||||
// we expect the addon install dialog to appear, we need to accept the
|
||||
// install from the dialog.
|
||||
info("Waiting for install dialog");
|
||||
let panel = document.getElementById("servicesInstall-notification");
|
||||
PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() {
|
||||
PopupNotifications.panel.removeEventListener("popupshown", onpopupshown);
|
||||
@ -95,20 +65,16 @@ var tests = {
|
||||
panel.button.click();
|
||||
})
|
||||
|
||||
let id = "social-status-button-" + manifest3.origin;
|
||||
let toolbar = document.getElementById("nav-bar");
|
||||
let currentset = toolbar.getAttribute("currentset").split(',');
|
||||
ok(currentset.indexOf(id) < 0, "button is not part of currentset at start");
|
||||
|
||||
let activationURL = manifest3.origin + "/browser/browser/base/content/test/social/social_activate.html"
|
||||
addTab(activationURL, function(tab) {
|
||||
let doc = tab.linkedBrowser.contentDocument;
|
||||
Social.installProvider(doc, manifest3, function(addonManifest) {
|
||||
// enable the provider so we know the button would have appeared
|
||||
SocialService.addBuiltinProvider(manifest3.origin, function(provider) {
|
||||
ok(provider, "provider is installed");
|
||||
currentset = toolbar.getAttribute("currentset").split(',');
|
||||
ok(currentset.indexOf(id) < 0, "button was not added to currentset");
|
||||
is(provider.origin, manifest3.origin, "provider is installed");
|
||||
let id = SocialStatus._toolbarHelper.idFromOrigin(provider.origin);
|
||||
let widget = CustomizableUI.getWidget(id);
|
||||
ok(!widget || !widget.forWindow(window).node, "no button added to widget set");
|
||||
Social.uninstallProvider(manifest3.origin, function() {
|
||||
gBrowser.removeTab(tab);
|
||||
next();
|
||||
@ -117,46 +83,31 @@ var tests = {
|
||||
});
|
||||
});
|
||||
},
|
||||
testButtonOnInstall: function(next) {
|
||||
// we expect the addon install dialog to appear, we need to accept the
|
||||
// install from the dialog.
|
||||
info("Waiting for install dialog");
|
||||
testButtonOnEnable: function(next) {
|
||||
let panel = document.getElementById("servicesInstall-notification");
|
||||
PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() {
|
||||
PopupNotifications.panel.removeEventListener("popupshown", onpopupshown);
|
||||
info("servicesInstall-notification panel opened");
|
||||
panel.button.click();
|
||||
})
|
||||
});
|
||||
|
||||
// enable the provider now
|
||||
let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html"
|
||||
addTab(activationURL, function(tab) {
|
||||
let doc = tab.linkedBrowser.contentDocument;
|
||||
Social.installProvider(doc, manifest2, function(addonManifest) {
|
||||
// at this point, we should have a button id in the currentset for our provider
|
||||
let id = "social-status-button-" + manifest2.origin;
|
||||
let toolbar = document.getElementById("nav-bar");
|
||||
|
||||
waitForCondition(function() {
|
||||
let currentset = toolbar.getAttribute("currentset").split(',');
|
||||
return currentset.indexOf(id) >= 0;
|
||||
},
|
||||
function() {
|
||||
// no longer need the tab
|
||||
gBrowser.removeTab(tab);
|
||||
next();
|
||||
}, "status button added to currentset");
|
||||
SocialService.addBuiltinProvider(manifest2.origin, function(provider) {
|
||||
is(provider.origin, manifest2.origin, "provider is installed");
|
||||
let id = SocialStatus._toolbarHelper.idFromOrigin(manifest2.origin);
|
||||
let widget = CustomizableUI.getWidget(id).forWindow(window);
|
||||
ok(widget.node, "button added to widget set");
|
||||
checkSocialUI(window);
|
||||
gBrowser.removeTab(tab);
|
||||
next();
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
testButtonOnEnable: function(next) {
|
||||
// enable the provider now
|
||||
SocialService.addBuiltinProvider(manifest2.origin, function(provider) {
|
||||
ok(provider, "provider is installed");
|
||||
let id = "social-status-button-" + manifest2.origin;
|
||||
waitForCondition(function() { return document.getElementById(id) },
|
||||
next, "button exists after enabling social");
|
||||
});
|
||||
},
|
||||
testStatusPanel: function(next) {
|
||||
let icon = {
|
||||
name: "testIcon",
|
||||
@ -165,8 +116,9 @@ var tests = {
|
||||
};
|
||||
// click on panel to open and wait for visibility
|
||||
let provider = Social._getProviderFromOrigin(manifest2.origin);
|
||||
let id = "social-status-button-" + provider.origin;
|
||||
let btn = document.getElementById(id)
|
||||
let id = SocialStatus._toolbarHelper.idFromOrigin(manifest2.origin);
|
||||
let widget = CustomizableUI.getWidget(id);
|
||||
let btn = widget.forWindow(window).node;
|
||||
ok(btn, "got a status button");
|
||||
let port = provider.getWorkerPort();
|
||||
|
||||
@ -202,19 +154,11 @@ var tests = {
|
||||
let provider = Social._getProviderFromOrigin(manifest2.origin);
|
||||
ok(provider, "provider is installed");
|
||||
SocialService.removeProvider(manifest2.origin, function() {
|
||||
let id = "social-status-button-" + manifest2.origin;
|
||||
let id = SocialStatus._toolbarHelper.idFromOrigin(manifest2.origin);
|
||||
waitForCondition(function() { return !document.getElementById(id) },
|
||||
next, "button does not exist after disabling the provider");
|
||||
});
|
||||
},
|
||||
testButtonOnUninstall: function(next) {
|
||||
Social.uninstallProvider(manifest2.origin, function() {
|
||||
// test that the button is no longer persisted
|
||||
let id = "social-status-button-" + manifest2.origin;
|
||||
let toolbar = document.getElementById("nav-bar");
|
||||
let currentset = toolbar.getAttribute("currentset").split(',');
|
||||
is(currentset.indexOf(id), -1, "button no longer in currentset");
|
||||
next();
|
||||
function() {
|
||||
Social.uninstallProvider(manifest2.origin, next);
|
||||
}, "button does not exist after disabling the provider");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -19,17 +19,9 @@ function test() {
|
||||
|
||||
// required to test status button in combination with the toolbaritem
|
||||
Services.prefs.setBoolPref("social.allowMultipleWorkers", true);
|
||||
|
||||
// Preset the currentSet so the statusbutton is in the toolbar on addition. We
|
||||
// bypass the SocialStatus class here since it requires the manifest already
|
||||
// be installed.
|
||||
let tbh = SocialStatus._toolbarHelper;
|
||||
tbh.setPersistentPosition(tbh.idFromOrgin(manifests[1].origin));
|
||||
|
||||
runSocialTestWithProvider(manifests, function (finishcb) {
|
||||
runSocialTests(tests, undefined, undefined, function() {
|
||||
Services.prefs.clearUserPref("social.allowMultipleWorkers");
|
||||
SocialStatus.removePosition(manifests[1].origin);
|
||||
finishcb();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user