diff options
author | olli.raula <olli.raula@intel.com> | 2015-11-17 00:48:57 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-17 08:49:32 +0000 |
commit | f0c74ba417388d1e120713b12022299e3a0ca84e (patch) | |
tree | 0308d3deb546c3f13778bd3ee4823d47bcb940bb /extensions/common/manifest_handlers | |
parent | 5f1951ded893fd0ffb804ea2a5d88d5524b6dbb9 (diff) | |
download | chromium_src-f0c74ba417388d1e120713b12022299e3a0ca84e.zip chromium_src-f0c74ba417388d1e120713b12022299e3a0ca84e.tar.gz chromium_src-f0c74ba417388d1e120713b12022299e3a0ca84e.tar.bz2 |
Clean code related to ManifestTest::ManifestData
Added more use of scoped_ptr and cleaned the code.
Review URL: https://codereview.chromium.org/1438723002
Cr-Commit-Position: refs/heads/master@{#360039}
Diffstat (limited to 'extensions/common/manifest_handlers')
-rw-r--r-- | extensions/common/manifest_handlers/oauth2_manifest_unittest.cc | 99 |
1 files changed, 48 insertions, 51 deletions
diff --git a/extensions/common/manifest_handlers/oauth2_manifest_unittest.cc b/extensions/common/manifest_handlers/oauth2_manifest_unittest.cc index bd22eb5..e52a103 100644 --- a/extensions/common/manifest_handlers/oauth2_manifest_unittest.cc +++ b/extensions/common/manifest_handlers/oauth2_manifest_unittest.cc @@ -40,50 +40,47 @@ class OAuth2ManifestTest : public ManifestTest { CLIENT_ID_EMPTY }; - base::DictionaryValue* CreateManifest( + scoped_ptr<base::DictionaryValue> CreateManifest( AutoApproveValue auto_approve, bool extension_id_whitelisted, ClientIdValue client_id) { - parsed_manifest_.reset(base::test::ParseJson( - "{ \n" - " \"name\": \"test\", \n" - " \"version\": \"0.1\", \n" - " \"manifest_version\": 2, \n" - " \"oauth2\": { \n" - " \"scopes\": [ \"scope1\" ], \n" - " }, \n" - "} \n").release()); - base::DictionaryValue* ext_manifest; - EXPECT_TRUE(parsed_manifest_->GetAsDictionary(&ext_manifest)); + scoped_ptr<base::DictionaryValue> manifest = base::DictionaryValue::From( + base::test::ParseJson("{ \n" + " \"name\": \"test\", \n" + " \"version\": \"0.1\", \n" + " \"manifest_version\": 2, \n" + " \"oauth2\": { \n" + " \"scopes\": [ \"scope1\" ], \n" + " }, \n" + "} \n")); + EXPECT_TRUE(manifest); switch (auto_approve) { case AUTO_APPROVE_NOT_SET: break; case AUTO_APPROVE_FALSE: - ext_manifest->SetBoolean(keys::kOAuth2AutoApprove, false); + manifest->SetBoolean(keys::kOAuth2AutoApprove, false); break; case AUTO_APPROVE_TRUE: - ext_manifest->SetBoolean(keys::kOAuth2AutoApprove, true); + manifest->SetBoolean(keys::kOAuth2AutoApprove, true); break; case AUTO_APPROVE_INVALID: - ext_manifest->SetString(keys::kOAuth2AutoApprove, "incorrect value"); + manifest->SetString(keys::kOAuth2AutoApprove, "incorrect value"); break; } switch (client_id) { case CLIENT_ID_DEFAULT: - ext_manifest->SetString(keys::kOAuth2ClientId, "client1"); + manifest->SetString(keys::kOAuth2ClientId, "client1"); break; case CLIENT_ID_NOT_SET: break; case CLIENT_ID_EMPTY: - ext_manifest->SetString(keys::kOAuth2ClientId, ""); + manifest->SetString(keys::kOAuth2ClientId, ""); } if (extension_id_whitelisted) - ext_manifest->SetString(keys::kKey, kExtensionKey); - return ext_manifest; + manifest->SetString(keys::kKey, kExtensionKey); + return manifest; } - private: - scoped_ptr<base::Value> parsed_manifest_; }; TEST_F(OAuth2ManifestTest, OAuth2SectionParsing) { @@ -157,9 +154,9 @@ TEST_F(OAuth2ManifestTest, OAuth2SectionParsing) { } TEST_F(OAuth2ManifestTest, AutoApproveNotSetExtensionNotOnWhitelist) { - base::DictionaryValue* ext_manifest = + scoped_ptr<base::DictionaryValue> ext_manifest = CreateManifest(AUTO_APPROVE_NOT_SET, false, CLIENT_ID_DEFAULT); - ManifestData manifest(ext_manifest, "test"); + ManifestData manifest(ext_manifest.Pass(), "test"); scoped_refptr<extensions::Extension> extension = LoadAndExpectSuccess(manifest); EXPECT_TRUE(extension->install_warnings().empty()); @@ -167,9 +164,9 @@ TEST_F(OAuth2ManifestTest, AutoApproveNotSetExtensionNotOnWhitelist) { } TEST_F(OAuth2ManifestTest, AutoApproveFalseExtensionNotOnWhitelist) { - base::DictionaryValue* ext_manifest = + scoped_ptr<base::DictionaryValue> ext_manifest = CreateManifest(AUTO_APPROVE_FALSE, false, CLIENT_ID_DEFAULT); - ManifestData manifest(ext_manifest, "test"); + ManifestData manifest(ext_manifest.Pass(), "test"); scoped_refptr<extensions::Extension> extension = LoadAndExpectSuccess(manifest); EXPECT_EQ(1U, extension->install_warnings().size()); @@ -180,9 +177,9 @@ TEST_F(OAuth2ManifestTest, AutoApproveFalseExtensionNotOnWhitelist) { } TEST_F(OAuth2ManifestTest, AutoApproveTrueExtensionNotOnWhitelist) { - base::DictionaryValue* ext_manifest = + scoped_ptr<base::DictionaryValue> ext_manifest = CreateManifest(AUTO_APPROVE_TRUE, false, CLIENT_ID_DEFAULT); - ManifestData manifest(ext_manifest, "test"); + ManifestData manifest(ext_manifest.Pass(), "test"); scoped_refptr<extensions::Extension> extension = LoadAndExpectSuccess(manifest); EXPECT_EQ(1U, extension->install_warnings().size()); @@ -193,9 +190,9 @@ TEST_F(OAuth2ManifestTest, AutoApproveTrueExtensionNotOnWhitelist) { } TEST_F(OAuth2ManifestTest, AutoApproveInvalidExtensionNotOnWhitelist) { - base::DictionaryValue* ext_manifest = + scoped_ptr<base::DictionaryValue> ext_manifest = CreateManifest(AUTO_APPROVE_INVALID, false, CLIENT_ID_DEFAULT); - ManifestData manifest(ext_manifest, "test"); + ManifestData manifest(ext_manifest.Pass(), "test"); scoped_refptr<extensions::Extension> extension = LoadAndExpectSuccess(manifest); EXPECT_EQ(1U, extension->install_warnings().size()); @@ -206,9 +203,9 @@ TEST_F(OAuth2ManifestTest, AutoApproveInvalidExtensionNotOnWhitelist) { } TEST_F(OAuth2ManifestTest, AutoApproveNotSetExtensionOnWhitelist) { - base::DictionaryValue* ext_manifest = + scoped_ptr<base::DictionaryValue> ext_manifest = CreateManifest(AUTO_APPROVE_NOT_SET, true, CLIENT_ID_DEFAULT); - ManifestData manifest(ext_manifest, "test"); + ManifestData manifest(ext_manifest.Pass(), "test"); scoped_refptr<extensions::Extension> extension = LoadAndExpectSuccess(manifest); EXPECT_TRUE(extension->install_warnings().empty()); @@ -216,9 +213,9 @@ TEST_F(OAuth2ManifestTest, AutoApproveNotSetExtensionOnWhitelist) { } TEST_F(OAuth2ManifestTest, AutoApproveFalseExtensionOnWhitelist) { - base::DictionaryValue* ext_manifest = + scoped_ptr<base::DictionaryValue> ext_manifest = CreateManifest(AUTO_APPROVE_FALSE, true, CLIENT_ID_DEFAULT); - ManifestData manifest(ext_manifest, "test"); + ManifestData manifest(ext_manifest.Pass(), "test"); scoped_refptr<extensions::Extension> extension = LoadAndExpectSuccess(manifest); EXPECT_TRUE(extension->install_warnings().empty()); @@ -226,9 +223,9 @@ TEST_F(OAuth2ManifestTest, AutoApproveFalseExtensionOnWhitelist) { } TEST_F(OAuth2ManifestTest, AutoApproveTrueExtensionOnWhitelist) { - base::DictionaryValue* ext_manifest = + scoped_ptr<base::DictionaryValue> ext_manifest = CreateManifest(AUTO_APPROVE_TRUE, true, CLIENT_ID_DEFAULT); - ManifestData manifest(ext_manifest, "test"); + ManifestData manifest(ext_manifest.Pass(), "test"); scoped_refptr<extensions::Extension> extension = LoadAndExpectSuccess(manifest); EXPECT_TRUE(extension->install_warnings().empty()); @@ -236,9 +233,9 @@ TEST_F(OAuth2ManifestTest, AutoApproveTrueExtensionOnWhitelist) { } TEST_F(OAuth2ManifestTest, AutoApproveInvalidExtensionOnWhitelist) { - base::DictionaryValue* ext_manifest = + scoped_ptr<base::DictionaryValue> ext_manifest = CreateManifest(AUTO_APPROVE_INVALID, true, CLIENT_ID_DEFAULT); - ManifestData manifest(ext_manifest, "test"); + ManifestData manifest(ext_manifest.Pass(), "test"); std::string error; scoped_refptr<extensions::Extension> extension = LoadExtension(manifest, &error); @@ -249,17 +246,17 @@ TEST_F(OAuth2ManifestTest, AutoApproveInvalidExtensionOnWhitelist) { TEST_F(OAuth2ManifestTest, InvalidClientId) { { - base::DictionaryValue* ext_manifest = + scoped_ptr<base::DictionaryValue> ext_manifest = CreateManifest(AUTO_APPROVE_NOT_SET, false, CLIENT_ID_NOT_SET); - ManifestData manifest(ext_manifest, "test"); + ManifestData manifest(ext_manifest.Pass(), "test"); std::string error; LoadAndExpectError(manifest, errors::kInvalidOAuth2ClientId); } { - base::DictionaryValue* ext_manifest = + scoped_ptr<base::DictionaryValue> ext_manifest = CreateManifest(AUTO_APPROVE_NOT_SET, false, CLIENT_ID_EMPTY); - ManifestData manifest(ext_manifest, "test"); + ManifestData manifest(ext_manifest.Pass(), "test"); std::string error; LoadAndExpectError(manifest, errors::kInvalidOAuth2ClientId); } @@ -268,9 +265,9 @@ TEST_F(OAuth2ManifestTest, InvalidClientId) { TEST_F(OAuth2ManifestTest, ComponentInvalidClientId) { // Component Apps without auto_approve must include a client ID. { - base::DictionaryValue* ext_manifest = + scoped_ptr<base::DictionaryValue> ext_manifest = CreateManifest(AUTO_APPROVE_NOT_SET, false, CLIENT_ID_NOT_SET); - ManifestData manifest(ext_manifest, "test"); + ManifestData manifest(ext_manifest.Pass(), "test"); std::string error; LoadAndExpectError(manifest, errors::kInvalidOAuth2ClientId, @@ -278,9 +275,9 @@ TEST_F(OAuth2ManifestTest, ComponentInvalidClientId) { } { - base::DictionaryValue* ext_manifest = + scoped_ptr<base::DictionaryValue> ext_manifest = CreateManifest(AUTO_APPROVE_NOT_SET, false, CLIENT_ID_EMPTY); - ManifestData manifest(ext_manifest, "test"); + ManifestData manifest(ext_manifest.Pass(), "test"); std::string error; LoadAndExpectError(manifest, errors::kInvalidOAuth2ClientId, @@ -290,18 +287,18 @@ TEST_F(OAuth2ManifestTest, ComponentInvalidClientId) { TEST_F(OAuth2ManifestTest, ComponentWithChromeClientId) { { - base::DictionaryValue* ext_manifest = + scoped_ptr<base::DictionaryValue> ext_manifest = CreateManifest(AUTO_APPROVE_TRUE, true, CLIENT_ID_NOT_SET); - ManifestData manifest(ext_manifest, "test"); + ManifestData manifest(ext_manifest.Pass(), "test"); scoped_refptr<extensions::Extension> extension = LoadAndExpectSuccess(manifest, extensions::Manifest::COMPONENT); EXPECT_TRUE(OAuth2Info::GetOAuth2Info(extension.get()).client_id.empty()); } { - base::DictionaryValue* ext_manifest = + scoped_ptr<base::DictionaryValue> ext_manifest = CreateManifest(AUTO_APPROVE_TRUE, true, CLIENT_ID_EMPTY); - ManifestData manifest(ext_manifest, "test"); + ManifestData manifest(ext_manifest.Pass(), "test"); scoped_refptr<extensions::Extension> extension = LoadAndExpectSuccess(manifest, extensions::Manifest::COMPONENT); EXPECT_TRUE(OAuth2Info::GetOAuth2Info(extension.get()).client_id.empty()); @@ -309,9 +306,9 @@ TEST_F(OAuth2ManifestTest, ComponentWithChromeClientId) { } TEST_F(OAuth2ManifestTest, ComponentWithStandardClientId) { - base::DictionaryValue* ext_manifest = + scoped_ptr<base::DictionaryValue> ext_manifest = CreateManifest(AUTO_APPROVE_TRUE, true, CLIENT_ID_DEFAULT); - ManifestData manifest(ext_manifest, "test"); + ManifestData manifest(ext_manifest.Pass(), "test"); scoped_refptr<extensions::Extension> extension = LoadAndExpectSuccess(manifest, extensions::Manifest::COMPONENT); EXPECT_EQ("client1", OAuth2Info::GetOAuth2Info(extension.get()).client_id); |