Chromium Code Reviews| Index: chrome/browser/resources/settings/prefs/prefs.js |
| diff --git a/chrome/browser/resources/settings/prefs/prefs.js b/chrome/browser/resources/settings/prefs/prefs.js |
| index 98c82f78b5c4543a20fc1dd601e5bfabe98b010c..51b6163cc4a5137650488bf8330803692efbcb14 100644 |
| --- a/chrome/browser/resources/settings/prefs/prefs.js |
| +++ b/chrome/browser/resources/settings/prefs/prefs.js |
| @@ -107,13 +107,19 @@ function ListPrefWrapper(prefObj) { |
| 'prefsChanged_(prefs.*)', |
| ], |
| + settingsApi_: chrome.settingsPrivate, |
| + |
| /** @override */ |
| created: function() { |
| + // Set window.mockApi to pass a custom settings API, i.e. for tests. |
| + // TODO(michaelpg): don't use a global. |
| + if (window.mockApi) |
| + this.settingsApi_ = window.mockApi; |
| CrSettingsPrefs.isInitialized = false; |
| - chrome.settingsPrivate.onPrefsChanged.addListener( |
| + this.settingsApi_.onPrefsChanged.addListener( |
| this.onSettingsPrivatePrefsChanged_.bind(this)); |
| - chrome.settingsPrivate.getAllPrefs( |
| + this.settingsApi_.getAllPrefs( |
| this.onSettingsPrivatePrefsFetched_.bind(this)); |
| }, |
| @@ -127,6 +133,9 @@ function ListPrefWrapper(prefObj) { |
| return; |
| var key = this.getPrefKeyFromPath_(change.path); |
| + if (!key) |
|
stevenjb
2015/09/11 21:03:47
Should this normally happen? If not, maybe log an
michaelpg
2015/09/13 03:01:05
I can't recall why or when this may happen. It's p
|
| + return; |
| + |
| var prefWrapper = this.prefWrappers_[key]; |
| if (!prefWrapper) |
| return; |
| @@ -140,7 +149,7 @@ function ListPrefWrapper(prefObj) { |
| if (prefWrapper.equals(this.createPrefWrapper_(prefObj))) |
| return; |
| - chrome.settingsPrivate.setPref( |
| + this.settingsApi_.setPref( |
| key, |
| prefObj.value, |
| /* pageId */ '', |
| @@ -182,7 +191,7 @@ function ListPrefWrapper(prefObj) { |
| // Get the current pref value from chrome.settingsPrivate to ensure the |
| // UI stays up to date. |
| - chrome.settingsPrivate.getPref(key, function(pref) { |
| + this.settingsApi_.getPref(key, function(pref) { |
| this.updatePrefs_([pref]); |
| }.bind(this)); |
| }, |
| @@ -229,24 +238,18 @@ function ListPrefWrapper(prefObj) { |
| }, |
| /** |
| - * Sets or updates the pref denoted by newPrefObj.key in the publicy exposed |
| - * |prefs| property. |
| + * Sets or updates the pref denoted by newPrefObj.key in the publicly |
| + * exposed |prefs| property. |
| * @param {chrome.settingsPrivate.PrefObject} newPrefObj The pref object to |
| * update the pref with. |
| * @private |
| */ |
| setPref_: function(newPrefObj) { |
| - // Check if the pref exists already in the Polymer |prefs| object. |
| - if (this.get(newPrefObj.key, this.prefs)) { |
| - // Update just the value, notifying listeners of the change. |
| - this.set('prefs.' + newPrefObj.key + '.value', newPrefObj.value); |
| - } else { |
| - // Add the pref to |prefs|. cr.exportPath doesn't use Polymer.Base.set, |
| - // which is OK because the nested property update events aren't useful. |
| - cr.exportPath(newPrefObj.key, newPrefObj, this.prefs); |
| - // Notify listeners of the change at the preference key. |
| - this.notifyPath('prefs.' + newPrefObj.key, newPrefObj); |
| - } |
| + // Add the pref to |prefs|. cr.exportPath doesn't use Polymer.Base.set, |
| + // which is OK because the nested property update events aren't useful. |
| + cr.exportPath(newPrefObj.key, newPrefObj, this.prefs); |
| + // Notify listeners of the change at the preference key. |
| + this.notifyPath('prefs.' + newPrefObj.key, newPrefObj); |
| }, |
| /** |