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 /** | 5 /** |
6 * @fileoverview Fake implementation of chrome.languageSettingsPrivate | 6 * @fileoverview Fake implementation of chrome.languageSettingsPrivate |
7 * for testing. | 7 * for testing. |
8 */ | 8 */ |
9 cr.define('settings', function() { | 9 cr.define('settings', function() { |
10 /** | 10 /** |
11 * Returns a function that calls assertNotReached with the given name. | 11 * Returns a function that calls assertNotReached with the given name. |
12 * Necessary to include the callee in the stack trace. | 12 * Necessary to include the callee in the stack trace. |
13 * @param {string} name | 13 * @param {string} name |
14 * @return {function()} | 14 * @return {function()} |
15 */ | 15 */ |
16 function wrapAssertNotReached(name) { | 16 function wrapAssertNotReached(name) { |
17 return function() { | 17 return function() { |
18 assertNotReached('Not implemented in fake: ' + name); | 18 assertNotReached('Not implemented in fake: ' + name); |
19 }; | 19 }; |
20 } | 20 } |
21 | 21 |
22 /** | 22 /** |
23 * Fake of the chrome.languageSettingsPrivate API. | 23 * Fake of the chrome.languageSettingsPrivate API. |
24 * @constructor | 24 * @constructor |
| 25 * @extends {TestBrowserProxy} |
25 * @implements {LanguageSettingsPrivate} | 26 * @implements {LanguageSettingsPrivate} |
26 */ | 27 */ |
27 function FakeLanguageSettingsPrivate() { | 28 function FakeLanguageSettingsPrivate() { |
| 29 // List of method names expected to be tested with whenCalled() |
| 30 settings.TestBrowserProxy.call(this, [ |
| 31 'getSpellcheckWords', |
| 32 ]); |
| 33 |
28 /** @type {!Array<!chrome.languageSettingsPrivate.Language>} */ | 34 /** @type {!Array<!chrome.languageSettingsPrivate.Language>} */ |
29 this.languages = [{ | 35 this.languages = [{ |
30 // English and some variants. | 36 // English and some variants. |
31 code: 'en', | 37 code: 'en', |
32 displayName: 'English', | 38 displayName: 'English', |
33 nativeDisplayName: 'English', | 39 nativeDisplayName: 'English', |
34 supportsTranslate: true, | 40 supportsTranslate: true, |
35 }, { | 41 }, { |
36 code: 'en-CA', | 42 code: 'en-CA', |
37 displayName: 'English (Canada)', | 43 displayName: 'English (Canada)', |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 enabled: false, | 98 enabled: false, |
93 }, { | 99 }, { |
94 id: '_comp_ime_abcdefghijklmnopqrstuvwxyzabcdefxkb:us:sw', | 100 id: '_comp_ime_abcdefghijklmnopqrstuvwxyzabcdefxkb:us:sw', |
95 displayName: 'US Swahili keyboard', | 101 displayName: 'US Swahili keyboard', |
96 languageCodes: ['en', 'en-US', 'sw'], | 102 languageCodes: ['en', 'en-US', 'sw'], |
97 enabled: false, | 103 enabled: false, |
98 }]; | 104 }]; |
99 } | 105 } |
100 | 106 |
101 FakeLanguageSettingsPrivate.prototype = { | 107 FakeLanguageSettingsPrivate.prototype = { |
| 108 __proto__: settings.TestBrowserProxy.prototype, |
102 // Methods for use in testing. | 109 // Methods for use in testing. |
103 | 110 |
104 /** @param {SettingsPrefsElement} */ | 111 /** @param {SettingsPrefsElement} */ |
105 setSettingsPrefs: function(settingsPrefs) { | 112 setSettingsPrefs: function(settingsPrefs) { |
106 this.settingsPrefs_ = settingsPrefs; | 113 this.settingsPrefs_ = settingsPrefs; |
107 }, | 114 }, |
108 | 115 |
109 // LanguageSettingsPrivate fake. | 116 // LanguageSettingsPrivate fake. |
110 | 117 |
111 /** | 118 /** |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 * !chrome.languageSettingsPrivate.SpellcheckDictionaryStatus>):void} | 172 * !chrome.languageSettingsPrivate.SpellcheckDictionaryStatus>):void} |
166 * callback | 173 * callback |
167 */ | 174 */ |
168 getSpellcheckDictionaryStatuses: | 175 getSpellcheckDictionaryStatuses: |
169 wrapAssertNotReached('getSpellcheckDictionaryStatuses'), | 176 wrapAssertNotReached('getSpellcheckDictionaryStatuses'), |
170 | 177 |
171 /** | 178 /** |
172 * Gets the custom spell check words, in sorted order. | 179 * Gets the custom spell check words, in sorted order. |
173 * @param {function(!Array<string>):void} callback | 180 * @param {function(!Array<string>):void} callback |
174 */ | 181 */ |
175 getSpellcheckWords: wrapAssertNotReached('getSpellcheckWords'), | 182 getSpellcheckWords: function(callback) { |
| 183 callback([]); |
| 184 this.methodCalled('getSpellcheckWords'); |
| 185 }, |
176 | 186 |
177 /** | 187 /** |
178 * Adds a word to the custom dictionary. | 188 * Adds a word to the custom dictionary. |
179 * @param {string} word | 189 * @param {string} word |
180 */ | 190 */ |
181 addSpellcheckWord: wrapAssertNotReached('addSpellcheckWord'), | 191 addSpellcheckWord: function(word) { |
| 192 // Current tests don't actually care about this implementation. |
| 193 }, |
182 | 194 |
183 /** | 195 /** |
184 * Removes a word from the custom dictionary. | 196 * Removes a word from the custom dictionary. |
185 * @param {string} word | 197 * @param {string} word |
186 */ | 198 */ |
187 removeSpellcheckWord: wrapAssertNotReached('removeSpellcheckWord'), | 199 removeSpellcheckWord: wrapAssertNotReached('removeSpellcheckWord'), |
188 | 200 |
189 /** | 201 /** |
190 * Gets the translate target language (in most cases, the display locale). | 202 * Gets the translate target language (in most cases, the display locale). |
191 * @param {function(string):void} callback | 203 * @param {function(string):void} callback |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 280 |
269 /** | 281 /** |
270 * Called when an input method is removed. | 282 * Called when an input method is removed. |
271 * @type {!ChromeEvent} | 283 * @type {!ChromeEvent} |
272 */ | 284 */ |
273 onInputMethodRemoved: new FakeChromeEvent(), | 285 onInputMethodRemoved: new FakeChromeEvent(), |
274 }; | 286 }; |
275 | 287 |
276 return {FakeLanguageSettingsPrivate: FakeLanguageSettingsPrivate}; | 288 return {FakeLanguageSettingsPrivate: FakeLanguageSettingsPrivate}; |
277 }); | 289 }); |
OLD | NEW |