diff options
author | battre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-24 21:15:16 +0000 |
---|---|---|
committer | battre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-24 21:15:16 +0000 |
commit | 9a28f13d854c19ae09e2f2e260a2ddc366aef355 (patch) | |
tree | 15e513c433c89c64bd52f4e3c59de355e83696c2 | |
parent | dfb26435674c4ab5e9bb003b7a9355ba52b624bb (diff) | |
download | chromium_src-9a28f13d854c19ae09e2f2e260a2ddc366aef355.zip chromium_src-9a28f13d854c19ae09e2f2e260a2ddc366aef355.tar.gz chromium_src-9a28f13d854c19ae09e2f2e260a2ddc366aef355.tar.bz2 |
Added LevelOfControl to Preferences API's get() result
BUG=73427
TEST=./unit_tests --gtest_filter="PrefValueStoreTest.*" && ./unit_tests --gtest_filter="ExtensionPrefValueMapTest.*" && ./browser_tests --gtest_filter=ExtensionApiTest.IncognitoContentSettings && ./browser_tests --gtest_filter=ExtensionApiTest.ContentSettings
Review URL: http://codereview.chromium.org/6542021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75947 0039d316-1c4b-4281-b951-d872f2087c98
22 files changed, 303 insertions, 37 deletions
diff --git a/chrome/browser/extensions/extension_pref_value_map.cc b/chrome/browser/extensions/extension_pref_value_map.cc index e410a73..fb4abdf 100644 --- a/chrome/browser/extensions/extension_pref_value_map.cc +++ b/chrome/browser/extensions/extension_pref_value_map.cc @@ -46,6 +46,35 @@ void ExtensionPrefValueMap::RemoveExtensionPref(const std::string& ext_id, NotifyPrefValueChanged(key); } +bool ExtensionPrefValueMap::CanExtensionControlPref( + const std::string& extension_id, + const std::string& pref_key, + bool incognito) const { + ExtensionEntryMap::const_iterator ext = entries_.find(extension_id); + if (ext == entries_.end()) { + NOTREACHED(); + return false; + } + + ExtensionEntryMap::const_iterator winner = + GetEffectivePrefValueController(pref_key, incognito); + if (winner == entries_.end()) + return true; + + return winner->second->install_time <= ext->second->install_time; +} + +bool ExtensionPrefValueMap::DoesExtensionControlPref( + const std::string& extension_id, + const std::string& pref_key, + bool incognito) const { + ExtensionEntryMap::const_iterator winner = + GetEffectivePrefValueController(pref_key, incognito); + if (winner == entries_.end()) + return false; + return winner->first == extension_id; +} + void ExtensionPrefValueMap::RegisterExtension(const std::string& ext_id, const base::Time& install_time, bool is_enabled) { @@ -116,7 +145,25 @@ void ExtensionPrefValueMap::GetExtensionControlledKeys( const Value* ExtensionPrefValueMap::GetEffectivePrefValue( const std::string& key, bool incognito) const { - Value *winner = NULL; + ExtensionEntryMap::const_iterator winner = + GetEffectivePrefValueController(key, incognito); + if (winner == entries_.end()) + return NULL; + + Value* value = NULL; + const std::string& ext_id = winner->first; + if (incognito) + GetExtensionPrefValueMap(ext_id, true)->GetValue(key, &value); + if (!value) + GetExtensionPrefValueMap(ext_id, false)->GetValue(key, &value); + return value; +} + +ExtensionPrefValueMap::ExtensionEntryMap::const_iterator +ExtensionPrefValueMap::GetEffectivePrefValueController( + const std::string& key, + bool incognito) const { + ExtensionEntryMap::const_iterator winner = entries_.end(); base::Time winners_install_time; ExtensionEntryMap::const_iterator i; @@ -133,7 +180,7 @@ const Value* ExtensionPrefValueMap::GetEffectivePrefValue( Value* value = NULL; const PrefValueMap* prefs = GetExtensionPrefValueMap(ext_id, false); if (prefs->GetValue(key, &value)) { - winner = value; + winner = i; winners_install_time = install_time; } @@ -142,7 +189,7 @@ const Value* ExtensionPrefValueMap::GetEffectivePrefValue( prefs = GetExtensionPrefValueMap(ext_id, true); if (prefs->GetValue(key, &value)) { - winner = value; + winner = i; winners_install_time = install_time; } } diff --git a/chrome/browser/extensions/extension_pref_value_map.h b/chrome/browser/extensions/extension_pref_value_map.h index 896a68c..cc75da2 100644 --- a/chrome/browser/extensions/extension_pref_value_map.h +++ b/chrome/browser/extensions/extension_pref_value_map.h @@ -79,6 +79,25 @@ class ExtensionPrefValueMap { const std::string& key, bool incognito); + // Returns true if currently no extension with higher precedence controls the + // preference. + // Note that the this function does does not consider the existence of + // policies. An extension is only really able to control a preference if + // PrefService::Preference::IsExtensionModifiable() returns true as well. + bool CanExtensionControlPref(const std::string& extension_id, + const std::string& pref_key, + bool incognito) const; + + // Returns true if an extension identified by |extension_id| controls the + // preference. This means this extension has set a preference value and no + // other extension with higher precedence overrides it. + // Note that the this function does does not consider the existence of + // policies. An extension is only really able to control a preference if + // PrefService::Preference::IsExtensionModifiable() returns true as well. + bool DoesExtensionControlPref(const std::string& extension_id, + const std::string& pref_key, + bool incognito) const; + // Tell the store it's now fully initialized. void NotifyInitializationCompleted(); @@ -118,6 +137,9 @@ class ExtensionPrefValueMap { void GetExtensionControlledKeys(const ExtensionEntry& entry, std::set<std::string>* out) const; + ExtensionEntryMap::const_iterator GetEffectivePrefValueController( + const std::string& key, bool incognito) const; + void NotifyOfDestruction(); void NotifyPrefValueChanged(const std::string& key); void NotifyPrefValueChanged(const std::set<std::string>& keys); diff --git a/chrome/browser/extensions/extension_pref_value_map_unittest.cc b/chrome/browser/extensions/extension_pref_value_map_unittest.cc index 642bb03..4b514cf 100644 --- a/chrome/browser/extensions/extension_pref_value_map_unittest.cc +++ b/chrome/browser/extensions/extension_pref_value_map_unittest.cc @@ -27,7 +27,7 @@ static Value* CreateVal(const char* str) { } static base::Time CreateTime(int64 t) { - return base::Time::FromInternalValue(10); + return base::Time::FromInternalValue(t); } template <typename BASECLASS> @@ -98,6 +98,28 @@ TEST_F(ExtensionPrefValueMapTest, Override) { EXPECT_EQ("val8", GetValue(kPref3, false)); } +TEST_F(ExtensionPrefValueMapTest, OverrideChecks) { + epvm_.RegisterExtension(kExt1, CreateTime(10), true); + epvm_.RegisterExtension(kExt2, CreateTime(20), true); + epvm_.RegisterExtension(kExt3, CreateTime(30), true); + + EXPECT_FALSE(epvm_.DoesExtensionControlPref(kExt1, kPref1, false)); + EXPECT_FALSE(epvm_.DoesExtensionControlPref(kExt2, kPref1, false)); + EXPECT_FALSE(epvm_.DoesExtensionControlPref(kExt3, kPref1, false)); + EXPECT_TRUE(epvm_.CanExtensionControlPref(kExt1, kPref1, false)); + EXPECT_TRUE(epvm_.CanExtensionControlPref(kExt2, kPref1, false)); + EXPECT_TRUE(epvm_.CanExtensionControlPref(kExt3, kPref1, false)); + + epvm_.SetExtensionPref(kExt2, kPref1, false, CreateVal("val1")); + + EXPECT_FALSE(epvm_.DoesExtensionControlPref(kExt1, kPref1, false)); + EXPECT_TRUE(epvm_.DoesExtensionControlPref(kExt2, kPref1, false)); + EXPECT_FALSE(epvm_.DoesExtensionControlPref(kExt3, kPref1, false)); + EXPECT_FALSE(epvm_.CanExtensionControlPref(kExt1, kPref1, false)); + EXPECT_TRUE(epvm_.CanExtensionControlPref(kExt2, kPref1, false)); + EXPECT_TRUE(epvm_.CanExtensionControlPref(kExt3, kPref1, false)); +} + TEST_F(ExtensionPrefValueMapTest, SetAndGetPrefValueIncognito) { epvm_.RegisterExtension(kExt1, CreateTime(10), true); epvm_.SetExtensionPref(kExt1, kPref1, false, CreateVal("val1")); diff --git a/chrome/browser/extensions/extension_preference_api.cc b/chrome/browser/extensions/extension_preference_api.cc index 1652634..7472e41 100644 --- a/chrome/browser/extensions/extension_preference_api.cc +++ b/chrome/browser/extensions/extension_preference_api.cc @@ -20,6 +20,11 @@ struct PrefMappingEntry { const char* permission; }; +const char kNotControllable[] = "NotControllable"; +const char kControlledByOtherExtensions[] = "ControlledByOtherExtensions"; +const char kControllableByThisExtension[] = "ControllableByThisExtension"; +const char kControlledByThisExtension[] = "ControlledByThisExtension"; + PrefMappingEntry pref_mapping[] = { { "blockThirdPartyCookies", prefs::kBlockThirdPartyCookies, @@ -74,6 +79,28 @@ const char kPermissionErrorMessage[] = GetPreferenceFunction::~GetPreferenceFunction() { } +const char* GetPreferenceFunction::GetLevelOfControl( + const std::string& browser_pref, + bool incognito) const { + PrefService* prefs = incognito ? profile_->GetOffTheRecordPrefs() + : profile_->GetPrefs(); + const PrefService::Preference* pref = + prefs->FindPreference(browser_pref.c_str()); + CHECK(pref); + ExtensionPrefs* ep = profile_->GetExtensionService()->extension_prefs(); + + if (!pref->IsExtensionModifiable()) + return kNotControllable; + + if (ep->DoesExtensionControlPref(extension_id(), browser_pref, incognito)) + return kControlledByThisExtension; + + if (ep->CanExtensionControlPref(extension_id(), browser_pref, incognito)) + return kControllableByThisExtension; + + return kControlledByOtherExtensions; +} + bool GetPreferenceFunction::RunImpl() { std::string pref_key; EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); @@ -95,10 +122,16 @@ bool GetPreferenceFunction::RunImpl() { error_ = base::StringPrintf(kPermissionErrorMessage, pref_key.c_str()); return false; } + const PrefService::Preference* pref = prefs->FindPreference(browser_pref.c_str()); CHECK(pref); - result_.reset(pref->GetValue()->DeepCopy()); + std::string level_of_control = GetLevelOfControl(browser_pref, incognito); + + scoped_ptr<DictionaryValue> result(new DictionaryValue); + result->Set("value", pref->GetValue()->DeepCopy()); + result->Set("levelOfControl", Value::CreateStringValue(level_of_control)); + result_.reset(result.release()); return true; } diff --git a/chrome/browser/extensions/extension_preference_api.h b/chrome/browser/extensions/extension_preference_api.h index aa276c5..00b051f 100644 --- a/chrome/browser/extensions/extension_preference_api.h +++ b/chrome/browser/extensions/extension_preference_api.h @@ -6,6 +6,8 @@ #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFERENCE_API_H__ #pragma once +#include <string> + #include "chrome/browser/extensions/extension_function.h" class GetPreferenceFunction : public SyncExtensionFunction { @@ -13,6 +15,12 @@ class GetPreferenceFunction : public SyncExtensionFunction { virtual ~GetPreferenceFunction(); virtual bool RunImpl(); DECLARE_EXTENSION_FUNCTION_NAME("experimental.preferences.get") + + private: + // Returns a string constant (defined in API) indicating the level of + // control this extension has on the specified preference. + const char* GetLevelOfControl(const std::string& browser_pref, + bool incognito) const; }; class SetPreferenceFunction : public SyncExtensionFunction { diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc index a7ff547..2f6a31a 100644 --- a/chrome/browser/extensions/extension_prefs.cc +++ b/chrome/browser/extensions/extension_prefs.cc @@ -1318,6 +1318,30 @@ void ExtensionPrefs::RemoveExtensionControlledPref( extension_id, pref_key, incognito); } +bool ExtensionPrefs::CanExtensionControlPref(const std::string& extension_id, + const std::string& pref_key, + bool incognito) { + DCHECK(pref_service()->FindPreference(pref_key.c_str())) + << "Extension controlled preference key " << pref_key + << " not registered."; + + return extension_pref_value_map_->CanExtensionControlPref(extension_id, + pref_key, + incognito); +} + +bool ExtensionPrefs::DoesExtensionControlPref(const std::string& extension_id, + const std::string& pref_key, + bool incognito) { + DCHECK(pref_service()->FindPreference(pref_key.c_str())) + << "Extension controlled preference key " << pref_key + << " not registered."; + + return extension_pref_value_map_->DoesExtensionControlPref(extension_id, + pref_key, + incognito); +} + // static void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterDictionaryPref(kExtensionsPref); diff --git a/chrome/browser/extensions/extension_prefs.h b/chrome/browser/extensions/extension_prefs.h index a8ebe7d..611d4b1 100644 --- a/chrome/browser/extensions/extension_prefs.h +++ b/chrome/browser/extensions/extension_prefs.h @@ -288,6 +288,18 @@ class ExtensionPrefs { const std::string& pref_key, bool incognito); + // Returns true if currently no extension with higher precedence controls the + // preference. + bool CanExtensionControlPref(const std::string& extension_id, + const std::string& pref_key, + bool incognito); + + // Returns true if extension |extension_id| currently controls the + // preference. + bool DoesExtensionControlPref(const std::string& extension_id, + const std::string& pref_key, + bool incognito); + static void RegisterUserPrefs(PrefService* prefs); // The underlying PrefService. diff --git a/chrome/browser/extensions/extension_proxy_api.cc b/chrome/browser/extensions/extension_proxy_api.cc index f5a82fc..60a2d69 100644 --- a/chrome/browser/extensions/extension_proxy_api.cc +++ b/chrome/browser/extensions/extension_proxy_api.cc @@ -59,6 +59,7 @@ const char kProxyCfgRuleHost[] = "host"; const char kProxyCfgRulePort[] = "port"; const char kProxyCfgBypassList[] = "bypassList"; const char kProxyCfgScheme[] = "scheme"; +const char kProxyCfgValue[] = "value"; const char kProxyEventFatal[] = "fatal"; const char kProxyEventError[] = "error"; @@ -415,19 +416,24 @@ bool GetProxySettingsFunction::RunImpl() { DCHECK(result_->IsType(Value::TYPE_DICTIONARY)); + DictionaryValue* result_dict_ = static_cast<DictionaryValue*>(result_.get()); + // This is how it is stored in the PrefStores: - scoped_ptr<DictionaryValue> proxy_prefs( - static_cast<DictionaryValue*>(result_.release())); + DictionaryValue* proxy_prefs = NULL; + if (!result_dict_->GetDictionary(kProxyCfgValue, &proxy_prefs)) { + LOG(ERROR) << "Received invalid configuration."; + return false; + } // This is how it is presented to the API caller: scoped_ptr<DictionaryValue> out(new DictionaryValue); - if (!ConvertToApiFormat(proxy_prefs.get(), out.get())) { + if (!ConvertToApiFormat(proxy_prefs, out.get())) { // Do not set error message as ConvertToApiFormat does that. return false; } - result_.reset(out.release()); + result_dict_->Set(kProxyCfgValue, out.release()); return true; } diff --git a/chrome/browser/prefs/pref_service.cc b/chrome/browser/prefs/pref_service.cc index 0e55f31..d02b29d 100644 --- a/chrome/browser/prefs/pref_service.cc +++ b/chrome/browser/prefs/pref_service.cc @@ -686,3 +686,7 @@ bool PrefService::Preference::IsDefaultValue() const { bool PrefService::Preference::IsUserModifiable() const { return pref_value_store()->PrefValueUserModifiable(name_.c_str()); } + +bool PrefService::Preference::IsExtensionModifiable() const { + return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); +} diff --git a/chrome/browser/prefs/pref_service.h b/chrome/browser/prefs/pref_service.h index 3ec774c..54febc0 100644 --- a/chrome/browser/prefs/pref_service.h +++ b/chrome/browser/prefs/pref_service.h @@ -88,6 +88,11 @@ class PrefService : public base::NonThreadSafe { // Preference. bool IsUserModifiable() const; + // Returns true if an extension can change the Preference value, which is + // the case if no higher-priority source than the extension store controls + // the Preference. + bool IsExtensionModifiable() const; + private: friend class PrefService; diff --git a/chrome/browser/prefs/pref_value_store.cc b/chrome/browser/prefs/pref_value_store.cc index 80d3714..b97a4fb 100644 --- a/chrome/browser/prefs/pref_value_store.cc +++ b/chrome/browser/prefs/pref_value_store.cc @@ -164,6 +164,12 @@ bool PrefValueStore::PrefValueUserModifiable(const char* name) const { effective_store == INVALID_STORE; } +bool PrefValueStore::PrefValueExtensionModifiable(const char* name) const { + PrefStoreType effective_store = ControllingPrefStoreForPref(name); + return effective_store >= EXTENSION_STORE || + effective_store == INVALID_STORE; +} + bool PrefValueStore::PrefValueInStore( const char* name, PrefValueStore::PrefStoreType store) const { diff --git a/chrome/browser/prefs/pref_value_store.h b/chrome/browser/prefs/pref_value_store.h index 7406654..09a698e 100644 --- a/chrome/browser/prefs/pref_value_store.h +++ b/chrome/browser/prefs/pref_value_store.h @@ -98,6 +98,10 @@ class PrefValueStore { // there is no higher-priority source controlling it. bool PrefValueUserModifiable(const char* name) const; + // Check whether a Preference value is modifiable by an extension, i.e. + // whether there is no higher-priority source controlling it. + bool PrefValueExtensionModifiable(const char* name) const; + private: // PrefStores must be listed here in order from highest to lowest priority. // MANAGED_PLATFORM contains all managed preference values that are diff --git a/chrome/browser/prefs/pref_value_store_unittest.cc b/chrome/browser/prefs/pref_value_store_unittest.cc index e67de56..78a133f 100644 --- a/chrome/browser/prefs/pref_value_store_unittest.cc +++ b/chrome/browser/prefs/pref_value_store_unittest.cc @@ -613,3 +613,24 @@ TEST_F(PrefValueStoreTest, PrefValueUserModifiable) { EXPECT_TRUE(pref_value_store_->PrefValueUserModifiable( prefs::kMissingPref)); } + +TEST_F(PrefValueStoreTest, PrefValueExtensionModifiable) { + EXPECT_FALSE(pref_value_store_->PrefValueExtensionModifiable( + prefs::kManagedPlatformPref)); + EXPECT_FALSE(pref_value_store_->PrefValueExtensionModifiable( + prefs::kManagedCloudPref)); + EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable( + prefs::kExtensionPref)); + EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable( + prefs::kCommandLinePref)); + EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable( + prefs::kUserPref)); + EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable( + prefs::kRecommendedPlatformPref)); + EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable( + prefs::kRecommendedCloudPref)); + EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable( + prefs::kDefaultPref)); + EXPECT_TRUE(pref_value_store_->PrefValueExtensionModifiable( + prefs::kMissingPref)); +} diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json index a4afad4..1a2aa46 100644 --- a/chrome/common/extensions/api/extension_api.json +++ b/chrome/common/extensions/api/extension_api.json @@ -4564,9 +4564,20 @@ "type": "function", "parameters": [ { - "name": "value", - "description": "The value of the preference.", - "type": "any" + "name": "details", + "type": "object", + "description": "Details of the currently effective preference value.", + "properties": { + "value": { + "description": "The value of the preference.", + "type": "any" + }, + "levelOfControl": { + "description": "One of<br>NotControllable = cannot be controlled by any extension<br>ControlledByOtherExtensions = controlled by extensions with higher precedence<br>ControllableByThisExtension = can be controlled by this extension<br>ControlledByThisExtension = controlled by this extension", + "type": "string", + "enum": ["NotControllable", "ControlledByOtherExtensions", "ControllableByThisExtension", "ControlledByThisExtension"] + } + } } ] } diff --git a/chrome/test/data/extensions/api_test/content_settings/clear/test.html b/chrome/test/data/extensions/api_test/content_settings/clear/test.html index 52b8257..01c4259 100644 --- a/chrome/test/data/extensions/api_test/content_settings/clear/test.html +++ b/chrome/test/data/extensions/api_test/content_settings/clear/test.html @@ -7,8 +7,13 @@ chrome.test.runTests([ function getBlockThirdPartyCookies() { cs.misc.blockThirdPartyCookies.get({}, chrome.test.callbackPass( function(block) { - chrome.test.assertBool(block, true, - "third-party cookies should be blocked"); + chrome.test.assertEq( + block, + { + 'value': true, + 'levelOfControl': "ControllableByThisExtension" + }, + "third-party cookies should be blocked"); })); }, function setBlockThirdPartyCookies() { @@ -22,8 +27,13 @@ chrome.test.runTests([ function getBlockThirdPartyCookies2() { cs.misc.blockThirdPartyCookies.get({}, chrome.test.callbackPass( function(block) { - chrome.test.assertBool(block, true, - "third-party cookies should be blocked"); + chrome.test.assertEq( + block, + { + 'value': true, + 'levelOfControl': "ControllableByThisExtension" + }, + "third-party cookies should be blocked"); })); } ]); diff --git a/chrome/test/data/extensions/api_test/content_settings/incognito/test.html b/chrome/test/data/extensions/api_test/content_settings/incognito/test.html index 930dde1..4722161 100644 --- a/chrome/test/data/extensions/api_test/content_settings/incognito/test.html +++ b/chrome/test/data/extensions/api_test/content_settings/incognito/test.html @@ -1,28 +1,36 @@ <script> // Content settings API test -// Run with browser_tests --gtest_filter=ExtensionApiTest.ContentSettings +// Run with browser_tests --gtest_filter=ExtensionApiTest.IncognitoContentSettings var cs = chrome.experimental.contentSettings; function expect(expected, message) { return chrome.test.callbackPass(function(value) { - chrome.test.assertBool(value, expected, message); + chrome.test.assertEq(expected, value, message); }); } chrome.test.runTests([ function testIncognito() { cs.misc.blockThirdPartyCookies.get( - {}, expect(false, "third-party cookies should not be blocked")); + {}, + expect({ 'value': false, + 'levelOfControl': "ControllableByThisExtension" }, + "third-party cookies should not be blocked")); cs.misc.blockThirdPartyCookies.get( { 'incognito': true }, - expect(false, + expect({ 'value': false, + 'levelOfControl': "ControllableByThisExtension" }, "third-party cookies should not be blocked in incognito mode")); cs.misc.blockThirdPartyCookies.set( { 'incognito': true, 'value': true }, chrome.test.callbackPass()); cs.misc.blockThirdPartyCookies.get( - {}, expect(false, "third-party cookies should not be blocked")); + {}, + expect({ 'value': false, + 'levelOfControl': "ControllableByThisExtension" }, + "third-party cookies should not be blocked")); cs.misc.blockThirdPartyCookies.get( { 'incognito': true }, - expect(true, + expect({ 'value': true, + 'levelOfControl': "ControlledByThisExtension" }, "third-party cookies should be blocked in incognito mode")); }, ]); diff --git a/chrome/test/data/extensions/api_test/content_settings/standard/test.html b/chrome/test/data/extensions/api_test/content_settings/standard/test.html index c33400a..f1a441c 100644 --- a/chrome/test/data/extensions/api_test/content_settings/standard/test.html +++ b/chrome/test/data/extensions/api_test/content_settings/standard/test.html @@ -3,13 +3,18 @@ // Run with browser_tests --gtest_filter=ExtensionApiTest.ContentSettings var cs = chrome.experimental.contentSettings; +function expect(expected, message) { + return chrome.test.callbackPass(function(value) { + chrome.test.assertEq(expected, value, message); + }); +} chrome.test.runTests([ function getBlockThirdPartyCookies() { - cs.misc.blockThirdPartyCookies.get({}, chrome.test.callbackPass( - function(block) { - chrome.test.assertBool(block, true, - "third-party cookies should be blocked"); - })); + cs.misc.blockThirdPartyCookies.get( + {}, + expect({ 'value': true, + 'levelOfControl': "ControllableByThisExtension" }, + "third-party cookies should be blocked")); }, function setBlockThirdPartyCookies() { cs.misc.blockThirdPartyCookies.set( diff --git a/chrome/test/data/extensions/api_test/proxy/auto/test.js b/chrome/test/data/extensions/api_test/proxy/auto/test.js index 92c13a1..fd1a10f 100644 --- a/chrome/test/data/extensions/api_test/proxy/auto/test.js +++ b/chrome/test/data/extensions/api_test/proxy/auto/test.js @@ -21,9 +21,13 @@ chrome.test.runTests([ chrome.test.callbackPass()); chrome.experimental.proxy.settings.get( {'incognito': false}, - expect(config, "invalid proxy settings")); + expect({ 'value': config, + 'levelOfControl': "ControlledByThisExtension" }, + "invalid proxy settings")); chrome.experimental.proxy.settings.get( {'incognito': true}, - expect(config, "invalid proxy settings")); + expect({ 'value': config, + 'levelOfControl': "ControlledByThisExtension" }, + "invalid proxy settings")); } ]); diff --git a/chrome/test/data/extensions/api_test/proxy/bypass/test.js b/chrome/test/data/extensions/api_test/proxy/bypass/test.js index d2a3d3c..58f0679 100644 --- a/chrome/test/data/extensions/api_test/proxy/bypass/test.js +++ b/chrome/test/data/extensions/api_test/proxy/bypass/test.js @@ -39,9 +39,13 @@ chrome.test.runTests([ chrome.test.callbackPass()); chrome.experimental.proxy.settings.get( {'incognito': false}, - expect(configExpected, "invalid proxy settings")); + expect({ 'value': configExpected, + 'levelOfControl': "ControlledByThisExtension" }, + "invalid proxy settings")); chrome.experimental.proxy.settings.get( {'incognito': true}, - expect(configExpected, "invalid proxy settings")); + expect({ 'value': configExpected, + 'levelOfControl': "ControlledByThisExtension" }, + "invalid proxy settings")); } ]); diff --git a/chrome/test/data/extensions/api_test/proxy/direct/test.js b/chrome/test/data/extensions/api_test/proxy/direct/test.js index cf10f82..9341d28 100644 --- a/chrome/test/data/extensions/api_test/proxy/direct/test.js +++ b/chrome/test/data/extensions/api_test/proxy/direct/test.js @@ -21,9 +21,13 @@ chrome.test.runTests([ chrome.test.callbackPass()); chrome.experimental.proxy.settings.get( {'incognito': false}, - expect(config, "invalid proxy settings")); + expect({ 'value': config, + 'levelOfControl': "ControlledByThisExtension" }, + "invalid proxy settings")); chrome.experimental.proxy.settings.get( {'incognito': true}, - expect(config, "invalid proxy settings")); + expect({ 'value': config, + 'levelOfControl': "ControlledByThisExtension" }, + "invalid proxy settings")); } ]); diff --git a/chrome/test/data/extensions/api_test/proxy/individual/test.js b/chrome/test/data/extensions/api_test/proxy/individual/test.js index e37ccf2..bf47e45 100644 --- a/chrome/test/data/extensions/api_test/proxy/individual/test.js +++ b/chrome/test/data/extensions/api_test/proxy/individual/test.js @@ -66,9 +66,13 @@ chrome.test.runTests([ chrome.test.callbackPass()); chrome.experimental.proxy.settings.get( {'incognito': false}, - expect(configExpected, "invalid proxy settings")); + expect({ 'value': configExpected, + 'levelOfControl': "ControlledByThisExtension" }, + "invalid proxy settings")); chrome.experimental.proxy.settings.get( {'incognito': true}, - expect(configExpected, "invalid proxy settings")); - } + expect({ 'value': configExpected, + 'levelOfControl': "ControlledByThisExtension" }, + "invalid proxy settings")); + } ]); diff --git a/chrome/test/data/extensions/api_test/proxy/pacdata/test.js b/chrome/test/data/extensions/api_test/proxy/pacdata/test.js index 1fbc65b..bb7d0f3 100644 --- a/chrome/test/data/extensions/api_test/proxy/pacdata/test.js +++ b/chrome/test/data/extensions/api_test/proxy/pacdata/test.js @@ -29,6 +29,8 @@ chrome.test.runTests([ chrome.test.callbackPass()); chrome.experimental.proxy.settings.get( {'incognito': false}, - expect(config, "invalid proxy settings")); + expect({ 'value': config, + 'levelOfControl': "ControlledByThisExtension" }, + "invalid proxy settings")); } ]); |