michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: let navbar = document.getElementById("nav-bar"); michael@0: let navbarCT = navbar.customizationTarget; michael@0: let overflowPanelList = document.getElementById("widget-overflow-list"); michael@0: michael@0: // Reading currentset michael@0: add_task(function() { michael@0: let nodeIds = []; michael@0: for (let node of navbarCT.childNodes) { michael@0: if (node.getAttribute("skipintoolbarset") != "true") { michael@0: nodeIds.push(node.id); michael@0: } michael@0: } michael@0: for (let node of overflowPanelList.childNodes) { michael@0: if (node.getAttribute("skipintoolbarset") != "true") { michael@0: nodeIds.push(node.id); michael@0: } michael@0: } michael@0: let currentSet = navbar.currentSet; michael@0: is(currentSet.split(',').length, nodeIds.length, "Should be just as many nodes as there are."); michael@0: is(currentSet, nodeIds.join(','), "Current set and node IDs should match."); michael@0: }); michael@0: michael@0: // Insert, then remove items michael@0: add_task(function() { michael@0: let currentSet = navbar.currentSet; michael@0: let newCurrentSet = currentSet.replace('home-button', 'feed-button,sync-button,home-button'); michael@0: navbar.currentSet = newCurrentSet; michael@0: is(newCurrentSet, navbar.currentSet, "Current set should match expected current set."); michael@0: let feedBtn = document.getElementById("feed-button"); michael@0: let syncBtn = document.getElementById("sync-button"); michael@0: ok(feedBtn, "Feed button should have been added."); michael@0: ok(syncBtn, "Sync button should have been added."); michael@0: if (feedBtn && syncBtn) { michael@0: let feedParent = feedBtn.parentNode; michael@0: let syncParent = syncBtn.parentNode; michael@0: ok(feedParent == navbarCT || feedParent == overflowPanelList, michael@0: "Feed button should be in navbar or overflow"); michael@0: ok(syncParent == navbarCT || syncParent == overflowPanelList, michael@0: "Feed button should be in navbar or overflow"); michael@0: is(feedBtn.nextElementSibling, syncBtn, "Feed button should be next to sync button."); michael@0: let homeBtn = document.getElementById("home-button"); michael@0: is(syncBtn.nextElementSibling, homeBtn, "Sync button should be next to home button."); michael@0: } michael@0: navbar.currentSet = currentSet; michael@0: is(currentSet, navbar.currentSet, "Should be able to remove the added items."); michael@0: }); michael@0: michael@0: // Simultaneous insert/remove: michael@0: add_task(function() { michael@0: let currentSet = navbar.currentSet; michael@0: let newCurrentSet = currentSet.replace('home-button', 'feed-button'); michael@0: navbar.currentSet = newCurrentSet; michael@0: is(newCurrentSet, navbar.currentSet, "Current set should match expected current set."); michael@0: let feedBtn = document.getElementById("feed-button"); michael@0: ok(feedBtn, "Feed button should have been added."); michael@0: let homeBtn = document.getElementById("home-button"); michael@0: ok(!homeBtn, "Home button should have been removed."); michael@0: if (feedBtn) { michael@0: let feedParent = feedBtn.parentNode; michael@0: ok(feedParent == navbarCT || feedParent == overflowPanelList, michael@0: "Feed button should be in navbar or overflow"); michael@0: } michael@0: navbar.currentSet = currentSet; michael@0: is(currentSet, navbar.currentSet, "Should be able to return to original state."); michael@0: }); michael@0: michael@0: add_task(function asyncCleanup() { michael@0: yield resetCustomization(); michael@0: });