browser/components/customizableui/test/browser_887438_currentset_shim.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/customizableui/test/browser_887438_currentset_shim.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,75 @@
     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 +let navbar = document.getElementById("nav-bar");
    1.11 +let navbarCT = navbar.customizationTarget;
    1.12 +let overflowPanelList = document.getElementById("widget-overflow-list");
    1.13 +
    1.14 +// Reading currentset
    1.15 +add_task(function() {
    1.16 +  let nodeIds = [];
    1.17 +  for (let node of navbarCT.childNodes) {
    1.18 +    if (node.getAttribute("skipintoolbarset") != "true") {
    1.19 +      nodeIds.push(node.id);
    1.20 +    }
    1.21 +  }
    1.22 +  for (let node of overflowPanelList.childNodes) {
    1.23 +    if (node.getAttribute("skipintoolbarset") != "true") {
    1.24 +      nodeIds.push(node.id);
    1.25 +    }
    1.26 +  }
    1.27 +  let currentSet = navbar.currentSet;
    1.28 +  is(currentSet.split(',').length, nodeIds.length, "Should be just as many nodes as there are.");
    1.29 +  is(currentSet, nodeIds.join(','), "Current set and node IDs should match.");
    1.30 +});
    1.31 +
    1.32 +// Insert, then remove items
    1.33 +add_task(function() {
    1.34 +  let currentSet = navbar.currentSet;
    1.35 +  let newCurrentSet = currentSet.replace('home-button', 'feed-button,sync-button,home-button');
    1.36 +  navbar.currentSet = newCurrentSet;
    1.37 +  is(newCurrentSet, navbar.currentSet, "Current set should match expected current set.");
    1.38 +  let feedBtn = document.getElementById("feed-button");
    1.39 +  let syncBtn = document.getElementById("sync-button");
    1.40 +  ok(feedBtn, "Feed button should have been added.");
    1.41 +  ok(syncBtn, "Sync button should have been added.");
    1.42 +  if (feedBtn && syncBtn) {
    1.43 +    let feedParent = feedBtn.parentNode;
    1.44 +    let syncParent = syncBtn.parentNode;
    1.45 +    ok(feedParent == navbarCT || feedParent == overflowPanelList,
    1.46 +       "Feed button should be in navbar or overflow");
    1.47 +    ok(syncParent == navbarCT || syncParent == overflowPanelList,
    1.48 +       "Feed button should be in navbar or overflow");
    1.49 +    is(feedBtn.nextElementSibling, syncBtn, "Feed button should be next to sync button.");
    1.50 +    let homeBtn = document.getElementById("home-button");
    1.51 +    is(syncBtn.nextElementSibling, homeBtn, "Sync button should be next to home button.");
    1.52 +  }
    1.53 +  navbar.currentSet = currentSet;
    1.54 +  is(currentSet, navbar.currentSet, "Should be able to remove the added items.");
    1.55 +});
    1.56 +
    1.57 +// Simultaneous insert/remove:
    1.58 +add_task(function() {
    1.59 +  let currentSet = navbar.currentSet;
    1.60 +  let newCurrentSet = currentSet.replace('home-button', 'feed-button');
    1.61 +  navbar.currentSet = newCurrentSet;
    1.62 +  is(newCurrentSet, navbar.currentSet, "Current set should match expected current set.");
    1.63 +  let feedBtn = document.getElementById("feed-button");
    1.64 +  ok(feedBtn, "Feed button should have been added.");
    1.65 +  let homeBtn = document.getElementById("home-button");
    1.66 +  ok(!homeBtn, "Home button should have been removed.");
    1.67 +  if (feedBtn) {
    1.68 +    let feedParent = feedBtn.parentNode;
    1.69 +    ok(feedParent == navbarCT || feedParent == overflowPanelList,
    1.70 +       "Feed button should be in navbar or overflow");
    1.71 +  }
    1.72 +  navbar.currentSet = currentSet;
    1.73 +  is(currentSet, navbar.currentSet, "Should be able to return to original state.");
    1.74 +});
    1.75 +
    1.76 +add_task(function asyncCleanup() {
    1.77 +  yield resetCustomization();
    1.78 +});

mercurial