Chromium Code Reviews| Index: chrome/test/data/webui/md_bookmarks/store_test.js |
| diff --git a/chrome/test/data/webui/md_bookmarks/store_test.js b/chrome/test/data/webui/md_bookmarks/store_test.js |
| index a1cf7e0e42cf12e54260a79b23a8a7a35bce2eaf..2e491430207858cc69e2f5c0eec1410da1d85dcd 100644 |
| --- a/chrome/test/data/webui/md_bookmarks/store_test.js |
| +++ b/chrome/test/data/webui/md_bookmarks/store_test.js |
| @@ -6,6 +6,11 @@ suite('<bookmarks-store>', function() { |
| var store; |
| var TEST_TREE; |
| + function navigateTo(route) { |
| + window.history.replaceState({}, '', route); |
| + window.dispatchEvent(new CustomEvent('location-changed')); |
| + } |
| + |
| setup(function() { |
| TEST_TREE = createFolder('0', [ |
| createFolder( |
| @@ -23,6 +28,11 @@ suite('<bookmarks-store>', function() { |
| store.setupStore_(TEST_TREE); |
| }); |
| + teardown (function() { |
| + /** Clean up anything left in URL */ |
|
calamity
2017/01/18 03:37:22
//
angelayang
2017/01/18 06:34:03
Done.
|
| + navigateTo('/'); |
| + }); |
| + |
| test('initNodes inserts nodes into idToNodeMap', function(){ |
| assertEquals(TEST_TREE, store.idToNodeMap_['0']); |
| assertEquals(TEST_TREE.children[0], store.idToNodeMap_['1']); |
| @@ -176,10 +186,7 @@ suite('<bookmarks-store>', function() { |
| 'apple', |
| 'Paris', |
| ]; |
| - |
| - chrome.bookmarks.search = function(searchTerm, callback) { |
| - callback(SEARCH_RESULTS); |
| - }; |
| + replaceChromeSearch(SEARCH_RESULTS); |
| // Search for a non-empty string. |
| store.searchTerm = 'a'; |
| @@ -196,9 +203,7 @@ suite('<bookmarks-store>', function() { |
| // Search with no bookmarks returned. |
| var EMPTY_RESULT = []; |
| - chrome.bookmarks.search = function(searchTerm, callback) { |
| - callback(EMPTY_RESULT); |
| - }; |
| + replaceChromeSearch(EMPTY_RESULT); |
| store.searchTerm = 'asdf'; |
| assertEquals(EMPTY_RESULT, store.displayedList); |
| }); |
| @@ -222,4 +227,34 @@ suite('<bookmarks-store>', function() { |
| assertEquals('test', store.idToNodeMap_['2'].title); |
| assertEquals('http://www.google.com', store.idToNodeMap_['2'].url); |
| }); |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// 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.
|
| + test('search updates from route', function() { |
| + replaceChromeSearch([]); |
| + var searchTerm = 'Boat24'; |
| + navigateTo('/?q=' + searchTerm); |
| + store.setupStore_(TEST_TREE); |
| + assertEquals(searchTerm, store.searchTerm); |
| + }); |
| + |
| + test('route updates from search', function() { |
| + replaceChromeSearch([]); |
| + var searchTerm = 'Boat24'; |
| + store.searchTerm = searchTerm; |
| + assertEquals('chrome://bookmarks/?q=' + searchTerm, window.location.href); |
| + }); |
| + |
| + test('selectedId updates from route', function() { |
| + var selectedId = '2'; |
| + navigateTo('/' + selectedId); |
| + store.setupStore_(TEST_TREE); |
| + assertEquals(selectedId, store.selectedId); |
| + }); |
| + |
| + test('route updates from selectedId', function() { |
| + var selectedId = '2'; |
| + store.selectedId = selectedId; |
| + assertEquals('chrome://bookmarks/' + selectedId, window.location.href); |
| + }); |
| }); |