Commit 9a982024 authored by Esmael El-Moslimany's avatar Esmael El-Moslimany Committed by Commit Bot

WebUI: for search in toolbar, replace multiple whitespace with single space

Bug: 794289
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: If1ed00732e07bd0f9b3bdf2cf97cd257d8054f8e
Reviewed-on: https://chromium-review.googlesource.com/1069793Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Esmael El-Moslimany <aee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#562027}
parent a3e02569
...@@ -56,14 +56,14 @@ cr.define('cr_toolbar_search_field', function() { ...@@ -56,14 +56,14 @@ cr.define('cr_toolbar_search_field', function() {
test('opens and closes correctly', function() { test('opens and closes correctly', function() {
assertFalse(field.showingSearch); assertFalse(field.showingSearch);
MockInteractions.tap(field); field.click();
assertTrue(field.showingSearch); assertTrue(field.showingSearch);
assertEquals(field.$.searchInput, field.root.activeElement); assertEquals(field.$.searchInput, field.root.activeElement);
MockInteractions.blur(field.$.searchInput); MockInteractions.blur(field.$.searchInput);
assertFalse(field.showingSearch); assertFalse(field.showingSearch);
MockInteractions.tap(field); field.click();
assertEquals(field.$.searchInput, field.root.activeElement); assertEquals(field.$.searchInput, field.root.activeElement);
MockInteractions.pressAndReleaseKeyOn( MockInteractions.pressAndReleaseKeyOn(
...@@ -73,7 +73,7 @@ cr.define('cr_toolbar_search_field', function() { ...@@ -73,7 +73,7 @@ cr.define('cr_toolbar_search_field', function() {
}); });
test('clear search button clears and refocuses input', function() { test('clear search button clears and refocuses input', function() {
MockInteractions.tap(field); field.click();
simulateSearch('query1'); simulateSearch('query1');
Polymer.dom.flush(); Polymer.dom.flush();
assertTrue(field.hasSearchText); assertTrue(field.hasSearchText);
...@@ -88,7 +88,7 @@ cr.define('cr_toolbar_search_field', function() { ...@@ -88,7 +88,7 @@ cr.define('cr_toolbar_search_field', function() {
}); });
test('notifies on new searches', function() { test('notifies on new searches', function() {
MockInteractions.tap(field); field.click();
simulateSearch('query1'); simulateSearch('query1');
Polymer.dom.flush(); Polymer.dom.flush();
assertEquals('query1', field.getValue()); assertEquals('query1', field.getValue());
...@@ -105,7 +105,7 @@ cr.define('cr_toolbar_search_field', function() { ...@@ -105,7 +105,7 @@ cr.define('cr_toolbar_search_field', function() {
}); });
test('notifies on setValue', function() { test('notifies on setValue', function() {
MockInteractions.tap(field); field.click();
field.setValue('foo'); field.setValue('foo');
field.setValue(''); field.setValue('');
field.setValue('bar'); field.setValue('bar');
...@@ -116,13 +116,29 @@ cr.define('cr_toolbar_search_field', function() { ...@@ -116,13 +116,29 @@ cr.define('cr_toolbar_search_field', function() {
}); });
test('does not notify on setValue with noEvent=true', function() { test('does not notify on setValue with noEvent=true', function() {
MockInteractions.tap(field); field.click();
field.setValue('foo', true); field.setValue('foo', true);
field.setValue('bar'); field.setValue('bar');
field.setValue('baz', true); field.setValue('baz', true);
assertEquals(['bar'].join(), searches.join()); assertEquals(['bar'].join(), searches.join());
}); });
test('treat consecutive whitespace as single space', function() {
field.click();
const query = ' foo bar baz ';
simulateSearch(query);
Polymer.dom.flush();
assertEquals(query, field.getValue());
// Expecting effectively the same query to be ignored.
const effectivelySameQuery = ' foo bar baz ';
simulateSearch(effectivelySameQuery);
Polymer.dom.flush();
assertEquals(effectivelySameQuery, field.getValue());
assertEquals(' foo bar baz ', searches.join());
});
// Tests that calling setValue() from within a 'search-changed' callback // Tests that calling setValue() from within a 'search-changed' callback
// does not result in an infinite loop. // does not result in an infinite loop.
test('no infinite loop', function() { test('no infinite loop', function() {
...@@ -134,14 +150,14 @@ cr.define('cr_toolbar_search_field', function() { ...@@ -134,14 +150,14 @@ cr.define('cr_toolbar_search_field', function() {
field.setValue(event.detail); field.setValue(event.detail);
}); });
MockInteractions.tap(field); field.click();
field.setValue('bar'); field.setValue('bar');
assertEquals(1, counter); assertEquals(1, counter);
assertEquals(['bar'].join(), searches.join()); assertEquals(['bar'].join(), searches.join());
}); });
test('blur does not close field when a search is active', function() { test('blur does not close field when a search is active', function() {
MockInteractions.tap(field); field.click();
simulateSearch('test'); simulateSearch('test');
MockInteractions.blur(field.$.searchInput); MockInteractions.blur(field.$.searchInput);
......
...@@ -81,12 +81,13 @@ var CrSearchFieldBehavior = { ...@@ -81,12 +81,13 @@ var CrSearchFieldBehavior = {
* @private * @private
*/ */
onValueChanged_: function(newValue, noEvent) { onValueChanged_: function(newValue, noEvent) {
if (newValue == this.lastValue_) const effectiveValue = newValue.replace(/\s+/g, ' ');
if (effectiveValue == this.lastValue_)
return; return;
this.lastValue_ = newValue; this.lastValue_ = effectiveValue;
if (!noEvent) if (!noEvent)
this.fire('search-changed', newValue); this.fire('search-changed', effectiveValue);
}, },
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment