OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" |
| 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h" |
| 9 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 10 |
| 11 namespace keys = extension_manifest_keys; |
| 12 |
| 13 namespace extensions { |
| 14 |
| 15 class OAuth2ManifestTest : public ExtensionManifestTest { |
| 16 protected: |
| 17 virtual void SetUp() OVERRIDE { |
| 18 ManifestHandler::Register(extension_manifest_keys::kOAuth2, |
| 19 new OAuth2ManifestHandler); |
| 20 } |
| 21 }; |
| 22 |
| 23 TEST_F(OAuth2ManifestTest, OAuth2SectionParsing) { |
| 24 DictionaryValue base_manifest; |
| 25 |
| 26 base_manifest.SetString(keys::kName, "test"); |
| 27 base_manifest.SetString(keys::kVersion, "0.1"); |
| 28 base_manifest.SetInteger(keys::kManifestVersion, 2); |
| 29 base_manifest.SetString(keys::kOAuth2ClientId, "client1"); |
| 30 ListValue* scopes = new ListValue(); |
| 31 scopes->Append(Value::CreateStringValue("scope1")); |
| 32 scopes->Append(Value::CreateStringValue("scope2")); |
| 33 base_manifest.Set(keys::kOAuth2Scopes, scopes); |
| 34 |
| 35 // OAuth2 section should be parsed for an extension. |
| 36 { |
| 37 DictionaryValue ext_manifest; |
| 38 // Lack of "app" section representa an extension. So the base manifest |
| 39 // itself represents an extension. |
| 40 ext_manifest.MergeDictionary(&base_manifest); |
| 41 |
| 42 Manifest manifest(&ext_manifest, "test"); |
| 43 scoped_refptr<extensions::Extension> extension = |
| 44 LoadAndExpectSuccess(manifest); |
| 45 EXPECT_TRUE(extension->install_warnings().empty()); |
| 46 EXPECT_EQ("client1", OAuth2Info::GetOAuth2Info(extension).client_id); |
| 47 EXPECT_EQ(2U, OAuth2Info::GetOAuth2Info(extension).scopes.size()); |
| 48 EXPECT_EQ("scope1", OAuth2Info::GetOAuth2Info(extension).scopes[0]); |
| 49 EXPECT_EQ("scope2", OAuth2Info::GetOAuth2Info(extension).scopes[1]); |
| 50 } |
| 51 |
| 52 // OAuth2 section should be parsed for a packaged app. |
| 53 { |
| 54 DictionaryValue app_manifest; |
| 55 app_manifest.SetString(keys::kLaunchLocalPath, "launch.html"); |
| 56 app_manifest.MergeDictionary(&base_manifest); |
| 57 |
| 58 Manifest manifest(&app_manifest, "test"); |
| 59 scoped_refptr<extensions::Extension> extension = |
| 60 LoadAndExpectSuccess(manifest); |
| 61 EXPECT_TRUE(extension->install_warnings().empty()); |
| 62 EXPECT_EQ("client1", OAuth2Info::GetOAuth2Info(extension).client_id); |
| 63 EXPECT_EQ(2U, OAuth2Info::GetOAuth2Info(extension).scopes.size()); |
| 64 EXPECT_EQ("scope1", OAuth2Info::GetOAuth2Info(extension).scopes[0]); |
| 65 EXPECT_EQ("scope2", OAuth2Info::GetOAuth2Info(extension).scopes[1]); |
| 66 } |
| 67 |
| 68 // OAuth2 section should NOT be parsed for a hosted app. |
| 69 { |
| 70 DictionaryValue app_manifest; |
| 71 app_manifest.SetString(keys::kLaunchWebURL, "http://www.google.com"); |
| 72 app_manifest.MergeDictionary(&base_manifest); |
| 73 |
| 74 Manifest manifest(&app_manifest, "test"); |
| 75 scoped_refptr<extensions::Extension> extension = |
| 76 LoadAndExpectSuccess(manifest); |
| 77 EXPECT_EQ(1U, extension->install_warnings().size()); |
| 78 const extensions::InstallWarning& warning = |
| 79 extension->install_warnings()[0]; |
| 80 EXPECT_EQ("'oauth2' is only allowed for extensions, legacy packaged apps " |
| 81 "and packaged apps, and this is a hosted app.", |
| 82 warning.message); |
| 83 EXPECT_EQ("", OAuth2Info::GetOAuth2Info(extension).client_id); |
| 84 EXPECT_TRUE(OAuth2Info::GetOAuth2Info(extension).scopes.empty()); |
| 85 } |
| 86 } |
| 87 |
| 88 } // namespace extensions |
OLD | NEW |