Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 suite('<bookmarks-store>', function() { | 5 suite('<bookmarks-store>', function() { |
| 6 var store; | 6 var store; |
| 7 var TEST_TREE = { | 7 var TEST_TREE = { |
| 8 id: '0', | 8 id: '0', |
| 9 children: [ | 9 children: [ |
| 10 { | 10 { |
| 11 id: '1', | 11 id: '1', |
| 12 children: [ | 12 children: [ |
| 13 {id: '2', url: 'link2'}, | 13 {id: '2', url: 'link2'}, |
| 14 {id: '3', children: []} | 14 {id: '3', children: []} |
| 15 ] | 15 ] |
| 16 }, | 16 }, |
| 17 {id: '4', url: 'link4'}, | 17 {id: '4', url: 'link4'}, |
| 18 {id: '5', url: 'link5'} | 18 {id: '5', url: 'link5'} |
| 19 ] | 19 ] |
| 20 }; | 20 }; |
| 21 | 21 |
| 22 setup(function() { | 22 setup(function() { |
| 23 store = document.createElement('bookmarks-store'); | 23 store = document.createElement('bookmarks-store'); |
| 24 store.isTesting_ = true; | 24 store.isTesting_ = true; |
| 25 replaceBody(store); | 25 replaceBody(store); |
| 26 store.setupStore_(TEST_TREE); | 26 store.setupStore_(TEST_TREE); |
| 27 }); | 27 }); |
| 28 | 28 |
| 29 test('initNodes inserts nodes into idToNodeMap', function(){ | 29 test('mapNodes inserts nodes into idToNodeMap', function(){ |
|
tsergeant
2017/01/03 23:31:17
Undo all changes to this file. These were comments
jiaxi
2017/01/04 02:50:16
Done.
| |
| 30 assertEquals(TEST_TREE, store.idToNodeMap_['0']); | 30 assertEquals(TEST_TREE, store.idToNodeMap_['0']); |
| 31 assertEquals(TEST_TREE.children[0], store.idToNodeMap_['1']); | 31 assertEquals(TEST_TREE.children[0], store.idToNodeMap_['1']); |
| 32 assertEquals(TEST_TREE.children[0].children[0], store.idToNodeMap_['2']); | 32 assertEquals(TEST_TREE.children[0].children[0], store.idToNodeMap_['2']); |
| 33 assertEquals(TEST_TREE.children[0].children[1], store.idToNodeMap_['3']); | 33 assertEquals(TEST_TREE.children[0].children[1], store.idToNodeMap_['3']); |
| 34 assertEquals(TEST_TREE.children[1], store.idToNodeMap_['4']); | 34 assertEquals(TEST_TREE.children[1], store.idToNodeMap_['4']); |
| 35 assertEquals(TEST_TREE.children[2], store.idToNodeMap_['5']); | 35 assertEquals(TEST_TREE.children[2], store.idToNodeMap_['5']); |
| 36 }); | 36 }); |
| 37 | 37 |
| 38 test('changing selectedId changes the selectedNode', function(){ | 38 test('changing selectedId is changing the selectedNode', function(){ |
| 39 store.selectedId = '0'; | 39 store.selectedId = '0'; |
| 40 assertEquals(TEST_TREE, store.selectedNode); | 40 assertEquals(TEST_TREE, store.selectedNode); |
| 41 store.selectedId = '1'; | 41 store.selectedId = '1'; |
| 42 assertEquals(TEST_TREE.children[0], store.selectedNode); | 42 assertEquals(TEST_TREE.children[0], store.selectedNode); |
| 43 store.selectedId = '2'; | 43 store.selectedId = '2'; |
| 44 assertEquals(TEST_TREE.children[0].children[0], store.selectedNode); | 44 assertEquals(TEST_TREE.children[0].children[0], store.selectedNode); |
| 45 store.selectedId = '3'; | 45 store.selectedId = '3'; |
| 46 assertEquals(TEST_TREE.children[0].children[1], store.selectedNode); | 46 assertEquals(TEST_TREE.children[0].children[1], store.selectedNode); |
| 47 store.selectedId = '4'; | 47 store.selectedId = '4'; |
| 48 assertEquals(TEST_TREE.children[1], store.selectedNode); | 48 assertEquals(TEST_TREE.children[1], store.selectedNode); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 assertTrue(store.idToNodeMap_['3'].isSelected); | 80 assertTrue(store.idToNodeMap_['3'].isSelected); |
| 81 assertFalse(store.idToNodeMap_['1'].isSelected); | 81 assertFalse(store.idToNodeMap_['1'].isSelected); |
| 82 | 82 |
| 83 // Select a folder in separate subtree. | 83 // Select a folder in separate subtree. |
| 84 store.fire('selected-folder-changed', '5'); | 84 store.fire('selected-folder-changed', '5'); |
| 85 assertEquals('5', store.selectedId); | 85 assertEquals('5', store.selectedId); |
| 86 assertTrue(store.idToNodeMap_['5'].isSelected); | 86 assertTrue(store.idToNodeMap_['5'].isSelected); |
| 87 assertFalse(store.idToNodeMap_['3'].isSelected); | 87 assertFalse(store.idToNodeMap_['3'].isSelected); |
| 88 }); | 88 }); |
| 89 | 89 |
| 90 test('store updates on open and close', function() { | 90 test('store update on folder open and closed', function() { |
| 91 // All folders are open by default. | 91 // All folders are open by default. |
| 92 for (var id in store.idToNodeMap_) { | 92 for (var id in store.idToNodeMap_) { |
| 93 if (store.idToNodeMap_[id].url) | 93 if (store.idToNodeMap_[id].url) |
| 94 continue; | 94 continue; |
| 95 | 95 |
| 96 assertTrue(store.idToNodeMap_[id].isOpen); | 96 assertTrue(store.idToNodeMap_[id].isOpen); |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Closing a folder doesn't close any descendants. | 99 // Closing a folder doesn't close any descendants. |
| 100 store.fire('folder-open-changed', {id: '1', open: false}); | 100 store.fire('folder-open-changed', {id: '1', open: false}); |
| 101 assertFalse(store.idToNodeMap_['1'].isOpen); | 101 assertFalse(store.idToNodeMap_['1'].isOpen); |
| 102 assertTrue(store.idToNodeMap_['3'].isOpen); | 102 assertTrue(store.idToNodeMap_['3'].isOpen); |
| 103 store.fire('folder-open-changed', {id: '1', open: true}); | 103 store.fire('folder-open-changed', {id: '1', open: true}); |
| 104 | 104 |
| 105 // Closing an ancestor folder of a selected folder selects the ancestor. | 105 // Closing an ancestor folder of a selected folder selects the ancestor. |
| 106 store.fire('selected-folder-changed', '3'); | 106 store.fire('selected-folder-changed', '3'); |
| 107 store.fire('folder-open-changed', {id: '1', open: false}); | 107 store.fire('folder-open-changed', {id: '1', open: false}); |
| 108 assertFalse(store.idToNodeMap_['1'].isOpen); | 108 assertFalse(store.idToNodeMap_['1'].isOpen); |
| 109 assertEquals('1', store.selectedId); | 109 assertEquals('1', store.selectedId); |
| 110 assertTrue(store.idToNodeMap_['1'].isSelected); | 110 assertTrue(store.idToNodeMap_['1'].isSelected); |
| 111 assertFalse(store.idToNodeMap_['3'].isSelected); | 111 assertFalse(store.idToNodeMap_['3'].isSelected); |
| 112 }); | 112 }); |
| 113 }); | 113 }); |
| OLD | NEW |