Chromium Code Reviews| Index: chrome/browser/extensions/api/developer_private/developer_private_api_unittest.cc | 
| diff --git a/chrome/browser/extensions/api/developer_private/developer_private_api_unittest.cc b/chrome/browser/extensions/api/developer_private/developer_private_api_unittest.cc | 
| index 341cc4c1d0bfe3b6e4a475554c26e6957d1642f5..2a0f8837158e716bcc0a7a4c4db0b9faac282e4a 100644 | 
| --- a/chrome/browser/extensions/api/developer_private/developer_private_api_unittest.cc | 
| +++ b/chrome/browser/extensions/api/developer_private/developer_private_api_unittest.cc | 
| @@ -55,11 +55,11 @@ class DeveloperPrivateApiUnitTest : public ExtensionServiceTestBase { | 
| // it to be reloaded. | 
| const Extension* LoadUnpackedExtension(); | 
| - // Tests a developer private function (T) that sets an extension pref, and | 
| - // verifies it with |has_pref|. | 
| - template<typename T> | 
| + // Tests setting various extension prefs. | 
| void TestExtensionPrefSetting( | 
| - bool (*has_pref)(const std::string&, content::BrowserContext*)); | 
| + bool (*has_pref)(const std::string&, content::BrowserContext*), | 
| + api::developer_private::PermissionType permission, | 
| + bool require_user_gesture); | 
| testing::AssertionResult TestPackExtensionFunction( | 
| const base::ListValue& args, | 
| @@ -97,7 +97,8 @@ const Extension* DeveloperPrivateApiUnitTest::LoadUnpackedExtension() { | 
| "{" | 
| " \"name\": \"foo\"," | 
| " \"version\": \"1.0\"," | 
| - " \"manifest_version\": 2" | 
| + " \"manifest_version\": 2," | 
| + " \"permissions\": [\"*://*/*\"]" | 
| "}"; | 
| test_extension_dirs_.push_back(new TestExtensionDir); | 
| @@ -124,37 +125,45 @@ const Extension* DeveloperPrivateApiUnitTest::LoadUnpackedExtension() { | 
| return extension; | 
| } | 
| -template<typename T> | 
| void DeveloperPrivateApiUnitTest::TestExtensionPrefSetting( | 
| - bool (*has_pref)(const std::string&, content::BrowserContext*)) { | 
| + bool (*has_pref)(const std::string&, content::BrowserContext*), | 
| + api::developer_private::PermissionType permission, | 
| + bool require_user_gesture) { | 
| // Sadly, we need a "real" directory here, because toggling incognito causes | 
| // a reload (which needs a path). | 
| std::string extension_id = LoadUnpackedExtension()->id(); | 
| - scoped_refptr<UIThreadExtensionFunction> function(new T()); | 
| - | 
| - base::ListValue enable_args; | 
| - enable_args.AppendString(extension_id); | 
| - enable_args.AppendBoolean(true); | 
| + scoped_refptr<UIThreadExtensionFunction> function( | 
| + new api::DeveloperPrivateSetExtensionPermissionFunction()); | 
| - EXPECT_FALSE(has_pref(extension_id, profile())); | 
| + std::string permission_string = api::developer_private::ToString(permission); | 
| - // Pref-setting should require a user action. | 
| - EXPECT_FALSE(RunFunction(function, enable_args)); | 
| - EXPECT_EQ(std::string("This action requires a user gesture."), | 
| - function->GetError()); | 
| + base::ListValue args; | 
| + base::DictionaryValue* parameters = new base::DictionaryValue(); | 
| + parameters->SetString("extensionId", extension_id); | 
| + parameters->SetString("permission", permission_string); | 
| + parameters->SetBoolean("isActive", true); | 
| + args.Append(parameters); | 
| 
 
not at google - send to devlin
2015/03/16 21:48:08
consider using DictionaryBuilder
 
Devlin
2015/03/16 22:41:37
I did consider it, but this is shorter when we wan
 
 | 
| + | 
| + EXPECT_FALSE(has_pref(extension_id, profile())) << permission_string; | 
| + | 
| + scoped_ptr<ExtensionFunction::ScopedUserGestureForTests> scoped_user_gesture; | 
| + if (require_user_gesture) { | 
| + EXPECT_FALSE(RunFunction(function, args)) << permission_string; | 
| + EXPECT_EQ(std::string("This action requires a user gesture."), | 
| + function->GetError()); | 
| + scoped_user_gesture.reset( | 
| + new ExtensionFunction::ScopedUserGestureForTests()); | 
| + function = new api::DeveloperPrivateSetExtensionPermissionFunction(); | 
| + } | 
| - ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture; | 
| - function = new T(); | 
| - EXPECT_TRUE(RunFunction(function, enable_args)); | 
| - EXPECT_TRUE(has_pref(extension_id, profile())); | 
| + EXPECT_TRUE(RunFunction(function, args)) << permission_string; | 
| + EXPECT_TRUE(has_pref(extension_id, profile())) << permission_string; | 
| - base::ListValue disable_args; | 
| - disable_args.AppendString(extension_id); | 
| - disable_args.AppendBoolean(false); | 
| - function = new T(); | 
| - EXPECT_TRUE(RunFunction(function, disable_args)); | 
| - EXPECT_FALSE(has_pref(extension_id, profile())); | 
| + parameters->SetBoolean("isActive", false); | 
| + function = new api::DeveloperPrivateSetExtensionPermissionFunction(); | 
| + EXPECT_TRUE(RunFunction(function, args)) << permission_string; | 
| + EXPECT_FALSE(has_pref(extension_id, profile())) << permission_string; | 
| } | 
| testing::AssertionResult DeveloperPrivateApiUnitTest::TestPackExtensionFunction( | 
| @@ -213,10 +222,22 @@ void DeveloperPrivateApiUnitTest::TearDown() { | 
| ExtensionServiceTestBase::TearDown(); | 
| } | 
| -// Test developerPrivate.allowIncognito. | 
| -TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateAllowIncognito) { | 
| - TestExtensionPrefSetting<api::DeveloperPrivateAllowIncognitoFunction>( | 
| - &util::IsIncognitoEnabled); | 
| +// Test developerPrivate.setExtensionPermission. | 
| +TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateSetExtensionPermission) { | 
| + FeatureSwitch::ScopedOverride scripts_require_action( | 
| + FeatureSwitch::scripts_require_action(), true); | 
| + TestExtensionPrefSetting( | 
| + &util::IsIncognitoEnabled, | 
| + api::developer_private::PERMISSION_TYPE_INCOGNITO_ACCESS, | 
| + true); | 
| + TestExtensionPrefSetting( | 
| + &util::AllowFileAccess, | 
| + api::developer_private::PERMISSION_TYPE_FILE_ACCESS, | 
| + true); | 
| + TestExtensionPrefSetting( | 
| + &util::AllowedScriptingOnAllUrls, | 
| + api::developer_private::PERMISSION_TYPE_RUN_ON_ALL_URLS, | 
| + true); | 
| } | 
| // Test developerPrivate.reload. | 
| @@ -238,12 +259,6 @@ TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateReload) { | 
| EXPECT_EQ(extension_id, reloaded_extension->id()); | 
| } | 
| -// Test developerPrivate.allowFileAccess. | 
| -TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateAllowFileAccess) { | 
| - TestExtensionPrefSetting<api::DeveloperPrivateAllowFileAccessFunction>( | 
| - &util::AllowFileAccess); | 
| -} | 
| - | 
| // Test developerPrivate.packDirectory. | 
| TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivatePackFunction) { | 
| ResetThreadBundle(content::TestBrowserThreadBundle::DEFAULT); |