Bug 1029098 support global sidebar state for users who do not turn on restore session state, r=felipe

This commit is contained in:
Shane Caraveo 2014-06-25 13:15:08 -07:00
Родитель e03a6ff4a9
Коммит de7cffa9f0
2 изменённых файлов: 82 добавлений и 8 удалений

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

@ -90,6 +90,7 @@ SocialUI = {
if (!this._initialized) {
return;
}
SocialSidebar.saveWindowState();
Services.obs.removeObserver(this, "social:ambient-notification-changed");
Services.obs.removeObserver(this, "social:profile-changed");
@ -710,6 +711,11 @@ SocialSidebar = {
},
restoreWindowState: function() {
// Window state is used to allow different sidebar providers in each window.
// We also store the provider used in a pref as the default sidebar to
// maintain that state for users who do not restore window state. The
// existence of social.sidebar.provider means the sidebar is open with that
// provider.
this._initialized = true;
if (!this.canShow)
return;
@ -737,13 +743,22 @@ SocialSidebar = {
let data = SessionStore.getWindowValue(window, "socialSidebar");
// if this window doesn't have it's own state, use the state from the opener
if (!data && window.opener && !window.opener.closed) {
data = SessionStore.getWindowValue(window.opener, "socialSidebar");
try {
data = SessionStore.getWindowValue(window.opener, "socialSidebar");
} catch(e) {
// Window is not tracked, which happens on osx if the window is opened
// from the hidden window. That happens when you close the last window
// without quiting firefox, then open a new window.
}
}
if (data) {
data = JSON.parse(data);
document.getElementById("social-sidebar-browser").setAttribute("origin", data.origin);
if (!data.hidden)
this.show(data.origin);
} else if (Services.prefs.prefHasUserValue("social.sidebar.provider")) {
// no window state, use the global state if it is available
this.show(Services.prefs.getCharPref("social.sidebar.provider"));
}
},
@ -754,7 +769,18 @@ SocialSidebar = {
"hidden": broadcaster.hidden,
"origin": sidebarOrigin
};
SessionStore.setWindowValue(window, "socialSidebar", JSON.stringify(data));
// Save a global state for users who do not restore state.
if (broadcaster.hidden)
Services.prefs.clearUserPref("social.sidebar.provider");
else
Services.prefs.setCharPref("social.sidebar.provider", sidebarOrigin);
try {
SessionStore.setWindowValue(window, "socialSidebar", JSON.stringify(data));
} catch(e) {
// window not tracked during uninit
}
},
setSidebarVisibilityState: function(aEnabled) {

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

@ -30,17 +30,20 @@ function openWindowAndWaitForInit(parentWin, callback) {
}, topic, false);
}
function closeWindow(w, cb) {
waitForNotification("domwindowclosed", cb);
w.close();
}
function closeOneWindow(cb) {
let w = createdWindows.pop();
if (!w) {
if (!w || w.closed) {
cb();
return;
}
waitForCondition(function() w.closed,
function() {
info("window closed, " + createdWindows.length + " windows left");
closeOneWindow(cb);
}, "window did not close");
closeWindow(w, function() {
closeOneWindow(cb);
});
w.close();
}
@ -126,6 +129,51 @@ let tests = {
}, cbnext);
},
testGlobalState: function(cbnext) {
setManifestPref("social.manifest.test", manifest);
ok(!SocialSidebar.opened, "sidebar is closed initially");
ok(!Services.prefs.prefHasUserValue("social.sidebar.provider"), "global state unset");
// mimick no session state in opener so we exercise the global state via pref
SessionStore.deleteWindowValue(window, "socialSidebar");
ok(!SessionStore.getWindowValue(window, "socialSidebar"), "window state unset");
SocialService.addProvider(manifest, function() {
openWindowAndWaitForInit(window, function(w1) {
w1.SocialSidebar.show();
waitForCondition(function() w1.SocialSidebar.opened,
function() {
ok(Services.prefs.prefHasUserValue("social.sidebar.provider"), "global state set");
ok(!SocialSidebar.opened, "1. main sidebar is still closed");
ok(w1.SocialSidebar.opened, "1. window sidebar is open");
closeWindow(w1, function() {
// this time, the global state should cause the sidebar to be opened
// in the new window
openWindowAndWaitForInit(window, function(w1) {
ok(!SocialSidebar.opened, "2. main sidebar is still closed");
ok(w1.SocialSidebar.opened, "2. window sidebar is open");
w1.SocialSidebar.hide();
ok(!w1.SocialSidebar.opened, "2. window sidebar is closed");
ok(!Services.prefs.prefHasUserValue("social.sidebar.provider"), "2. global state unset");
// global state should now be no sidebar gets opened on new window
closeWindow(w1, function() {
ok(!Services.prefs.prefHasUserValue("social.sidebar.provider"), "3. global state unset");
ok(!SocialSidebar.opened, "3. main sidebar is still closed");
openWindowAndWaitForInit(window, function(w1) {
ok(!Services.prefs.prefHasUserValue("social.sidebar.provider"), "4. global state unset");
ok(!SocialSidebar.opened, "4. main sidebar is still closed");
ok(!w1.SocialSidebar.opened, "4. window sidebar is closed");
SocialService.removeProvider(manifest.origin, function() {
Services.prefs.clearUserPref("social.manifest.test");
cbnext();
});
});
});
});
});
});
});
});
},
// Check per window sidebar functionality, including migration from using
// prefs to using session state, and state inheritance of windows (new windows
// inherit state from the opener).