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