OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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-router>', function() { | 5 suite('<bookmarks-router>', function() { |
6 var store; | 6 var store; |
7 var router; | 7 var router; |
8 | 8 |
9 function navigateTo(route) { | 9 function navigateTo(route) { |
10 window.history.replaceState({}, '', route); | 10 window.history.replaceState({}, '', route); |
(...skipping 25 matching lines...) Expand all Loading... |
36 assertEquals('select-folder', store.lastAction.name); | 36 assertEquals('select-folder', store.lastAction.name); |
37 assertEquals('2', store.lastAction.id); | 37 assertEquals('2', store.lastAction.id); |
38 }); | 38 }); |
39 | 39 |
40 test('route updates from ID', function() { | 40 test('route updates from ID', function() { |
41 store.data.selectedFolder = '2'; | 41 store.data.selectedFolder = '2'; |
42 store.notifyObservers(); | 42 store.notifyObservers(); |
43 | 43 |
44 return Promise.resolve().then(function() { | 44 return Promise.resolve().then(function() { |
45 assertEquals('chrome://bookmarks/?id=2', window.location.href); | 45 assertEquals('chrome://bookmarks/?id=2', window.location.href); |
| 46 store.data.selectedFolder = '1'; |
| 47 store.notifyObservers(); |
| 48 }).then(function() { |
| 49 // Selecting Bookmarks bar clears route. |
| 50 assertEquals('chrome://bookmarks/', window.location.href); |
46 }); | 51 }); |
47 }); | 52 }); |
48 | 53 |
49 test('route updates from search', function() { | 54 test('route updates from search', function() { |
50 store.data.search = {term: 'bloop'}; | 55 store.data.search = {term: 'bloop'}; |
51 store.notifyObservers(); | 56 store.notifyObservers(); |
52 | 57 |
53 return Promise.resolve() | 58 return Promise.resolve() |
54 .then(function() { | 59 .then(function() { |
55 assertEquals('chrome://bookmarks/?q=bloop', window.location.href); | 60 assertEquals('chrome://bookmarks/?q=bloop', window.location.href); |
56 | 61 |
57 // Ensure that the route doesn't change when the search finishes. | 62 // Ensure that the route doesn't change when the search finishes. |
58 store.data.selectedFolder = null; | 63 store.data.selectedFolder = null; |
59 store.notifyObservers(); | 64 store.notifyObservers(); |
60 }) | 65 }) |
61 .then(function() { | 66 .then(function() { |
62 assertEquals('chrome://bookmarks/?q=bloop', window.location.href); | 67 assertEquals('chrome://bookmarks/?q=bloop', window.location.href); |
63 }); | 68 }); |
64 }); | 69 }); |
| 70 |
| 71 test('bookmarks bar selected with empty route', function() { |
| 72 navigateTo('/?id=2'); |
| 73 navigateTo('/'); |
| 74 assertEquals('select-folder', store.lastAction.name); |
| 75 assertEquals('1', store.lastAction.id); |
| 76 }); |
65 }); | 77 }); |
66 | 78 |
67 suite('URL preload', function() { | 79 suite('URL preload', function() { |
68 /** | 80 /** |
69 * Reset the page state with a <bookmarks-app> and a clean Store, with the | 81 * Reset the page state with a <bookmarks-app> and a clean Store, with the |
70 * given |url| to trigger routing initialization code. | 82 * given |url| to trigger routing initialization code. |
71 */ | 83 */ |
72 function setupWithUrl(url) { | 84 function setupWithUrl(url) { |
73 PolymerTest.clearBody(); | 85 PolymerTest.clearBody(); |
74 bookmarks.Store.instance_ = undefined; | 86 bookmarks.Store.instance_ = undefined; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 var state = bookmarks.Store.getInstance().data; | 125 var state = bookmarks.Store.getInstance().data; |
114 assertEquals('2', state.selectedFolder); | 126 assertEquals('2', state.selectedFolder); |
115 assertDeepEquals(['21'], bookmarks.util.getDisplayedList(state)); | 127 assertDeepEquals(['21'], bookmarks.util.getDisplayedList(state)); |
116 }); | 128 }); |
117 | 129 |
118 test('loading an invalid folder URL selects the Bookmarks Bar', function() { | 130 test('loading an invalid folder URL selects the Bookmarks Bar', function() { |
119 setupWithUrl('/?id=42'); | 131 setupWithUrl('/?id=42'); |
120 var state = bookmarks.Store.getInstance().data; | 132 var state = bookmarks.Store.getInstance().data; |
121 assertEquals('1', state.selectedFolder); | 133 assertEquals('1', state.selectedFolder); |
122 return Promise.resolve().then(function() { | 134 return Promise.resolve().then(function() { |
123 assertEquals('chrome://bookmarks/?id=1', window.location.href); | 135 assertEquals('chrome://bookmarks/', window.location.href); |
124 }); | 136 }); |
125 }); | 137 }); |
126 }); | 138 }); |
OLD | NEW |