| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 MockInteractions.tap(field); | 103 MockInteractions.tap(field); |
| 104 field.setValue('foo'); | 104 field.setValue('foo'); |
| 105 field.setValue(''); | 105 field.setValue(''); |
| 106 field.setValue('bar'); | 106 field.setValue('bar'); |
| 107 // Expecting identical query to be ignored. | 107 // Expecting identical query to be ignored. |
| 108 field.setValue('bar'); | 108 field.setValue('bar'); |
| 109 field.setValue('baz'); | 109 field.setValue('baz'); |
| 110 assertEquals(['foo', '', 'bar', 'baz'].join(), searches.join()); | 110 assertEquals(['foo', '', 'bar', 'baz'].join(), searches.join()); |
| 111 }); | 111 }); |
| 112 | 112 |
| 113 test('does not notify on setValue with noEvent=true', function() { |
| 114 MockInteractions.tap(field); |
| 115 field.setValue('foo', true); |
| 116 field.setValue('bar'); |
| 117 field.setValue('baz', true); |
| 118 assertEquals(['bar'].join(), searches.join()); |
| 119 }); |
| 120 |
| 113 // Tests that calling setValue() from within a 'search-changed' callback | 121 // Tests that calling setValue() from within a 'search-changed' callback |
| 114 // does not result in an infinite loop. | 122 // does not result in an infinite loop. |
| 115 test('no infinite loop', function() { | 123 test('no infinite loop', function() { |
| 116 var counter = 0; | 124 var counter = 0; |
| 117 field.addEventListener('search-changed', function(event) { | 125 field.addEventListener('search-changed', function(event) { |
| 118 counter++; | 126 counter++; |
| 119 // Calling setValue() with the already existing value should not | 127 // Calling setValue() with the already existing value should not |
| 120 // trigger another 'search-changed' event. | 128 // trigger another 'search-changed' event. |
| 121 field.setValue(event.detail); | 129 field.setValue(event.detail); |
| 122 }); | 130 }); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 146 assertFalse(clearSearch.hidden); | 154 assertFalse(clearSearch.hidden); |
| 147 assertTrue(field.showingSearch); | 155 assertTrue(field.showingSearch); |
| 148 }); | 156 }); |
| 149 }); | 157 }); |
| 150 } | 158 } |
| 151 | 159 |
| 152 return { | 160 return { |
| 153 registerTests: registerTests, | 161 registerTests: registerTests, |
| 154 }; | 162 }; |
| 155 }); | 163 }); |
| OLD | NEW |