Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: chrome/test/data/webui/md_bookmarks/store_test.js

Issue 2637023002: [MD Bookmarks] Add routing. (Closed)
Patch Set: First patch fix Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 function navigateTo(route) {
10 window.history.replaceState({}, '', route);
11 window.dispatchEvent(new CustomEvent('location-changed'));
12 }
13
9 setup(function() { 14 setup(function() {
10 TEST_TREE = createFolder('0', [ 15 TEST_TREE = createFolder('0', [
11 createFolder( 16 createFolder(
12 '1', 17 '1',
13 [ 18 [
14 createItem('2', {url: 'link2'}), 19 createItem('2', {url: 'link2'}),
15 createFolder('3', []), 20 createFolder('3', []),
16 ]), 21 ]),
17 createItem('4', {url: 'link4'}), 22 createItem('4', {url: 'link4'}),
18 createItem('5', {url: 'link5'}), 23 createItem('5', {url: 'link5'}),
19 ]); 24 ]);
20 25
21 store = document.createElement('bookmarks-store'); 26 store = document.createElement('bookmarks-store');
22 replaceBody(store); 27 replaceBody(store);
23 store.setupStore_(TEST_TREE); 28 store.setupStore_(TEST_TREE);
24 }); 29 });
25 30
31 teardown (function() {
32 /** Clean up anything left in URL */
calamity 2017/01/18 03:37:22 //
angelayang 2017/01/18 06:34:03 Done.
33 navigateTo('/');
34 });
35
26 test('initNodes inserts nodes into idToNodeMap', function(){ 36 test('initNodes inserts nodes into idToNodeMap', function(){
27 assertEquals(TEST_TREE, store.idToNodeMap_['0']); 37 assertEquals(TEST_TREE, store.idToNodeMap_['0']);
28 assertEquals(TEST_TREE.children[0], store.idToNodeMap_['1']); 38 assertEquals(TEST_TREE.children[0], store.idToNodeMap_['1']);
29 assertEquals(TEST_TREE.children[0].children[0], store.idToNodeMap_['2']); 39 assertEquals(TEST_TREE.children[0].children[0], store.idToNodeMap_['2']);
30 assertEquals(TEST_TREE.children[0].children[1], store.idToNodeMap_['3']); 40 assertEquals(TEST_TREE.children[0].children[1], store.idToNodeMap_['3']);
31 assertEquals(TEST_TREE.children[1], store.idToNodeMap_['4']); 41 assertEquals(TEST_TREE.children[1], store.idToNodeMap_['4']);
32 assertEquals(TEST_TREE.children[2], store.idToNodeMap_['5']); 42 assertEquals(TEST_TREE.children[2], store.idToNodeMap_['5']);
33 }); 43 });
34 44
35 test('changing selectedId changes the displayedList', function(){ 45 test('changing selectedId changes the displayedList', function(){
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 assertTrue(store.idToNodeMap_['0'].isSelected); 179 assertTrue(store.idToNodeMap_['0'].isSelected);
170 assertEquals('0', store.selectedId); 180 assertEquals('0', store.selectedId);
171 }); 181 });
172 182
173 test('displayedList updates after searchTerm changes', function() { 183 test('displayedList updates after searchTerm changes', function() {
174 var SEARCH_RESULTS = [ 184 var SEARCH_RESULTS = [
175 'cat', 185 'cat',
176 'apple', 186 'apple',
177 'Paris', 187 'Paris',
178 ]; 188 ];
179 189 replaceChromeSearch(SEARCH_RESULTS);
180 chrome.bookmarks.search = function(searchTerm, callback) {
181 callback(SEARCH_RESULTS);
182 };
183 190
184 // Search for a non-empty string. 191 // Search for a non-empty string.
185 store.searchTerm = 'a'; 192 store.searchTerm = 'a';
186 assertFalse(store.rootNode.children[0].isSelected); 193 assertFalse(store.rootNode.children[0].isSelected);
187 assertEquals(null, store.selectedId); 194 assertEquals(null, store.selectedId);
188 assertEquals(SEARCH_RESULTS, store.displayedList); 195 assertEquals(SEARCH_RESULTS, store.displayedList);
189 196
190 // Clear the searchTerm. 197 // Clear the searchTerm.
191 store.searchTerm = ''; 198 store.searchTerm = '';
192 var defaultFolder = store.rootNode.children[0]; 199 var defaultFolder = store.rootNode.children[0];
193 assertTrue(defaultFolder.isSelected); 200 assertTrue(defaultFolder.isSelected);
194 assertEquals(defaultFolder.id, store.selectedId); 201 assertEquals(defaultFolder.id, store.selectedId);
195 assertEquals(defaultFolder.children, store.displayedList); 202 assertEquals(defaultFolder.children, store.displayedList);
196 203
197 // Search with no bookmarks returned. 204 // Search with no bookmarks returned.
198 var EMPTY_RESULT = []; 205 var EMPTY_RESULT = [];
199 chrome.bookmarks.search = function(searchTerm, callback) { 206 replaceChromeSearch(EMPTY_RESULT);
200 callback(EMPTY_RESULT);
201 };
202 store.searchTerm = 'asdf'; 207 store.searchTerm = 'asdf';
203 assertEquals(EMPTY_RESULT, store.displayedList); 208 assertEquals(EMPTY_RESULT, store.displayedList);
204 }); 209 });
205 210
206 test('bookmark gets updated after editing', function() { 211 test('bookmark gets updated after editing', function() {
207 // Edit title updates idToNodeMap_ properly. 212 // Edit title updates idToNodeMap_ properly.
208 store.onBookmarkChanged_('4', {'title': 'test'}); 213 store.onBookmarkChanged_('4', {'title': 'test'});
209 assertEquals('test', store.idToNodeMap_['4'].title); 214 assertEquals('test', store.idToNodeMap_['4'].title);
210 assertEquals('link4', store.idToNodeMap_['4'].url); 215 assertEquals('link4', store.idToNodeMap_['4'].url);
211 216
212 // Edit url updates idToNodeMap_ properly. 217 // Edit url updates idToNodeMap_ properly.
213 store.onBookmarkChanged_('5', {'url': 'http://www.google.com'}); 218 store.onBookmarkChanged_('5', {'url': 'http://www.google.com'});
214 assertEquals('', store.idToNodeMap_['5'].title); 219 assertEquals('', store.idToNodeMap_['5'].title);
215 assertEquals('http://www.google.com', store.idToNodeMap_['5'].url); 220 assertEquals('http://www.google.com', store.idToNodeMap_['5'].url);
216 221
217 // Edit url and title updates idToNodeMap_ properly. 222 // Edit url and title updates idToNodeMap_ properly.
218 store.onBookmarkChanged_('2', { 223 store.onBookmarkChanged_('2', {
219 'title': 'test', 224 'title': 'test',
220 'url': 'http://www.google.com', 225 'url': 'http://www.google.com',
221 }); 226 });
222 assertEquals('test', store.idToNodeMap_['2'].title); 227 assertEquals('test', store.idToNodeMap_['2'].title);
223 assertEquals('http://www.google.com', store.idToNodeMap_['2'].url); 228 assertEquals('http://www.google.com', store.idToNodeMap_['2'].url);
224 }); 229 });
230
231 ////////////////////////////////////////////////////////////////////////////////
232 // router tests:
calamity 2017/01/18 03:37:22 clang-format will want this indented. Restyle acco
angelayang 2017/01/18 06:34:03 Done.
233 test('search updates from route', function() {
234 replaceChromeSearch([]);
235 var searchTerm = 'Boat24';
236 navigateTo('/?q=' + searchTerm);
237 store.setupStore_(TEST_TREE);
238 assertEquals(searchTerm, store.searchTerm);
239 });
240
241 test('route updates from search', function() {
242 replaceChromeSearch([]);
243 var searchTerm = 'Boat24';
244 store.searchTerm = searchTerm;
245 assertEquals('chrome://bookmarks/?q=' + searchTerm, window.location.href);
246 });
247
248 test('selectedId updates from route', function() {
249 var selectedId = '2';
250 navigateTo('/' + selectedId);
251 store.setupStore_(TEST_TREE);
252 assertEquals(selectedId, store.selectedId);
253 });
254
255 test('route updates from selectedId', function() {
256 var selectedId = '2';
257 store.selectedId = selectedId;
258 assertEquals('chrome://bookmarks/' + selectedId, window.location.href);
259 });
225 }); 260 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698