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 cr.define('md_history.history_routing_test', function() { | 5 cr.define('md_history.history_routing_test', function() { |
6 function registerTests() { | 6 function registerTests() { |
7 suite('routing-test', function() { | 7 suite('routing-test', function() { |
8 var app; | 8 var app; |
9 var list; | 9 var list; |
10 var toolbar; | 10 var toolbar; |
11 | 11 |
12 suiteSetup(function() { | 12 function navigateTo(route) { |
13 app = $('history-app'); | 13 window.history.replaceState({}, '', route); |
| 14 window.dispatchEvent(new CustomEvent('location-changed')); |
| 15 } |
| 16 |
| 17 setup(function() { |
| 18 assertEquals('chrome://history/', window.location.href); |
| 19 app = replaceApp(); |
14 sidebar = app.$['content-side-bar'] | 20 sidebar = app.$['content-side-bar'] |
15 toolbar = app.$['toolbar']; | 21 toolbar = app.$['toolbar']; |
16 }); | 22 }); |
17 | 23 |
18 test('changing route changes active view', function() { | 24 test('changing route changes active view', function() { |
19 assertEquals('history', app.$.content.selected); | 25 assertEquals('history', app.$.content.selected); |
20 app.set('routeData_.page', 'syncedTabs'); | 26 navigateTo('/syncedTabs'); |
21 return flush().then(function() { | 27 return flush().then(function() { |
22 assertEquals('syncedTabs', app.$.content.selected); | 28 assertEquals('syncedTabs', app.$.content.selected); |
23 assertEquals('chrome://history/syncedTabs', window.location.href); | 29 assertEquals('chrome://history/syncedTabs', window.location.href); |
24 }); | 30 }); |
25 }); | 31 }); |
26 | 32 |
27 test('route updates from sidebar', function() { | 33 test('route updates from sidebar', function() { |
28 var menu = sidebar.$.menu; | 34 var menu = sidebar.$.menu; |
29 assertEquals('', app.routeData_.page); | 35 assertEquals('history', app.selectedPage_); |
30 assertEquals('chrome://history/', window.location.href); | 36 assertEquals('chrome://history/', window.location.href); |
31 | 37 |
32 MockInteractions.tap(menu.children[1]); | 38 MockInteractions.tap(menu.children[1]); |
33 assertEquals('syncedTabs', app.routeData_.page); | 39 assertEquals('syncedTabs', app.selectedPage_); |
34 assertEquals('chrome://history/syncedTabs', window.location.href); | 40 assertEquals('chrome://history/syncedTabs', window.location.href); |
35 | 41 |
36 MockInteractions.keyDownOn(menu.children[0], 32, '', "Space"); | 42 MockInteractions.keyDownOn(menu.children[0], 32, '', "Space"); |
37 assertEquals('', app.routeData_.page); | 43 assertEquals('history', app.selectedPage_); |
38 assertEquals('chrome://history/', window.location.href); | 44 assertEquals('chrome://history/', window.location.href); |
39 }); | 45 }); |
40 | 46 |
| 47 test('search updates from route', function() { |
| 48 assertEquals('chrome://history/', window.location.href); |
| 49 var searchTerm = 'Mei'; |
| 50 assertEquals('history', app.$.content.selected); |
| 51 navigateTo('/?q=' + searchTerm); |
| 52 assertEquals(searchTerm, toolbar.searchTerm); |
| 53 }); |
| 54 |
41 test('route updates from search', function() { | 55 test('route updates from search', function() { |
42 var searchTerm = 'McCree'; | 56 var searchTerm = 'McCree'; |
43 assertEquals('', app.routeData_.page); | |
44 toolbar.setSearchTerm(searchTerm); | |
45 assertEquals(searchTerm, app.queryParams_.q); | |
46 }); | |
47 | |
48 test('search updates from route', function() { | |
49 var searchTerm = 'Mei'; | |
50 assertEquals('history', app.$.content.selected); | 57 assertEquals('history', app.$.content.selected); |
51 app.set('queryParams_.q', searchTerm); | 58 app.set('queryState_.searchTerm', searchTerm); |
52 assertEquals(searchTerm, toolbar.searchTerm); | 59 assertEquals('chrome://history/?q=' + searchTerm, window.location.href); |
53 }); | 60 }); |
54 | 61 |
55 test('search preserved across menu items', function() { | 62 test('search preserved across menu items', function() { |
56 var searchTerm = 'Soldier 76'; | 63 var searchTerm = 'Soldier76'; |
57 var menu = sidebar.$.menu; | 64 var menu = sidebar.$.menu; |
58 assertEquals('', app.routeData_.page); | 65 assertEquals('history', app.selectedPage_); |
59 assertEquals('history', app.$.content.selected); | 66 navigateTo('/?q=' + searchTerm); |
60 app.set('queryParams_.q', searchTerm); | |
61 | 67 |
62 MockInteractions.tap(menu.children[1]); | 68 MockInteractions.tap(menu.children[1]); |
63 assertEquals('syncedTabs', app.routeData_.page); | 69 assertEquals('syncedTabs', app.selectedPage_); |
64 assertEquals(searchTerm, app.queryParams_.q); | |
65 assertEquals(searchTerm, toolbar.searchTerm); | 70 assertEquals(searchTerm, toolbar.searchTerm); |
| 71 assertEquals( |
| 72 'chrome://history/syncedTabs?q=' + searchTerm, |
| 73 window.location.href); |
66 | 74 |
67 MockInteractions.tap(menu.children[0]); | 75 MockInteractions.tap(menu.children[0]); |
68 assertEquals('', app.routeData_.page); | 76 assertEquals('history', app.selectedPage_); |
69 assertEquals(searchTerm, app.queryParams_.q); | |
70 assertEquals(searchTerm, toolbar.searchTerm); | 77 assertEquals(searchTerm, toolbar.searchTerm); |
| 78 assertEquals('chrome://history/?q=' + searchTerm, window.location.href); |
71 }); | 79 }); |
72 | 80 |
73 teardown(function() { | 81 teardown(function() { |
74 app.set('routeData_.page', ''); | 82 // Reset back to initial navigation state. |
75 app.set('queryParams_.q', null); | 83 navigateTo('/'); |
76 }); | 84 }); |
77 }); | 85 }); |
78 } | 86 } |
79 return { | 87 return { |
80 registerTests: registerTests | 88 registerTests: registerTests |
81 }; | 89 }; |
82 }); | 90 }); |
83 | 91 |
84 cr.define('md_history.history_routing_test_with_query_param', function() { | 92 cr.define('md_history.history_routing_test_with_query_param', function() { |
85 function registerTests() { | 93 function registerTests() { |
(...skipping 27 matching lines...) Expand all Loading... |
113 } | 121 } |
114 | 122 |
115 registerMessageCallback('queryHistory', this, verifyFunction); | 123 registerMessageCallback('queryHistory', this, verifyFunction); |
116 }); | 124 }); |
117 }); | 125 }); |
118 } | 126 } |
119 return { | 127 return { |
120 registerTests: registerTests | 128 registerTests: registerTests |
121 }; | 129 }; |
122 }); | 130 }); |
OLD | NEW |