Chromium Code Reviews| Index: chrome/test/data/webui/md_bookmarks/util_test.js |
| diff --git a/chrome/test/data/webui/md_bookmarks/util_test.js b/chrome/test/data/webui/md_bookmarks/util_test.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..58dd1728a907769720306bf90c1f65fe9de40d76 |
| --- /dev/null |
| +++ b/chrome/test/data/webui/md_bookmarks/util_test.js |
| @@ -0,0 +1,58 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +suite('util', function() { |
| + test('getDescendants collects all children', function() { |
| + var nodes = testTree(createFolder('0', [ |
| + createFolder('1', []), |
| + createFolder( |
| + '2', |
| + [ |
| + createItem('3'), |
| + createFolder( |
| + '4', |
| + [ |
| + createItem('6'), |
| + createFolder('7', []), |
| + ]), |
| + createItem('5'), |
| + ]), |
| + ])); |
| + |
| + function normalizeSet(set) { |
| + return Array.from(set).sort(); |
| + } |
|
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
|
| + |
| + var descendants = bookmarks.util.getDescendants(nodes, '1'); |
| + assertDeepEquals(['1'], normalizeSet(descendants)); |
| + |
| + descendants = bookmarks.util.getDescendants(nodes, '4'); |
| + assertDeepEquals(['4', '6', '7'], normalizeSet(descendants)); |
| + |
| + descendants = bookmarks.util.getDescendants(nodes, '2'); |
| + assertDeepEquals(['2', '3', '4', '5', '6', '7'], normalizeSet(descendants)); |
| + |
| + descendants = bookmarks.util.getDescendants(nodes, '42'); |
| + assertDeepEquals([], normalizeSet(descendants)); |
| + }); |
| + |
| + test('removeNodesFromMap', function() { |
| + var map = { |
| + '1': true, |
| + '2': false, |
| + '4': true, |
| + }; |
| + |
| + var nodes = new Set([2, 3, 4]); |
| + |
| + var newMap = bookmarks.util.removeNodesFromMap(map, nodes); |
| + |
| + assertEquals(undefined, newMap['2']); |
| + assertEquals(undefined, newMap['4']); |
| + assertTrue(newMap['1']); |
| + |
| + // Should not have changed the input map. |
| + assertFalse(map['2']); |
| + }); |
| +}); |