Chromium Code Reviews| Index: chrome/test/data/extensions/api_test/preference/standard/test.js |
| diff --git a/chrome/test/data/extensions/api_test/preference/standard/test.js b/chrome/test/data/extensions/api_test/preference/standard/test.js |
| index 5ffc64038fa97ac416e113aa0f88466eda909832..72259d26d5b98f1f78b0e2154fac6b7fc3024b13 100644 |
| --- a/chrome/test/data/extensions/api_test/preference/standard/test.js |
| +++ b/chrome/test/data/extensions/api_test/preference/standard/test.js |
| @@ -6,86 +6,113 @@ |
| // Run with browser_tests --gtest_filter=ExtensionPreferenceApiTest.Standard |
| var pn = chrome.privacy.network; |
| +// The collection of preferences to test, split into objects with a "root" |
| +// (the root object they preferences are exposed on) and a dictionary of |
| +// preference name -> default value. |
| var preferences_to_test = [ |
| { |
| root: chrome.privacy.network, |
| - preferences: [ |
| - 'networkPredictionEnabled', |
| - 'webRTCMultipleRoutesEnabled', |
| - 'webRTCNonProxiedUdpEnabled' |
| - ] |
| + preferences: { |
| + networkPredictionEnabled: false, |
| + webRTCMultipleRoutesEnabled: false, |
| + webRTCNonProxiedUdpEnabled: false, |
| + } |
| }, |
| { |
| root: chrome.privacy.websites, |
| - preferences: [ |
| - 'thirdPartyCookiesAllowed', |
| - 'hyperlinkAuditingEnabled', |
| - 'referrersEnabled', |
| - 'protectedContentEnabled' |
| - ] |
| + preferences: { |
| + thirdPartyCookiesAllowed: false, |
| + hyperlinkAuditingEnabled: false, |
| + referrersEnabled: false, |
| + protectedContentEnabled: true, |
| + } |
| }, |
| { |
| root: chrome.privacy.services, |
| - preferences: [ |
| - 'alternateErrorPagesEnabled', |
| - 'autofillEnabled', |
| - 'hotwordSearchEnabled', |
| - 'passwordSavingEnabled', |
| - 'safeBrowsingEnabled', |
| - 'safeBrowsingExtendedReportingEnabled', |
| - 'searchSuggestEnabled', |
| - 'spellingServiceEnabled', |
| - 'translationServiceEnabled' |
| - ] |
| + preferences: { |
| + alternateErrorPagesEnabled: false, |
| + autofillEnabled: false, |
| + hotwordSearchEnabled: false, |
| + passwordSavingEnabled: false, |
| + safeBrowsingEnabled: false, |
| + safeBrowsingExtendedReportingEnabled: false, |
| + searchSuggestEnabled: false, |
| + spellingServiceEnabled: false, |
| + translationServiceEnabled: false, |
| + } |
| }, |
| ]; |
| // Some preferences are only present on certain platforms or are hidden |
| // behind flags and might not be present when this test runs. |
| var possibly_missing_preferences = new Set([ |
| - 'protectedContentEnabled', // Windows/ChromeOS only |
| 'webRTCMultipleRoutesEnabled', // requires ENABLE_WEBRTC=1 |
| - 'webRTCNonProxiedUdpEnabled' // requires ENABLE_WEBRTC=1 |
| + 'webRTCNonProxiedUdpEnabled', // requires ENABLE_WEBRTC=1 |
| ]); |
| +if (navigator.userAgent.indexOf('Windows') == -1 && |
| + navigator.userAgent.indexOf('CrOS') == -1) { |
|
msramek
2017/07/19 00:44:07
nit: String.prototype.includes()
Devlin
2017/07/19 17:43:23
Done.
|
| + possibly_missing_preferences.add('protectedContentEnabled'); |
| +} |
| + |
| function expect(expected, message) { |
| return chrome.test.callbackPass(function(value) { |
| chrome.test.assertEq(expected, value, message); |
| }); |
| } |
| -function expectFalse(pref) { |
| +// Verifies that the preference has the expected default value. |
| +function expectDefault(prefName, defaultValue) { |
| return expect({ |
| - value: false, |
| + value: defaultValue, |
| levelOfControl: 'controllable_by_this_extension' |
| - }, '`' + pref + '` is expected to be false.'); |
| + }, '`' + prefName + '` is expected to be default.'); |
|
msramek
2017/07/19 00:44:07
optional: '...default, which is ' + defaultValue
Devlin
2017/07/19 17:43:23
Done.
|
| +} |
| + |
| +// Verifies that the preference is properly controlled by the extension. |
| +function expectControlled(prefName, newValue) { |
| + return expect({ |
| + value: newValue, |
| + levelOfControl: 'controlled_by_this_extension', |
| + }, '`' + prefName + '` is expected to be controlled by this extension.'); |
| } |
| -function prefGetter(pref) { |
| - if (possibly_missing_preferences.has(pref) && !this[pref]) { |
| - return true; |
| +// Tests getting the preference value (which should be uncontrolled and at its |
| +// default value). |
| +function prefGetter(prefName, defaultValue) { |
| + if (possibly_missing_preferences.has(prefName) && !this[prefName]) { |
| + return; |
| } |
| - this[pref].get({}, expectFalse(pref)); |
| + this[prefName].get({}, expectDefault(prefName, defaultValue)); |
| } |
| -function prefSetter(pref) { |
| - if (possibly_missing_preferences.has(pref) && !this[pref]) { |
| - return true; |
| +// Tests setting the preference value (to the inverse of the default, so that |
| +// it should be controlled by this extension). |
| +function prefSetter(prefName, defaultValue) { |
| + if (possibly_missing_preferences.has(prefName) && !this[prefName]) { |
| + return; |
| } |
| - this[pref].set({value: true}, chrome.test.callbackPass()); |
| + this[prefName].set({value: !defaultValue}, |
| + chrome.test.callbackPass(function() { |
| + this[prefName].get({}, expectControlled(prefName, !defaultValue)); |
| + }.bind(this))); |
| } |
| chrome.test.runTests([ |
| function getPreferences() { |
| - for (var i = 0; i < preferences_to_test.length; i++) { |
| - preferences_to_test[i].preferences.forEach( |
| - prefGetter.bind(preferences_to_test[i].root)); |
| + for (let preferenceSet of preferences_to_test) { |
| + for (let key in preferenceSet.preferences) { |
| + prefGetter.call(preferenceSet.root, key, |
| + preferenceSet.preferences[key]); |
| + } |
| } |
| }, |
| function setGlobals() { |
| - for (var i = 0; i < preferences_to_test.length; i++) { |
| - preferences_to_test[i].preferences.forEach( |
| - prefSetter.bind(preferences_to_test[i].root)); |
| + for (let preferenceSet of preferences_to_test) { |
| + for (let key in preferenceSet.preferences) { |
| + prefSetter.call(preferenceSet.root, key, |
| + preferenceSet.preferences[key]); |
| + } |
| } |
| }, |
| // Set the WebRTCIPHhandlingPolicy and verify it in the get function. |