Bug 996364 - Calling CustomizableUI.registerArea a second time for the same area throws an exception. r=Gijs

This commit is contained in:
Jared Wein 2014-04-15 15:22:45 -04:00
parent c946c29ace
commit c8af83622f
3 changed files with 64 additions and 1 deletions

View File

@ -297,6 +297,10 @@ let CustomizableUIInternal = {
let areaIsKnown = gAreas.has(aName);
let props = areaIsKnown ? gAreas.get(aName) : new Map();
if (areaIsKnown && aProperties["type"] &&
props.get("type") != aProperties["type"]) {
throw new Error("An area cannot change types");
}
for (let key in aProperties) {
//XXXgijs for special items, we need to make sure they have an appropriate ID
// so we aren't perpetually in a non-default state:
@ -311,7 +315,9 @@ let CustomizableUIInternal = {
props.set("type", CustomizableUI.TYPE_TOOLBAR);
}
if (props.get("type") == CustomizableUI.TYPE_TOOLBAR) {
if (!aInternalCaller && props.has("defaultCollapsed")) {
// Check aProperties instead of props because this check is only interested
// in the passed arguments, not the state of a potentially pre-existing area.
if (!aInternalCaller && aProperties["defaultCollapsed"]) {
throw new Error("defaultCollapsed is only allowed for default toolbars.")
}
if (!props.has("defaultCollapsed")) {

View File

@ -105,5 +105,6 @@ skip-if = os == "linux"
[browser_992747_toggle_noncustomizable_toolbar.js]
[browser_993322_widget_notoolbar.js]
[browser_995164_registerArea_during_customize_mode.js]
[browser_996364_defaultCollapsed.js]
[browser_bootstrapped_custom_toolbar.js]
[browser_panel_toggle.js]

View File

@ -0,0 +1,56 @@
/* 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/. */
"use strict";
// Calling CustomizableUI.registerArea twice with no
// properties should not throw an exception.
add_task(function() {
try {
CustomizableUI.registerArea("area-996364", {});
CustomizableUI.registerArea("area-996364", {});
} catch (ex) {
ok(false, ex.message);
}
CustomizableUI.unregisterArea("area-996364", true);
});
add_task(function() {
let exceptionThrown = false;
try {
CustomizableUI.registerArea("area-996364-2", {"type": CustomizableUI.TYPE_TOOLBAR, "defaultCollapsed": "false"});
} catch (ex) {
exceptionThrown = true;
}
ok(exceptionThrown, "defaultCollapsed is not allowed as an external property");
// No need to unregister the area because registration fails.
});
add_task(function() {
let exceptionThrown;
try {
CustomizableUI.registerArea("area-996364-3", {"type": CustomizableUI.TYPE_TOOLBAR});
CustomizableUI.registerArea("area-996364-3", {"type": CustomizableUI.TYPE_MENU_PANEL});
} catch (ex) {
exceptionThrown = ex;
}
ok(exceptionThrown, "Exception expected, an area cannot change types: " + (exceptionThrown ? exceptionThrown : "[no exception]"));
CustomizableUI.unregisterArea("area-996364-3", true);
});
add_task(function() {
let exceptionThrown;
try {
CustomizableUI.registerArea("area-996364-4", {"type": CustomizableUI.TYPE_MENU_PANEL});
CustomizableUI.registerArea("area-996364-4", {"type": CustomizableUI.TYPE_TOOLBAR});
} catch (ex) {
exceptionThrown = ex;
}
ok(exceptionThrown, "Exception expected, an area cannot change types: " + (exceptionThrown ? exceptionThrown : "[no exception]"));
CustomizableUI.unregisterArea("area-996364-4", true);
});