Commit b09ad1be authored by rbpotter's avatar rbpotter Committed by Commit Bot

Settings: Remove global settings.languageSettingsPrivateApiForTest

In Polymer 3/JS modules, there is no settings global namespace and
undefined variables cause an error, so the edit dictionary page cannot
simply check the global settings.languageSettingsPrivateApiForTest.
Instead, use the LanguagesBrowserProxy in the edit dictionary page to
get languageSettingsPrivate, and add a way to set this value in the
TestLanguagesBrowserProxy so that it can be overridden for tests.

Bug: 1026426
Change-Id: I8aa69ac6a3272b74195ca6bb9c1b41ad0b3bdd77
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2076787
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745250}
parent 6304eb38
...@@ -17,6 +17,7 @@ js_type_check("closure_compile") { ...@@ -17,6 +17,7 @@ js_type_check("closure_compile") {
js_library("edit_dictionary_page") { js_library("edit_dictionary_page") {
deps = [ deps = [
":languages_browser_proxy",
"..:global_scroll_target_behavior", "..:global_scroll_target_behavior",
"..:route", "..:route",
"../prefs", "../prefs",
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
<link rel="import" href="../route.html"> <link rel="import" href="../route.html">
<link rel="import" href="../settings_shared_css.html"> <link rel="import" href="../settings_shared_css.html">
<link rel="import" href="../settings_vars_css.html"> <link rel="import" href="../settings_vars_css.html">
<link rel="import" href="./languages_browser_proxy.html">
<dom-module id="settings-edit-dictionary-page"> <dom-module id="settings-edit-dictionary-page">
<template> <template>
......
...@@ -47,21 +47,21 @@ Polymer({ ...@@ -47,21 +47,21 @@ Polymer({
}, },
}, },
/** @type {LanguageSettingsPrivate} */ /** @private {LanguageSettingsPrivate} */
languageSettingsPrivate: null, languageSettingsPrivate_: null,
/** @override */ /** @override */
ready() { ready() {
this.languageSettingsPrivate = settings.languageSettingsPrivateApiForTest || this.languageSettingsPrivate_ =
/** @type {!LanguageSettingsPrivate} */ settings.LanguagesBrowserProxyImpl.getInstance()
(chrome.languageSettingsPrivate); .getLanguageSettingsPrivate();
this.languageSettingsPrivate.getSpellcheckWords(words => { this.languageSettingsPrivate_.getSpellcheckWords(words => {
this.hasWords_ = words.length > 0; this.hasWords_ = words.length > 0;
this.words_ = words; this.words_ = words;
}); });
this.languageSettingsPrivate.onCustomDictionaryChanged.addListener( this.languageSettingsPrivate_.onCustomDictionaryChanged.addListener(
this.onCustomDictionaryChanged_.bind(this)); this.onCustomDictionaryChanged_.bind(this));
// Add a key handler for the new-word input. // Add a key handler for the new-word input.
...@@ -77,7 +77,7 @@ Polymer({ ...@@ -77,7 +77,7 @@ Polymer({
const word = this.getTrimmedNewWord_(); const word = this.getTrimmedNewWord_();
this.newWordValue_ = ''; this.newWordValue_ = '';
if (word) { if (word) {
this.languageSettingsPrivate.addSpellcheckWord(word); this.languageSettingsPrivate_.addSpellcheckWord(word);
} }
}, },
...@@ -204,6 +204,6 @@ Polymer({ ...@@ -204,6 +204,6 @@ Polymer({
* @param {!{model: !{item: string}}} e * @param {!{model: !{item: string}}} e
*/ */
onRemoveWordTap_(e) { onRemoveWordTap_(e) {
this.languageSettingsPrivate.removeSpellcheckWord(e.model.item); this.languageSettingsPrivate_.removeSpellcheckWord(e.model.item);
}, },
}); });
...@@ -1669,8 +1669,10 @@ CrSettingsEditDictionaryPageTest.prototype = { ...@@ -1669,8 +1669,10 @@ CrSettingsEditDictionaryPageTest.prototype = {
extraLibraries: CrSettingsBrowserTest.prototype.extraLibraries.concat([ extraLibraries: CrSettingsBrowserTest.prototype.extraLibraries.concat([
'../fake_chrome_event.js', '../fake_chrome_event.js',
'fake_settings_private.js', 'fake_settings_private.js',
'chromeos/fake_input_method_private.js',
'../test_browser_proxy.js', '../test_browser_proxy.js',
'fake_language_settings_private.js', 'fake_language_settings_private.js',
'test_languages_browser_proxy.js',
'edit_dictionary_page_test.js', 'edit_dictionary_page_test.js',
]), ]),
}; };
......
...@@ -66,7 +66,9 @@ suite('settings-edit-dictionary-page', function() { ...@@ -66,7 +66,9 @@ suite('settings-edit-dictionary-page', function() {
languageSettingsPrivate = new settings.FakeLanguageSettingsPrivate(); languageSettingsPrivate = new settings.FakeLanguageSettingsPrivate();
languageSettingsPrivate.setSettingsPrefs(settingsPrefs); languageSettingsPrivate.setSettingsPrefs(settingsPrefs);
settings.languageSettingsPrivateApiForTest = languageSettingsPrivate; const browserProxy = new settings.TestLanguagesBrowserProxy();
settings.LanguagesBrowserProxyImpl.instance_ = browserProxy;
browserProxy.setLanguageSettingsPrivate(languageSettingsPrivate);
editDictPage = document.createElement('settings-edit-dictionary-page'); editDictPage = document.createElement('settings-edit-dictionary-page');
......
...@@ -30,6 +30,11 @@ cr.define('settings', function() { ...@@ -30,6 +30,11 @@ cr.define('settings', function() {
getInputMethodPrivate() { getInputMethodPrivate() {
return this.inputMethodPrivate_; return this.inputMethodPrivate_;
} }
/** @param {!LanguageSettingsPrivate} languageSettingsPrivate */
setLanguageSettingsPrivate(languageSettingsPrivate) {
this.languageSettingsPrivate_ = languageSettingsPrivate;
}
} }
if (cr.isChromeOS || cr.isWindows) { if (cr.isChromeOS || cr.isWindows) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment