| 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 "extensions/common/extension_api.h" | 5 #include "extensions/common/extension_api.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 const char* const kTestFeatures[] = { | 37 const char* const kTestFeatures[] = { |
| 38 "test1", "test2", "test3", "test4", "test5", | 38 "test1", "test2", "test3", "test4", "test5", |
| 39 "test6", "test7", "parent1", "parent2", "parent3", | 39 "test6", "test7", "parent1", "parent2", "parent3", |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 const char* const kAliasTestApis[] = {"alias_api_source"}; | 42 const char* const kAliasTestApis[] = {"alias_api_source"}; |
| 43 | 43 |
| 44 const char* const kSessionTypeTestFeatures[] = { | 44 const char* const kSessionTypeTestFeatures[] = { |
| 45 "test1", "kiosk_only", "non_kiosk", "multiple_session_types"}; | 45 "test6", "kiosk_only", "non_kiosk", "multiple_session_types", |
| 46 "autolaunched_kiosk"}; |
| 46 | 47 |
| 47 struct FeatureSessionTypesTestData { | 48 struct FeatureSessionTypesTestData { |
| 48 std::string api_name; | 49 std::string api_name; |
| 49 bool expect_available; | 50 bool expect_available; |
| 50 FeatureSessionType current_session_type; | 51 FeatureSessionType current_session_type; |
| 51 }; | 52 }; |
| 52 | 53 |
| 53 class TestExtensionAPI : public ExtensionAPI { | 54 class TestExtensionAPI : public ExtensionAPI { |
| 54 public: | 55 public: |
| 55 TestExtensionAPI() {} | 56 TestExtensionAPI() {} |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 ASSERT_TRUE(test_feature); | 331 ASSERT_TRUE(test_feature); |
| 331 EXPECT_EQ(test_data[i].expect_is_available, | 332 EXPECT_EQ(test_data[i].expect_is_available, |
| 332 api.IsAnyFeatureAvailableToContext( | 333 api.IsAnyFeatureAvailableToContext( |
| 333 *test_feature, test_data[i].extension, test_data[i].context, | 334 *test_feature, test_data[i].extension, test_data[i].context, |
| 334 test_data[i].url, CheckAliasStatus::NOT_ALLOWED)) | 335 test_data[i].url, CheckAliasStatus::NOT_ALLOWED)) |
| 335 << i; | 336 << i; |
| 336 } | 337 } |
| 337 } | 338 } |
| 338 | 339 |
| 339 TEST(ExtensionAPITest, SessionTypeFeature) { | 340 TEST(ExtensionAPITest, SessionTypeFeature) { |
| 341 scoped_refptr<const Extension> app = |
| 342 ExtensionBuilder() |
| 343 .SetManifest( |
| 344 DictionaryBuilder() |
| 345 .Set("name", "app") |
| 346 .Set("app", |
| 347 DictionaryBuilder() |
| 348 .Set("background", |
| 349 DictionaryBuilder() |
| 350 .Set("scripts", ListBuilder() |
| 351 .Append("background.js") |
| 352 .Build()) |
| 353 .Build()) |
| 354 .Build()) |
| 355 .Set("version", "1") |
| 356 .Set("manifest_version", 2) |
| 357 .Build()) |
| 358 .Build(); |
| 359 |
| 340 const std::vector<FeatureSessionTypesTestData> kTestData( | 360 const std::vector<FeatureSessionTypesTestData> kTestData( |
| 341 {{"kiosk_only", true, FeatureSessionType::KIOSK}, | 361 {{"kiosk_only", true, FeatureSessionType::KIOSK}, |
| 362 {"kiosk_only", true, FeatureSessionType::AUTOLAUNCHED_KIOSK}, |
| 342 {"kiosk_only", false, FeatureSessionType::REGULAR}, | 363 {"kiosk_only", false, FeatureSessionType::REGULAR}, |
| 343 {"kiosk_only", false, FeatureSessionType::UNKNOWN}, | 364 {"kiosk_only", false, FeatureSessionType::UNKNOWN}, |
| 344 {"non_kiosk", false, FeatureSessionType::KIOSK}, | 365 {"non_kiosk", false, FeatureSessionType::KIOSK}, |
| 345 {"non_kiosk", true, FeatureSessionType::REGULAR}, | 366 {"non_kiosk", true, FeatureSessionType::REGULAR}, |
| 346 {"non_kiosk", false, FeatureSessionType::UNKNOWN}, | 367 {"non_kiosk", false, FeatureSessionType::UNKNOWN}, |
| 368 {"autolaunched_kiosk", true, FeatureSessionType::AUTOLAUNCHED_KIOSK}, |
| 369 {"autolaunched_kiosk", false, FeatureSessionType::KIOSK}, |
| 370 {"autolaunched_kiosk", false, FeatureSessionType::REGULAR}, |
| 347 {"multiple_session_types", true, FeatureSessionType::KIOSK}, | 371 {"multiple_session_types", true, FeatureSessionType::KIOSK}, |
| 348 {"multiple_session_types", true, FeatureSessionType::REGULAR}, | 372 {"multiple_session_types", true, FeatureSessionType::REGULAR}, |
| 349 {"multiple_session_types", false, FeatureSessionType::UNKNOWN}, | 373 {"multiple_session_types", false, FeatureSessionType::UNKNOWN}, |
| 350 {"test1", true, FeatureSessionType::KIOSK}, | 374 // test6.foo is available to apps and has no session type restrictions. |
| 351 {"test1", true, FeatureSessionType::REGULAR}, | 375 {"test6.foo", true, FeatureSessionType::KIOSK}, |
| 352 {"test1", true, FeatureSessionType::UNKNOWN}}); | 376 {"test6.foo", true, FeatureSessionType::AUTOLAUNCHED_KIOSK}, |
| 377 {"test6.foo", true, FeatureSessionType::REGULAR}, |
| 378 {"test6.foo", true, FeatureSessionType::UNKNOWN}}); |
| 353 | 379 |
| 354 UnittestFeatureProvider api_feature_provider; | 380 UnittestFeatureProvider api_feature_provider; |
| 355 | 381 |
| 356 for (const auto& test : kTestData) { | 382 for (const auto& test : kTestData) { |
| 357 TestExtensionAPI api; | 383 TestExtensionAPI api; |
| 358 api.RegisterDependencyProvider("api", &api_feature_provider); | 384 api.RegisterDependencyProvider("api", &api_feature_provider); |
| 359 for (const auto& key : kSessionTypeTestFeatures) | 385 for (const auto& key : kSessionTypeTestFeatures) |
| 360 api.add_fake_schema(key); | 386 api.add_fake_schema(key); |
| 361 ExtensionAPI::OverrideSharedInstanceForTest scope(&api); | 387 ExtensionAPI::OverrideSharedInstanceForTest scope(&api); |
| 362 | 388 |
| 363 std::unique_ptr<base::AutoReset<FeatureSessionType>> current_session( | 389 std::unique_ptr<base::AutoReset<FeatureSessionType>> current_session( |
| 364 ScopedCurrentFeatureSessionType(test.current_session_type)); | 390 ScopedCurrentFeatureSessionType(test.current_session_type)); |
| 365 EXPECT_EQ(test.expect_available, | 391 EXPECT_EQ(test.expect_available, |
| 366 api.IsAvailable(test.api_name, nullptr, | 392 api.IsAvailable(test.api_name, app.get(), |
| 367 Feature::BLESSED_EXTENSION_CONTEXT, GURL(), | 393 Feature::BLESSED_EXTENSION_CONTEXT, GURL(), |
| 368 CheckAliasStatus::NOT_ALLOWED) | 394 CheckAliasStatus::NOT_ALLOWED) |
| 369 .is_available()) | 395 .is_available()) |
| 370 << "Test case (" << test.api_name << ", " | 396 << "Test case (" << test.api_name << ", " |
| 371 << static_cast<int>(test.current_session_type) << ")."; | 397 << static_cast<int>(test.current_session_type) << ")."; |
| 372 } | 398 } |
| 373 } | 399 } |
| 374 | 400 |
| 375 TEST(ExtensionAPITest, LazyGetSchema) { | 401 TEST(ExtensionAPITest, LazyGetSchema) { |
| 376 std::unique_ptr<ExtensionAPI> apis( | 402 std::unique_ptr<ExtensionAPI> apis( |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 CheckAliasStatus::NOT_ALLOWED) | 946 CheckAliasStatus::NOT_ALLOWED) |
| 921 .is_available()); | 947 .is_available()); |
| 922 EXPECT_FALSE(extension_api | 948 EXPECT_FALSE(extension_api |
| 923 ->IsAvailable("pageAction", extension.get(), | 949 ->IsAvailable("pageAction", extension.get(), |
| 924 Feature::BLESSED_EXTENSION_CONTEXT, GURL(), | 950 Feature::BLESSED_EXTENSION_CONTEXT, GURL(), |
| 925 CheckAliasStatus::NOT_ALLOWED) | 951 CheckAliasStatus::NOT_ALLOWED) |
| 926 .is_available()); | 952 .is_available()); |
| 927 } | 953 } |
| 928 | 954 |
| 929 } // namespace extensions | 955 } // namespace extensions |
| OLD | NEW |