Chromium Code Reviews| 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=ExtensionPreferenceApiTest.Standard | 6 // Run with browser_tests --gtest_filter=ExtensionPreferenceApiTest.Standard |
| 7 | 7 |
| 8 var pn = chrome.privacy.network; | 8 var pn = chrome.privacy.network; |
| 9 // The collection of preferences to test, split into objects with a "root" | |
| 10 // (the root object they preferences are exposed on) and a dictionary of | |
| 11 // preference name -> default value. | |
| 9 var preferences_to_test = [ | 12 var preferences_to_test = [ |
| 10 { | 13 { |
| 11 root: chrome.privacy.network, | 14 root: chrome.privacy.network, |
| 12 preferences: [ | 15 preferences: { |
| 13 'networkPredictionEnabled', | 16 networkPredictionEnabled: false, |
| 14 'webRTCMultipleRoutesEnabled', | 17 webRTCMultipleRoutesEnabled: false, |
| 15 'webRTCNonProxiedUdpEnabled' | 18 webRTCNonProxiedUdpEnabled: false, |
| 16 ] | 19 } |
| 17 }, | 20 }, |
| 18 { | 21 { |
| 19 root: chrome.privacy.websites, | 22 root: chrome.privacy.websites, |
| 20 preferences: [ | 23 preferences: { |
| 21 'thirdPartyCookiesAllowed', | 24 thirdPartyCookiesAllowed: false, |
| 22 'hyperlinkAuditingEnabled', | 25 hyperlinkAuditingEnabled: false, |
| 23 'referrersEnabled', | 26 referrersEnabled: false, |
| 24 'protectedContentEnabled' | 27 protectedContentEnabled: true, |
| 25 ] | 28 } |
| 26 }, | 29 }, |
| 27 { | 30 { |
| 28 root: chrome.privacy.services, | 31 root: chrome.privacy.services, |
| 29 preferences: [ | 32 preferences: { |
| 30 'alternateErrorPagesEnabled', | 33 alternateErrorPagesEnabled: false, |
| 31 'autofillEnabled', | 34 autofillEnabled: false, |
| 32 'hotwordSearchEnabled', | 35 hotwordSearchEnabled: false, |
| 33 'passwordSavingEnabled', | 36 passwordSavingEnabled: false, |
| 34 'safeBrowsingEnabled', | 37 safeBrowsingEnabled: false, |
| 35 'safeBrowsingExtendedReportingEnabled', | 38 safeBrowsingExtendedReportingEnabled: false, |
| 36 'searchSuggestEnabled', | 39 searchSuggestEnabled: false, |
| 37 'spellingServiceEnabled', | 40 spellingServiceEnabled: false, |
| 38 'translationServiceEnabled' | 41 translationServiceEnabled: false, |
| 39 ] | 42 } |
| 40 }, | 43 }, |
| 41 ]; | 44 ]; |
| 42 | 45 |
| 43 // Some preferences are only present on certain platforms or are hidden | 46 // Some preferences are only present on certain platforms or are hidden |
| 44 // behind flags and might not be present when this test runs. | 47 // behind flags and might not be present when this test runs. |
| 45 var possibly_missing_preferences = new Set([ | 48 var possibly_missing_preferences = new Set([ |
| 46 'protectedContentEnabled', // Windows/ChromeOS only | |
| 47 'webRTCMultipleRoutesEnabled', // requires ENABLE_WEBRTC=1 | 49 'webRTCMultipleRoutesEnabled', // requires ENABLE_WEBRTC=1 |
| 48 'webRTCNonProxiedUdpEnabled' // requires ENABLE_WEBRTC=1 | 50 'webRTCNonProxiedUdpEnabled', // requires ENABLE_WEBRTC=1 |
| 49 ]); | 51 ]); |
| 50 | 52 |
| 53 if (navigator.userAgent.indexOf('Windows') == -1 && | |
| 54 navigator.userAgent.indexOf('CrOS') == -1) { | |
|
msramek
2017/07/19 00:44:07
nit: String.prototype.includes()
Devlin
2017/07/19 17:43:23
Done.
| |
| 55 possibly_missing_preferences.add('protectedContentEnabled'); | |
| 56 } | |
| 57 | |
| 51 function expect(expected, message) { | 58 function expect(expected, message) { |
| 52 return chrome.test.callbackPass(function(value) { | 59 return chrome.test.callbackPass(function(value) { |
| 53 chrome.test.assertEq(expected, value, message); | 60 chrome.test.assertEq(expected, value, message); |
| 54 }); | 61 }); |
| 55 } | 62 } |
| 56 | 63 |
| 57 function expectFalse(pref) { | 64 // Verifies that the preference has the expected default value. |
| 65 function expectDefault(prefName, defaultValue) { | |
| 58 return expect({ | 66 return expect({ |
| 59 value: false, | 67 value: defaultValue, |
| 60 levelOfControl: 'controllable_by_this_extension' | 68 levelOfControl: 'controllable_by_this_extension' |
| 61 }, '`' + pref + '` is expected to be false.'); | 69 }, '`' + 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.
| |
| 62 } | 70 } |
| 63 | 71 |
| 64 function prefGetter(pref) { | 72 // Verifies that the preference is properly controlled by the extension. |
| 65 if (possibly_missing_preferences.has(pref) && !this[pref]) { | 73 function expectControlled(prefName, newValue) { |
| 66 return true; | 74 return expect({ |
| 67 } | 75 value: newValue, |
| 68 this[pref].get({}, expectFalse(pref)); | 76 levelOfControl: 'controlled_by_this_extension', |
| 77 }, '`' + prefName + '` is expected to be controlled by this extension.'); | |
| 69 } | 78 } |
| 70 | 79 |
| 71 function prefSetter(pref) { | 80 // Tests getting the preference value (which should be uncontrolled and at its |
| 72 if (possibly_missing_preferences.has(pref) && !this[pref]) { | 81 // default value). |
| 73 return true; | 82 function prefGetter(prefName, defaultValue) { |
| 83 if (possibly_missing_preferences.has(prefName) && !this[prefName]) { | |
| 84 return; | |
| 74 } | 85 } |
| 75 this[pref].set({value: true}, chrome.test.callbackPass()); | 86 this[prefName].get({}, expectDefault(prefName, defaultValue)); |
| 87 } | |
| 88 | |
| 89 // Tests setting the preference value (to the inverse of the default, so that | |
| 90 // it should be controlled by this extension). | |
| 91 function prefSetter(prefName, defaultValue) { | |
| 92 if (possibly_missing_preferences.has(prefName) && !this[prefName]) { | |
| 93 return; | |
| 94 } | |
| 95 this[prefName].set({value: !defaultValue}, | |
| 96 chrome.test.callbackPass(function() { | |
| 97 this[prefName].get({}, expectControlled(prefName, !defaultValue)); | |
| 98 }.bind(this))); | |
| 76 } | 99 } |
| 77 | 100 |
| 78 chrome.test.runTests([ | 101 chrome.test.runTests([ |
| 79 function getPreferences() { | 102 function getPreferences() { |
| 80 for (var i = 0; i < preferences_to_test.length; i++) { | 103 for (let preferenceSet of preferences_to_test) { |
| 81 preferences_to_test[i].preferences.forEach( | 104 for (let key in preferenceSet.preferences) { |
| 82 prefGetter.bind(preferences_to_test[i].root)); | 105 prefGetter.call(preferenceSet.root, key, |
| 106 preferenceSet.preferences[key]); | |
| 107 } | |
| 83 } | 108 } |
| 84 }, | 109 }, |
| 85 function setGlobals() { | 110 function setGlobals() { |
| 86 for (var i = 0; i < preferences_to_test.length; i++) { | 111 for (let preferenceSet of preferences_to_test) { |
| 87 preferences_to_test[i].preferences.forEach( | 112 for (let key in preferenceSet.preferences) { |
| 88 prefSetter.bind(preferences_to_test[i].root)); | 113 prefSetter.call(preferenceSet.root, key, |
| 114 preferenceSet.preferences[key]); | |
| 115 } | |
| 89 } | 116 } |
| 90 }, | 117 }, |
| 91 // Set the WebRTCIPHhandlingPolicy and verify it in the get function. | 118 // Set the WebRTCIPHhandlingPolicy and verify it in the get function. |
| 92 function testWebRTCIPHandlingPolicy() { | 119 function testWebRTCIPHandlingPolicy() { |
| 93 if (pn.webRTCIPHandlingPolicy == undefined) { | 120 if (pn.webRTCIPHandlingPolicy == undefined) { |
| 94 chrome.test.callbackPass(); | 121 chrome.test.callbackPass(); |
| 95 return; | 122 return; |
| 96 } | 123 } |
| 97 pn.webRTCIPHandlingPolicy.get( | 124 pn.webRTCIPHandlingPolicy.get( |
| 98 {}, | 125 {}, |
| 99 expect( | 126 expect( |
| 100 {value: chrome.privacy.IPHandlingPolicy.DEFAULT_PUBLIC_INTERFACE_ONLY, | 127 {value: chrome.privacy.IPHandlingPolicy.DEFAULT_PUBLIC_INTERFACE_ONLY, |
| 101 levelOfControl: 'controllable_by_this_extension'}, | 128 levelOfControl: 'controllable_by_this_extension'}, |
| 102 'should receive default_public_interface_only.')); | 129 'should receive default_public_interface_only.')); |
| 103 | 130 |
| 104 pn.webRTCIPHandlingPolicy.set( | 131 pn.webRTCIPHandlingPolicy.set( |
| 105 {value: chrome.privacy.IPHandlingPolicy.DISABLE_NON_PROXIED_UDP}); | 132 {value: chrome.privacy.IPHandlingPolicy.DISABLE_NON_PROXIED_UDP}); |
| 106 | 133 |
| 107 pn.webRTCIPHandlingPolicy.get( | 134 pn.webRTCIPHandlingPolicy.get( |
| 108 {}, | 135 {}, |
| 109 expect( | 136 expect( |
| 110 {value: chrome.privacy.IPHandlingPolicy.DISABLE_NON_PROXIED_UDP, | 137 {value: chrome.privacy.IPHandlingPolicy.DISABLE_NON_PROXIED_UDP, |
| 111 levelOfControl: 'controlled_by_this_extension'}, | 138 levelOfControl: 'controlled_by_this_extension'}, |
| 112 'should receive disable_non_proxied_udp.')); | 139 'should receive disable_non_proxied_udp.')); |
| 113 } | 140 } |
| 114 ]); | 141 ]); |
| OLD | NEW |