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 | 8 |
| 9 setup(function() { | 9 setup(function() { |
| 10 TEST_TREE = createFolder('0', [ | 10 TEST_TREE = createFolder('0', [ |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 | 25 |
| 26 test('initNodes inserts nodes into idToNodeMap', function(){ | 26 test('initNodes inserts nodes into idToNodeMap', function(){ |
| 27 assertEquals(TEST_TREE, store.idToNodeMap_['0']); | 27 assertEquals(TEST_TREE, store.idToNodeMap_['0']); |
| 28 assertEquals(TEST_TREE.children[0], store.idToNodeMap_['1']); | 28 assertEquals(TEST_TREE.children[0], store.idToNodeMap_['1']); |
| 29 assertEquals(TEST_TREE.children[0].children[0], store.idToNodeMap_['2']); | 29 assertEquals(TEST_TREE.children[0].children[0], store.idToNodeMap_['2']); |
| 30 assertEquals(TEST_TREE.children[0].children[1], store.idToNodeMap_['3']); | 30 assertEquals(TEST_TREE.children[0].children[1], store.idToNodeMap_['3']); |
| 31 assertEquals(TEST_TREE.children[1], store.idToNodeMap_['4']); | 31 assertEquals(TEST_TREE.children[1], store.idToNodeMap_['4']); |
| 32 assertEquals(TEST_TREE.children[2], store.idToNodeMap_['5']); | 32 assertEquals(TEST_TREE.children[2], store.idToNodeMap_['5']); |
| 33 }); | 33 }); |
| 34 | 34 |
| 35 test('changing selectedId changes the selectedNode', function(){ | 35 test('changing selectedId changes the displayedList', function(){ |
| 36 store.selectedId = '0'; | 36 store.selectedId = '0'; |
| 37 assertEquals(TEST_TREE, store.selectedNode); | 37 assertEquals(TEST_TREE.children, store.displayedList); |
| 38 store.selectedId = '1'; | 38 store.selectedId = '1'; |
| 39 assertEquals(TEST_TREE.children[0], store.selectedNode); | 39 assertEquals(TEST_TREE.children[0].children, store.displayedList); |
| 40 store.selectedId = '2'; | 40 store.selectedId = '2'; |
| 41 assertEquals(TEST_TREE.children[0].children[0], store.selectedNode); | 41 assertEquals( |
| 42 TEST_TREE.children[0].children[0].children, store.displayedList); | |
| 42 store.selectedId = '3'; | 43 store.selectedId = '3'; |
| 43 assertEquals(TEST_TREE.children[0].children[1], store.selectedNode); | 44 assertEquals( |
| 45 TEST_TREE.children[0].children[1].children, store.displayedList); | |
| 44 store.selectedId = '4'; | 46 store.selectedId = '4'; |
| 45 assertEquals(TEST_TREE.children[1], store.selectedNode); | 47 assertEquals(TEST_TREE.children[1].children, store.displayedList); |
| 46 store.selectedId = '5'; | 48 store.selectedId = '5'; |
| 47 assertEquals(TEST_TREE.children[2], store.selectedNode); | 49 assertEquals(TEST_TREE.children[2].children, store.displayedList); |
| 48 }); | 50 }); |
| 49 | 51 |
| 50 test('correct paths generated for nodes', function() { | 52 test('correct paths generated for nodes', function() { |
| 51 var TEST_PATHS = { | 53 var TEST_PATHS = { |
| 52 '0': 'rootNode', | 54 '0': 'rootNode', |
| 53 '1': 'rootNode.children.#0', | 55 '1': 'rootNode.children.#0', |
| 54 '2': 'rootNode.children.#0.children.#0', | 56 '2': 'rootNode.children.#0.children.#0', |
| 55 '3': 'rootNode.children.#0.children.#1', | 57 '3': 'rootNode.children.#0.children.#1', |
| 56 '4': 'rootNode.children.#1', | 58 '4': 'rootNode.children.#1', |
| 57 '5': 'rootNode.children.#2', | 59 '5': 'rootNode.children.#2', |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 assertTrue(store.idToNodeMap_['1'].isSelected); | 163 assertTrue(store.idToNodeMap_['1'].isSelected); |
| 162 assertEquals('1', store.selectedId); | 164 assertEquals('1', store.selectedId); |
| 163 | 165 |
| 164 // A folder with selected folder in it gets removed. | 166 // A folder with selected folder in it gets removed. |
| 165 store.selectedId = '3'; | 167 store.selectedId = '3'; |
| 166 store.onBookmarkRemoved_('1', {parentId:'0', index:'0'}); | 168 store.onBookmarkRemoved_('1', {parentId:'0', index:'0'}); |
| 167 assertTrue(store.idToNodeMap_['0'].isSelected); | 169 assertTrue(store.idToNodeMap_['0'].isSelected); |
| 168 assertEquals('0', store.selectedId); | 170 assertEquals('0', store.selectedId); |
| 169 }); | 171 }); |
| 170 | 172 |
| 173 test('displayedList updates after searchTerm changes', function() { | |
| 174 var SEARCH_RESULTS = [ | |
| 175 'cat', | |
| 176 'apple', | |
| 177 'Paris', | |
| 178 ]; | |
| 179 | |
| 180 chrome.bookmarks.search = function(searchTerm, callback) { | |
|
tsergeant
2017/01/13 01:56:23
No need to do anything here, but it'd be good to d
| |
| 181 callback(SEARCH_RESULTS); | |
| 182 }; | |
| 183 | |
| 184 // Search for a non-empty string. | |
| 185 store.searchTerm = 'a'; | |
| 186 assertFalse(store.rootNode.children[0].isSelected); | |
| 187 assertEquals(null, store.selectedId); | |
| 188 assertEquals(SEARCH_RESULTS, store.displayedList); | |
| 189 | |
| 190 // Clear the searchTerm. | |
| 191 store.searchTerm = ''; | |
| 192 var defaultFolder = store.rootNode.children[0]; | |
| 193 assertTrue(defaultFolder.isSelected); | |
| 194 assertEquals(defaultFolder.id, store.selectedId); | |
| 195 assertEquals(defaultFolder.children, store.displayedList); | |
| 196 | |
| 197 // Search with no bookmarks returned. | |
| 198 var EMPTY_RESULT = []; | |
| 199 chrome.bookmarks.search = function(searchTerm, callback) { | |
| 200 callback(EMPTY_RESULT); | |
| 201 }; | |
| 202 store.searchTerm = 'asdf'; | |
| 203 assertEquals(EMPTY_RESULT, store.displayedList); | |
| 204 }); | |
| 205 | |
| 171 test('bookmark gets updated after editing', function() { | 206 test('bookmark gets updated after editing', function() { |
| 172 // Edit title updates idToNodeMap_ properly. | 207 // Edit title updates idToNodeMap_ properly. |
| 173 store.onBookmarkChanged_('4', {'title': 'test'}); | 208 store.onBookmarkChanged_('4', {'title': 'test'}); |
| 174 assertEquals('test', store.idToNodeMap_['4'].title); | 209 assertEquals('test', store.idToNodeMap_['4'].title); |
| 175 assertEquals('link4', store.idToNodeMap_['4'].url); | 210 assertEquals('link4', store.idToNodeMap_['4'].url); |
| 176 | 211 |
| 177 // Edit url updates idToNodeMap_ properly. | 212 // Edit url updates idToNodeMap_ properly. |
| 178 store.onBookmarkChanged_('5', {'url': 'http://www.google.com'}); | 213 store.onBookmarkChanged_('5', {'url': 'http://www.google.com'}); |
| 179 assertEquals('', store.idToNodeMap_['5'].title); | 214 assertEquals('', store.idToNodeMap_['5'].title); |
| 180 assertEquals('http://www.google.com', store.idToNodeMap_['5'].url); | 215 assertEquals('http://www.google.com', store.idToNodeMap_['5'].url); |
| 181 | 216 |
| 182 // Edit url and title updates idToNodeMap_ properly. | 217 // Edit url and title updates idToNodeMap_ properly. |
| 183 store.onBookmarkChanged_('2', { | 218 store.onBookmarkChanged_('2', { |
| 184 'title': 'test', | 219 'title': 'test', |
| 185 'url': 'http://www.google.com', | 220 'url': 'http://www.google.com', |
| 186 }); | 221 }); |
| 187 assertEquals('test', store.idToNodeMap_['2'].title); | 222 assertEquals('test', store.idToNodeMap_['2'].title); |
| 188 assertEquals('http://www.google.com', store.idToNodeMap_['2'].url); | 223 assertEquals('http://www.google.com', store.idToNodeMap_['2'].url); |
| 189 }); | 224 }); |
| 190 }); | 225 }); |
| OLD | NEW |