1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/customizableui/test/browser_873501_handle_specials.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +const kToolbarName = "test-specials-toolbar"; 1.11 + 1.12 +registerCleanupFunction(removeCustomToolbars); 1.13 + 1.14 +// Add a toolbar with two springs and the downloads button. 1.15 +add_task(function addToolbarWith2SpringsAndDownloadsButton() { 1.16 + // Create the toolbar with a single spring: 1.17 + createToolbarWithPlacements(kToolbarName, ["spring"]); 1.18 + ok(document.getElementById(kToolbarName), "Toolbar should be created."); 1.19 + 1.20 + // Check it's there with a generated ID: 1.21 + assertAreaPlacements(kToolbarName, [/customizableui-special-spring\d+/]); 1.22 + let [springId] = getAreaWidgetIds(kToolbarName); 1.23 + 1.24 + // Add a second spring, check if that's there and doesn't share IDs 1.25 + CustomizableUI.addWidgetToArea("spring", kToolbarName); 1.26 + assertAreaPlacements(kToolbarName, [springId, 1.27 + /customizableui-special-spring\d+/]); 1.28 + let [, spring2Id] = getAreaWidgetIds(kToolbarName); 1.29 + 1.30 + isnot(springId, spring2Id, "Springs shouldn't have identical IDs."); 1.31 + 1.32 + // Try moving the downloads button to this new toolbar, between the two springs: 1.33 + CustomizableUI.addWidgetToArea("downloads-button", kToolbarName, 1); 1.34 + assertAreaPlacements(kToolbarName, [springId, "downloads-button", spring2Id]); 1.35 + yield removeCustomToolbars(); 1.36 +}); 1.37 + 1.38 +// Add separators around the downloads button. 1.39 +add_task(function addSeparatorsAroundDownloadsButton() { 1.40 + createToolbarWithPlacements(kToolbarName, ["separator"]); 1.41 + ok(document.getElementById(kToolbarName), "Toolbar should be created."); 1.42 + 1.43 + // Check it's there with a generated ID: 1.44 + assertAreaPlacements(kToolbarName, [/customizableui-special-separator\d+/]); 1.45 + let [separatorId] = getAreaWidgetIds(kToolbarName); 1.46 + 1.47 + CustomizableUI.addWidgetToArea("separator", kToolbarName); 1.48 + assertAreaPlacements(kToolbarName, [separatorId, 1.49 + /customizableui-special-separator\d+/]); 1.50 + let [, separator2Id] = getAreaWidgetIds(kToolbarName); 1.51 + 1.52 + isnot(separatorId, separator2Id, "Separator ids shouldn't be equal."); 1.53 + 1.54 + CustomizableUI.addWidgetToArea("downloads-button", kToolbarName, 1); 1.55 + assertAreaPlacements(kToolbarName, [separatorId, "downloads-button", separator2Id]); 1.56 + yield removeCustomToolbars(); 1.57 +}); 1.58 + 1.59 +// Add spacers around the downloads button. 1.60 +add_task(function addSpacersAroundDownloadsButton() { 1.61 + createToolbarWithPlacements(kToolbarName, ["spacer"]); 1.62 + ok(document.getElementById(kToolbarName), "Toolbar should be created."); 1.63 + 1.64 + // Check it's there with a generated ID: 1.65 + assertAreaPlacements(kToolbarName, [/customizableui-special-spacer\d+/]); 1.66 + let [spacerId] = getAreaWidgetIds(kToolbarName); 1.67 + 1.68 + CustomizableUI.addWidgetToArea("spacer", kToolbarName); 1.69 + assertAreaPlacements(kToolbarName, [spacerId, 1.70 + /customizableui-special-spacer\d+/]); 1.71 + let [, spacer2Id] = getAreaWidgetIds(kToolbarName); 1.72 + 1.73 + isnot(spacerId, spacer2Id, "Spacer ids shouldn't be equal."); 1.74 + 1.75 + CustomizableUI.addWidgetToArea("downloads-button", kToolbarName, 1); 1.76 + assertAreaPlacements(kToolbarName, [spacerId, "downloads-button", spacer2Id]); 1.77 + yield removeCustomToolbars(); 1.78 +}); 1.79 + 1.80 +add_task(function asyncCleanup() { 1.81 + yield resetCustomization(); 1.82 +});