Chromium Code Reviews| 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('settings_main_page', function() { | 5 cr.define('settings_main_page', function() { |
| 6 /** | 6 /** |
| 7 * @implements {SearchManager} | 7 * @implements {SearchManager} |
| 8 * @extends {settings.TestBrowserProxy} | |
|
tommycli
2016/10/27 21:07:17
If I understand correctly? : The TestSearchManager
dpapad
2016/10/28 20:23:39
Added comment. Even though TestBrowserProxy has be
| |
| 8 */ | 9 */ |
| 9 var TestSearchManager = function() { | 10 var TestSearchManager = function() { |
| 11 settings.TestBrowserProxy.call(this, [ | |
| 12 'search', | |
| 13 ]); | |
| 14 | |
| 10 /** @private {boolean} */ | 15 /** @private {boolean} */ |
| 11 this.matchesFound_ = true; | 16 this.matchesFound_ = true; |
| 12 | 17 |
| 13 /** @private {?settings.SearchRequest} */ | 18 /** @private {?settings.SearchRequest} */ |
| 14 this.searchRequest_ = null; | 19 this.searchRequest_ = null; |
| 15 } | 20 } |
| 16 | 21 |
| 17 TestSearchManager.prototype = { | 22 TestSearchManager.prototype = { |
| 23 __proto__: settings.TestBrowserProxy.prototype, | |
| 24 | |
| 18 /** | 25 /** |
| 19 * @param {boolean} matchesFound | 26 * @param {boolean} matchesFound |
| 20 */ | 27 */ |
| 21 setMatchesFound: function(matchesFound) { | 28 setMatchesFound: function(matchesFound) { |
| 22 this.matchesFound_ = matchesFound; | 29 this.matchesFound_ = matchesFound; |
| 23 }, | 30 }, |
| 24 | 31 |
| 25 /** @override */ | 32 /** @override */ |
| 26 search: function(text, page) { | 33 search: function(text, page) { |
| 34 this.methodCalled('search', text); | |
| 35 | |
| 27 if (this.searchRequest_ == null || !this.searchRequest_.isSame(text)) { | 36 if (this.searchRequest_ == null || !this.searchRequest_.isSame(text)) { |
| 28 this.searchRequest_ = new settings.SearchRequest(text); | 37 this.searchRequest_ = new settings.SearchRequest(text); |
| 29 this.searchRequest_.finished = true; | 38 this.searchRequest_.finished = true; |
| 30 this.searchRequest_.updateMatches(this.matchesFound_); | 39 this.searchRequest_.updateMatches(this.matchesFound_); |
| 31 this.searchRequest_.resolver.resolve(this.searchRequest_); | 40 this.searchRequest_.resolver.resolve(this.searchRequest_); |
| 32 } | 41 } |
| 33 return this.searchRequest_.resolver.promise; | 42 return this.searchRequest_.resolver.promise; |
| 34 }, | 43 }, |
| 35 }; | 44 }; |
| 36 | 45 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 55 settings.setSearchManagerForTesting(searchManager); | 64 settings.setSearchManagerForTesting(searchManager); |
| 56 PolymerTest.clearBody(); | 65 PolymerTest.clearBody(); |
| 57 settingsMain = document.createElement('settings-main'); | 66 settingsMain = document.createElement('settings-main'); |
| 58 settingsMain.prefs = settingsPrefs.prefs; | 67 settingsMain.prefs = settingsPrefs.prefs; |
| 59 settingsMain.toolbarSpinnerActive = false; | 68 settingsMain.toolbarSpinnerActive = false; |
| 60 document.body.appendChild(settingsMain); | 69 document.body.appendChild(settingsMain); |
| 61 }); | 70 }); |
| 62 | 71 |
| 63 teardown(function() { settingsMain.remove(); }); | 72 teardown(function() { settingsMain.remove(); }); |
| 64 | 73 |
| 74 /** | |
| 75 * Triggers a navigation to a URL that has a 'search' parameter for the | |
| 76 * given query. | |
| 77 * @param {string} query | |
| 78 */ | |
| 79 function triggerSearchByUrl(query) { | |
| 80 settings.navigateTo( | |
| 81 settings.Route.BASIC, | |
| 82 new URLSearchParams(`search=${query}`)); | |
| 83 } | |
| 84 | |
| 85 test('search URL parameter triggers search', function() { | |
| 86 Polymer.dom.flush(); | |
| 87 | |
| 88 var expectedQuery1 = 'foo'; | |
| 89 var expectedQuery2 = 'bar'; | |
| 90 var expectedQuery3 = ''; | |
| 91 | |
| 92 triggerSearchByUrl(expectedQuery1); | |
| 93 return searchManager.whenCalled('search').then(function(query) { | |
| 94 assertEquals(expectedQuery1, query); | |
| 95 | |
| 96 searchManager.resetResolver('search'); | |
| 97 triggerSearchByUrl(expectedQuery2); | |
| 98 return searchManager.whenCalled('search'); | |
| 99 }).then(function(query) { | |
| 100 assertEquals(expectedQuery2, query); | |
| 101 | |
| 102 searchManager.resetResolver('search'); | |
| 103 triggerSearchByUrl(expectedQuery3); | |
| 104 return searchManager.whenCalled('search'); | |
| 105 }).then(function(query) { | |
| 106 assertEquals(expectedQuery3, query); | |
| 107 }); | |
| 108 }); | |
| 109 | |
| 65 test('no results page shows and hides', function() { | 110 test('no results page shows and hides', function() { |
| 66 Polymer.dom.flush(); | 111 Polymer.dom.flush(); |
| 67 var noSearchResults = settingsMain.$.noSearchResults; | 112 var noSearchResults = settingsMain.$.noSearchResults; |
| 68 assertTrue(!!noSearchResults); | 113 assertTrue(!!noSearchResults); |
| 69 assertTrue(noSearchResults.hidden); | 114 assertTrue(noSearchResults.hidden); |
| 70 | 115 |
| 71 var toggleContainer = settingsMain.$$('#toggleContainer'); | 116 var toggleContainer = settingsMain.$$('#toggleContainer'); |
| 72 assertTrue(!!toggleContainer); | 117 assertTrue(!!toggleContainer); |
| 73 assertNotEquals('none', toggleContainer.style.display); | 118 assertNotEquals('none', toggleContainer.style.display); |
| 74 | 119 |
| 75 searchManager.setMatchesFound(false); | 120 searchManager.setMatchesFound(false); |
| 76 return settingsMain.searchContents('Query1').then(function() { | 121 return settingsMain.searchContents_('Query1').then(function() { |
| 77 assertFalse(noSearchResults.hidden); | 122 assertFalse(noSearchResults.hidden); |
| 78 assertEquals('none', toggleContainer.style.display); | 123 assertEquals('none', toggleContainer.style.display); |
| 79 | 124 |
| 80 searchManager.setMatchesFound(true); | 125 searchManager.setMatchesFound(true); |
| 81 return settingsMain.searchContents('Query2'); | 126 return settingsMain.searchContents_('Query2'); |
| 82 }).then(function() { | 127 }).then(function() { |
| 83 assertTrue(noSearchResults.hidden); | 128 assertTrue(noSearchResults.hidden); |
| 84 }); | 129 }); |
| 85 }); | 130 }); |
| 86 | 131 |
| 87 // Ensure that when the user clears the search box, the "no results" page | 132 // Ensure that when the user clears the search box, the "no results" page |
| 88 // is hidden and the "advanced page toggle" is visible again. | 133 // is hidden and the "advanced page toggle" is visible again. |
| 89 test('no results page hides on clear', function() { | 134 test('no results page hides on clear', function() { |
| 90 Polymer.dom.flush(); | 135 Polymer.dom.flush(); |
| 91 var noSearchResults = settingsMain.$.noSearchResults; | 136 var noSearchResults = settingsMain.$.noSearchResults; |
| 92 assertTrue(!!noSearchResults); | 137 assertTrue(!!noSearchResults); |
| 93 assertTrue(noSearchResults.hidden); | 138 assertTrue(noSearchResults.hidden); |
| 94 | 139 |
| 95 var toggleContainer = settingsMain.$$('#toggleContainer'); | 140 var toggleContainer = settingsMain.$$('#toggleContainer'); |
| 96 assertTrue(!!toggleContainer); | 141 assertTrue(!!toggleContainer); |
| 97 assertNotEquals('none', toggleContainer.style.display); | 142 assertNotEquals('none', toggleContainer.style.display); |
| 98 | 143 |
| 99 searchManager.setMatchesFound(false); | 144 searchManager.setMatchesFound(false); |
| 100 // Clearing the search box is effectively a search for the empty string. | 145 // Clearing the search box is effectively a search for the empty string. |
| 101 return settingsMain.searchContents('').then(function() { | 146 return settingsMain.searchContents_('').then(function() { |
| 102 Polymer.dom.flush(); | 147 Polymer.dom.flush(); |
| 103 assertTrue(noSearchResults.hidden); | 148 assertTrue(noSearchResults.hidden); |
| 104 assertNotEquals('none', toggleContainer.style.display); | 149 assertNotEquals('none', toggleContainer.style.display); |
| 105 }); | 150 }); |
| 106 }); | 151 }); |
| 107 | 152 |
| 108 /** | 153 /** |
| 109 * Asserts the visibility of the basic and advanced pages after exiting | 154 * Asserts the visibility of the basic and advanced pages after exiting |
| 110 * search mode. | 155 * search mode. |
| 111 * @param {string} Expected 'display' value for the basic page. | 156 * @param {string} Expected 'display' value for the basic page. |
| 112 * @param {string} Expected 'display' value for the advanced page. | 157 * @param {string} Expected 'display' value for the advanced page. |
| 113 * @return {!Promise} | 158 * @return {!Promise} |
| 114 */ | 159 */ |
| 115 function assertPageVisibilityAfterSearch( | 160 function assertPageVisibilityAfterSearch( |
| 116 expectedBasic, expectedAdvanced) { | 161 expectedBasic, expectedAdvanced) { |
| 117 searchManager.setMatchesFound(true); | 162 searchManager.setMatchesFound(true); |
| 118 return settingsMain.searchContents('Query1').then(function() { | 163 return settingsMain.searchContents_('Query1').then(function() { |
| 119 searchManager.setMatchesFound(false); | 164 searchManager.setMatchesFound(false); |
| 120 return settingsMain.searchContents(''); | 165 return settingsMain.searchContents_(''); |
| 121 }).then(function() { | 166 }).then(function() { |
| 122 Polymer.dom.flush(); | 167 Polymer.dom.flush(); |
| 123 assertEquals( | 168 assertEquals( |
| 124 expectedBasic, | 169 expectedBasic, |
| 125 settingsMain.$$('settings-basic-page').style.display); | 170 settingsMain.$$('settings-basic-page').style.display); |
| 126 assertEquals( | 171 assertEquals( |
| 127 expectedAdvanced, | 172 expectedAdvanced, |
| 128 settingsMain.$$('settings-advanced-page').style.display); | 173 settingsMain.$$('settings-advanced-page').style.display); |
| 129 }); | 174 }); |
| 130 } | 175 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 146 }); | 191 }); |
| 147 | 192 |
| 148 // Ensure that searching, then entering a subpage, then going back | 193 // Ensure that searching, then entering a subpage, then going back |
| 149 // lands the user in a page where both basic and advanced sections are | 194 // lands the user in a page where both basic and advanced sections are |
| 150 // visible, because the page is still in search mode. | 195 // visible, because the page is still in search mode. |
| 151 test('returning from subpage to search results', function() { | 196 test('returning from subpage to search results', function() { |
| 152 settings.navigateTo(settings.Route.BASIC); | 197 settings.navigateTo(settings.Route.BASIC); |
| 153 Polymer.dom.flush(); | 198 Polymer.dom.flush(); |
| 154 | 199 |
| 155 searchManager.setMatchesFound(true); | 200 searchManager.setMatchesFound(true); |
| 156 return settingsMain.searchContents('Query1').then(function() { | 201 return settingsMain.searchContents_('Query1').then(function() { |
| 157 // Simulate navigating into a subpage. | 202 // Simulate navigating into a subpage. |
| 158 settings.navigateTo(settings.Route.SEARCH_ENGINES); | 203 settings.navigateTo(settings.Route.SEARCH_ENGINES); |
| 159 settingsMain.$$('settings-basic-page').fire('subpage-expand'); | 204 settingsMain.$$('settings-basic-page').fire('subpage-expand'); |
| 160 Polymer.dom.flush(); | 205 Polymer.dom.flush(); |
| 161 | 206 |
| 162 // Simulate clicking the left arrow to go back to the search results. | 207 // Simulate clicking the left arrow to go back to the search results. |
| 163 settingsMain.currentRouteChanged(settings.Route.BASIC); | 208 settingsMain.currentRouteChanged(settings.Route.BASIC); |
| 164 Polymer.dom.flush(); | 209 Polymer.dom.flush(); |
| 165 assertEquals( | 210 assertEquals( |
| 166 '', settingsMain.$$('settings-basic-page').style.display); | 211 '', settingsMain.$$('settings-basic-page').style.display); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 194 | 239 |
| 195 assertTrue(settingsMain.showPages_.advanced); | 240 assertTrue(settingsMain.showPages_.advanced); |
| 196 }); | 241 }); |
| 197 }); | 242 }); |
| 198 } | 243 } |
| 199 | 244 |
| 200 return { | 245 return { |
| 201 registerTests: registerTests, | 246 registerTests: registerTests, |
| 202 }; | 247 }; |
| 203 }); | 248 }); |
| OLD | NEW |