Bug 952963 - areaType getter in widget wrapper shouldn't assume area exists, r=jaws

--HG--
extra : rebase_source : adf2bb0d616b9ad92d88854a903f1b9de33661bb
This commit is contained in:
Gijs Kruitbosch 2014-01-02 21:17:58 +00:00
parent 835ba547a7
commit 9d2bc9127f
3 changed files with 57 additions and 2 deletions

View File

@ -2889,7 +2889,8 @@ function WidgetGroupWrapper(aWidget) {
});
this.__defineGetter__("areaType", function() {
return gAreas.get(aWidget.currentArea).get("type");
let areaProps = gAreas.get(aWidget.currentArea);
return areaProps && areaProps.get("type");
});
Object.freeze(this);
@ -2990,7 +2991,8 @@ function XULWidgetGroupWrapper(aWidgetId) {
return null;
}
return gAreas.get(placement.area).get("type");
let areaProps = gAreas.get(placement.area);
return areaProps && areaProps.get("type");
});
this.__defineGetter__("instances", function() {

View File

@ -50,4 +50,5 @@ skip-if = os == "mac"
[browser_945739_showInPrivateBrowsing_customize_mode.js]
[browser_947987_removable_default.js]
[browser_948985_non_removable_defaultArea.js]
[browser_952963_areaType_getter_no_area.js]
[browser_panel_toggle.js]

View File

@ -0,0 +1,52 @@
/* 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";
const kToolbarName = "test-unregisterArea-areaType";
const kUnregisterAreaTestWidget = "test-widget-for-unregisterArea-areaType";
const kTestWidget = "test-widget-no-area-areaType";
registerCleanupFunction(removeCustomToolbars);
function checkAreaType(widget) {
try {
is(widget.areaType, null, "areaType should be null");
} catch (ex) {
info("Fetching areaType threw: " + ex);
ok(false, "areaType getter shouldn't throw.");
}
}
// widget wrappers in unregisterArea'd areas and nowhere shouldn't throw when checking areaTypes.
add_task(function() {
// Using the ID before it's been created will imply a XUL wrapper; we'll test
// an API-based wrapper below
let toolbarNode = createToolbarWithPlacements(kToolbarName, [kUnregisterAreaTestWidget]);
CustomizableUI.unregisterArea(kToolbarName);
toolbarNode.remove();
let w = CustomizableUI.getWidget(kUnregisterAreaTestWidget);
checkAreaType(w);
w = CustomizableUI.getWidget(kTestWidget);
checkAreaType(w);
let spec = {id: kUnregisterAreaTestWidget, type: 'button', removable: true,
label: "areaType test", tooltiptext: "areaType test"};
CustomizableUI.createWidget(spec);
let toolbarNode = createToolbarWithPlacements(kToolbarName, [kUnregisterAreaTestWidget]);
CustomizableUI.unregisterArea(kToolbarName);
toolbarNode.remove();
w = CustomizableUI.getWidget(spec.id);
checkAreaType(w);
CustomizableUI.removeWidgetFromArea(kUnregisterAreaTestWidget);
checkAreaType(w);
//XXXgijs: ensure cleanup function doesn't barf:
gAddedToolbars.delete(kToolbarName);
});
add_task(function asyncCleanup() {
yield resetCustomization();
});