| 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 function navigateTo(route) { | 12 function navigateTo(route) { |
| 13 window.history.replaceState({}, '', route); | 13 window.history.replaceState({}, '', route); |
| 14 window.dispatchEvent(new CustomEvent('location-changed')); | 14 window.dispatchEvent(new CustomEvent('location-changed')); |
| 15 // Update from the URL synchronously. |
| 16 app.$$('history-router').flushDebouncer('parseUrl'); |
| 15 } | 17 } |
| 16 | 18 |
| 17 setup(function() { | 19 setup(function() { |
| 20 app = replaceApp(); |
| 18 assertEquals('chrome://history/', window.location.href); | 21 assertEquals('chrome://history/', window.location.href); |
| 19 app = replaceApp(); | |
| 20 sidebar = app.$['content-side-bar'] | 22 sidebar = app.$['content-side-bar'] |
| 21 toolbar = app.$['toolbar']; | 23 toolbar = app.$['toolbar']; |
| 24 return PolymerTest.flushTasks(); |
| 22 }); | 25 }); |
| 23 | 26 |
| 24 test('changing route changes active view', function() { | 27 test('changing route changes active view', function() { |
| 25 assertEquals('history', app.$.content.selected); | 28 assertEquals('history', app.$.content.selected); |
| 26 navigateTo('/syncedTabs'); | 29 navigateTo('/syncedTabs'); |
| 27 return PolymerTest.flushTasks().then(function() { | 30 return PolymerTest.flushTasks().then(function() { |
| 28 assertEquals('syncedTabs', app.$.content.selected); | 31 assertEquals('syncedTabs', app.$.content.selected); |
| 29 assertEquals('chrome://history/syncedTabs', window.location.href); | 32 assertEquals('chrome://history/syncedTabs', window.location.href); |
| 30 }); | 33 }); |
| 31 }); | 34 }); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 assertEquals( | 74 assertEquals( |
| 72 'chrome://history/syncedTabs?q=' + searchTerm, | 75 'chrome://history/syncedTabs?q=' + searchTerm, |
| 73 window.location.href); | 76 window.location.href); |
| 74 | 77 |
| 75 MockInteractions.tap(menu.children[0]); | 78 MockInteractions.tap(menu.children[0]); |
| 76 assertEquals('history', app.selectedPage_); | 79 assertEquals('history', app.selectedPage_); |
| 77 assertEquals(searchTerm, toolbar.searchTerm); | 80 assertEquals(searchTerm, toolbar.searchTerm); |
| 78 assertEquals('chrome://history/?q=' + searchTerm, window.location.href); | 81 assertEquals('chrome://history/?q=' + searchTerm, window.location.href); |
| 79 }); | 82 }); |
| 80 | 83 |
| 81 teardown(function() { | 84 test('changing route changes grouped range and offset', function() { |
| 82 // Reset back to initial navigation state. | 85 app.grouped_ = true; |
| 86 navigateTo('/history/week?offset=1'); |
| 87 assertEquals(HistoryRange.WEEK, app.queryState_.range); |
| 88 assertEquals(1, app.queryState_.groupedOffset); |
| 89 |
| 90 navigateTo('/history/month'); |
| 91 assertEquals(HistoryRange.MONTH, app.queryState_.range); |
| 92 assertEquals(0, app.queryState_.groupedOffset); |
| 93 |
| 83 navigateTo('/'); | 94 navigateTo('/'); |
| 95 assertEquals(HistoryRange.ALL_TIME, app.queryState_.range); |
| 96 }); |
| 97 |
| 98 test('route updates from grouped range and offset', function() { |
| 99 app.grouped_ = true; |
| 100 |
| 101 app.fire('change-query', {range: HistoryRange.WEEK}); |
| 102 assertEquals('chrome://history/history/week', window.location.href); |
| 103 |
| 104 app.fire('change-query', {range: HistoryRange.MONTH, offset: 5}); |
| 105 assertEquals( |
| 106 'chrome://history/history/month?offset=5', window.location.href); |
| 107 |
| 108 app.fire('change-query', {range: HistoryRange.ALL_TIME}); |
| 109 assertEquals('chrome://history/', window.location.href); |
| 84 }); | 110 }); |
| 85 }); | 111 }); |
| 86 } | 112 } |
| 87 return { | 113 return { |
| 88 registerTests: registerTests | 114 registerTests: registerTests |
| 89 }; | 115 }; |
| 90 }); | 116 }); |
| 91 | 117 |
| 92 cr.define('md_history.history_routing_test_with_query_param', function() { | 118 cr.define('md_history.history_routing_test_with_query_param', function() { |
| 93 function registerTests() { | 119 function registerTests() { |
| 94 suite('routing-with-query-param', function() { | 120 suite('routing-with-query-param', function() { |
| 95 var app; | 121 var app; |
| 96 var toolbar; | 122 var toolbar; |
| 97 var expectedQuery; | 123 var expectedQuery; |
| 98 | 124 |
| 99 suiteSetup(function() { | 125 suiteSetup(function() { |
| 100 app = $('history-app'); | 126 app = $('history-app'); |
| 101 toolbar = app.$['toolbar']; | 127 toolbar = app.$['toolbar']; |
| 102 expectedQuery = 'query'; | 128 expectedQuery = 'query'; |
| 103 }); | 129 }); |
| 104 | 130 |
| 105 test('search initiated on load', function(done) { | 131 test('search initiated on load', function(done) { |
| 106 var verifyFunction = function(info) { | 132 var verifyFunction = function(info) { |
| 107 assertEquals(expectedQuery, info[0]); | 133 assertEquals(expectedQuery, info[0]); |
| 134 assertEquals(5, info[1]); |
| 135 assertEquals(HistoryRange.WEEK, info[2]); |
| 108 PolymerTest.flushTasks().then(function() { | 136 PolymerTest.flushTasks().then(function() { |
| 109 assertEquals( | 137 assertEquals( |
| 110 expectedQuery, | 138 expectedQuery, |
| 111 toolbar.$['main-toolbar'].getSearchField().getValue()); | 139 toolbar.$['main-toolbar'].getSearchField().getValue()); |
| 112 done(); | 140 done(); |
| 113 }); | 141 }); |
| 114 }; | 142 }; |
| 115 | 143 |
| 116 if (window.historyQueryInfo) { | 144 if (window.historyQueryInfo) { |
| 117 verifyFunction(window.historyQueryInfo); | 145 verifyFunction(window.historyQueryInfo); |
| 118 return; | 146 return; |
| 119 } | 147 } |
| 120 | 148 |
| 121 registerMessageCallback('queryHistory', this, verifyFunction); | 149 registerMessageCallback('queryHistory', this, verifyFunction); |
| 122 }); | 150 }); |
| 123 }); | 151 }); |
| 124 } | 152 } |
| 125 return { | 153 return { |
| 126 registerTests: registerTests | 154 registerTests: registerTests |
| 127 }; | 155 }; |
| 128 }); | 156 }); |
| OLD | NEW |