bug 935640 part 3 Australis, update social sidebar with new ux, test updates, r=markh

This commit is contained in:
Shane Caraveo 2013-12-16 21:38:39 -08:00
parent c5597b6319
commit c76a02a6a5
9 changed files with 83 additions and 384 deletions

View File

@ -35,12 +35,10 @@ support-files =
[browser_social_flyout.js]
[browser_social_isVisible.js]
[browser_social_marks.js]
[browser_social_mozSocial_API.js]
[browser_social_multiprovider.js]
[browser_social_multiworker.js]
[browser_social_perwindowPB.js]
[browser_social_sidebar.js]
[browser_social_status.js]
[browser_social_toolbar.js]
[browser_social_window.js]
[browser_social_workercrash.js]

View File

@ -209,6 +209,12 @@ var tests = {
testBuiltinInstallWithoutManifest: function(next) {
// send installProvider null for the manifest
AddonManager.addAddonListener(installListener(next, manifest));
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 prefname = getManifestPrefname(manifest);
let activationURL = manifest.origin + "/browser/browser/base/content/test/social/social_activate.html"
@ -229,6 +235,12 @@ var tests = {
testBuiltinInstall: function(next) {
// send installProvider a json object for the manifest
AddonManager.addAddonListener(installListener(next, manifest));
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 prefname = getManifestPrefname(manifest);
let activationURL = manifest.origin + "/browser/browser/base/content/test/social/social_activate.html"
@ -248,6 +260,12 @@ var tests = {
},
testWhitelistInstall: function(next) {
AddonManager.addAddonListener(installListener(next, manifest2));
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 activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html"
addTab(activationURL, function(tab) {
@ -266,6 +284,12 @@ var tests = {
},
testDirectoryInstall: function(next) {
AddonManager.addAddonListener(installListener(next, manifest2));
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 activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html"
addTab(activationURL, function(tab) {
@ -286,6 +310,13 @@ var tests = {
// add the provider, change the pref, add it again. The provider at that
// point should be upgraded
let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html"
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();
});
addTab(activationURL, function(tab) {
let doc = tab.linkedBrowser.contentDocument;
let installFrom = doc.nodePrincipal.origin;

View File

@ -14,7 +14,7 @@ function postTestCleanup(callback) {
tabsToRemove = [];
// theses tests use the notification panel but don't bother waiting for it
// to fully open - the end result is that the panel might stay open
SocialUI.activationPanel.hidePopup();
//SocialUI.activationPanel.hidePopup();
Services.prefs.clearUserPref("social.whitelist");
@ -141,19 +141,27 @@ function clickAddonRemoveButton(tab, aCallback) {
}
function activateOneProvider(manifest, finishActivation, aCallback) {
let panel = document.getElementById("servicesInstall-notification");
PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() {
PopupNotifications.panel.removeEventListener("popupshown", onpopupshown);
info("servicesInstall-notification panel opened");
if (finishActivation)
panel.button.click();
else
panel.closebutton.click();
});
activateProvider(manifest.origin, function() {
waitForProviderLoad(function() {
ok(!SocialUI.activationPanel.hidden, "activation panel is showing");
is(Social.provider.origin, manifest.origin, "new provider is active");
checkSocialUI();
if (finishActivation)
document.getElementById("social-activation-button").click();
else
document.getElementById("social-undoactivation-button").click();
if (!finishActivation) {
ok(panel.hidden, "activation panel is not showing");
executeSoon(aCallback);
});
} else {
waitForProviderLoad(function() {
is(Social.provider.origin, manifest.origin, "new provider is active");
checkSocialUI();
executeSoon(aCallback);
});
}
});
}
@ -194,7 +202,8 @@ var tests = {
Services.prefs.setBoolPref("social.remote-install.enabled", false);
activateProvider(gTestDomains[0], function() {
is(SocialUI.enabled, false, "SocialUI is not enabled");
ok(SocialUI.activationPanel.hidden, "activation panel still hidden");
let panel = document.getElementById("servicesInstall-notification");
ok(panel.hidden, "activation panel still hidden");
checkSocialUI();
Services.prefs.clearUserPref("social.remote-install.enabled");
next();
@ -206,7 +215,8 @@ var tests = {
activateIFrameProvider(gTestDomains[0], function() {
is(SocialUI.enabled, false, "SocialUI is not enabled");
ok(!Social.provider, "provider is not installed");
ok(SocialUI.activationPanel.hidden, "activation panel still hidden");
let panel = document.getElementById("servicesInstall-notification");
ok(panel.hidden, "activation panel still hidden");
checkSocialUI();
Services.prefs.clearUserPref("social.whitelist");
next();
@ -263,38 +273,6 @@ var tests = {
});
},
testRemoveNonCurrentProvider: function(next) {
Services.prefs.setCharPref("social.whitelist", gTestDomains.join(","));
SocialService.addProvider(gProviders[0], function() {
SocialService.addProvider(gProviders[1], function() {
Social.provider = Social.providers[1];
checkSocialUI();
// activate the last provider.
let prefname = addBuiltinManifest(gProviders[2]);
activateProvider(gTestDomains[2], function() {
waitForProviderLoad(function() {
ok(!SocialUI.activationPanel.hidden, "activation panel is showing");
is(Social.provider.origin, gTestDomains[2], "new provider is active");
checkSocialUI();
// A bit contrived, but set a new provider current while the
// activation ui is up.
Social.provider = Social.providers[1];
// hit "undo"
document.getElementById("social-undoactivation-button").click();
executeSoon(function() {
// we deactivated - the same provider should be enabled.
is(Social.provider.origin, Social.providers[1].origin, "original provider still be active");
checkSocialUI();
Services.prefs.clearUserPref("social.whitelist");
resetBuiltinManifestPref(prefname);
next();
});
});
});
});
});
},
testAddonManagerDoubleInstall: function(next) {
Services.prefs.setCharPref("social.whitelist", gTestDomains.join(","));
// Create a new tab and load about:addons

View File

@ -1,87 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
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"
};
runSocialTestWithProvider(manifest, function (finishcb) {
runSocialTests(tests, undefined, undefined, finishcb);
});
}
var tests = {
testStatusIcons: function(next) {
let icon = {
name: "testIcon",
iconURL: "chrome://browser/skin/Info.png",
contentPanel: "https://example.com/browser/browser/base/content/test/social/social_panel.html",
counter: 1
};
let iconsReady = false;
let gotSidebarMessage = false;
function checkNext() {
if (iconsReady && gotSidebarMessage)
triggerIconPanel();
}
function triggerIconPanel() {
let pButton = document.getElementById("social-provider-button");
waitForCondition(function() {
// wait for a new button to be inserted inbetween the provider and mark
// button
return !!pButton.nextSibling;
}, function() {
// Click the button to trigger its contentPanel
let statusIcon = pButton.nextSibling;
EventUtils.synthesizeMouseAtCenter(statusIcon, {});
}, "Status icon didn't become non-hidden");
}
let port = Social.provider.getWorkerPort();
ok(port, "provider has a port");
port.onmessage = function (e) {
let topic = e.data.topic;
switch (topic) {
case "test-init-done":
iconsReady = true;
checkNext();
break;
case "got-panel-message":
ok(true, "got panel message");
// Check the panel isn't in our history.
gURLsNotRemembered.push(e.data.location);
break;
case "got-social-panel-visibility":
if (e.data.result == "shown") {
ok(true, "panel shown");
let panel = document.getElementById("social-notification-panel");
panel.hidePopup();
} else if (e.data.result == "hidden") {
ok(true, "panel hidden");
port.close();
next();
}
break;
case "got-sidebar-message":
// The sidebar message will always come first, since it loads by default
ok(true, "got sidebar message");
gotSidebarMessage = true;
// load a status panel
port.postMessage({topic: "test-ambient-notification", data: icon});
checkNext();
break;
}
}
port.postMessage({topic: "test-init"});
}
}

View File

@ -29,8 +29,8 @@ let gProviders = [
var tests = {
testProviderSwitch: function(next) {
let menu = document.getElementById("social-statusarea-popup");
function checkProviderMenu(selectedProvider) {
let menu = document.getElementById("social-statusarea-popup");
let menuProviders = menu.querySelectorAll(".social-provider-menuitem");
is(menuProviders.length, gProviders.length, "correct number of providers listed in the menu");
// Find the selectedProvider's menu item
@ -39,59 +39,44 @@ var tests = {
is(el[0].getAttribute("checked"), "true", "selected provider menu item is checked");
}
checkProviderMenu(gProviders[0]);
// the menu is not populated until onpopupshowing, so wait for popupshown
function theTest() {
checkProviderMenu(gProviders[0]);
// Now wait for the initial provider profile to be set
waitForProviderLoad(function() {
checkUIStateMatchesProvider(gProviders[0]);
// Now wait for the initial provider profile to be set
waitForProviderLoad(function() {
menu.removeEventListener("popupshown", theTest, true);
checkUIStateMatchesProvider(gProviders[0]);
// Now activate "provider 2"
observeProviderSet(function () {
waitForProviderLoad(function() {
checkUIStateMatchesProvider(gProviders[1]);
// disable social, click on the provider menuitem to switch providers
Social.enabled = false;
let menu = document.getElementById("social-statusarea-popup");
let el = menu.getElementsByAttribute("origin", gProviders[0].origin);
is(el.length, 1, "selected provider menu item exists");
el[0].click();
// Now activate "provider 2"
observeProviderSet(function () {
waitForProviderLoad(function() {
checkUIStateMatchesProvider(gProviders[0]);
next();
checkUIStateMatchesProvider(gProviders[1]);
// disable social, click on the provider menuitem to switch providers
Social.enabled = false;
let el = menu.getElementsByAttribute("origin", gProviders[0].origin);
is(el.length, 1, "selected provider menu item exists");
el[0].click();
waitForProviderLoad(function() {
checkUIStateMatchesProvider(gProviders[0]);
next();
});
});
});
Social.activateFromOrigin("https://test1.example.com");
});
Social.activateFromOrigin("https://test1.example.com");
});
};
menu.addEventListener("popupshown", theTest, true);
let button = document.getElementById("social-sidebar-button");
EventUtils.synthesizeMouseAtCenter(button, {});
}
}
function checkUIStateMatchesProvider(provider) {
let profileData = getExpectedProfileData(provider);
// The toolbar
let loginStatus = document.getElementsByClassName("social-statusarea-loggedInStatus");
for (let label of loginStatus) {
is(label.value, profileData.userName, "username name matches provider profile");
}
// Sidebar
is(document.getElementById("social-sidebar-browser").getAttribute("src"), provider.sidebarURL, "side bar URL is set");
}
function getExpectedProfileData(provider) {
// This data is defined in social_worker.js
if (provider.origin == "https://test1.example.com") {
return {
displayName: "Test1 User",
userName: "tester"
};
}
return {
displayName: "Kuma Lisa",
userName: "trickster"
};
}
function observeProviderSet(cb) {
Services.obs.addObserver(function providerSet(subject, topic, data) {
Services.obs.removeObserver(providerSet, "social:provider-set");

View File

@ -21,7 +21,7 @@ function doTest(finishcb) {
let command = document.getElementById("Social:ToggleSidebar");
let sidebar = document.getElementById("social-sidebar-box");
let browser = sidebar.firstChild;
let browser = sidebar.lastChild;
function checkShown(shouldBeShown) {
is(command.getAttribute("checked"), shouldBeShown ? "true" : "false",

View File

@ -41,7 +41,7 @@ function test() {
waitForExplicitFinish();
Services.prefs.setBoolPref("social.allowMultipleWorkers", true);
runSocialTestWithProvider(manifest, function () {
runSocialTestWithProvider(manifest, function (finishcb) {
runSocialTests(tests, undefined, undefined, function () {
Services.prefs.clearUserPref("social.remote-install.enabled");
// just in case the tests failed, clear these here as well
@ -49,7 +49,7 @@ function test() {
Services.prefs.clearUserPref("social.whitelist");
ok(CustomizableUI.inDefaultState, "Should be in the default state when we finish");
CustomizableUI.reset();
finish();
finishcb();
});
});
}

View File

@ -1,198 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
let manifests = [{
name: "provider 1",
origin: "https://example.com",
sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar_empty.html",
iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png"
}, { // used for testing install
name: "provider test1",
origin: "https://test1.example.com",
statusURL: "https://test1.example.com/browser/browser/base/content/test/social/social_panel.html",
iconURL: "https://test1.example.com/browser/browser/base/content/test/general/moz.png",
}];
function test() {
waitForExplicitFinish();
// required to test status button in combination with the toolbaritem
Services.prefs.setBoolPref("social.allowMultipleWorkers", true);
runSocialTestWithProvider(manifests, function (finishcb) {
runSocialTests(tests, undefined, undefined, function() {
Services.prefs.clearUserPref("social.allowMultipleWorkers");
finishcb();
});
});
}
var tests = {
testProfileNone: function(next, useNull) {
let profile = useNull ? null : {};
Social.provider.updateUserProfile(profile);
// check dom values
let portrait = document.getElementsByClassName("social-statusarea-user-portrait")[0].getAttribute("src");
// this is the default image for the profile area when not logged in.
ok(!portrait, "portrait is empty");
let userDetailsBroadcaster = document.getElementById("socialBroadcaster_userDetails");
let notLoggedInStatusValue = userDetailsBroadcaster.getAttribute("notLoggedInLabel");
let userButton = document.getElementsByClassName("social-statusarea-loggedInStatus")[0];
ok(!userButton.hidden, "username is visible");
is(userButton.getAttribute("label"), notLoggedInStatusValue, "label reflects not being logged in");
next();
},
testProfileNull: function(next) {
this.testProfileNone(next, true);
},
testProfileSet: function(next) {
let statusIcon = document.getElementById("social-provider-button").style.listStyleImage;
is(statusIcon, "url(\"" + manifests[0].iconURL + "\")", "manifest iconURL is showing");
let profile = {
portrait: "https://example.com/portrait.jpg",
userName: "trickster",
displayName: "Kuma Lisa",
profileURL: "http://example.com/Kuma_Lisa",
iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png"
}
Social.provider.updateUserProfile(profile);
// check dom values
statusIcon = document.getElementById("social-provider-button").style.listStyleImage;
is(statusIcon, "url(\"" + profile.iconURL + "\")", "profile iconURL is showing");
let portrait = document.getElementsByClassName("social-statusarea-user-portrait")[0].getAttribute("src");
is(profile.portrait, portrait, "portrait is set");
let userButton = document.getElementsByClassName("social-statusarea-loggedInStatus")[0];
ok(!userButton.hidden, "username is visible");
is(userButton.value, profile.userName, "username is set");
next();
},
testNoAmbientNotificationsIsNoKeyboardMenu: function(next) {
// The menu bar isn't as easy to instrument on Mac.
if (navigator.platform.contains("Mac")) {
info("Skipping checking the menubar on Mac OS");
next();
return;
}
// Test that keyboard accessible menuitem doesn't exist when no ambient icons specified.
let toolsPopup = document.getElementById("menu_ToolsPopup");
toolsPopup.addEventListener("popupshown", function ontoolspopupshownNoAmbient() {
toolsPopup.removeEventListener("popupshown", ontoolspopupshownNoAmbient);
let socialToggleMore = document.getElementById("menu_socialAmbientMenu");
ok(socialToggleMore, "Keyboard accessible social menu should exist");
is(socialToggleMore.querySelectorAll("menuitem").length, 6, "The minimum number of menuitems is two when there are no ambient notifications.");
is(socialToggleMore.hidden, false, "Menu should be visible since we show some non-ambient notifications in the menu.");
toolsPopup.hidePopup();
next();
}, false);
document.getElementById("menu_ToolsPopup").openPopup();
},
testAmbientNotifications: function(next) {
let ambience = {
name: "testIcon",
iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png",
contentPanel: "about:blank",
counter: 42,
label: "Test Ambient 1 \u2046",
menuURL: "https://example.com/testAmbient1"
};
let ambience2 = {
name: "testIcon2",
iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png",
contentPanel: "about:blank",
counter: 0,
label: "Test Ambient 2",
menuURL: "https://example.com/testAmbient2"
};
let ambience3 = {
name: "testIcon3",
iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png",
contentPanel: "about:blank",
counter: 0,
label: "Test Ambient 3",
menuURL: "https://example.com/testAmbient3"
};
let ambience4 = {
name: "testIcon4",
iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png",
contentPanel: "about:blank",
counter: 0,
label: "Test Ambient 4",
menuURL: "https://example.com/testAmbient4"
};
Social.provider.setAmbientNotification(ambience);
// for Bug 813834. Check preference whether stored data is correct.
is(JSON.parse(Services.prefs.getComplexValue("social.cached.ambientNotificationIcons", Ci.nsISupportsString).data).data.testIcon.label, "Test Ambient 1 \u2046", "label is stored into preference correctly");
Social.provider.setAmbientNotification(ambience2);
Social.provider.setAmbientNotification(ambience3);
try {
Social.provider.setAmbientNotification(ambience4);
} catch(e) {}
let numIcons = Object.keys(Social.provider.ambientNotificationIcons).length;
ok(numIcons == 3, "prevent adding more than 3 ambient notification icons");
let pButton = document.getElementById("social-provider-button");
waitForCondition(function() {
// wait for a new button to be inserted inbetween the provider and mark
// button
return !!pButton.nextSibling;
}, function () {
let statusIcon = pButton.nextSibling;
let badge = statusIcon.getAttribute("badge");
is(badge, "42", "status value is correct");
// If there is a counter, the aria-label should reflect it.
is(statusIcon.getAttribute("aria-label"), "Test Ambient 1 \u2046 (42)");
ambience.counter = 0;
Social.provider.setAmbientNotification(ambience);
statusIcon = pButton.nextSibling;
badge = statusIcon.getAttribute("badge");
is(badge, "", "status value is correct");
// If there is no counter, the aria-label should be the same as the label
is(statusIcon.getAttribute("aria-label"), "Test Ambient 1 \u2046");
// The menu bar isn't as easy to instrument on Mac.
if (navigator.platform.contains("Mac")) {
next();
return;
}
// Test that keyboard accessible menuitem was added.
let toolsPopup = document.getElementById("menu_ToolsPopup");
toolsPopup.addEventListener("popupshown", function ontoolspopupshownAmbient() {
toolsPopup.removeEventListener("popupshown", ontoolspopupshownAmbient);
let socialToggleMore = document.getElementById("menu_socialAmbientMenu");
ok(socialToggleMore, "Keyboard accessible social menu should exist");
is(socialToggleMore.querySelectorAll("menuitem").length, 9, "The number of menuitems is minimum plus three ambient notification menuitems.");
is(socialToggleMore.hidden, false, "Menu is visible when ambient notifications have label & menuURL");
let menuitem = socialToggleMore.querySelector(".ambient-menuitem");
is(menuitem.getAttribute("label"), "Test Ambient 1 \u2046", "Keyboard accessible ambient menuitem should have specified label");
toolsPopup.hidePopup();
next();
}, false);
document.getElementById("menu_ToolsPopup").openPopup();
}, "statusIcon was never found");
},
testMenuitemsExist: function(next) {
let toggleSidebarMenuitems = document.getElementsByClassName("social-toggle-sidebar-menuitem");
is(toggleSidebarMenuitems.length, 2, "Toggle Sidebar menuitems exist");
let toggleDesktopNotificationsMenuitems = document.getElementsByClassName("social-toggle-notifications-menuitem");
is(toggleDesktopNotificationsMenuitems.length, 2, "Toggle notifications menuitems exist");
let toggleSocialMenuitems = document.getElementsByClassName("social-toggle-menuitem");
is(toggleSocialMenuitems.length, 2, "Toggle Social menuitems exist");
next();
},
testToggleNotifications: function(next) {
let enabled = Services.prefs.getBoolPref("social.toast-notifications.enabled");
let cmd = document.getElementById("Social:ToggleNotifications");
is(cmd.getAttribute("checked"), enabled ? "true" : "false");
enabled = !enabled;
Services.prefs.setBoolPref("social.toast-notifications.enabled", enabled);
is(cmd.getAttribute("checked"), enabled ? "true" : "false");
Services.prefs.clearUserPref("social.toast-notifications.enabled");
next();
}
}

View File

@ -242,14 +242,6 @@ function checkSocialUI(win) {
isbool(win.SocialChatBar.isAvailable, enabled, "chatbar available?");
isbool(!win.SocialChatBar.chatbar.hidden, enabled, "chatbar visible?");
isbool(!doc.getElementById("social-toolbar-item").hidden, active, "toolbar items visible?");
if (active) {
if (!enabled || (Social.defaultProvider.statusURL && Social.allowMultipleWorkers)) {
_ok(!win.SocialToolbar.button.style.listStyleImage, "toolbar button is default icon");
} else {
_is(win.SocialToolbar.button.style.listStyleImage, 'url("' + Social.defaultProvider.iconURL + '")', "toolbar button has provider icon");
}
}
// the menus should always have the provider name
if (provider) {
let contextMenus = [