Index: chrome/browser/ui/webui/options/multilanguage_options_webui_browsertest.js |
diff --git a/chrome/browser/ui/webui/options/multilanguage_options_webui_browsertest.js b/chrome/browser/ui/webui/options/multilanguage_options_webui_browsertest.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f7c3cc35ba29f080088fa3784ff31e5916813d2c |
--- /dev/null |
+++ b/chrome/browser/ui/webui/options/multilanguage_options_webui_browsertest.js |
@@ -0,0 +1,228 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+GEN('#include "chrome/browser/ui/webui/options/multilanguage_options_webui_browsertest.h"'); |
+ |
+/** |
+ * Test C++ fixture for Language Options WebUI testing. |
+ * @constructor |
+ * @extends {testing.Test} |
+ */ |
+function MultilanguageOptionsWebUIBrowserTest() {} |
+ |
+MultilanguageOptionsWebUIBrowserTest.prototype = { |
+ __proto__: testing.Test.prototype, |
+ |
+ /** |
+ * 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.
|
+ */ |
+ browsePreload: 'chrome://settings-frame/languages', |
+ |
+ /** @override */ |
+ typedefCppFixture: 'MultilanguageOptionsWebUIBrowserTest', |
+ |
+ /** @override */ |
+ 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.
|
+ |
+ /** @override */ |
+ setUp: function() { |
+ testing.Test.prototype.setUp.call(this); |
+ |
+ assertTrue(loadTimeData.getBoolean('enableMultilingualSpellChecker')); |
+ assertFalse(cr.isMac); |
+ expectTrue($('spellcheck-language-button').hidden); |
+ |
+ // Make sure the only language currently selected is 'fr'. |
+ var langOpts = LanguageOptions.getInstance(); |
+ 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.
|
+ expectEquals(1, langs.length); |
+ expectEquals('fr', langs[0]); |
+ }, |
+}; |
+ |
+// Test opening language options has correct location. |
+TEST_F('MultilanguageOptionsWebUIBrowserTest', 'TestOpenLanguageOptions', |
+ function() { |
+ expectEquals('chrome://settings-frame/languages', document.location.href); |
+}); |
+ |
+// Verify that the option to enable the spelling service is hidden when |
+// multilingual spellchecking is enabled. |
+TEST_F('MultilanguageOptionsWebUIBrowserTest', 'HideSpellingServiceCheckbox', |
+ function() { |
+ assertTrue(loadTimeData.getBoolean('enableMultilingualSpellChecker')); |
+ expectTrue($('spelling-enabled-container').hidden); |
+ testDone(); |
+}); |
+ |
+// Test that only certain languages can be selected and used for spellchecking. |
+// prefs::kLanguagePreferredLanguages/prefs::kAcceptLanguages is set to |
+// "fr,es,de,en" for the test. |
+TEST_F('MultilanguageOptionsWebUIBrowserTest', 'ChangeSpellcheckLanguages', |
+ function() { |
+ var langOpts = LanguageOptions.getInstance(); |
+ var langs = Object.keys(langOpts.spellCheckLanguages_); |
+ |
+ // Make sure 'es' exists in the language list and is unchecked. |
+ expectTrue($('language-options-list').selectLanguageByCode('es')); |
+ LanguageOptions.updateSpellCheckLanguageControls('es'); |
+ expectFalse($('spellcheck-language-checkbox').checked, 'es'); |
+ |
+ // Click 'es' and ensure that its checkbox gets checked. |
+ $('spellcheck-language-checkbox').click(); |
+ expectTrue($('spellcheck-language-checkbox').checked, 'es'); |
+ |
+ // Make sure 'fr' stays checked. |
+ $('language-options-list').selectLanguageByCode('fr'); |
+ LanguageOptions.updateSpellCheckLanguageControls('fr'); |
+ expectTrue($('spellcheck-language-checkbox').checked); |
+ |
+ // Make sure 'fr' and 'es' are the only two languages being spellchecked with. |
+ langs = Object.keys(langOpts.spellCheckLanguages_); |
+ expectEquals(2, langs.length); |
+ expectEquals('fr', langs[0]); |
+ expectEquals('es', langs[1]); |
+ |
+ // Make sure 'fr' exists in the language list and is checked. |
+ expectTrue($('language-options-list').selectLanguageByCode('fr')); |
+ LanguageOptions.updateSpellCheckLanguageControls('fr'); |
+ expectTrue($('spellcheck-language-checkbox').checked); |
+ |
+ // Click 'fr' and ensure that its checkbox gets unchecked. |
+ $('spellcheck-language-checkbox').click(); |
+ expectFalse($('spellcheck-language-checkbox').checked); |
+ |
+ // Make sure 'es' stays checked. |
+ $('language-options-list').selectLanguageByCode('es'); |
+ LanguageOptions.updateSpellCheckLanguageControls('es'); |
+ expectTrue($('spellcheck-language-checkbox').checked); |
+ |
+ // Make sure es' is the only language being spellchecked with. |
+ langs = Object.keys(langOpts.spellCheckLanguages_); |
+ expectEquals(1, langs.length); |
+ expectEquals('es', langs[0]); |
+}); |
+ |
+// Make sure 'am' cannot be selected as a language and 'fr' stays selected. |
+TEST_F('MultilanguageOptionsWebUIBrowserTest', 'NotAcceptLanguage', |
+ function() { |
+ var langOpts = LanguageOptions.getInstance(); |
+ var langs = Object.keys(langOpts.spellCheckLanguages_); |
+ |
+ // Try to select 'am' from the language list. |
+ expectFalse($('language-options-list').selectLanguageByCode('am')); |
+ |
+ // Make sure 'fr' is still the only thing selected. |
+ $('language-options-list').selectLanguageByCode('fr'); |
+ expectTrue($('spellcheck-language-checkbox').checked); |
+ expectEquals(1, langs.length); |
+ expectEquals('fr', langs[0]); |
+}); |
+ |
+// Make sure 'en' cannot be selected as a language and 'fr' stays selected. |
+TEST_F('MultilanguageOptionsWebUIBrowserTest', 'UnusableLanguage', |
+ function() { |
+ var langOpts = LanguageOptions.getInstance(); |
+ var langs = Object.keys(langOpts.spellCheckLanguages_); |
+ |
+ // Try to select 'en' from the language list. |
+ expectTrue($('language-options-list').selectLanguageByCode('en')); |
+ LanguageOptions.updateSpellCheckLanguageControls('en'); |
+ expectTrue($('spellcheck-language-checkbox-container').hidden); |
+ expectFalse($('spellcheck-language-checkbox').checked); |
+ |
+ // Make sure 'fr' is still the only thing selected. |
+ expectEquals(1, langs.length); |
+ expectEquals('fr', langs[0]); |
+}); |
+ |
Dan Beam
2015/06/25 02:44:27
/** @constructor @extends {...} */ like above
Julius
2015/07/06 22:38:53
Deleted this.
|
+function MultilanguagePreferenceWebUIBrowserTest() {} |
+ |
+/** |
+ * Wait for the method specified by |methodName|, on the |object| object, to be |
+ * called, then execute |afterFunction|. |
+ * @param {*} object Object with callable property named |methodName|. |
+ * @param {string} methodName The name of the property on |object| to use as a |
+ * callback. |
+ * @param {!Function} afterFunction A function to call after object.methodName() |
+ * is called. |
+ */ |
+function waitForResponse(object, methodName, afterFunction) { |
+ var originalCallback = object[methodName]; |
+ |
+ // Install a wrapper that temporarily replaces the original function. |
+ object[methodName] = function() { |
+ object[methodName] = originalCallback; |
+ originalCallback.apply(this, arguments); |
+ afterFunction(); |
+ }; |
+} |
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.
|
+ |
+MultilanguagePreferenceWebUIBrowserTest.prototype = { |
+ __proto__: testing.Test.prototype, |
+ |
+ /** |
+ * Browse to the language options page & call our preLoad(). |
+ */ |
+ browsePreload: 'chrome://settings-frame/languages', |
+ |
+ /** @override */ |
+ typedefCppFixture: 'MultilanguageOptionsWebUIBrowserTest', |
+ |
Dan Beam
2015/06/25 02:44:27
/** @override */
Julius
2015/07/06 22:38:53
Done.
|
+ testGenPreamble: function() { |
+ GEN('SetBlankDictionariesPref();'); |
+ }, |
+ |
+ /** @override */ |
+ accessibilityIssuesAreErrors: true, |
+ |
+ isAsync: true, |
+ |
+ /** @override */ |
+ setUp: function() { |
+ testing.Test.prototype.setUp.call(this); |
+ |
+ assertTrue(loadTimeData.getBoolean('enableMultilingualSpellChecker')); |
+ assertFalse(cr.isMac); |
+ 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.
|
+ |
+ // Make sure no language is currently selected. |
+ var langOpts = LanguageOptions.getInstance(); |
+ var langs = Object.keys(langOpts.spellCheckLanguages_); |
+ var regPrefs = options.Preferences.getInstance().registeredPreferences_; |
+ expectEquals(0, langs.length); |
+ expectEquals('', regPrefs['spellcheck.dictionaries'].orig.value); |
+ }, |
+}; |
+ |
+// Make sure the case where no languages are selected is handled properly. |
+TEST_F('MultilanguagePreferenceWebUIBrowserTest', 'BlankSpellcheckLanguges', |
+ function() { |
+ var langOpts = LanguageOptions.getInstance(); |
+ var langs = Object.keys(langOpts.spellCheckLanguages_); |
+ var regPrefs = options.Preferences.getInstance().registeredPreferences_; |
+ |
+ // We are starting with a blank preference. |
+ expectEquals(0, langs.length); |
+ expectEquals('', regPrefs['spellcheck.dictionaries'].orig.value); |
+ |
+ // Make sure 'fr' is not already checked. |
+ expectTrue($('language-options-list').selectLanguageByCode('fr')); |
+ LanguageOptions.updateSpellCheckLanguageControls('fr'); |
+ expectFalse($('spellcheck-language-checkbox').checked); |
+ |
+ // Click 'fr' and ensure that the preference is updated correctly and that |
+ // 'fr' is the only thing in the dictionary object. |
+ $('spellcheck-language-checkbox').click(); |
+ 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.
|
+ function() { |
+ expectTrue($('spellcheck-language-checkbox').checked); |
+ expectEquals('fr', regPrefs['spellcheck.dictionaries'].orig.value); |
+ |
+ langs = Object.keys(langOpts.spellCheckLanguages_); |
+ expectEquals(1, langs.length); |
+ expectEquals('fr', langs[0]); |
+ testDone(); |
+ }); |
+}); |