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.
5 GEN('#include "chrome/browser/ui/webui/options/' +
6 'multilanguage_options_browsertest.h"');
9 * Test C++ fixture for Language Options WebUI testing.
11 * @extends {testing.Test}
13 function MultilanguageOptionsWebUIBrowserTest() {}
15 MultilanguageOptionsWebUIBrowserTest.prototype = {
16 __proto__: testing.Test.prototype,
19 browsePreload: 'chrome://settings-frame/languages',
22 typedefCppFixture: 'MultilanguageOptionsBrowserTest',
25 accessibilityIssuesAreErrors: true,
27 /** @param {string} expected Sorted currently selected languages. */
28 expectCurrentlySelected: function(expected) {
29 var languages = LanguageOptions.getInstance().spellCheckLanguages_;
30 expectEquals(expected, Object.keys(languages).sort().join());
35 testing.Test.prototype.setUp.call(this);
37 assertTrue(loadTimeData.getBoolean('enableMultilingualSpellChecker'));
38 assertFalse(cr.isMac);
39 expectTrue($('spellcheck-language-button').hidden);
40 expectFalse($('edit-custom-dictionary-button').hidden);
41 this.expectEnableSpellcheckCheckboxHidden();
42 this.expectCurrentlySelected('fr');
46 tearDown: function() {
47 testing.Test.prototype.tearDown.call(this);
48 this.expectEnableSpellcheckCheckboxHidden();
51 /** Make sure the 'Enable spell checking' checkbox is not visible. */
52 expectEnableSpellcheckCheckboxHidden: function() {
53 if ($('enable-spellcheck-container'))
54 expectTrue($('enable-spellcheck-container').hidden);
58 // Test that opening language options has the correct location.
59 TEST_F('MultilanguageOptionsWebUIBrowserTest', 'TestOpenLanguageOptions',
61 expectEquals('chrome://settings-frame/languages', document.location.href);
64 // Test that only certain languages can be selected and used for spellchecking.
65 // prefs::kLanguagePreferredLanguages/prefs::kAcceptLanguages is set to
66 // 'fr,es,de,en' and prefs::kSpellCheckDictionaries is just 'fr'
67 TEST_F('MultilanguageOptionsWebUIBrowserTest', 'ChangeSpellcheckLanguages',
69 expectTrue($('language-options-list').selectLanguageByCode('es'));
70 expectFalse($('spellcheck-language-checkbox').checked, 'es');
72 // Click 'es' and ensure that it gets checked and 'fr' stays checked.
73 $('spellcheck-language-checkbox').click();
74 expectTrue($('spellcheck-language-checkbox').checked, 'es');
75 expectTrue($('language-options-list').selectLanguageByCode('fr'));
76 expectTrue($('spellcheck-language-checkbox').checked, 'fr');
77 this.expectCurrentlySelected('es,fr');
79 // Click 'fr' and ensure that it gets unchecked and 'es' stays checked.
80 $('spellcheck-language-checkbox').click();
81 expectFalse($('spellcheck-language-checkbox').checked, 'fr');
82 $('language-options-list').selectLanguageByCode('es');
83 expectTrue($('spellcheck-language-checkbox').checked, 'es');
84 this.expectCurrentlySelected('es');
87 // Make sure 'am' cannot be selected as a language and 'fr' stays selected.
88 TEST_F('MultilanguageOptionsWebUIBrowserTest', 'NotAcceptLanguage', function() {
89 expectFalse($('language-options-list').selectLanguageByCode('am'));
90 expectTrue($('language-options-list').selectLanguageByCode('fr'));
91 expectTrue($('spellcheck-language-checkbox').checked, 'fr');
92 this.expectCurrentlySelected('fr');
95 // Make sure 'en' cannot be used as a language and 'fr' stays selected.
96 TEST_F('MultilanguageOptionsWebUIBrowserTest', 'UnusableLanguage', function() {
97 expectTrue($('language-options-list').selectLanguageByCode('en'));
98 expectTrue($('spellcheck-language-checkbox-container').hidden);
99 expectFalse($('spellcheck-language-checkbox').checked, 'en');
100 this.expectCurrentlySelected('fr');
104 * Test C++ fixture for Language Options WebUI testing.
106 * @extends {MultilanguageOptionsWebUIBrowserTest}
108 function MultilanguagePreferenceWebUIBrowserTest() {}
110 MultilanguagePreferenceWebUIBrowserTest.prototype = {
111 __proto__: MultilanguageOptionsWebUIBrowserTest.prototype,
114 testGenPreamble: function() {
115 GEN('ClearSpellcheckDictionaries();');
122 * @param {string} expected Sorted languages in the kSpellCheckDictionaries
125 expectRegisteredDictionariesPref: function(expected) {
126 var registeredPrefs =
127 options.Preferences.getInstance().registeredPreferences_;
128 expectEquals(expected,
129 registeredPrefs['spellcheck.dictionaries'].orig.value.sort().join());
133 * Watch for a change to the preference |pref| and then call |callback|.
134 * @param {string} pref The preference to listen for a change on.
135 * @param {function} callback The function to run after a listener event.
137 addPreferenceListener: function(pref, callback) {
138 options.Preferences.getInstance().addEventListener(pref, callback);
143 testing.Test.prototype.setUp.call(this);
145 assertTrue(loadTimeData.getBoolean('enableMultilingualSpellChecker'));
146 assertFalse(cr.isMac);
147 expectTrue($('spellcheck-language-button').hidden);
148 expectTrue($('edit-custom-dictionary-button').hidden);
149 this.expectEnableSpellcheckCheckboxHidden();
150 this.expectCurrentlySelected('');
151 this.expectRegisteredDictionariesPref('');
155 // Make sure the case where no languages are selected is handled properly.
156 TEST_F('MultilanguagePreferenceWebUIBrowserTest', 'SelectFromBlank',
158 expectTrue($('language-options-list').selectLanguageByCode('fr'));
159 expectFalse($('spellcheck-language-checkbox').checked, 'fr');
160 expectTrue($('edit-custom-dictionary-button').hidden);
162 // Add a preference change event listener which ensures that the preference is
163 // updated correctly and that 'fr' is the only thing in the dictionary object.
164 this.addPreferenceListener('spellcheck.dictionaries', function() {
165 expectTrue($('spellcheck-language-checkbox').checked, 'fr');
166 this.expectRegisteredDictionariesPref('fr');
167 this.expectCurrentlySelected('fr');
168 expectFalse($('edit-custom-dictionary-button').hidden);
172 // Click 'fr' and trigger the preference listener.
173 $('spellcheck-language-checkbox').click();