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-languages', function() { | 5 cr.define('settings-languages', function() { |
6 /** | 6 /** |
7 * Data-binds two Polymer properties using the property-changed events and | 7 * Data-binds two Polymer properties using the property-changed events and |
8 * set/notifyPath API. Useful for testing components which would normally be | 8 * set/notifyPath API. Useful for testing components which would normally be |
9 * used together. | 9 * used together. |
10 * @param {!HTMLElement} el1 | 10 * @param {!HTMLElement} el1 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 }); | 56 }); |
57 fakePrefs.push({ | 57 fakePrefs.push({ |
58 key: 'settings.language.enabled_extension_imes', | 58 key: 'settings.language.enabled_extension_imes', |
59 type: chrome.settingsPrivate.PrefType.STRING, | 59 type: chrome.settingsPrivate.PrefType.STRING, |
60 value: '', | 60 value: '', |
61 }); | 61 }); |
62 } | 62 } |
63 return fakePrefs; | 63 return fakePrefs; |
64 } | 64 } |
65 | 65 |
| 66 /** |
| 67 * @param {!Array<string>} expected |
| 68 */ |
| 69 function assertLanguageOrder(expected) { |
| 70 assertEquals(expected.length, languageHelper.languages.enabled.length); |
| 71 for (var i = 0; i < expected.length; i++) { |
| 72 assertEquals( |
| 73 expected[i], languageHelper.languages.enabled[i].language.code); |
| 74 } |
| 75 } |
| 76 |
66 var languageHelper; | 77 var languageHelper; |
67 var languageSettingsPrivate; | 78 var languageSettingsPrivate; |
68 | 79 |
69 suiteSetup(function() { | 80 suiteSetup(function() { |
70 CrSettingsPrefs.deferInitialization = true; | 81 CrSettingsPrefs.deferInitialization = true; |
71 }); | 82 }); |
72 | 83 |
73 setup(function() { | 84 setup(function() { |
74 var settingsPrefs = document.createElement('settings-prefs'); | 85 var settingsPrefs = document.createElement('settings-prefs'); |
75 var settingsPrivate = new settings.FakeSettingsPrivate(getFakePrefs()); | 86 var settingsPrivate = new settings.FakeSettingsPrivate(getFakePrefs()); |
(...skipping 10 matching lines...) Expand all Loading... |
86 | 97 |
87 return languageHelper.whenReady(); | 98 return languageHelper.whenReady(); |
88 }); | 99 }); |
89 | 100 |
90 test('languages model', function() { | 101 test('languages model', function() { |
91 for (var i = 0; i < languageSettingsPrivate.languages.length; | 102 for (var i = 0; i < languageSettingsPrivate.languages.length; |
92 i++) { | 103 i++) { |
93 assertEquals(languageSettingsPrivate.languages[i].code, | 104 assertEquals(languageSettingsPrivate.languages[i].code, |
94 languageHelper.languages.supported[i].code); | 105 languageHelper.languages.supported[i].code); |
95 } | 106 } |
96 assertEquals(2, languageHelper.languages.enabled.length); | 107 assertLanguageOrder(['en-US', 'sw']); |
97 assertEquals('en-US', | |
98 languageHelper.languages.enabled[0].language.code); | |
99 assertEquals('sw', | |
100 languageHelper.languages.enabled[1].language.code); | |
101 assertEquals('en', languageHelper.languages.translateTarget); | 108 assertEquals('en', languageHelper.languages.translateTarget); |
102 | 109 |
103 // TODO(michaelpg): Test other aspects of the model. | 110 // TODO(michaelpg): Test other aspects of the model. |
104 }); | 111 }); |
105 | 112 |
106 test('modifying languages', function() { | 113 test('modifying languages', function() { |
107 assertTrue(languageHelper.isLanguageEnabled('en-US')); | 114 assertTrue(languageHelper.isLanguageEnabled('en-US')); |
108 assertTrue(languageHelper.isLanguageEnabled('sw')); | 115 assertTrue(languageHelper.isLanguageEnabled('sw')); |
109 assertFalse(languageHelper.isLanguageEnabled('en-CA')); | 116 assertFalse(languageHelper.isLanguageEnabled('en-CA')); |
110 | 117 |
111 languageHelper.enableLanguage('en-CA'); | 118 languageHelper.enableLanguage('en-CA'); |
112 assertTrue(languageHelper.isLanguageEnabled('en-CA')); | 119 assertTrue(languageHelper.isLanguageEnabled('en-CA')); |
113 languageHelper.disableLanguage('sw'); | 120 languageHelper.disableLanguage('sw'); |
114 assertFalse(languageHelper.isLanguageEnabled('sw')); | 121 assertFalse(languageHelper.isLanguageEnabled('sw')); |
115 | 122 |
116 // TODO(michaelpg): Test other modifications. | 123 // TODO(michaelpg): Test other modifications. |
117 }); | 124 }); |
118 | 125 |
119 test('reorder languages', function() { | 126 test('reorder languages', function() { |
| 127 // New language is added at the end. |
120 languageHelper.enableLanguage('en-CA'); | 128 languageHelper.enableLanguage('en-CA'); |
121 assertEquals('en-US', languageHelper.languages.enabled[0].language.code); | 129 assertLanguageOrder(['en-US', 'sw', 'en-CA']); |
122 assertEquals('sw', languageHelper.languages.enabled[1].language.code); | |
123 assertEquals('en-CA', languageHelper.languages.enabled[2].language.code); | |
124 | 130 |
125 // Can move a language up. | 131 // Can move a language up. |
126 languageHelper.moveLanguage('en-CA', -1); | 132 languageHelper.moveLanguage('en-CA', -1); |
127 assertEquals('en-US', languageHelper.languages.enabled[0].language.code); | 133 assertLanguageOrder(['en-US', 'en-CA', 'sw']); |
128 assertEquals('en-CA', languageHelper.languages.enabled[1].language.code); | |
129 assertEquals('sw', languageHelper.languages.enabled[2].language.code); | |
130 | 134 |
131 // Can move a language down. | 135 // Can move a language down. |
132 languageHelper.moveLanguage('en-US', 1); | 136 languageHelper.moveLanguage('en-US', 1); |
133 assertEquals('en-CA', languageHelper.languages.enabled[0].language.code); | 137 assertLanguageOrder(['en-CA', 'en-US', 'sw']); |
134 assertEquals('en-US', languageHelper.languages.enabled[1].language.code); | 138 |
135 assertEquals('sw', languageHelper.languages.enabled[2].language.code); | 139 // Can move a language to the front. |
| 140 languageHelper.moveLanguageToFront('sw'); |
| 141 var expectedOrder = ['sw', 'en-CA', 'en-US']; |
| 142 assertLanguageOrder(expectedOrder); |
136 | 143 |
137 // Moving the first language up has no effect. | 144 // Moving the first language up has no effect. |
138 languageHelper.moveLanguage('en-CA', -1); | 145 languageHelper.moveLanguage('sw', -1); |
139 assertEquals('en-CA', languageHelper.languages.enabled[0].language.code); | 146 assertLanguageOrder(expectedOrder); |
140 assertEquals('en-US', languageHelper.languages.enabled[1].language.code); | 147 |
141 assertEquals('sw', languageHelper.languages.enabled[2].language.code); | 148 // Moving the first language to top has no effect. |
| 149 languageHelper.moveLanguageToFront('sw'); |
| 150 assertLanguageOrder(expectedOrder); |
142 | 151 |
143 // Moving the last language down has no effect. | 152 // Moving the last language down has no effect. |
144 languageHelper.moveLanguage('sw', 1); | 153 languageHelper.moveLanguage('en-US', 1); |
145 assertEquals('en-CA', languageHelper.languages.enabled[0].language.code); | 154 assertLanguageOrder(expectedOrder); |
146 assertEquals('en-US', languageHelper.languages.enabled[1].language.code); | |
147 assertEquals('sw', languageHelper.languages.enabled[2].language.code); | |
148 }); | 155 }); |
149 | 156 |
150 if (cr.isChromeOS) { | 157 if (cr.isChromeOS) { |
151 test('modifying input methods', function() { | 158 test('modifying input methods', function() { |
152 assertEquals(2, languageHelper.languages.inputMethods.enabled.length); | 159 assertEquals(2, languageHelper.languages.inputMethods.enabled.length); |
153 var inputMethods = languageHelper.getInputMethodsForLanguage('en-US'); | 160 var inputMethods = languageHelper.getInputMethodsForLanguage('en-US'); |
154 assertEquals(3, inputMethods.length); | 161 assertEquals(3, inputMethods.length); |
155 | 162 |
156 // We can remove one input method. | 163 // We can remove one input method. |
157 var dvorak = | 164 var dvorak = |
(...skipping 19 matching lines...) Expand all Loading... |
177 // The US Swahili keyboard should still be enabled, because it supports | 184 // The US Swahili keyboard should still be enabled, because it supports |
178 // English which is still enabled. | 185 // English which is still enabled. |
179 assertTrue(languageHelper.languages.inputMethods.enabled.some( | 186 assertTrue(languageHelper.languages.inputMethods.enabled.some( |
180 function(inputMethod) { | 187 function(inputMethod) { |
181 return inputMethod.id == swUS; | 188 return inputMethod.id == swUS; |
182 })); | 189 })); |
183 }); | 190 }); |
184 } | 191 } |
185 }); | 192 }); |
186 }); | 193 }); |
OLD | NEW |