| 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 "base/test/values_test_util.h" | 5 #include "base/test/values_test_util.h" |
| 6 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h" | |
| 7 #include "chrome/common/extensions/manifest_tests/chrome_manifest_test.h" | |
| 8 #include "extensions/common/manifest_constants.h" | 6 #include "extensions/common/manifest_constants.h" |
| 7 #include "extensions/common/manifest_handlers/oauth2_manifest_handler.h" |
| 8 #include "extensions/common/manifest_test.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace extensions { | 11 namespace extensions { |
| 12 | 12 |
| 13 namespace keys = manifest_keys; | 13 namespace keys = manifest_keys; |
| 14 namespace errors = manifest_errors; | 14 namespace errors = manifest_errors; |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // Produces extension ID = "mdbihdcgjmagbcapkhhkjbbdlkflmbfo". | 18 // Produces extension ID = "mdbihdcgjmagbcapkhhkjbbdlkflmbfo". |
| 19 const char kExtensionKey[] = | 19 const char kExtensionKey[] = |
| 20 "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCV9PlZjcTIXfnlB3HXo50OlM/CnIq0y7jm" | 20 "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCV9PlZjcTIXfnlB3HXo50OlM/CnIq0y7jm" |
| 21 "KfPVyStaWsmFB7NaVnqUXoGb9swBDfVnZ6BrupwnxL76TWEJPo+KQMJ6uz0PPdJWi2jQfZiG" | 21 "KfPVyStaWsmFB7NaVnqUXoGb9swBDfVnZ6BrupwnxL76TWEJPo+KQMJ6uz0PPdJWi2jQfZiG" |
| 22 "iheDiKH5Gv+dVd67qf7ly8QWW0o8qmFpqBZQpksm1hOGbfsupv9W4c42tMEIicDMLQIDAQAB"; | 22 "iheDiKH5Gv+dVd67qf7ly8QWW0o8qmFpqBZQpksm1hOGbfsupv9W4c42tMEIicDMLQIDAQAB"; |
| 23 const char kAutoApproveNotAllowedWarning[] = | 23 const char kAutoApproveNotAllowedWarning[] = |
| 24 "'oauth2.auto_approve' is not allowed for specified extension ID."; | 24 "'oauth2.auto_approve' is not allowed for specified extension ID."; |
| 25 | 25 |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 class OAuth2ManifestTest : public ChromeManifestTest { | 28 class OAuth2ManifestTest : public ManifestTest { |
| 29 protected: | 29 protected: |
| 30 enum AutoApproveValue { | 30 enum AutoApproveValue { |
| 31 AUTO_APPROVE_NOT_SET, | 31 AUTO_APPROVE_NOT_SET, |
| 32 AUTO_APPROVE_FALSE, | 32 AUTO_APPROVE_FALSE, |
| 33 AUTO_APPROVE_TRUE, | 33 AUTO_APPROVE_TRUE, |
| 34 AUTO_APPROVE_INVALID | 34 AUTO_APPROVE_INVALID |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 enum ClientIdValue { | 37 enum ClientIdValue { |
| 38 CLIENT_ID_DEFAULT, | 38 CLIENT_ID_DEFAULT, |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 } | 289 } |
| 290 | 290 |
| 291 TEST_F(OAuth2ManifestTest, ComponentWithChromeClientId) { | 291 TEST_F(OAuth2ManifestTest, ComponentWithChromeClientId) { |
| 292 { | 292 { |
| 293 base::DictionaryValue* ext_manifest = | 293 base::DictionaryValue* ext_manifest = |
| 294 CreateManifest(AUTO_APPROVE_TRUE, true, CLIENT_ID_NOT_SET); | 294 CreateManifest(AUTO_APPROVE_TRUE, true, CLIENT_ID_NOT_SET); |
| 295 ManifestData manifest(ext_manifest, "test"); | 295 ManifestData manifest(ext_manifest, "test"); |
| 296 scoped_refptr<extensions::Extension> extension = | 296 scoped_refptr<extensions::Extension> extension = |
| 297 LoadAndExpectSuccess(manifest, extensions::Manifest::COMPONENT); | 297 LoadAndExpectSuccess(manifest, extensions::Manifest::COMPONENT); |
| 298 EXPECT_TRUE(OAuth2Info::GetOAuth2Info(extension.get()).client_id.empty()); | 298 EXPECT_TRUE(OAuth2Info::GetOAuth2Info(extension.get()).client_id.empty()); |
| 299 | |
| 300 } | 299 } |
| 301 | 300 |
| 302 { | 301 { |
| 303 base::DictionaryValue* ext_manifest = | 302 base::DictionaryValue* ext_manifest = |
| 304 CreateManifest(AUTO_APPROVE_TRUE, true, CLIENT_ID_EMPTY); | 303 CreateManifest(AUTO_APPROVE_TRUE, true, CLIENT_ID_EMPTY); |
| 305 ManifestData manifest(ext_manifest, "test"); | 304 ManifestData manifest(ext_manifest, "test"); |
| 306 scoped_refptr<extensions::Extension> extension = | 305 scoped_refptr<extensions::Extension> extension = |
| 307 LoadAndExpectSuccess(manifest, extensions::Manifest::COMPONENT); | 306 LoadAndExpectSuccess(manifest, extensions::Manifest::COMPONENT); |
| 308 EXPECT_TRUE(OAuth2Info::GetOAuth2Info(extension.get()).client_id.empty()); | 307 EXPECT_TRUE(OAuth2Info::GetOAuth2Info(extension.get()).client_id.empty()); |
| 309 | |
| 310 } | 308 } |
| 311 } | 309 } |
| 312 | 310 |
| 313 TEST_F(OAuth2ManifestTest, ComponentWithStandardClientId) { | 311 TEST_F(OAuth2ManifestTest, ComponentWithStandardClientId) { |
| 314 base::DictionaryValue* ext_manifest = | 312 base::DictionaryValue* ext_manifest = |
| 315 CreateManifest(AUTO_APPROVE_TRUE, true, CLIENT_ID_DEFAULT); | 313 CreateManifest(AUTO_APPROVE_TRUE, true, CLIENT_ID_DEFAULT); |
| 316 ManifestData manifest(ext_manifest, "test"); | 314 ManifestData manifest(ext_manifest, "test"); |
| 317 scoped_refptr<extensions::Extension> extension = | 315 scoped_refptr<extensions::Extension> extension = |
| 318 LoadAndExpectSuccess(manifest, extensions::Manifest::COMPONENT); | 316 LoadAndExpectSuccess(manifest, extensions::Manifest::COMPONENT); |
| 319 EXPECT_EQ("client1", OAuth2Info::GetOAuth2Info(extension.get()).client_id); | 317 EXPECT_EQ("client1", OAuth2Info::GetOAuth2Info(extension.get()).client_id); |
| 320 } | 318 } |
| 321 | 319 |
| 322 } // namespace extensions | 320 } // namespace extensions |
| OLD | NEW |