Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(411)

Side by Side Diff: chrome/browser/ui/webui/options/multilanguage_options_webui_browsertest.js

Issue 1156473007: Enables the user to select multiple languages for spellchecking (UI) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed nits and rebased. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 GEN('#include "chrome/browser/ui/webui/options/multilanguage_options_webui_brows ertest.h"');
6
7 /**
8 * Test C++ fixture for Language Options WebUI testing.
9 * @constructor
10 * @extends {testing.Test}
11 */
12 function MultilanguageOptionsWebUIBrowserTest() {}
13
14 MultilanguageOptionsWebUIBrowserTest.prototype = {
15 __proto__: testing.Test.prototype,
16
17 /**
18 * Browse to the language options page & call our preLoad().
Dan Beam 2015/06/25 02:44:28 & -> and eh, this whole doc comment should probab
Julius 2015/07/06 22:38:53 Done.
19 */
20 browsePreload: 'chrome://settings-frame/languages',
21
22 /** @override */
23 typedefCppFixture: 'MultilanguageOptionsWebUIBrowserTest',
24
25 /** @override */
26 accessibilityIssuesAreErrors: true,
Dan Beam 2015/06/25 02:44:28 reduce yo copy pasta /** @return {Array<string>}
Julius 2015/07/06 22:38:53 Done.
27
28 /** @override */
29 setUp: function() {
30 testing.Test.prototype.setUp.call(this);
31
32 assertTrue(loadTimeData.getBoolean('enableMultilingualSpellChecker'));
33 assertFalse(cr.isMac);
34 expectTrue($('spellcheck-language-button').hidden);
35
36 // Make sure the only language currently selected is 'fr'.
37 var langOpts = LanguageOptions.getInstance();
38 var langs = Object.keys(langOpts.spellCheckLanguages_);
Dan Beam 2015/06/25 02:44:27 make your variables as verbose as possible without
Julius 2015/07/06 22:38:53 Done.
39 expectEquals(1, langs.length);
40 expectEquals('fr', langs[0]);
41 },
42 };
43
44 // Test opening language options has correct location.
45 TEST_F('MultilanguageOptionsWebUIBrowserTest', 'TestOpenLanguageOptions',
46 function() {
47 expectEquals('chrome://settings-frame/languages', document.location.href);
48 });
49
50 // Verify that the option to enable the spelling service is hidden when
51 // multilingual spellchecking is enabled.
52 TEST_F('MultilanguageOptionsWebUIBrowserTest', 'HideSpellingServiceCheckbox',
53 function() {
54 assertTrue(loadTimeData.getBoolean('enableMultilingualSpellChecker'));
55 expectTrue($('spelling-enabled-container').hidden);
56 testDone();
57 });
58
59 // Test that only certain languages can be selected and used for spellchecking.
60 // prefs::kLanguagePreferredLanguages/prefs::kAcceptLanguages is set to
61 // "fr,es,de,en" for the test.
62 TEST_F('MultilanguageOptionsWebUIBrowserTest', 'ChangeSpellcheckLanguages',
63 function() {
64 var langOpts = LanguageOptions.getInstance();
65 var langs = Object.keys(langOpts.spellCheckLanguages_);
66
67 // Make sure 'es' exists in the language list and is unchecked.
68 expectTrue($('language-options-list').selectLanguageByCode('es'));
69 LanguageOptions.updateSpellCheckLanguageControls('es');
70 expectFalse($('spellcheck-language-checkbox').checked, 'es');
71
72 // Click 'es' and ensure that its checkbox gets checked.
73 $('spellcheck-language-checkbox').click();
74 expectTrue($('spellcheck-language-checkbox').checked, 'es');
75
76 // Make sure 'fr' stays checked.
77 $('language-options-list').selectLanguageByCode('fr');
78 LanguageOptions.updateSpellCheckLanguageControls('fr');
79 expectTrue($('spellcheck-language-checkbox').checked);
80
81 // Make sure 'fr' and 'es' are the only two languages being spellchecked with.
82 langs = Object.keys(langOpts.spellCheckLanguages_);
83 expectEquals(2, langs.length);
84 expectEquals('fr', langs[0]);
85 expectEquals('es', langs[1]);
86
87 // Make sure 'fr' exists in the language list and is checked.
88 expectTrue($('language-options-list').selectLanguageByCode('fr'));
89 LanguageOptions.updateSpellCheckLanguageControls('fr');
90 expectTrue($('spellcheck-language-checkbox').checked);
91
92 // Click 'fr' and ensure that its checkbox gets unchecked.
93 $('spellcheck-language-checkbox').click();
94 expectFalse($('spellcheck-language-checkbox').checked);
95
96 // Make sure 'es' stays checked.
97 $('language-options-list').selectLanguageByCode('es');
98 LanguageOptions.updateSpellCheckLanguageControls('es');
99 expectTrue($('spellcheck-language-checkbox').checked);
100
101 // Make sure es' is the only language being spellchecked with.
102 langs = Object.keys(langOpts.spellCheckLanguages_);
103 expectEquals(1, langs.length);
104 expectEquals('es', langs[0]);
105 });
106
107 // Make sure 'am' cannot be selected as a language and 'fr' stays selected.
108 TEST_F('MultilanguageOptionsWebUIBrowserTest', 'NotAcceptLanguage',
109 function() {
110 var langOpts = LanguageOptions.getInstance();
111 var langs = Object.keys(langOpts.spellCheckLanguages_);
112
113 // Try to select 'am' from the language list.
114 expectFalse($('language-options-list').selectLanguageByCode('am'));
115
116 // Make sure 'fr' is still the only thing selected.
117 $('language-options-list').selectLanguageByCode('fr');
118 expectTrue($('spellcheck-language-checkbox').checked);
119 expectEquals(1, langs.length);
120 expectEquals('fr', langs[0]);
121 });
122
123 // Make sure 'en' cannot be selected as a language and 'fr' stays selected.
124 TEST_F('MultilanguageOptionsWebUIBrowserTest', 'UnusableLanguage',
125 function() {
126 var langOpts = LanguageOptions.getInstance();
127 var langs = Object.keys(langOpts.spellCheckLanguages_);
128
129 // Try to select 'en' from the language list.
130 expectTrue($('language-options-list').selectLanguageByCode('en'));
131 LanguageOptions.updateSpellCheckLanguageControls('en');
132 expectTrue($('spellcheck-language-checkbox-container').hidden);
133 expectFalse($('spellcheck-language-checkbox').checked);
134
135 // Make sure 'fr' is still the only thing selected.
136 expectEquals(1, langs.length);
137 expectEquals('fr', langs[0]);
138 });
139
Dan Beam 2015/06/25 02:44:27 /** @constructor @extends {...} */ like above
Julius 2015/07/06 22:38:53 Deleted this.
140 function MultilanguagePreferenceWebUIBrowserTest() {}
141
142 /**
143 * Wait for the method specified by |methodName|, on the |object| object, to be
144 * called, then execute |afterFunction|.
145 * @param {*} object Object with callable property named |methodName|.
146 * @param {string} methodName The name of the property on |object| to use as a
147 * callback.
148 * @param {!Function} afterFunction A function to call after object.methodName()
149 * is called.
150 */
151 function waitForResponse(object, methodName, afterFunction) {
152 var originalCallback = object[methodName];
153
154 // Install a wrapper that temporarily replaces the original function.
155 object[methodName] = function() {
156 object[methodName] = originalCallback;
157 originalCallback.apply(this, arguments);
158 afterFunction();
159 };
160 }
Dan Beam 2015/06/25 02:44:28 why is this in the middle of MultilanguagePreferen
Julius 2015/07/06 22:38:53 Deleted this.
161
162 MultilanguagePreferenceWebUIBrowserTest.prototype = {
163 __proto__: testing.Test.prototype,
164
165 /**
166 * Browse to the language options page & call our preLoad().
167 */
168 browsePreload: 'chrome://settings-frame/languages',
169
170 /** @override */
171 typedefCppFixture: 'MultilanguageOptionsWebUIBrowserTest',
172
Dan Beam 2015/06/25 02:44:27 /** @override */
Julius 2015/07/06 22:38:53 Done.
173 testGenPreamble: function() {
174 GEN('SetBlankDictionariesPref();');
175 },
176
177 /** @override */
178 accessibilityIssuesAreErrors: true,
179
180 isAsync: true,
181
182 /** @override */
183 setUp: function() {
184 testing.Test.prototype.setUp.call(this);
185
186 assertTrue(loadTimeData.getBoolean('enableMultilingualSpellChecker'));
187 assertFalse(cr.isMac);
188 expectTrue($('spellcheck-language-button').hidden);
Dan Beam 2015/06/25 02:44:27 this class looks pretty similar to MultilanguageOp
Julius 2015/07/06 22:38:54 Done.
189
190 // Make sure no language is currently selected.
191 var langOpts = LanguageOptions.getInstance();
192 var langs = Object.keys(langOpts.spellCheckLanguages_);
193 var regPrefs = options.Preferences.getInstance().registeredPreferences_;
194 expectEquals(0, langs.length);
195 expectEquals('', regPrefs['spellcheck.dictionaries'].orig.value);
196 },
197 };
198
199 // Make sure the case where no languages are selected is handled properly.
200 TEST_F('MultilanguagePreferenceWebUIBrowserTest', 'BlankSpellcheckLanguges',
201 function() {
202 var langOpts = LanguageOptions.getInstance();
203 var langs = Object.keys(langOpts.spellCheckLanguages_);
204 var regPrefs = options.Preferences.getInstance().registeredPreferences_;
205
206 // We are starting with a blank preference.
207 expectEquals(0, langs.length);
208 expectEquals('', regPrefs['spellcheck.dictionaries'].orig.value);
209
210 // Make sure 'fr' is not already checked.
211 expectTrue($('language-options-list').selectLanguageByCode('fr'));
212 LanguageOptions.updateSpellCheckLanguageControls('fr');
213 expectFalse($('spellcheck-language-checkbox').checked);
214
215 // Click 'fr' and ensure that the preference is updated correctly and that
216 // 'fr' is the only thing in the dictionary object.
217 $('spellcheck-language-checkbox').click();
218 waitForResponse(langOpts, 'updateSpellCheckLanguageControls_',
Dan Beam 2015/06/25 02:44:28 I don't suppose you could just do: options.Pref
Julius 2015/07/06 22:38:53 Done.
219 function() {
220 expectTrue($('spellcheck-language-checkbox').checked);
221 expectEquals('fr', regPrefs['spellcheck.dictionaries'].orig.value);
222
223 langs = Object.keys(langOpts.spellCheckLanguages_);
224 expectEquals(1, langs.length);
225 expectEquals('fr', langs[0]);
226 testDone();
227 });
228 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698