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 settings-languages-page. */ | 5 /** @fileoverview Suite of tests for settings-languages-page. */ |
6 | 6 |
7 /** @const {string} Path to root from chrome/test/data/webui/settings/. */ | 7 /** @const {string} Path to root from chrome/test/data/webui/settings/. */ |
8 var ROOT_PATH = '../../../../../'; | 8 var ROOT_PATH = '../../../../../'; |
9 | 9 |
10 // Polymer BrowserTest fixture. | 10 // Polymer BrowserTest fixture. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } | 80 } |
81 | 81 |
82 suiteSetup(function() { | 82 suiteSetup(function() { |
83 advanced.set('pageVisibility.languages', true); | 83 advanced.set('pageVisibility.languages', true); |
84 Polymer.dom.flush(); | 84 Polymer.dom.flush(); |
85 | 85 |
86 languagesSection = assert(this.getSection(advanced, 'languages')); | 86 languagesSection = assert(this.getSection(advanced, 'languages')); |
87 languagesPage = assert( | 87 languagesPage = assert( |
88 languagesSection.querySelector('settings-languages-page')); | 88 languagesSection.querySelector('settings-languages-page')); |
89 languagesCollapse = languagesPage.$.languagesCollapse; | 89 languagesCollapse = languagesPage.$.languagesCollapse; |
| 90 languagesCollapse.opened = true; |
90 | 91 |
91 languageHelper = languagesPage.languageHelper; | 92 languageHelper = languagesPage.languageHelper; |
92 return languageHelper.whenReady(); | 93 return languageHelper.whenReady(); |
93 }.bind(this)); | 94 }.bind(this)); |
94 | 95 |
95 teardown(function(done) { | 96 teardown(function(done) { |
96 // Close the section if we're in a sub-page. | 97 // Close the section if we're in a sub-page. |
97 if (settings.getCurrentRoute().isSubpage()) { | 98 if (settings.getCurrentRoute().isSubpage()) { |
98 settings.navigateTo(settings.Route.BASIC); | 99 settings.navigateTo(settings.Route.BASIC); |
99 setTimeout(done); | 100 setTimeout(done); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 187 |
187 // The action button should close and remove the dialog, enabling the | 188 // The action button should close and remove the dialog, enabling the |
188 // checked languages. | 189 // checked languages. |
189 MockInteractions.tap(actionButton); | 190 MockInteractions.tap(actionButton); |
190 | 191 |
191 // Wait for the languages to be enabled by the browser. | 192 // Wait for the languages to be enabled by the browser. |
192 return whenNumEnabledLanguagesBecomes(numEnabled + 2); | 193 return whenNumEnabledLanguagesBecomes(numEnabled + 2); |
193 }); | 194 }); |
194 }); | 195 }); |
195 | 196 |
196 test('should not set UI language', function() { | 197 suite('language menu', function() { |
197 var languageOptionsDropdownTrigger = languagesCollapse.querySelector( | 198 var origTranslateEnabled; |
198 'paper-icon-button'); | |
199 assertTrue(!!languageOptionsDropdownTrigger); | |
200 | 199 |
201 // This shouldn't get called. | 200 suiteSetup(function() { |
202 languageHelper.setUILanguage = assertNotReached; | 201 // Cache the value of Translate to avoid side effects. |
| 202 origTranslateEnabled = languageHelper.prefs.translate.enabled.value; |
| 203 }); |
203 | 204 |
204 // Tap the menu trigger twice to open and close the menu. | 205 suiteTeardown(function() { |
205 MockInteractions.tap(languageOptionsDropdownTrigger); | 206 var cur = languageHelper.prefs.translate.enabled.value; |
206 MockInteractions.tap(languageOptionsDropdownTrigger); | 207 // Restore the value of Translate. |
| 208 languageHelper.setPrefValue('translate.enabled', origTranslateEnabled); |
| 209 cur = languageHelper.prefs.translate.enabled.value; |
| 210 }); |
207 | 211 |
208 languageHelper.setUILanguage = languageHelper.__proto__.setUILanguage; | 212 test('structure', function(done) { |
209 }); | 213 var languageOptionsDropdownTrigger = languagesCollapse.querySelector( |
| 214 'paper-icon-button'); |
| 215 assertTrue(!!languageOptionsDropdownTrigger); |
| 216 MockInteractions.tap(languageOptionsDropdownTrigger); |
| 217 var languageMenu = assert(languagesPage.$$('cr-shared-menu')); |
210 | 218 |
211 test('remove language', function() { | 219 listenOnce(languageMenu, 'iron-overlay-opened', function() { |
212 var numEnabled = languagesPage.languages.enabled.length; | 220 assertTrue(languageMenu.menuOpen); |
213 | 221 |
214 // Enabled a language which we can then disable. | 222 // Enable Translate so the menu always shows the Translate checkbox. |
215 var newLanguage = getAvailableLanguage(); | 223 languageHelper.setPrefValue('translate.enabled', true); |
216 languageHelper.enableLanguage(newLanguage.code); | |
217 | 224 |
218 // Wait for the language to be enabled. | 225 var separator = languageMenu.querySelector('hr'); |
219 return whenNumEnabledLanguagesBecomes(numEnabled + 1).then(function() { | 226 assertEquals(1, separator.offsetHeight); |
220 // Populate the dom-repeat. | |
221 Polymer.dom.flush(); | |
222 | 227 |
223 // Find the new language item. | 228 // Disable Translate. On platforms that can't change the UI language, |
224 var items = languagesCollapse.querySelectorAll('.list-item'); | 229 // this hides all the checkboxes, so the separator isn't needed. |
225 var domRepeat = assert( | 230 // Chrome OS and Windows still show a checkbox and thus the separator. |
226 languagesCollapse.querySelector('template[is="dom-repeat"]')); | 231 languageHelper.setPrefValue('translate.enabled', false); |
227 var item = Array.from(items).find(function(el) { | 232 if (cr.isChromeOS || cr.isWindows) |
228 return domRepeat.itemForElement(el) && | 233 assertEquals(1, separator.offsetHeight); |
229 domRepeat.itemForElement(el).language == newLanguage; | 234 else |
| 235 assertEquals(0, separator.offsetHeight); |
| 236 |
| 237 MockInteractions.tap(languageOptionsDropdownTrigger); |
| 238 assertFalse(languageMenu.menuOpen); |
| 239 done(); |
230 }); | 240 }); |
| 241 }); |
231 | 242 |
232 // Open the menu and select Remove. | 243 test('remove language', function() { |
233 MockInteractions.tap(item.querySelector('paper-icon-button')); | 244 var numEnabled = languagesPage.languages.enabled.length; |
234 | 245 |
235 var languageMenu = assert(languagesPage.$$('cr-shared-menu')); | 246 // Enabled a language which we can then disable. |
236 assertTrue(languageMenu.menuOpen); | 247 var newLanguage = getAvailableLanguage(); |
237 var removeMenuItem = assert(languageMenu.querySelector( | 248 languageHelper.enableLanguage(newLanguage.code); |
238 '.dropdown-item:last-child')); | |
239 assertFalse(removeMenuItem.disabled); | |
240 MockInteractions.tap(removeMenuItem); | |
241 assertFalse(languageMenu.menuOpen); | |
242 | 249 |
243 // We should go back down to the original number of enabled languages. | 250 // Wait for the language to be enabled. |
244 return whenNumEnabledLanguagesBecomes(numEnabled).then(function() { | 251 return whenNumEnabledLanguagesBecomes(numEnabled + 1).then(function() { |
245 assertFalse(languageHelper.isLanguageEnabled(newLanguage.code)); | 252 // Populate the dom-repeat. |
| 253 Polymer.dom.flush(); |
| 254 |
| 255 // Find the new language item. |
| 256 var items = languagesCollapse.querySelectorAll('.list-item'); |
| 257 var domRepeat = assert( |
| 258 languagesCollapse.querySelector('template[is="dom-repeat"]')); |
| 259 var item = Array.from(items).find(function(el) { |
| 260 return domRepeat.itemForElement(el) && |
| 261 domRepeat.itemForElement(el).language == newLanguage; |
| 262 }); |
| 263 |
| 264 // Open the menu and select Remove. |
| 265 MockInteractions.tap(item.querySelector('paper-icon-button')); |
| 266 |
| 267 var languageMenu = assert(languagesPage.$$('cr-shared-menu')); |
| 268 assertTrue(languageMenu.menuOpen); |
| 269 var removeMenuItem = assert(languageMenu.querySelector( |
| 270 '.dropdown-item:last-child')); |
| 271 assertFalse(removeMenuItem.disabled); |
| 272 MockInteractions.tap(removeMenuItem); |
| 273 assertFalse(languageMenu.menuOpen); |
| 274 |
| 275 // We should go back down to the original number of enabled languages. |
| 276 return whenNumEnabledLanguagesBecomes(numEnabled).then(function() { |
| 277 assertFalse(languageHelper.isLanguageEnabled(newLanguage.code)); |
| 278 }); |
246 }); | 279 }); |
247 }); | 280 }); |
248 }); | 281 }); |
249 | 282 |
250 test('manage input methods', function() { | 283 test('manage input methods', function() { |
251 var inputMethodsCollapse = languagesPage.$.inputMethodsCollapse; | 284 var inputMethodsCollapse = languagesPage.$.inputMethodsCollapse; |
252 var inputMethodSettingsExist = !!inputMethodsCollapse; | 285 var inputMethodSettingsExist = !!inputMethodsCollapse; |
253 if (cr.isChromeOS) { | 286 if (cr.isChromeOS) { |
254 assertTrue(inputMethodSettingsExist); | 287 assertTrue(inputMethodSettingsExist); |
255 var manageInputMethodsButton = | 288 var manageInputMethodsButton = |
(...skipping 17 matching lines...) Expand all Loading... |
273 assertTrue(!!languagesPage.$$('settings-edit-dictionary-page')); | 306 assertTrue(!!languagesPage.$$('settings-edit-dictionary-page')); |
274 } | 307 } |
275 }); | 308 }); |
276 }.bind(this)); | 309 }.bind(this)); |
277 | 310 |
278 // TODO(michaelpg): Test more aspects of the languages UI. | 311 // TODO(michaelpg): Test more aspects of the languages UI. |
279 | 312 |
280 // Run all registered tests. | 313 // Run all registered tests. |
281 mocha.run(); | 314 mocha.run(); |
282 }); | 315 }); |
OLD | NEW |