Bug 971626 - [Australis] Restore Defaults should collapse Title Bar. r=Gijs

This commit is contained in:
Jared Wein 2014-02-14 13:51:33 -05:00
parent 509f166438
commit 19ada84adb
5 changed files with 99 additions and 26 deletions

View File

@ -1360,6 +1360,9 @@ pref("network.disable.ipc.security", true);
// CustomizableUI debug logging.
pref("browser.uiCustomization.debug", false);
// CustomizableUI state of the browser's user interface
pref("browser.uiCustomization.state", "");
// The URL where remote content that composes the UI for Firefox Accounts should
// be fetched. Must use HTTPS.
pref("identity.fxaccounts.remote.uri", "https://accounts.firefox.com/?service=sync&context=fx_desktop_v1");

View File

@ -30,7 +30,7 @@
<menupopup id="customization-toolbar-menu" onpopupshowing="onViewToolbarsPopupShowing(event)"/>
</button>
<spacer flex="1"/>
<button id="customization-undo-reset"
<button id="customization-undo-reset-button"
class="customizationmode-button"
hidden="true"
oncommand="gCustomizeMode.undoReset();"

View File

@ -36,6 +36,7 @@ const kSpecialWidgetPfx = "customizableui-special-";
const kPrefCustomizationState = "browser.uiCustomization.state";
const kPrefCustomizationAutoAdd = "browser.uiCustomization.autoAdd";
const kPrefCustomizationDebug = "browser.uiCustomization.debug";
const kPrefDrawInTitlebar = "browser.tabs.drawInTitlebar";
/**
* The keys are the handlers that are fired when the event type (the value)
@ -128,7 +129,10 @@ let gGroupWrapperCache = new Map();
let gSingleWrapperCache = new WeakMap();
let gListeners = new Set();
let gUIStateBeforeReset = null;
let gUIStateBeforeReset = {
uiCustomizationState: null,
drawInTitlebar: null,
};
let gModuleName = "[CustomizableUI]";
#include logging.js
@ -697,7 +701,7 @@ let CustomizableUIInternal = {
this.insertNode(aWidgetId, aArea, aPosition, true);
if (!gResetting) {
gUIStateBeforeReset = null;
this._clearPreviousUIState();
}
},
@ -756,19 +760,19 @@ let CustomizableUIInternal = {
}
}
if (!gResetting) {
gUIStateBeforeReset = null;
this._clearPreviousUIState();
}
},
onWidgetMoved: function(aWidgetId, aArea, aOldPosition, aNewPosition) {
this.insertNode(aWidgetId, aArea, aNewPosition);
if (!gResetting) {
gUIStateBeforeReset = null;
this._clearPreviousUIState();
}
},
onCustomizeEnd: function(aWindow) {
gUIStateBeforeReset = null;
this._clearPreviousUIState();
},
registerBuildArea: function(aArea, aNode) {
@ -2076,10 +2080,12 @@ let CustomizableUIInternal = {
_resetUIState: function() {
try {
gUIStateBeforeReset = Services.prefs.getCharPref(kPrefCustomizationState);
gUIStateBeforeReset.drawInTitlebar = Services.prefs.getBoolPref(kPrefDrawInTitlebar);
gUIStateBeforeReset.uiCustomizationState = Services.prefs.getCharPref(kPrefCustomizationState);
} catch(e) { }
Services.prefs.clearUserPref(kPrefCustomizationState);
Services.prefs.clearUserPref(kPrefDrawInTitlebar);
LOG("State reset");
// Reset placements to make restoring default placements possible.
@ -2114,17 +2120,31 @@ let CustomizableUIInternal = {
* Undoes a previous reset, restoring the state of the UI to the state prior to the reset.
*/
undoReset: function() {
if (!gUIStateBeforeReset) {
if (gUIStateBeforeReset.uiCustomizationState == null ||
gUIStateBeforeReset.drawInTitlebar == null) {
return;
}
Services.prefs.setCharPref(kPrefCustomizationState, gUIStateBeforeReset);
let uiCustomizationState = gUIStateBeforeReset.uiCustomizationState;
let drawInTitlebar = gUIStateBeforeReset.drawInTitlebar;
// Need to clear the previous state before setting the prefs
// because pref observers may check if there is a previous UI state.
this._clearPreviousUIState();
Services.prefs.setCharPref(kPrefCustomizationState, uiCustomizationState);
Services.prefs.setBoolPref(kPrefDrawInTitlebar, drawInTitlebar);
this.loadSavedState();
for (let areaId of Object.keys(gSavedState.placements)) {
let placements = gSavedState.placements[areaId];
gPlacements.set(areaId, placements);
}
this._rebuildRegisteredAreas();
gUIStateBeforeReset = null;
},
_clearPreviousUIState: function() {
Object.getOwnPropertyNames(gUIStateBeforeReset).forEach((prop) => {
gUIStateBeforeReset[prop] = null;
});
},
/**
@ -2271,6 +2291,11 @@ let CustomizableUIInternal = {
}
}
if (Services.prefs.prefHasUserValue(kPrefDrawInTitlebar)) {
LOG(kPrefDrawInTitlebar + " pref is non-default");
return false;
}
return true;
}
};
@ -2894,7 +2919,8 @@ this.CustomizableUI = {
* Restore Defaults can be performed.
*/
get canUndoReset() {
return !!gUIStateBeforeReset;
return gUIStateBeforeReset.uiCustomizationState != null ||
gUIStateBeforeReset.drawInTitlebar != null;
},
/**

View File

@ -999,8 +999,8 @@ CustomizeMode.prototype = {
},
_updateUndoResetButton: function() {
let undoReset = this.document.getElementById("customization-undo-reset");
undoReset.hidden = !CustomizableUI.canUndoReset;
let undoResetButton = this.document.getElementById("customization-undo-reset-button");
undoResetButton.hidden = !CustomizableUI.canUndoReset;
},
handleEvent: function(aEvent) {
@ -1052,7 +1052,9 @@ CustomizeMode.prototype = {
observe: function(aSubject, aTopic, aData) {
switch (aTopic) {
case "nsPref:changed":
this._updateResetButton();
this._updateTitlebarButton();
this._updateUndoResetButton();
break;
}
},

View File

@ -11,18 +11,18 @@ add_task(function() {
yield startCustomizing();
ok(!CustomizableUI.inDefaultState, "Not in default state to begin with");
is(CustomizableUI.getPlacementOfWidget(homeButtonId), null, "Home button is in palette");
let undoReset = document.getElementById("customization-undo-reset");
is(undoReset.hidden, true, "The undo button is hidden before reset");
let undoResetButton = document.getElementById("customization-undo-reset-button");
is(undoResetButton.hidden, true, "The undo button is hidden before reset");
yield gCustomizeMode.reset();
ok(CustomizableUI.inDefaultState, "In default state after reset");
is(undoReset.hidden, false, "The undo button is visible after reset");
is(undoResetButton.hidden, false, "The undo button is visible after reset");
undoReset.click();
undoResetButton.click();
yield waitForCondition(function() !gCustomizeMode.resetting);
ok(!CustomizableUI.inDefaultState, "Not in default state after reset-undo");
is(undoReset.hidden, true, "The undo button is hidden after clicking on the undo button");
is(undoResetButton.hidden, true, "The undo button is hidden after clicking on the undo button");
is(CustomizableUI.getPlacementOfWidget(homeButtonId), null, "Home button is in palette");
yield gCustomizeMode.reset();
@ -34,29 +34,71 @@ add_task(function() {
CustomizableUI.removeWidgetFromArea(homeButtonId);
ok(!CustomizableUI.inDefaultState, "Not in default state to begin with");
is(CustomizableUI.getPlacementOfWidget(homeButtonId), null, "Home button is in palette");
let undoReset = document.getElementById("customization-undo-reset");
is(undoReset.hidden, true, "The undo button is hidden before reset");
let undoResetButton = document.getElementById("customization-undo-reset-button");
is(undoResetButton.hidden, true, "The undo button is hidden before reset");
yield gCustomizeMode.reset();
ok(CustomizableUI.inDefaultState, "In default state after reset");
is(undoReset.hidden, false, "The undo button is visible after reset");
is(undoResetButton.hidden, false, "The undo button is visible after reset");
CustomizableUI.addWidgetToArea(homeButtonId, CustomizableUI.AREA_PANEL);
is(undoReset.hidden, true, "The undo button is hidden after another change");
is(undoResetButton.hidden, true, "The undo button is hidden after another change");
});
// "Restore defaults", exiting customize, and re-entering shouldn't show the Undo button
add_task(function() {
let undoReset = document.getElementById("customization-undo-reset");
is(undoReset.hidden, true, "The undo button is hidden before a reset");
let undoResetButton = document.getElementById("customization-undo-reset-button");
is(undoResetButton.hidden, true, "The undo button is hidden before a reset");
ok(!CustomizableUI.inDefaultState, "The browser should not be in default state");
yield gCustomizeMode.reset();
is(undoReset.hidden, false, "The undo button is hidden after a reset");
is(undoResetButton.hidden, false, "The undo button is visible after a reset");
yield endCustomizing();
yield startCustomizing();
is(undoReset.hidden, true, "The undo reset button should be hidden after entering customization mode");
is(undoResetButton.hidden, true, "The undo reset button should be hidden after entering customization mode");
});
// Bug 971626 - Restore Defaults should collapse the Title Bar
add_task(function() {
if (Services.appinfo.OS != "WINNT" &&
Services.appinfo.OS != "Darwin") {
return;
}
let prefName = "browser.tabs.drawInTitlebar";
let defaultValue = Services.prefs.getBoolPref(prefName);
let restoreDefaultsButton = document.getElementById("customization-reset-button");
let titleBarButton = document.getElementById("customization-titlebar-visibility-button");
let undoResetButton = document.getElementById("customization-undo-reset-button");
ok(CustomizableUI.inDefaultState, "Should be in default state at start of test");
ok(restoreDefaultsButton.disabled, "Restore defaults button should be disabled when in default state");
is(titleBarButton.hasAttribute("checked"), !defaultValue, "Title bar button should reflect pref value");
is(undoResetButton.hidden, true, "Undo reset button should be hidden at start of test");
Services.prefs.setBoolPref(prefName, !defaultValue);
ok(!restoreDefaultsButton.disabled, "Restore defaults button should be enabled when pref changed");
is(titleBarButton.hasAttribute("checked"), defaultValue, "Title bar button should reflect changed pref value");
ok(!CustomizableUI.inDefaultState, "With titlebar flipped, no longer default");
is(undoResetButton.hidden, true, "Undo reset button should be hidden after pref change");
yield gCustomizeMode.reset();
ok(restoreDefaultsButton.disabled, "Restore defaults button should be disabled after reset");
is(titleBarButton.hasAttribute("checked"), !defaultValue, "Title bar button should reflect default value after reset");
is(Services.prefs.getBoolPref(prefName), defaultValue, "Reset should reset drawInTitlebar");
ok(CustomizableUI.inDefaultState, "In default state after titlebar reset");
is(undoResetButton.hidden, false, "Undo reset button should be visible after reset");
ok(!undoResetButton.disabled, "Undo reset button should be enabled after reset");
yield gCustomizeMode.undoReset();
ok(!restoreDefaultsButton.disabled, "Restore defaults button should be enabled after undo-reset");
is(titleBarButton.hasAttribute("checked"), defaultValue, "Title bar button should reflect undo-reset value");
ok(!CustomizableUI.inDefaultState, "No longer in default state after undo");
is(Services.prefs.getBoolPref(prefName), !defaultValue, "Undo-reset goes back to previous pref value");
is(undoResetButton.hidden, true, "Undo reset button should be hidden after undo-reset clicked");
Services.prefs.clearUserPref(prefName);
ok(CustomizableUI.inDefaultState, "In default state after pref cleared");
is(undoResetButton.hidden, true, "Undo reset button should be hidden at end of test");
});
add_task(function asyncCleanup() {