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

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 some clarity issues. 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 /** @override */
18 browsePreload: 'chrome://settings-frame/languages',
19
20 /** @override */
21 typedefCppFixture: 'MultilanguageOptionsWebUIBrowserTest',
Dan Beam 2015/07/08 23:41:36 the C++ and JS class should not be the same name
Julius 2015/07/09 03:54:51 Done.
22
23 /** @override */
24 accessibilityIssuesAreErrors: true,
25
26 /** @param {string} Sorted, expected currently selected languages. */
27 expectCurrentlySelected: function(expected) {
28 var languages = LanguageOptions.getInstance().spellCheckLanguages_;
29 expectEquals(expected, Object.keys(languages).sort().join());
30 },
31
32 /** @override */
33 setUp: function() {
34 testing.Test.prototype.setUp.call(this);
35
36 assertTrue(loadTimeData.getBoolean('enableMultilingualSpellChecker'));
37 assertFalse(cr.isMac);
38 expectTrue($('spellcheck-language-button').hidden);
39
40 // Make sure the only language currently selected is 'fr'.
41 this.expectCurrentlySelected('fr');
42 },
43 };
44
45 // Test opening language options has correct location.
46 TEST_F('MultilanguageOptionsWebUIBrowserTest', 'TestOpenLanguageOptions',
47 function() {
48 expectEquals('chrome://settings-frame/languages', document.location.href);
49 });
50
51 // Verify that the option to enable the spelling service is hidden when
52 // multilingual spellchecking is enabled.
53 TEST_F('MultilanguageOptionsWebUIBrowserTest', 'HideSpellingServiceCheckbox',
54 function() {
55 assertTrue(loadTimeData.getBoolean('enableMultilingualSpellChecker'));
56 expectTrue($('spelling-enabled-container').hidden);
57 testDone();
58 });
59
60 // Test that only certain languages can be selected and used for spellchecking.
61 // prefs::kLanguagePreferredLanguages/prefs::kAcceptLanguages is set to
62 // "fr,es,de,en" for the test.
63 TEST_F('MultilanguageOptionsWebUIBrowserTest', 'ChangeSpellcheckLanguages',
64 function() {
65 // Make sure 'es' exists in the language list and is unchecked.
66 expectTrue($('language-options-list').selectLanguageByCode('es'));
67 LanguageOptions.updateSpellCheckLanguageControls('es');
68 expectFalse($('spellcheck-language-checkbox').checked, 'es');
69
70 // Click 'es' and ensure that its checkbox gets checked.
71 $('spellcheck-language-checkbox').click();
72 expectTrue($('spellcheck-language-checkbox').checked, 'es');
73
74 // Make sure 'fr' stays checked.
75 $('language-options-list').selectLanguageByCode('fr');
76 LanguageOptions.updateSpellCheckLanguageControls('fr');
77 expectTrue($('spellcheck-language-checkbox').checked);
78
79 // Make sure 'fr' and 'es' are the only two languages being spellchecked with.
Dan Beam 2015/07/08 23:41:37 don't think these comments are necessary any longe
Julius 2015/07/09 03:54:51 Done, and I tried to consolidate and trim other un
80 this.expectCurrentlySelected('es,fr');
81
82 // Make sure 'fr' exists in the language list and is checked.
83 expectTrue($('language-options-list').selectLanguageByCode('fr'));
84 LanguageOptions.updateSpellCheckLanguageControls('fr');
85 expectTrue($('spellcheck-language-checkbox').checked);
86
87 // Click 'fr' and ensure that its checkbox gets unchecked.
88 $('spellcheck-language-checkbox').click();
89 expectFalse($('spellcheck-language-checkbox').checked);
90
91 // Make sure 'es' stays checked.
92 $('language-options-list').selectLanguageByCode('es');
93 LanguageOptions.updateSpellCheckLanguageControls('es');
94 expectTrue($('spellcheck-language-checkbox').checked);
95
96 // Make sure 'es' is the only language being spellchecked with.
97 this.expectCurrentlySelected('es');
98 });
99
100 // Make sure 'am' cannot be selected as a language and 'fr' stays selected.
101 TEST_F('MultilanguageOptionsWebUIBrowserTest', 'NotAcceptLanguage',
102 function() {
103 // Try to select 'am' from the language list.
104 expectFalse($('language-options-list').selectLanguageByCode('am'));
105
106 // Make sure 'fr' is still the only thing selected.
107 $('language-options-list').selectLanguageByCode('fr');
108 expectTrue($('spellcheck-language-checkbox').checked);
109 this.expectCurrentlySelected('fr');
110 });
111
112 // Make sure 'en' cannot be selected as a language and 'fr' stays selected.
113 TEST_F('MultilanguageOptionsWebUIBrowserTest', 'UnusableLanguage',
114 function() {
115 // Try to select 'en' from the language list.
116 expectTrue($('language-options-list').selectLanguageByCode('en'));
117 LanguageOptions.updateSpellCheckLanguageControls('en');
118 expectTrue($('spellcheck-language-checkbox-container').hidden);
119 expectFalse($('spellcheck-language-checkbox').checked);
120
121 // Make sure 'fr' is still the only thing selected.
122 this.expectCurrentlySelected('fr');
123 });
124
125 function MultilanguagePreferenceWebUIBrowserTest() {}
126
127 /**
128 * Test C++ fixture for Language Options WebUI testing.
129 * @constructor
130 * @extends {MultilanguageOptionsWebUIBrowserTest}
131 */
132 MultilanguagePreferenceWebUIBrowserTest.prototype = {
133 __proto__: MultilanguageOptionsWebUIBrowserTest.prototype,
134
135 /** @override */
136 typedefCppFixture: 'MultilanguageOptionsWebUIBrowserTest',
137
138 /** @override */
139 testGenPreamble: function() {
140 GEN('SetBlankDictionariesPref();');
141 },
142
143 isAsync: true,
144
145 /** @override */
146 setUp: function() {
147 testing.Test.prototype.setUp.call(this);
148
149 assertTrue(loadTimeData.getBoolean('enableMultilingualSpellChecker'));
150 assertFalse(cr.isMac);
151 expectTrue($('spellcheck-language-button').hidden);
152
153 // Make sure we're starting with a blank preference.
154 this.expectCurrentlySelected('');
155 var registeredPrefs =
156 options.Preferences.getInstance().registeredPreferences_;
157 expectEquals(0,
158 registeredPrefs['spellcheck.dictionaries'].orig.value.length);
Dan Beam 2015/07/08 23:41:36 combine this and the code at L177
Julius 2015/07/09 03:54:52 Done.
159 },
160 };
161
162 // Make sure the case where no languages are selected is handled properly.
163 TEST_F('MultilanguagePreferenceWebUIBrowserTest', 'BlankSpellcheckLanguges',
164 function() {
165 // Make sure 'fr' is not already checked.
166 expectTrue($('language-options-list').selectLanguageByCode('fr'));
167 LanguageOptions.updateSpellCheckLanguageControls('fr');
168 expectFalse($('spellcheck-language-checkbox').checked);
169
170 // Add a preference change event listener which ensures that the preference is
171 // updated correctly and that 'fr' is the only thing in the dictionary object.
172 options.Preferences.getInstance().addEventListener('spellcheck.dictionaries',
Dan Beam 2015/07/08 23:41:36 var prefs = options.Preferences.getInstance(); pre
Julius 2015/07/09 03:54:52 Done. Even though this is the only places prefs is
173 function() {
174 expectTrue($('spellcheck-language-checkbox').checked);
175
176 var registeredPrefs =
177 options.Preferences.getInstance().registeredPreferences_;
178 expectEquals(1,
179 registeredPrefs['spellcheck.dictionaries'].orig.value.length);
Dan Beam 2015/07/08 23:41:37 var registerPrefs = prefs.registeredPreferences_;
Julius 2015/07/09 03:54:52 Done.
180 expectEquals('fr',
181 registeredPrefs['spellcheck.dictionaries'].orig.value[0]);
182 MultilanguagePreferenceWebUIBrowserTest.prototype.expectCurrentlySelected(
183 'fr');
Dan Beam 2015/07/08 23:41:36 after you bind(), this should work: this.expect
Julius 2015/07/09 03:54:52 Done.
184 testDone();
185 });
Dan Beam 2015/07/08 23:41:36 }.bind(this));
Julius 2015/07/09 03:54:51 Done.
186
187 // Click 'fr' and trigger the previously registered event listener.
188 $('spellcheck-language-checkbox').click();
189
Dan Beam 2015/07/08 23:41:37 remove \n
Julius 2015/07/09 03:54:52 Done.
190 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698