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

Unified Diff: chrome/browser/resources/settings/prefs/prefs.js

Issue 1310843010: Add Polymer tests for cr-settings-prefs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | chrome/test/data/webui/polymer_browser_test_base.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..9b311e84aa6336970fb326524d2f41cabd38ce0b 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,
michaelpg 2015/09/05 07:11:59 is this type-able? {chrome.settingsPrivate} itself
+
/** @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)
+ 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,8 +238,8 @@ 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
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | chrome/test/data/webui/polymer_browser_test_base.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698