Chromium Code Reviews| Index: extensions/common/features/simple_feature_unittest.cc |
| diff --git a/extensions/common/features/simple_feature_unittest.cc b/extensions/common/features/simple_feature_unittest.cc |
| index 662cf280e07642859345b1c4a9b2efd89d81ad74..65a62ec815d79f7307b26a6abe829d5d28fd22a6 100644 |
| --- a/extensions/common/features/simple_feature_unittest.cc |
| +++ b/extensions/common/features/simple_feature_unittest.cc |
| @@ -7,6 +7,7 @@ |
| #include <stddef.h> |
| #include <string> |
| +#include <vector> |
| #include "base/command_line.h" |
| #include "base/macros.h" |
| @@ -16,6 +17,7 @@ |
| #include "extensions/common/features/api_feature.h" |
| #include "extensions/common/features/complex_feature.h" |
| #include "extensions/common/features/feature_channel.h" |
| +#include "extensions/common/features/feature_session_type.h" |
| #include "extensions/common/features/json_feature_provider.h" |
| #include "extensions/common/features/permission_feature.h" |
| #include "extensions/common/manifest.h" |
| @@ -402,6 +404,96 @@ TEST_F(SimpleFeatureTest, Context) { |
| feature.set_max_manifest_version(25); |
| } |
| +TEST_F(SimpleFeatureTest, SessionType) { |
| + base::DictionaryValue manifest; |
| + manifest.SetString("name", "test"); |
| + manifest.SetString("version", "1"); |
| + manifest.SetInteger("manifest_version", 21); |
| + manifest.SetString("app.launch.local_path", "foo.html"); |
| + |
| + std::string error; |
| + scoped_refptr<const Extension> extension( |
| + Extension::Create(base::FilePath(), Manifest::INTERNAL, manifest, |
| + Extension::NO_FLAGS, &error)); |
| + EXPECT_EQ("", error); |
| + ASSERT_TRUE(extension.get()); |
| + |
| + struct { |
|
xiyuan
2016/08/18 21:24:00
nit: const
tbarzic
2016/08/18 22:18:56
Done.
|
| + std::string desc; |
| + Feature::AvailabilityResult expected_availability; |
| + FeatureSessionType current_session_type; |
| + std::initializer_list<FeatureSessionType> feature_session_types; |
| + } test_data[] = {{"kiosk_feature in kiosk session", |
|
xiyuan
2016/08/18 21:24:00
nit: test_data -> kTestData
tbarzic
2016/08/18 22:18:56
Done.
|
| + Feature::IS_AVAILABLE, |
| + FeatureSessionType::KIOSK, |
| + {FeatureSessionType::KIOSK}}, |
| + {"kiosk feature in regular session", |
| + Feature::INVALID_SESSION_TYPE, |
| + FeatureSessionType::REGULAR, |
| + {FeatureSessionType::KIOSK}}, |
| + {"kiosk feature in unknown session", |
| + Feature::INVALID_SESSION_TYPE, |
| + FeatureSessionType::UNKNOWN, |
| + {FeatureSessionType::KIOSK}}, |
| + {"non kiosk feature in kiosk session", |
| + Feature::INVALID_SESSION_TYPE, |
| + FeatureSessionType::KIOSK, |
| + {FeatureSessionType::REGULAR}}, |
| + {"non kiosk feature in regular session", |
| + Feature::IS_AVAILABLE, |
| + FeatureSessionType::REGULAR, |
| + {FeatureSessionType::REGULAR}}, |
| + {"non kiosk feature in unknown session", |
| + Feature::INVALID_SESSION_TYPE, |
| + FeatureSessionType::UNKNOWN, |
| + {FeatureSessionType::REGULAR}}, |
| + {"session agnostic feature in kiosk session", |
| + Feature::IS_AVAILABLE, |
| + FeatureSessionType::KIOSK, |
| + {}}, |
| + {"session_agnostic feature in regular session", |
| + Feature::IS_AVAILABLE, |
| + FeatureSessionType::REGULAR, |
| + {}}, |
| + {"session agnostic feature in unknown session", |
| + Feature::IS_AVAILABLE, |
| + FeatureSessionType::UNKNOWN, |
| + {}}, |
| + {"feature with multiple session types", |
| + Feature::IS_AVAILABLE, |
| + FeatureSessionType::REGULAR, |
| + {FeatureSessionType::REGULAR, FeatureSessionType::KIOSK}}, |
| + {"feature with multiple session types in unknown session", |
| + Feature::INVALID_SESSION_TYPE, |
| + FeatureSessionType::UNKNOWN, |
| + {FeatureSessionType::REGULAR, FeatureSessionType::KIOSK}}}; |
| + |
| + for (size_t i = 0; i < arraysize(test_data); ++i) { |
|
rkc
2016/08/18 20:35:28
Make test_data a vector, then use,
for (const auto
tbarzic
2016/08/18 22:18:56
Done.
|
| + std::unique_ptr<base::AutoReset<FeatureSessionType>> current_session( |
| + ScopedCurrentFeatureSessionType(test_data[i].current_session_type)); |
| + |
| + SimpleFeature feature; |
| + feature.set_session_types(test_data[i].feature_session_types); |
| + |
| + EXPECT_EQ(test_data[i].expected_availability, |
| + feature |
| + .IsAvailableToContext(extension.get(), |
| + Feature::BLESSED_EXTENSION_CONTEXT, |
| + Feature::CHROMEOS_PLATFORM) |
| + .result()) |
| + << "Failed test " << i << " (" << test_data[i].desc << ")."; |
| + |
| + EXPECT_EQ( |
| + Feature::IS_AVAILABLE, |
| + feature |
| + .IsAvailableToManifest(extension->id(), Manifest::TYPE_UNKNOWN, |
| + Manifest::INVALID_LOCATION, -1, |
| + Feature::CHROMEOS_PLATFORM) |
| + .result()) |
| + << "Failed test " << i << " (" << test_data[i].desc << ")."; |
| + } |
| +} |
| + |
| TEST_F(SimpleFeatureTest, Location) { |
| // Component extensions can access any location. |
| EXPECT_TRUE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION, |