| 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 /** @fileoverview Suite of tests for cr-toolbar-search-field. */ | 5 /** @fileoverview Suite of tests for cr-toolbar-search-field. */ |
| 6 cr.define('cr_toolbar_search_field', function() { | 6 cr.define('cr_toolbar_search_field', function() { |
| 7 function registerTests() { | 7 function registerTests() { |
| 8 suite('cr-toolbar-search-field', function() { | 8 suite('cr-toolbar-search-field', function() { |
| 9 /** @type {?CrToolbarSearchFieldElement} */ | 9 /** @type {?CrToolbarSearchFieldElement} */ |
| 10 var field = null; | 10 var field = null; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 MockInteractions.tap(field); | 86 MockInteractions.tap(field); |
| 87 field.setValue('foo'); | 87 field.setValue('foo'); |
| 88 field.setValue(''); | 88 field.setValue(''); |
| 89 field.setValue('bar'); | 89 field.setValue('bar'); |
| 90 // Expecting identical query to be ignored. | 90 // Expecting identical query to be ignored. |
| 91 field.setValue('bar'); | 91 field.setValue('bar'); |
| 92 field.setValue('baz'); | 92 field.setValue('baz'); |
| 93 assertEquals(['foo', '', 'bar', 'baz'].join(), searches.join()); | 93 assertEquals(['foo', '', 'bar', 'baz'].join(), searches.join()); |
| 94 }); | 94 }); |
| 95 | 95 |
| 96 // Tests that calling setValue() from within a 'search-changed' callback |
| 97 // does not result in an infinite loop. |
| 98 test('no infinite loop', function() { |
| 99 var counter = 0; |
| 100 field.addEventListener('search-changed', function(event) { |
| 101 counter++; |
| 102 // Calling setValue() with the already existing value should not |
| 103 // trigger another 'search-changed' event. |
| 104 field.setValue(event.detail); |
| 105 }); |
| 106 |
| 107 MockInteractions.tap(field); |
| 108 field.setValue('bar'); |
| 109 assertEquals(1, counter); |
| 110 assertEquals(['bar'].join(), searches.join()); |
| 111 }); |
| 112 |
| 96 test('blur does not close field when a search is active', function() { | 113 test('blur does not close field when a search is active', function() { |
| 97 MockInteractions.tap(field); | 114 MockInteractions.tap(field); |
| 98 simulateSearch('test'); | 115 simulateSearch('test'); |
| 99 MockInteractions.blur(field.$.searchInput); | 116 MockInteractions.blur(field.$.searchInput); |
| 100 | 117 |
| 101 assertTrue(field.showingSearch); | 118 assertTrue(field.showingSearch); |
| 102 }); | 119 }); |
| 103 | 120 |
| 104 test('opens when value is changed', function() { | 121 test('opens when value is changed', function() { |
| 105 // Change search value without explicity opening the field first. | 122 // Change search value without explicity opening the field first. |
| 106 // Similar to what happens when pasting or dragging into the input | 123 // Similar to what happens when pasting or dragging into the input |
| 107 // field. | 124 // field. |
| 108 simulateSearch('test'); | 125 simulateSearch('test'); |
| 109 Polymer.dom.flush(); | 126 Polymer.dom.flush(); |
| 110 | 127 |
| 111 var clearSearch = field.$$('#clearSearch'); | 128 var clearSearch = field.$$('#clearSearch'); |
| 112 assertFalse(clearSearch.hidden); | 129 assertFalse(clearSearch.hidden); |
| 113 assertTrue(field.showingSearch); | 130 assertTrue(field.showingSearch); |
| 114 }); | 131 }); |
| 115 }); | 132 }); |
| 116 } | 133 } |
| 117 | 134 |
| 118 return { | 135 return { |
| 119 registerTests: registerTests, | 136 registerTests: registerTests, |
| 120 }; | 137 }; |
| 121 }); | 138 }); |
| OLD | NEW |