OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Preferences API test | 5 // Preferences API test |
6 // Run with browser_tests --gtest_filter=ExtensionApiTest.PreferenceApi | 6 // Run with browser_tests --gtest_filter=ExtensionApiTest.PreferenceApi |
7 | 7 |
8 var preferences_to_test = [ | 8 var preferences_to_test = [ |
9 { | 9 { |
10 root: chrome.privacy.network, | 10 root: chrome.privacy.network, |
11 preferences: [ | 11 preferences: [ |
12 'networkPredictionEnabled' | 12 'networkPredictionEnabled', |
| 13 'webRTCMultipleRoutesEnabled' |
13 ] | 14 ] |
14 }, | 15 }, |
15 { | 16 { |
16 root: chrome.privacy.websites, | 17 root: chrome.privacy.websites, |
17 preferences: [ | 18 preferences: [ |
18 'thirdPartyCookiesAllowed', | 19 'thirdPartyCookiesAllowed', |
19 'hyperlinkAuditingEnabled', | 20 'hyperlinkAuditingEnabled', |
20 'referrersEnabled', | 21 'referrersEnabled', |
21 'protectedContentEnabled' | 22 'protectedContentEnabled' |
22 ] | 23 ] |
23 }, | 24 }, |
24 { | 25 { |
25 root: chrome.privacy.services, | 26 root: chrome.privacy.services, |
26 preferences: [ | 27 preferences: [ |
27 'alternateErrorPagesEnabled', | 28 'alternateErrorPagesEnabled', |
28 'autofillEnabled', | 29 'autofillEnabled', |
29 'hotwordSearchEnabled', | 30 'hotwordSearchEnabled', |
30 'passwordSavingEnabled', | 31 'passwordSavingEnabled', |
31 'safeBrowsingEnabled', | 32 'safeBrowsingEnabled', |
32 'safeBrowsingExtendedReportingEnabled', | 33 'safeBrowsingExtendedReportingEnabled', |
33 'searchSuggestEnabled', | 34 'searchSuggestEnabled', |
34 'spellingServiceEnabled', | 35 'spellingServiceEnabled', |
35 'translationServiceEnabled' | 36 'translationServiceEnabled' |
36 ] | 37 ] |
37 }, | 38 }, |
38 ]; | 39 ]; |
39 | 40 |
| 41 // Some preferences are only present on certain platforms or are hidden |
| 42 // behind flags and might not be present when this test runs. |
| 43 var possibly_missing_preferences = new Set([ |
| 44 'protectedContentEnabled', // Windows/ChromeOS only |
| 45 'webRTCMultipleRoutesEnabled' // requires ENABLE_WEBRTC=1 |
| 46 ]); |
| 47 |
40 function expect(expected, message) { | 48 function expect(expected, message) { |
41 return chrome.test.callbackPass(function(value) { | 49 return chrome.test.callbackPass(function(value) { |
42 chrome.test.assertEq(expected, value, message); | 50 chrome.test.assertEq(expected, value, message); |
43 }); | 51 }); |
44 } | 52 } |
45 | 53 |
46 function expectFalse(pref) { | 54 function expectFalse(pref) { |
47 return expect({ | 55 return expect({ |
48 value: false, | 56 value: false, |
49 levelOfControl: 'controllable_by_this_extension' | 57 levelOfControl: 'controllable_by_this_extension' |
50 }, '`' + pref + '` is expected to be false.'); | 58 }, '`' + pref + '` is expected to be false.'); |
51 } | 59 } |
52 | 60 |
53 function prefGetter(pref) { | 61 function prefGetter(pref) { |
54 if (pref === 'protectedContentEnabled' && !this[pref]) { | 62 if (possibly_missing_preferences.has(pref) && !this[pref]) { |
55 // `protectedContentEnabled` is Windows/ChromeOS only, so it might not exist | |
56 // when this test runs, and that's pretty much OK. | |
57 return true; | 63 return true; |
58 } | 64 } |
59 this[pref].get({}, expectFalse(pref)); | 65 this[pref].get({}, expectFalse(pref)); |
60 } | 66 } |
61 | 67 |
62 function prefSetter(pref) { | 68 function prefSetter(pref) { |
63 if (pref === 'protectedContentEnabled' && !this[pref]) { | 69 if (possibly_missing_preferences.has(pref) && !this[pref]) { |
64 // `protectedContentEnabled` is Windows/ChromeOS only, so it might not exist | |
65 // when this test runs, and that's pretty much OK. | |
66 return true; | 70 return true; |
67 } | 71 } |
68 this[pref].set({value: true}, chrome.test.callbackPass()); | 72 this[pref].set({value: true}, chrome.test.callbackPass()); |
69 } | 73 } |
70 | 74 |
71 chrome.test.runTests([ | 75 chrome.test.runTests([ |
72 function getPreferences() { | 76 function getPreferences() { |
73 for (var i = 0; i < preferences_to_test.length; i++) { | 77 for (var i = 0; i < preferences_to_test.length; i++) { |
74 preferences_to_test[i].preferences.forEach( | 78 preferences_to_test[i].preferences.forEach( |
75 prefGetter.bind(preferences_to_test[i].root)); | 79 prefGetter.bind(preferences_to_test[i].root)); |
76 } | 80 } |
77 }, | 81 }, |
78 function setGlobals() { | 82 function setGlobals() { |
79 for (var i = 0; i < preferences_to_test.length; i++) { | 83 for (var i = 0; i < preferences_to_test.length; i++) { |
80 preferences_to_test[i].preferences.forEach( | 84 preferences_to_test[i].preferences.forEach( |
81 prefSetter.bind(preferences_to_test[i].root)); | 85 prefSetter.bind(preferences_to_test[i].root)); |
82 } | 86 } |
83 } | 87 } |
84 ]); | 88 ]); |
OLD | NEW |