browser_873501_handle_specials.js (3303B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 const kToolbarName = "test-specials-toolbar"; 8 9 registerCleanupFunction(removeCustomToolbars); 10 11 // Add a toolbar with two springs and the downloads button. 12 add_task(async function addToolbarWith2SpringsAndDownloadsButton() { 13 // Create the toolbar with a single spring: 14 createToolbarWithPlacements(kToolbarName, ["spring"]); 15 ok(document.getElementById(kToolbarName), "Toolbar should be created."); 16 17 // Check it's there with a generated ID: 18 assertAreaPlacements(kToolbarName, [/customizableui-special-spring\d+/]); 19 let [springId] = getAreaWidgetIds(kToolbarName); 20 21 // Add a second spring, check if that's there and doesn't share IDs 22 CustomizableUI.addWidgetToArea("spring", kToolbarName); 23 assertAreaPlacements(kToolbarName, [ 24 springId, 25 /customizableui-special-spring\d+/, 26 ]); 27 let [, spring2Id] = getAreaWidgetIds(kToolbarName); 28 29 isnot(springId, spring2Id, "Springs shouldn't have identical IDs."); 30 31 // Try moving the downloads button to this new toolbar, between the two springs: 32 CustomizableUI.addWidgetToArea("downloads-button", kToolbarName, 1); 33 assertAreaPlacements(kToolbarName, [springId, "downloads-button", spring2Id]); 34 await removeCustomToolbars(); 35 }); 36 37 // Add separators around the downloads button. 38 add_task(async function addSeparatorsAroundDownloadsButton() { 39 createToolbarWithPlacements(kToolbarName, ["separator"]); 40 ok(document.getElementById(kToolbarName), "Toolbar should be created."); 41 42 // Check it's there with a generated ID: 43 assertAreaPlacements(kToolbarName, [/customizableui-special-separator\d+/]); 44 let [separatorId] = getAreaWidgetIds(kToolbarName); 45 46 CustomizableUI.addWidgetToArea("separator", kToolbarName); 47 assertAreaPlacements(kToolbarName, [ 48 separatorId, 49 /customizableui-special-separator\d+/, 50 ]); 51 let [, separator2Id] = getAreaWidgetIds(kToolbarName); 52 53 isnot(separatorId, separator2Id, "Separator ids shouldn't be equal."); 54 55 CustomizableUI.addWidgetToArea("downloads-button", kToolbarName, 1); 56 assertAreaPlacements(kToolbarName, [ 57 separatorId, 58 "downloads-button", 59 separator2Id, 60 ]); 61 await removeCustomToolbars(); 62 }); 63 64 // Add spacers around the downloads button. 65 add_task(async function addSpacersAroundDownloadsButton() { 66 createToolbarWithPlacements(kToolbarName, ["spacer"]); 67 ok(document.getElementById(kToolbarName), "Toolbar should be created."); 68 69 // Check it's there with a generated ID: 70 assertAreaPlacements(kToolbarName, [/customizableui-special-spacer\d+/]); 71 let [spacerId] = getAreaWidgetIds(kToolbarName); 72 73 CustomizableUI.addWidgetToArea("spacer", kToolbarName); 74 assertAreaPlacements(kToolbarName, [ 75 spacerId, 76 /customizableui-special-spacer\d+/, 77 ]); 78 let [, spacer2Id] = getAreaWidgetIds(kToolbarName); 79 80 isnot(spacerId, spacer2Id, "Spacer ids shouldn't be equal."); 81 82 CustomizableUI.addWidgetToArea("downloads-button", kToolbarName, 1); 83 assertAreaPlacements(kToolbarName, [spacerId, "downloads-button", spacer2Id]); 84 await removeCustomToolbars(); 85 }); 86 87 add_task(async function asyncCleanup() { 88 await resetCustomization(); 89 });