Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 suite('util', function() { | |
| 6 test('getDescendants collects all children', function() { | |
| 7 var nodes = testTree(createFolder('0', [ | |
| 8 createFolder('1', []), | |
| 9 createFolder( | |
| 10 '2', | |
| 11 [ | |
| 12 createItem('3'), | |
| 13 createFolder( | |
| 14 '4', | |
| 15 [ | |
| 16 createItem('6'), | |
| 17 createFolder('7', []), | |
| 18 ]), | |
| 19 createItem('5'), | |
| 20 ]), | |
| 21 ])); | |
| 22 | |
| 23 function normalizeSet(set) { | |
| 24 return Array.from(set).sort(); | |
| 25 } | |
|
calamity
2017/04/03 06:54:24
FYI, I needed this for another patch so I moved it
tsergeant
2017/04/04 04:42:28
Ack, picked up in the rebase
| |
| 26 | |
| 27 var descendants = bookmarks.util.getDescendants(nodes, '1'); | |
| 28 assertDeepEquals(['1'], normalizeSet(descendants)); | |
| 29 | |
| 30 descendants = bookmarks.util.getDescendants(nodes, '4'); | |
| 31 assertDeepEquals(['4', '6', '7'], normalizeSet(descendants)); | |
| 32 | |
| 33 descendants = bookmarks.util.getDescendants(nodes, '2'); | |
| 34 assertDeepEquals(['2', '3', '4', '5', '6', '7'], normalizeSet(descendants)); | |
| 35 | |
| 36 descendants = bookmarks.util.getDescendants(nodes, '42'); | |
| 37 assertDeepEquals([], normalizeSet(descendants)); | |
| 38 }); | |
| 39 | |
| 40 test('removeNodesFromMap', function() { | |
| 41 var map = { | |
| 42 '1': true, | |
| 43 '2': false, | |
| 44 '4': true, | |
| 45 }; | |
| 46 | |
| 47 var nodes = new Set([2, 3, 4]); | |
| 48 | |
| 49 var newMap = bookmarks.util.removeNodesFromMap(map, nodes); | |
| 50 | |
| 51 assertEquals(undefined, newMap['2']); | |
| 52 assertEquals(undefined, newMap['4']); | |
| 53 assertTrue(newMap['1']); | |
| 54 | |
| 55 // Should not have changed the input map. | |
| 56 assertFalse(map['2']); | |
| 57 }); | |
| 58 }); | |
| OLD | NEW |