| 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_toolbar_test', function() { | 5 cr.define('md_history.history_toolbar_test', function() { |
| 6 function registerTests() { | 6 function registerTests() { |
| 7 suite('history-toolbar', function() { | 7 suite('history-toolbar', function() { |
| 8 var app; | 8 var app; |
| 9 var element; | 9 var element; |
| 10 var toolbar; | 10 var toolbar; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 assertEquals(0, toolbar.count); | 43 assertEquals(0, toolbar.count); |
| 44 // Ensure that the toolbar boolean states that no items are selected. | 44 // Ensure that the toolbar boolean states that no items are selected. |
| 45 assertFalse(toolbar.itemsSelected_); | 45 assertFalse(toolbar.itemsSelected_); |
| 46 }); | 46 }); |
| 47 }); | 47 }); |
| 48 | 48 |
| 49 test('search term gathered correctly from toolbar', function(done) { | 49 test('search term gathered correctly from toolbar', function(done) { |
| 50 app.queryState_.queryingDisabled = false; | 50 app.queryState_.queryingDisabled = false; |
| 51 registerMessageCallback('queryHistory', this, function (info) { | 51 registerMessageCallback('queryHistory', this, function (info) { |
| 52 assertEquals('Test', info[0]); | 52 assertEquals('Test', info[0]); |
| 53 app.historyResult(createHistoryInfo(), TEST_HISTORY_RESULTS); |
| 53 done(); | 54 done(); |
| 54 }); | 55 }); |
| 55 | 56 |
| 56 toolbar.$$('cr-toolbar').fire('search-changed', 'Test'); | 57 toolbar.$$('cr-toolbar').fire('search-changed', 'Test'); |
| 57 }); | 58 }); |
| 58 | 59 |
| 59 test('shortcuts to open search field', function() { | |
| 60 var field = toolbar.$['main-toolbar'].getSearchField(); | |
| 61 field.blur(); | |
| 62 assertFalse(field.showingSearch); | |
| 63 | |
| 64 MockInteractions.pressAndReleaseKeyOn( | |
| 65 document.body, 191, '', '/'); | |
| 66 assertTrue(field.showingSearch); | |
| 67 assertEquals(field.$.searchInput, field.root.activeElement); | |
| 68 | |
| 69 MockInteractions.pressAndReleaseKeyOn( | |
| 70 field.$.searchInput, 27, '', 'Escape'); | |
| 71 assertFalse(field.showingSearch, 'Pressing escape closes field.'); | |
| 72 assertNotEquals(field.$.searchInput, field.root.activeElement); | |
| 73 | |
| 74 var modifier = 'ctrl'; | |
| 75 if (cr.isMac) | |
| 76 modifier = 'meta'; | |
| 77 | |
| 78 MockInteractions.pressAndReleaseKeyOn( | |
| 79 document.body, 70, modifier, 'f'); | |
| 80 assertTrue(field.showingSearch); | |
| 81 assertEquals(field.$.searchInput, field.root.activeElement); | |
| 82 }); | |
| 83 | |
| 84 test('spinner is active on search' , function(done) { | 60 test('spinner is active on search' , function(done) { |
| 85 app.queryState_.queryingDisabled = false; | 61 app.queryState_.queryingDisabled = false; |
| 86 registerMessageCallback('queryHistory', this, function (info) { | 62 registerMessageCallback('queryHistory', this, function (info) { |
| 87 assertTrue(toolbar.spinnerActive); | 63 PolymerTest.flushTasks().then(function() { |
| 88 app.historyResult(createHistoryInfo(), TEST_HISTORY_RESULTS); | 64 assertTrue(toolbar.spinnerActive); |
| 89 assertFalse(toolbar.spinnerActive); | 65 app.historyResult(createHistoryInfo(), TEST_HISTORY_RESULTS); |
| 90 done(); | 66 assertFalse(toolbar.spinnerActive); |
| 67 done(); |
| 68 }); |
| 91 }); | 69 }); |
| 92 | 70 |
| 93 toolbar.$$('cr-toolbar').fire('search-changed', 'Test2'); | 71 toolbar.$$('cr-toolbar').fire('search-changed', 'Test2'); |
| 94 }); | 72 }); |
| 95 | 73 |
| 96 test('grouped history navigation buttons', function() { | 74 test('grouped history navigation buttons', function() { |
| 97 var info = createHistoryInfo(); | 75 var info = createHistoryInfo(); |
| 98 info.finished = false; | 76 info.finished = false; |
| 99 app.historyResult(info, []); | 77 app.historyResult(info, []); |
| 100 app.grouped_ = true; | 78 app.grouped_ = true; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 126 | 104 |
| 127 teardown(function() { | 105 teardown(function() { |
| 128 registerMessageCallback('queryHistory', this, function() {}); | 106 registerMessageCallback('queryHistory', this, function() {}); |
| 129 }); | 107 }); |
| 130 }); | 108 }); |
| 131 } | 109 } |
| 132 return { | 110 return { |
| 133 registerTests: registerTests | 111 registerTests: registerTests |
| 134 }; | 112 }; |
| 135 }); | 113 }); |
| 136 | |
| 137 | |
| 138 cr.define('md_history.history_toolbar_focus_test', function() { | |
| 139 function registerTests() { | |
| 140 suite('history-toolbar', function() { | |
| 141 var app; | |
| 142 var element; | |
| 143 var toolbar; | |
| 144 var TEST_HISTORY_RESULTS = | |
| 145 [createHistoryEntry('2016-03-15', 'https://google.com')]; | |
| 146 ; | |
| 147 | |
| 148 setup(function() { | |
| 149 window.resultsRendered = false; | |
| 150 app = replaceApp(); | |
| 151 | |
| 152 element = app.$['history'].$['infinite-list']; | |
| 153 toolbar = app.$['toolbar']; | |
| 154 }); | |
| 155 | |
| 156 test('search bar is focused on load in wide mode', function() { | |
| 157 toolbar.$['main-toolbar'].narrow_ = false; | |
| 158 | |
| 159 historyResult(createHistoryInfo(), []); | |
| 160 return PolymerTest.flushTasks().then(() => { | |
| 161 // Ensure the search bar is focused on load. | |
| 162 assertTrue( | |
| 163 app.$.toolbar.$['main-toolbar'] | |
| 164 .getSearchField() | |
| 165 .isSearchFocused()); | |
| 166 }); | |
| 167 }); | |
| 168 | |
| 169 test('search bar is not focused on load in narrow mode', function() { | |
| 170 toolbar.$['main-toolbar'].narrow_ = true; | |
| 171 | |
| 172 historyResult(createHistoryInfo(), []); | |
| 173 return PolymerTest.flushTasks().then(() => { | |
| 174 // Ensure the search bar is focused on load. | |
| 175 assertFalse( | |
| 176 $('history-app') | |
| 177 .$.toolbar.$['main-toolbar'] | |
| 178 .getSearchField() | |
| 179 .isSearchFocused()); | |
| 180 }); | |
| 181 }); | |
| 182 }); | |
| 183 }; | |
| 184 | |
| 185 return { | |
| 186 registerTests: registerTests | |
| 187 }; | |
| 188 }); | |
| OLD | NEW |