mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 877178 - Tests for unregisterArea, r=jaws
--HG-- extra : rebase_source : a7ff14159918566306be0097ee0694941d07e30a
This commit is contained in:
parent
6b3f18f085
commit
01e58085c7
@ -12,6 +12,7 @@ include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MOCHITEST_BROWSER_FILES = \
|
||||
browser_873501_handle_specials.js \
|
||||
browser_877178_unregisterArea.js \
|
||||
head.js \
|
||||
$(NULL)
|
||||
|
||||
|
@ -0,0 +1,64 @@
|
||||
/* 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/. */
|
||||
|
||||
let gTests = [
|
||||
{
|
||||
desc: "Sanity checks",
|
||||
run: function() {
|
||||
SimpleTest.doesThrow(function() CustomizableUI.registerArea("@foo"),
|
||||
"Registering areas with an invalid ID should throw.");
|
||||
|
||||
SimpleTest.doesThrow(function() CustomizableUI.registerArea([]),
|
||||
"Registering areas with an invalid ID should throw.");
|
||||
|
||||
SimpleTest.doesThrow(function() CustomizableUI.registerArea(CustomizableUI.AREA_NAVBAR),
|
||||
"Registering an area with an ID that's already registered should throw.");
|
||||
|
||||
SimpleTest.doesThrow(function() CustomizableUI.unregisterArea("@foo"),
|
||||
"Unregistering areas with an invalid ID should throw.");
|
||||
|
||||
SimpleTest.doesThrow(function() CustomizableUI.unregisterArea([]),
|
||||
"Unregistering areas with an invalid ID should throw.");
|
||||
|
||||
SimpleTest.doesThrow(function() CustomizableUI.unregisterArea("unknown"),
|
||||
"Unregistering an area that's not registered should throw.");
|
||||
}
|
||||
},
|
||||
{
|
||||
desc: "Check areas are loaded with their default placements.",
|
||||
run: function() {
|
||||
ok(CustomizableUI.inDefaultState, "Everything should be in its default state.");
|
||||
}
|
||||
},
|
||||
{
|
||||
desc: "Check registering and unregistering a new area.",
|
||||
run: function() {
|
||||
const kToolbarId = "test-registration-toolbar";
|
||||
const kButtonId = "test-registration-button";
|
||||
createDummyXULButton(kButtonId);
|
||||
createToolbarWithPlacements(kToolbarId, ["spring", kButtonId, "spring"]);
|
||||
assertAreaPlacements(kToolbarId,
|
||||
[/customizableui-special-spring\d+/,
|
||||
kButtonId,
|
||||
/customizableui-special-spring\d+/]);
|
||||
ok(CustomizableUI.inDefaultState, "With a new toolbar and default placements, " +
|
||||
"everything should still be in a default state.");
|
||||
removeCustomToolbars(); // Will call unregisterArea for us
|
||||
ok(CustomizableUI.inDefaultState, "When the toolbar is unregistered, " +
|
||||
"everything should still be in a default state.");
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
function cleanup() {
|
||||
removeCustomToolbars();
|
||||
resetCustomization();
|
||||
}
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
registerCleanupFunction(cleanup);
|
||||
runTests(gTests);
|
||||
}
|
||||
|
@ -11,22 +11,30 @@ let {Task, CustomizableUI} = tmp;
|
||||
|
||||
const kNSXUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
||||
|
||||
function createDummyXULButton(id, label) {
|
||||
let btn = document.createElementNS(kNSXUL, "toolbarbutton");
|
||||
btn.id = id;
|
||||
btn.setAttribute("label", label || id);
|
||||
btn.className = "toolbarbutton-1 chromeclass-toolbar-additional";
|
||||
window.gNavToolbox.palette.appendChild(btn);
|
||||
return btn;
|
||||
}
|
||||
|
||||
function createToolbarWithPlacements(id, placements) {
|
||||
let tb = document.createElementNS(kNSXUL, "toolbar");
|
||||
tb.id = id;
|
||||
tb.setAttribute("customizable", "true");
|
||||
document.getElementById("customToolbars").appendChild(tb);
|
||||
CustomizableUI.registerArea(id, {
|
||||
type: CustomizableUI.TYPE_TOOLBAR
|
||||
type: CustomizableUI.TYPE_TOOLBAR,
|
||||
defaultPlacements: placements
|
||||
});
|
||||
for (let p of placements) {
|
||||
CustomizableUI.addWidgetToArea(p, id);
|
||||
}
|
||||
}
|
||||
|
||||
function removeCustomToolbars() {
|
||||
let customToolbarSet = document.getElementById("customToolbars");
|
||||
while (customToolbarSet.lastChild) {
|
||||
CustomizableUI.unregisterArea(customToolbarSet.lastChild.id);
|
||||
customToolbarSet.lastChild.remove();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user