1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Preferences API test
6 // Run with browser_tests --gtest_filter=ExtensionApiTest.PreferenceApi
8 var preferences_to_test = [
10 root: chrome.privacy.network,
12 'networkPredictionEnabled',
13 'webRTCMultipleRoutesEnabled',
14 'webRTCNonProxiedUdpEnabled'
18 root: chrome.privacy.websites,
20 'thirdPartyCookiesAllowed',
21 'hyperlinkAuditingEnabled',
23 'protectedContentEnabled'
27 root: chrome.privacy.services,
29 'alternateErrorPagesEnabled',
31 'hotwordSearchEnabled',
32 'passwordSavingEnabled',
33 'safeBrowsingEnabled',
34 'safeBrowsingExtendedReportingEnabled',
35 'searchSuggestEnabled',
36 'spellingServiceEnabled',
37 'translationServiceEnabled'
42 // Some preferences are only present on certain platforms or are hidden
43 // behind flags and might not be present when this test runs.
44 var possibly_missing_preferences = new Set([
45 'protectedContentEnabled', // Windows/ChromeOS only
46 'webRTCMultipleRoutesEnabled', // requires ENABLE_WEBRTC=1
47 'webRTCNonProxiedUdpEnabled' // requires ENABLE_WEBRTC=1
50 function expect(expected, message) {
51 return chrome.test.callbackPass(function(value) {
52 chrome.test.assertEq(expected, value, message);
56 function expectFalse(pref) {
59 levelOfControl: 'controllable_by_this_extension'
60 }, '`' + pref + '` is expected to be false.');
63 function prefGetter(pref) {
64 if (possibly_missing_preferences.has(pref) && !this[pref]) {
67 this[pref].get({}, expectFalse(pref));
70 function prefSetter(pref) {
71 if (possibly_missing_preferences.has(pref) && !this[pref]) {
74 this[pref].set({value: true}, chrome.test.callbackPass());
77 chrome.test.runTests([
78 function getPreferences() {
79 for (var i = 0; i < preferences_to_test.length; i++) {
80 preferences_to_test[i].preferences.forEach(
81 prefGetter.bind(preferences_to_test[i].root));
84 function setGlobals() {
85 for (var i = 0; i < preferences_to_test.length; i++) {
86 preferences_to_test[i].preferences.forEach(
87 prefSetter.bind(preferences_to_test[i].root));