| 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; |
| 11 var TEST_HISTORY_RESULTS; | 11 var TEST_HISTORY_RESULTS |
| 12 | 12 |
| 13 suiteSetup(function() { | 13 suiteSetup(function() { |
| 14 app = $('history-app'); | 14 app = $('history-app'); |
| 15 element = app.$['history'].$['infinite-list']; | 15 element = app.$['history'].$['infinite-list']; |
| 16 toolbar = app.$['toolbar']; | 16 toolbar = app.$['toolbar']; |
| 17 TEST_HISTORY_RESULTS = | 17 TEST_HISTORY_RESULTS = |
| 18 [createHistoryEntry('2016-03-15', 'https://google.com')]; | 18 [createHistoryEntry('2016-03-15', 'https://google.com')]; |
| 19 }); | 19 }); |
| 20 | 20 |
| 21 test('selecting checkbox causes toolbar to change', function() { | 21 test('selecting checkbox causes toolbar to change', function() { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 47 registerMessageCallback('queryHistory', this, function (info) { | 47 registerMessageCallback('queryHistory', this, function (info) { |
| 48 assertEquals('Test', info[0]); | 48 assertEquals('Test', info[0]); |
| 49 done(); | 49 done(); |
| 50 }); | 50 }); |
| 51 | 51 |
| 52 toolbar.$$('cr-toolbar').fire('search-changed', 'Test'); | 52 toolbar.$$('cr-toolbar').fire('search-changed', 'Test'); |
| 53 }); | 53 }); |
| 54 | 54 |
| 55 test('shortcuts to open search field', function() { | 55 test('shortcuts to open search field', function() { |
| 56 var field = toolbar.$['main-toolbar'].getSearchField(); | 56 var field = toolbar.$['main-toolbar'].getSearchField(); |
| 57 field.blur(); |
| 57 assertFalse(field.showingSearch); | 58 assertFalse(field.showingSearch); |
| 58 | 59 |
| 59 MockInteractions.pressAndReleaseKeyOn( | 60 MockInteractions.pressAndReleaseKeyOn( |
| 60 document.body, 191, '', '/'); | 61 document.body, 191, '', '/'); |
| 61 assertTrue(field.showingSearch); | 62 assertTrue(field.showingSearch); |
| 62 assertEquals(field.$.searchInput, field.root.activeElement); | 63 assertEquals(field.$.searchInput, field.root.activeElement); |
| 63 | 64 |
| 64 MockInteractions.pressAndReleaseKeyOn( | 65 MockInteractions.pressAndReleaseKeyOn( |
| 65 field.$.searchInput, 27, '', 'Escape'); | 66 field.$.searchInput, 27, '', 'Escape'); |
| 66 assertFalse(field.showingSearch, 'Pressing escape closes field.'); | 67 assertFalse(field.showingSearch, 'Pressing escape closes field.'); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 93 element.searchedTerm = ''; | 94 element.searchedTerm = ''; |
| 94 registerMessageCallback('queryHistory', this, undefined); | 95 registerMessageCallback('queryHistory', this, undefined); |
| 95 toolbar.count = 0; | 96 toolbar.count = 0; |
| 96 }); | 97 }); |
| 97 }); | 98 }); |
| 98 } | 99 } |
| 99 return { | 100 return { |
| 100 registerTests: registerTests | 101 registerTests: registerTests |
| 101 }; | 102 }; |
| 102 }); | 103 }); |
| 104 |
| 105 |
| 106 cr.define('md_history.history_toolbar_focus_test', function() { |
| 107 function registerTests() { |
| 108 suite('history-toolbar', function() { |
| 109 var app; |
| 110 var element; |
| 111 var toolbar; |
| 112 var TEST_HISTORY_RESULTS = |
| 113 [createHistoryEntry('2016-03-15', 'https://google.com')]; |
| 114 ; |
| 115 |
| 116 setup(function() { |
| 117 PolymerTest.clearBody(); |
| 118 app = document.createElement('history-app'); |
| 119 app.id = 'history-app'; |
| 120 document.body.appendChild(app); |
| 121 |
| 122 element = app.$['history'].$['infinite-list']; |
| 123 toolbar = app.$['toolbar']; |
| 124 }); |
| 125 |
| 126 test('search bar is focused on load in wide mode', function() { |
| 127 window.resultsRendered = false; |
| 128 app.hasDrawer = false; |
| 129 |
| 130 historyResult(createHistoryInfo(), []); |
| 131 return flush().then(() => { |
| 132 // Ensure the search bar is focused on load. |
| 133 assertTrue( |
| 134 app.$.toolbar.$['main-toolbar'] |
| 135 .getSearchField() |
| 136 .isSearchFocused()); |
| 137 }); |
| 138 }); |
| 139 |
| 140 test('search bar is not focused on load in narrow mode', function() { |
| 141 app.hasDrawer = true; |
| 142 |
| 143 historyResult(createHistoryInfo(), []); |
| 144 // Ensure the search bar is focused on load. |
| 145 assertFalse( |
| 146 $('history-app') |
| 147 .$.toolbar.$['main-toolbar'] |
| 148 .getSearchField() |
| 149 .isSearchFocused()); |
| 150 }); |
| 151 }); |
| 152 }; |
| 153 |
| 154 return { |
| 155 registerTests: registerTests |
| 156 }; |
| 157 }); |
| OLD | NEW |