Bug 984628 fix social button states, r=markh

This commit is contained in:
Shane Caraveo 2014-03-20 00:57:33 -07:00
Родитель 11ba72bb3c
Коммит 804475f701
4 изменённых файлов: 95 добавлений и 25 удалений

Просмотреть файл

@ -177,6 +177,7 @@ SocialUI = {
SocialShare.populateProviderMenu();
SocialStatus.populateToolbarPalette();
SocialMarks.populateToolbarPalette();
SocialShare.update();
},
// This handles "ActivateSocialFeature" events fired against content documents
@ -514,7 +515,7 @@ SocialShare = {
if (!provider)
provider = SocialSidebar.provider;
// if our provider has no shareURL, select the first one that does
if (provider && !provider.shareURL) {
if (!provider || !provider.shareURL) {
let providers = [p for (p of Social.providers) if (p.shareURL)];
provider = providers.length > 0 && providers[0];
}
@ -582,7 +583,10 @@ SocialShare = {
// also update the relevent command's disabled state so the keyboard
// shortcut only works when available.
let cmd = document.getElementById("Social:SharePage");
cmd.setAttribute("disabled", shareButton.disabled ? "true" : "false");
if (shareButton.disabled)
cmd.setAttribute("disabled", "true");
else
cmd.removeAttribute("disabled");
},
onShowing: function() {
@ -1411,6 +1415,7 @@ SocialMarks = {
for (let cfg of contextMenus) {
this._populateContextPopup(cfg, providers);
}
this.updatePanelButtons();
},
MENU_LIMIT: 3, // adjustable for testing

Просмотреть файл

@ -1,20 +1,20 @@
let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService;
let baseURL = "https://example.com/browser/browser/base/content/test/social/";
let manifest = { // normal provider
name: "provider 1",
origin: "https://example.com",
workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js",
iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png",
shareURL: "https://example.com/browser/browser/base/content/test/social/share.html"
};
function test() {
waitForExplicitFinish();
let manifest = { // normal provider
name: "provider 1",
origin: "https://example.com",
sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html",
workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js",
iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png",
shareURL: "https://example.com/browser/browser/base/content/test/social/share.html"
};
runSocialTestWithProvider(manifest, function (finishcb) {
runSocialTests(tests, undefined, undefined, finishcb);
});
runSocialTests(tests);
}
let corpus = [
@ -78,7 +78,7 @@ function loadURLInTab(url, callback) {
tab.linkedBrowser.addEventListener("load", function listener() {
is(tab.linkedBrowser.currentURI.spec, url, "tab loaded")
tab.linkedBrowser.removeEventListener("load", listener, true);
callback(tab);
executeSoon(function() { callback(tab) });
}, true);
}
@ -101,10 +101,46 @@ function hasoptions(testOptions, options) {
}
var tests = {
testShareDisabledOnActivation: function(next) {
// starting on about:blank page, share should be visible but disabled when
// adding provider
is(gBrowser.contentDocument.location.href, "about:blank");
SocialService.addProvider(manifest, function(provider) {
is(SocialUI.enabled, true, "SocialUI is enabled");
checkSocialUI();
// share should not be enabled since we only have about:blank page
let shareButton = SocialShare.shareButton;
is(shareButton.disabled, true, "share button is disabled");
// verify the attribute for proper css
is(shareButton.getAttribute("disabled"), "true", "share button attribute is disabled");
// button should be visible
is(shareButton.hidden, false, "share button is visible");
SocialService.removeProvider(manifest.origin, next);
});
},
testShareEnabledOnActivation: function(next) {
// starting from *some* page, share should be visible and enabled when
// activating provider
let testData = corpus[0];
loadURLInTab(testData.url, function(tab) {
SocialService.addProvider(manifest, function(provider) {
is(SocialUI.enabled, true, "SocialUI is enabled");
checkSocialUI();
// share should not be enabled since we only have about:blank page
let shareButton = SocialShare.shareButton;
is(shareButton.disabled, false, "share button is enabled");
// verify the attribute for proper css
ok(!shareButton.hasAttribute("disabled"), "share button is enabled");
// button should be visible
is(shareButton.hidden, false, "share button is visible");
gBrowser.removeTab(tab);
next();
});
});
},
testSharePage: function(next) {
let panel = document.getElementById("social-flyout-panel");
SocialSidebar.show();
let port = SocialSidebar.provider.getWorkerPort();
let provider = Social._getProviderFromOrigin(manifest.origin);
let port = provider.getWorkerPort();
ok(port, "provider has a port");
let testTab;
let testIndex = 0;
@ -120,22 +156,19 @@ var tests = {
port.onmessage = function (e) {
let topic = e.data.topic;
switch (topic) {
case "got-sidebar-message":
// open a tab with share data, then open the share panel
runOneTest();
break;
case "got-share-data-message":
gBrowser.removeTab(testTab);
hasoptions(testData.options, e.data.result);
testData = corpus[testIndex++];
if (testData) {
runOneTest();
executeSoon(runOneTest);
} else {
next();
SocialService.removeProvider(manifest.origin, next);
}
break;
}
}
port.postMessage({topic: "test-init"});
executeSoon(runOneTest);
}
}

Просмотреть файл

@ -70,6 +70,28 @@ function test() {
}
var tests = {
testButtonDisabledOnActivate: function(next) {
// starting on about:blank page, share should be visible but disabled when
// adding provider
is(gBrowser.contentDocument.location.href, "about:blank");
SocialService.addProvider(manifest2, 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");
// bypass widget go directly to dom, check attribute states
let button = document.getElementById(id);
is(button.disabled, true, "mark button is disabled");
// verify the attribute for proper css
is(button.getAttribute("disabled"), "true", "mark button attribute is disabled");
// button should be visible
is(button.hidden, false, "mark button is visible");
checkSocialUI(window);
SocialService.removeProvider(manifest2.origin, next);
});
},
testNoButtonOnEnable: function(next) {
// we expect the addon install dialog to appear, we need to accept the
// install from the dialog.
@ -117,6 +139,15 @@ var tests = {
let id = SocialMarks._toolbarHelper.idFromOrigin(manifest2.origin);
let widget = CustomizableUI.getWidget(id).forWindow(window)
ok(widget.node, "button added to widget set");
// bypass widget go directly to dom, check attribute states
let button = document.getElementById(id);
is(button.disabled, false, "mark button is disabled");
// verify the attribute for proper css
ok(!button.hasAttribute("disabled"), "mark button attribute is disabled");
// button should be visible
is(button.hidden, false, "mark button is visible");
checkSocialUI(window);
gBrowser.removeTab(tab);
next();

Просмотреть файл

@ -207,6 +207,7 @@ function checkSocialUI(win) {
let enabled = win.SocialUI.enabled;
let active = Social.providers.length > 0 && !win.SocialUI._chromeless &&
!PrivateBrowsingUtils.isWindowPrivate(win);
let sidebarEnabled = win.SocialSidebar.provider ? enabled : false;
// if we have enabled providers, we should also have instances of those
// providers
@ -235,7 +236,7 @@ function checkSocialUI(win) {
function isbool(a, b, msg) {
_is(!!a, !!b, msg);
}
isbool(win.SocialSidebar.canShow, enabled, "social sidebar active?");
isbool(win.SocialSidebar.canShow, sidebarEnabled, "social sidebar active?");
isbool(win.SocialChatBar.isAvailable, enabled, "chatbar available?");
isbool(!win.SocialChatBar.chatbar.hidden, enabled, "chatbar visible?");
@ -276,7 +277,7 @@ function checkSocialUI(win) {
}
// and for good measure, check all the social commands.
isbool(!doc.getElementById("Social:ToggleSidebar").hidden, enabled, "Social:ToggleSidebar visible?");
isbool(!doc.getElementById("Social:ToggleSidebar").hidden, sidebarEnabled, "Social:ToggleSidebar visible?");
isbool(!doc.getElementById("Social:ToggleNotifications").hidden, enabled, "Social:ToggleNotifications visible?");
isbool(!doc.getElementById("Social:FocusChat").hidden, enabled, "Social:FocusChat visible?");
isbool(doc.getElementById("Social:FocusChat").getAttribute("disabled"), enabled ? "false" : "true", "Social:FocusChat disabled?");