Bug 777177 - Keep the social sidebar loaded, and dispatch events when it is opened/closed, r=gavin

--HG--
extra : rebase_source : 169f829e129cdabf64db8aea28201a7660fd0446
This commit is contained in:
Shane Caraveo 2012-08-03 14:42:40 -07:00
Родитель 99e28f982d
Коммит bfaebdfb1c
2 изменённых файлов: 68 добавлений и 28 удалений

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

@ -406,6 +406,13 @@ var SocialSidebar = {
return Services.prefs.getBoolPref("social.sidebar.open");
},
dispatchEvent: function(aType, aDetail) {
let sbrowser = document.getElementById("social-sidebar-browser");
let evt = sbrowser.contentDocument.createEvent("CustomEvent");
evt.initCustomEvent(aType, true, true, aDetail ? aDetail : {});
sbrowser.contentDocument.documentElement.dispatchEvent(evt);
},
updateSidebar: function SocialSidebar_updateSidebar() {
// Hide the toggle menu item if the sidebar cannot appear
let command = document.getElementById("Social:ToggleSidebar");
@ -418,17 +425,29 @@ var SocialSidebar = {
broadcaster.hidden = hideSidebar;
command.setAttribute("checked", !hideSidebar);
// If the sidebar is hidden, unload its document
// XXX this results in a poor UX, we should revisit
let sbrowser = document.getElementById("social-sidebar-browser");
if (broadcaster.hidden) {
sbrowser.removeAttribute("origin");
sbrowser.setAttribute("src", "about:blank");
return;
if (hideSidebar) {
this.dispatchEvent("sidebarhide");
// If we're disabled, unload the sidebar content
if (!this.canShow) {
sbrowser.removeAttribute("origin");
sbrowser.setAttribute("src", "about:blank");
}
} else {
// Make sure the right sidebar URL is loaded
if (sbrowser.getAttribute("origin") != Social.provider.origin) {
sbrowser.setAttribute("origin", Social.provider.origin);
sbrowser.setAttribute("src", Social.provider.sidebarURL);
sbrowser.addEventListener("load", function sidebarOnShow() {
sbrowser.removeEventListener("load", sidebarOnShow);
// let load finish, then fire our event
setTimeout(function () {
SocialSidebar.dispatchEvent("sidebarshow");
}, 0);
});
} else {
this.dispatchEvent("sidebarshow");
}
}
// Load the sidebar document
sbrowser.setAttribute("origin", Social.provider.origin);
sbrowser.setAttribute("src", Social.provider.sidebarURL);
}
}

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

@ -15,9 +15,9 @@ function test() {
let manifest = { // normal provider
name: "provider 1",
origin: "https://example1.com",
sidebarURL: "https://example1.com/sidebar.html",
workerURL: "https://example1.com/worker.js",
origin: "https://example.com",
sidebarURL: "https://example.com/browser/browser/base/content/test/social_sidebar.html",
workerURL: "https://example.com/browser/browser/base/content/test/social_worker.js",
iconURL: "chrome://branding/content/icon48.png"
};
runSocialTestWithProvider(manifest, doTest);
@ -29,24 +29,45 @@ function doTest() {
let command = document.getElementById("Social:ToggleSidebar");
let sidebar = document.getElementById("social-sidebar-box");
let browser = sidebar.firstChild;
// Check the the sidebar is initially visible, and loaded
ok(!command.hidden, "sidebar toggle command should be visible");
is(command.getAttribute("checked"), "true", "sidebar toggle command should be checked");
ok(!sidebar.hidden, "sidebar itself should be visible");
ok(Services.prefs.getBoolPref("social.sidebar.open"), "sidebar open pref should be true");
is(sidebar.firstChild.getAttribute('src'), "https://example1.com/sidebar.html", "sidebar url should be set");
function checkShown(shouldBeShown) {
is(command.getAttribute("checked"), shouldBeShown ? "true" : "false",
"toggle command should be " + (shouldBeShown ? "checked" : "unchecked"));
is(sidebar.hidden, !shouldBeShown,
"sidebar should be " + (shouldBeShown ? "visible" : "hidden"));
is(Services.prefs.getBoolPref("social.sidebar.open"), shouldBeShown,
"sidebar open pref should be " + shouldBeShown);
if (shouldBeShown)
is(browser.getAttribute('src'), Social.provider.sidebarURL, "sidebar url should be set");
}
// Now toggle it!
info("Toggling sidebar");
// First check the the sidebar is initially visible, and loaded
ok(!command.hidden, "toggle command should be visible");
checkShown(true);
browser.addEventListener("sidebarhide", function sidebarhide() {
browser.removeEventListener("sidebarhide", sidebarhide);
checkShown(false);
browser.addEventListener("sidebarshow", function sidebarshow() {
browser.removeEventListener("sidebarshow", sidebarshow);
checkShown(true);
// Remove the test provider
SocialService.removeProvider(Social.provider.origin, finish);
});
// Toggle it back on
info("Toggling sidebar back on");
Social.toggleSidebar();
});
// Now toggle it off
info("Toggling sidebar off");
Social.toggleSidebar();
is(command.getAttribute("checked"), "false", "sidebar toggle command should not be checked");
ok(sidebar.hidden, "sidebar itself should not be visible");
ok(!Services.prefs.getBoolPref("social.sidebar.open"), "sidebar open pref should be false");
is(sidebar.firstChild.getAttribute('src'), "about:blank", "sidebar url should not be set");
// Remove the test provider
SocialService.removeProvider(Social.provider.origin, finish);
}
// XXX test sidebar in popup