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_test', function() { |
6 /** | 6 /** |
7 * Extending TestBrowserProxy even though SearchManager is not a browser proxy | 7 * Extending TestBrowserProxy even though SearchManager is not a browser proxy |
8 * itself. Essentially TestBrowserProxy can act as a "proxy" for any external | 8 * itself. Essentially TestBrowserProxy can act as a "proxy" for any external |
9 * dependency, not just "browser proxies" (and maybe should be renamed to | 9 * dependency, not just "browser proxies" (and maybe should be renamed to |
10 * TestProxy). | 10 * TestProxy). |
11 * | 11 * |
12 * @implements {SearchManager} | 12 * @implements {SearchManager} |
13 * @extends {settings.TestBrowserProxy} | 13 * @extends {settings.TestBrowserProxy} |
14 */ | 14 */ |
15 var TestSearchManager = function() { | 15 var TestSearchManager = function() { |
16 settings.TestBrowserProxy.call(this, [ | 16 settings.TestBrowserProxy.call(this, [ |
17 'search', | 17 'search', |
18 ]); | 18 ]); |
19 | 19 |
20 /** @private {boolean} */ | 20 /** @private {boolean} */ |
21 this.matchesFound_ = true; | 21 this.matchesFound_ = true; |
22 | 22 |
23 /** @private {?settings.SearchRequest} */ | 23 /** @private {?settings.SearchRequest} */ |
24 this.searchRequest_ = null; | 24 this.searchRequest_ = null; |
25 } | 25 }; |
26 | 26 |
27 TestSearchManager.prototype = { | 27 TestSearchManager.prototype = { |
28 __proto__: settings.TestBrowserProxy.prototype, | 28 __proto__: settings.TestBrowserProxy.prototype, |
29 | 29 |
30 /** | 30 /** |
31 * @param {boolean} matchesFound | 31 * @param {boolean} matchesFound |
32 */ | 32 */ |
33 setMatchesFound: function(matchesFound) { | 33 setMatchesFound: function(matchesFound) { |
34 this.matchesFound_ = matchesFound; | 34 this.matchesFound_ = matchesFound; |
35 }, | 35 }, |
36 | 36 |
37 /** @override */ | 37 /** @override */ |
38 search: function(text, page) { | 38 search: function(text, page) { |
39 this.methodCalled('search', text); | 39 this.methodCalled('search', text); |
40 | 40 |
41 if (this.searchRequest_ == null || !this.searchRequest_.isSame(text)) { | 41 if (this.searchRequest_ == null || !this.searchRequest_.isSame(text)) { |
42 this.searchRequest_ = new settings.SearchRequest(text); | 42 this.searchRequest_ = new settings.SearchRequest(text); |
43 this.searchRequest_.finished = true; | 43 this.searchRequest_.finished = true; |
44 this.searchRequest_.updateMatches(this.matchesFound_); | 44 this.searchRequest_.updateMatches(this.matchesFound_); |
45 this.searchRequest_.resolver.resolve(this.searchRequest_); | 45 this.searchRequest_.resolver.resolve(this.searchRequest_); |
46 } | 46 } |
47 return this.searchRequest_.resolver.promise; | 47 return this.searchRequest_.resolver.promise; |
48 }, | 48 }, |
49 }; | 49 }; |
50 | 50 |
51 function registerTests() { | 51 suite('MainPageTests', function() { |
52 var settingsPrefs = null; | 52 /** @type {?SettingsPrefsElement} */ |
| 53 var settingsPrefs = null; |
53 | 54 |
54 suiteSetup(function() { | |
55 settingsPrefs = document.createElement('settings-prefs'); | |
56 return CrSettingsPrefs.initialized; | |
57 }); | |
58 | |
59 suite('MainPageTests', function() { | |
60 /** @type {?TestSearchManager} */ | 55 /** @type {?TestSearchManager} */ |
61 var searchManager = null; | 56 var searchManager = null; |
62 | 57 |
63 /** @type {?SettingsMainElement} */ | 58 /** @type {?SettingsMainElement} */ |
64 var settingsMain = null; | 59 var settingsMain = null; |
65 | 60 |
| 61 suiteSetup(function() { |
| 62 CrOncStrings = {}; |
| 63 settingsPrefs = document.createElement('settings-prefs'); |
| 64 var fakePrefs = []; |
| 65 var fakeApi = new settings.FakeSettingsPrivate(fakePrefs); |
| 66 settingsPrefs.initialize(fakeApi); |
| 67 return CrSettingsPrefs.initialized; |
| 68 }); |
| 69 |
66 setup(function() { | 70 setup(function() { |
67 settings.navigateTo(settings.Route.BASIC); | 71 settings.navigateTo(settings.Route.BASIC); |
68 searchManager = new TestSearchManager(); | 72 searchManager = new TestSearchManager(); |
69 settings.setSearchManagerForTesting(searchManager); | 73 settings.setSearchManagerForTesting(searchManager); |
70 PolymerTest.clearBody(); | 74 PolymerTest.clearBody(); |
71 settingsMain = document.createElement('settings-main'); | 75 settingsMain = document.createElement('settings-main'); |
72 settingsMain.prefs = settingsPrefs.prefs; | 76 settingsMain.prefs = settingsPrefs.prefs; |
73 settingsMain.toolbarSpinnerActive = false; | 77 settingsMain.toolbarSpinnerActive = false; |
74 // Set default page visibility. | 78 // Set default page visibility. |
75 settingsMain.pageVisibility = {}; | 79 settingsMain.pageVisibility = {}; |
76 document.body.appendChild(settingsMain); | 80 document.body.appendChild(settingsMain); |
77 }); | 81 }); |
78 | 82 |
79 teardown(function() { settingsMain.remove(); }); | 83 teardown(function() { |
| 84 settingsMain.remove(); |
| 85 }); |
80 | 86 |
81 test('searchContents() triggers SearchManager', function() { | 87 test('searchContents() triggers SearchManager', function() { |
82 Polymer.dom.flush(); | 88 Polymer.dom.flush(); |
83 | 89 |
84 var expectedQuery1 = 'foo'; | 90 var expectedQuery1 = 'foo'; |
85 var expectedQuery2 = 'bar'; | 91 var expectedQuery2 = 'bar'; |
86 var expectedQuery3 = ''; | 92 var expectedQuery3 = ''; |
87 | 93 |
88 return settingsMain.searchContents(expectedQuery1).then(function() { | 94 return settingsMain.searchContents(expectedQuery1).then(function() { |
89 return searchManager.whenCalled('search'); | 95 return searchManager.whenCalled('search'); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // Clearing the search box is effectively a search for the empty string. | 168 // Clearing the search box is effectively a search for the empty string. |
163 return settingsMain.searchContents('').then(function() { | 169 return settingsMain.searchContents('').then(function() { |
164 Polymer.dom.flush(); | 170 Polymer.dom.flush(); |
165 assertTrue(noSearchResults.hidden); | 171 assertTrue(noSearchResults.hidden); |
166 assertToggleContainerVisible(true); | 172 assertToggleContainerVisible(true); |
167 }); | 173 }); |
168 }); | 174 }); |
169 | 175 |
170 /** | 176 /** |
171 * Asserts the visibility of the basic and advanced pages. | 177 * Asserts the visibility of the basic and advanced pages. |
172 * @param {string} Expected 'display' value for the basic page. | 178 * @param {string} expectedBasic 'display' value for the basic page. |
173 * @param {string} Expected 'display' value for the advanced page. | 179 * @param {string} expectedAdvanced 'display' value for the advanced page. |
174 */ | 180 */ |
175 function assertPageVisibility(expectedBasic, expectedAdvanced) { | 181 function assertPageVisibility(expectedBasic, expectedAdvanced) { |
176 Polymer.dom.flush(); | 182 Polymer.dom.flush(); |
177 var page = settingsMain.$$('settings-basic-page'); | 183 var page = settingsMain.$$('settings-basic-page'); |
178 assertEquals( | 184 assertEquals(expectedBasic, page.$$('#basicPage').style.display); |
179 expectedBasic, page.$$('#basicPage').style.display); | 185 |
180 assertEquals( | 186 var advanced = page.$$('#advancedPage'); |
181 expectedAdvanced, | 187 if (!advanced) { |
182 page.$$('#advancedPageTemplate').get().style.display); | 188 assertEquals(expectedAdvanced, 'none'); |
| 189 } else if (advanced.hidden) { |
| 190 assertEquals(expectedAdvanced, 'none'); |
| 191 } else { |
| 192 assertEquals(expectedAdvanced, advanced.style.display); |
| 193 } |
183 } | 194 } |
184 | 195 |
185 // TODO(michaelpg): It would be better not to drill into | 196 // TODO(michaelpg): It would be better not to drill into |
186 // settings-basic-page. If search should indeed only work in Settings | 197 // settings-basic-page. If search should indeed only work in Settings |
187 // (as opposed to Advanced), perhaps some of this logic should be | 198 // (as opposed to Advanced), perhaps some of this logic should be |
188 // delegated to settings-basic-page now instead of settings-main. | 199 // delegated to settings-basic-page now instead of settings-main. |
189 | 200 |
190 /** | 201 /** |
191 * Asserts the visibility of the basic and advanced pages after exiting | 202 * Asserts the visibility of the basic and advanced pages after exiting |
192 * search mode. | 203 * search mode. |
193 * @param {string} Expected 'display' value for the basic page. | 204 * @param {string} Expected 'display' value for the basic page. |
194 * @param {string} Expected 'display' value for the advanced page. | 205 * @param {string} Expected 'display' value for the advanced page. |
195 * @return {!Promise} | 206 * @return {!Promise} |
196 */ | 207 */ |
197 function assertPageVisibilityAfterSearch( | 208 function assertPageVisibilityAfterSearch( |
198 expectedBasic, expectedAdvanced) { | 209 expectedBasic, expectedAdvanced) { |
199 searchManager.setMatchesFound(true); | 210 searchManager.setMatchesFound(true); |
200 return settingsMain.searchContents('Query1').then(function() { | 211 return settingsMain.searchContents('Query1').then(function() { |
201 searchManager.setMatchesFound(false); | 212 searchManager.setMatchesFound(false); |
202 return settingsMain.searchContents(''); | 213 return settingsMain.searchContents(''); |
203 }).then(function() { | 214 }).then(function() { |
204 assertPageVisibility(expectedBasic, expectedAdvanced); | 215 assertPageVisibility(expectedBasic, expectedAdvanced); |
205 }); | 216 }); |
206 } | 217 } |
207 | 218 |
208 test('exiting search mode, advanced collapsed', function() { | 219 test('exiting search mode, advanced collapsed', function() { |
209 // Simulating searching while the advanced page is collapsed. | 220 // Simulating searching while the advanced page is collapsed. |
210 settingsMain.currentRouteChanged(settings.Route.BASIC); | 221 settingsMain.currentRouteChanged(settings.Route.BASIC); |
211 Polymer.dom.flush(); | 222 Polymer.dom.flush(); |
| 223 assertPageVisibility('', 'none'); |
212 return assertPageVisibilityAfterSearch('', 'none'); | 224 return assertPageVisibilityAfterSearch('', 'none'); |
213 }); | 225 }); |
214 | 226 |
215 // Ensure that clearing the search results restores both "basic" and | 227 // Ensure that clearing the search results restores both "basic" and |
216 // "advanced" page, when the search has been initiated from a subpage | 228 // "advanced" page, when the search has been initiated from a subpage |
217 // whose parent is the "advanced" page. | 229 // whose parent is the "advanced" page. |
218 test('exiting search mode, advanced expanded', function() { | 230 test('exiting search mode, advanced expanded', function() { |
219 settings.navigateTo(settings.Route.SITE_SETTINGS); | 231 settings.navigateTo(settings.Route.SITE_SETTINGS); |
220 Polymer.dom.flush(); | 232 Polymer.dom.flush(); |
221 return assertPageVisibilityAfterSearch('', ''); | 233 return assertPageVisibilityAfterSearch('', ''); |
(...skipping 27 matching lines...) Expand all Loading... |
249 var advancedToggle = | 261 var advancedToggle = |
250 getToggleContainer().querySelector('#advancedToggle'); | 262 getToggleContainer().querySelector('#advancedToggle'); |
251 assertTrue(!!advancedToggle); | 263 assertTrue(!!advancedToggle); |
252 | 264 |
253 MockInteractions.tap(advancedToggle); | 265 MockInteractions.tap(advancedToggle); |
254 Polymer.dom.flush(); | 266 Polymer.dom.flush(); |
255 | 267 |
256 assertPageVisibility('', 'none'); | 268 assertPageVisibility('', 'none'); |
257 }); | 269 }); |
258 | 270 |
| 271 test('navigating to an advanced page expands advanced', function() { |
| 272 settings.navigateTo(settings.Route.PRIVACY); |
| 273 Polymer.dom.flush(); |
| 274 return Polymer.Base.async(function() { |
| 275 assertToggleContainerVisible(true); |
| 276 assertPageVisibility('', ''); |
| 277 }); |
| 278 }); |
| 279 |
259 test('navigating to a basic page does not collapse advanced', function() { | 280 test('navigating to a basic page does not collapse advanced', function() { |
260 settings.navigateTo(settings.Route.PRIVACY); | 281 settings.navigateTo(settings.Route.PRIVACY); |
261 Polymer.dom.flush(); | 282 Polymer.dom.flush(); |
| 283 return Promise.all([ |
| 284 Polymer.Base.async(function() { |
| 285 assertToggleContainerVisible(true); |
| 286 assertPageVisibility('', ''); |
262 | 287 |
263 assertToggleContainerVisible(true); | 288 settings.navigateTo(settings.Route.PEOPLE); |
| 289 Polymer.dom.flush(); |
| 290 }), |
| 291 Polymer.Base.async(function() { |
| 292 assertPageVisibility('', ''); |
| 293 }) |
| 294 ]); |
| 295 }); |
264 | 296 |
265 settings.navigateTo(settings.Route.PEOPLE); | 297 test('basic pageVisibility', function() { |
266 Polymer.dom.flush(); | 298 Polymer.dom.flush(); |
| 299 var page = settingsMain.$$('settings-basic-page'); |
| 300 assertTrue(!!page); |
| 301 return Polymer.Base.async(function() { |
| 302 assertTrue(!!page.$$('settings-section[section="people"]')); |
| 303 assertTrue(!!page.$$('settings-section[section="appearance"]')); |
| 304 assertFalse(!!page.$$('settings-section[section="privacy"]')); |
| 305 assertFalse( |
| 306 !!page.$$('settings-section[section="passwordsAndForms"]')); |
| 307 }); |
| 308 }); |
267 | 309 |
268 assertPageVisibility('', ''); | 310 test('advanced pageVisibility', function() { |
| 311 Polymer.dom.flush(); |
| 312 var page = settingsMain.$$('settings-basic-page'); |
| 313 var advancedToggle = page.$$('#advancedToggle'); |
| 314 assertTrue(!!advancedToggle); |
| 315 MockInteractions.tap(advancedToggle); |
| 316 Polymer.dom.flush(); |
| 317 return Polymer.Base.async(function() { |
| 318 assertTrue(!!page.$$('settings-section[section="people"]')); |
| 319 assertTrue(!!page.$$('settings-section[section="appearance"]')); |
| 320 assertTrue(!!page.$$('settings-section[section="privacy"]')); |
| 321 assertTrue( |
| 322 !!page.$$('settings-section[section="passwordsAndForms"]')); |
| 323 }); |
| 324 }); |
| 325 |
| 326 test('custom pageVisibility', function() { |
| 327 Polymer.dom.flush(); |
| 328 var page = settingsMain.$$('settings-basic-page'); |
| 329 assertTrue(!!page); |
| 330 Polymer.dom.flush(); |
| 331 return Promise.all([ |
| 332 Polymer.Base.async(function() { |
| 333 assertTrue(!!page.$$('settings-section[section="people"]')); |
| 334 assertTrue(!!page.$$('settings-section[section="appearance"]')); |
| 335 }), |
| 336 Polymer.Base.async(function() { |
| 337 page.set('pageVisibility.appearance', false); |
| 338 Polymer.dom.flush(); |
| 339 }), |
| 340 Polymer.Base.async(function() { |
| 341 assertTrue(!!page.$$('settings-section[section="people"]')); |
| 342 assertFalse(!!page.$$('settings-section[section="appearance"]')); |
| 343 }) |
| 344 ]); |
269 }); | 345 }); |
270 }); | 346 }); |
271 } | |
272 | |
273 return { | |
274 registerTests: registerTests, | |
275 }; | |
276 }); | 347 }); |
OLD | NEW |