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> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
21 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
22 #include "chrome/common/extensions/extension_features_unittest.h" | 22 #include "chrome/common/extensions/extension_features_unittest.h" |
23 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
24 #include "extensions/common/extension_builder.h" | 24 #include "extensions/common/extension_builder.h" |
| 25 #include "extensions/common/features/feature_session_type.h" |
25 #include "extensions/common/features/simple_feature.h" | 26 #include "extensions/common/features/simple_feature.h" |
26 #include "extensions/common/manifest.h" | 27 #include "extensions/common/manifest.h" |
27 #include "extensions/common/manifest_constants.h" | 28 #include "extensions/common/manifest_constants.h" |
28 #include "extensions/common/test_util.h" | 29 #include "extensions/common/test_util.h" |
29 #include "extensions/common/value_builder.h" | 30 #include "extensions/common/value_builder.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
31 | 32 |
32 namespace extensions { | 33 namespace extensions { |
33 | 34 |
34 namespace { | 35 namespace { |
35 | 36 |
36 const char* const kTestFeatures[] = { | 37 const char* const kTestFeatures[] = { |
37 "test1", "test2", "test3", "test4", "test5", | 38 "test1", "test2", "test3", "test4", "test5", |
38 "test6", "test7", "parent1", "parent2", "parent3", | 39 "test6", "test7", "parent1", "parent2", "parent3", |
39 }; | 40 }; |
40 | 41 |
| 42 const char* const kSessionTypeTestFeatures[] = { |
| 43 "test1", "kiosk_only", "non_kiosk", "multiple_session_types"}; |
| 44 |
| 45 struct FeatureSessionTypesTestData { |
| 46 std::string api_name; |
| 47 bool expect_available; |
| 48 FeatureSessionType current_session_type; |
| 49 }; |
| 50 |
41 class TestExtensionAPI : public ExtensionAPI { | 51 class TestExtensionAPI : public ExtensionAPI { |
42 public: | 52 public: |
43 TestExtensionAPI() {} | 53 TestExtensionAPI() {} |
44 ~TestExtensionAPI() override {} | 54 ~TestExtensionAPI() override {} |
45 | 55 |
46 void add_fake_schema(const std::string& name) { fake_schemas_.insert(name); } | 56 void add_fake_schema(const std::string& name) { fake_schemas_.insert(name); } |
47 | 57 |
48 private: | 58 private: |
49 bool IsKnownAPI(const std::string& name, ExtensionsClient* client) override { | 59 bool IsKnownAPI(const std::string& name, ExtensionsClient* client) override { |
50 return fake_schemas_.count(name) != 0; | 60 return fake_schemas_.count(name) != 0; |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 ASSERT_TRUE(test_feature); | 284 ASSERT_TRUE(test_feature); |
275 EXPECT_EQ(test_data[i].expect_is_available, | 285 EXPECT_EQ(test_data[i].expect_is_available, |
276 api.IsAnyFeatureAvailableToContext(*test_feature, | 286 api.IsAnyFeatureAvailableToContext(*test_feature, |
277 test_data[i].extension, | 287 test_data[i].extension, |
278 test_data[i].context, | 288 test_data[i].context, |
279 test_data[i].url)) | 289 test_data[i].url)) |
280 << i; | 290 << i; |
281 } | 291 } |
282 } | 292 } |
283 | 293 |
| 294 TEST(ExtensionAPITest, SessionTypeFeature) { |
| 295 const std::vector<FeatureSessionTypesTestData> kTestData( |
| 296 {{"kiosk_only", true, FeatureSessionType::KIOSK}, |
| 297 {"kiosk_only", false, FeatureSessionType::REGULAR}, |
| 298 {"kiosk_only", false, FeatureSessionType::UNKNOWN}, |
| 299 {"non_kiosk", false, FeatureSessionType::KIOSK}, |
| 300 {"non_kiosk", true, FeatureSessionType::REGULAR}, |
| 301 {"non_kiosk", false, FeatureSessionType::UNKNOWN}, |
| 302 {"multiple_session_types", true, FeatureSessionType::KIOSK}, |
| 303 {"multiple_session_types", true, FeatureSessionType::REGULAR}, |
| 304 {"multiple_session_types", false, FeatureSessionType::UNKNOWN}, |
| 305 {"test1", true, FeatureSessionType::KIOSK}, |
| 306 {"test1", true, FeatureSessionType::REGULAR}, |
| 307 {"test1", true, FeatureSessionType::UNKNOWN}}); |
| 308 |
| 309 UnittestFeatureProvider api_feature_provider; |
| 310 |
| 311 for (const auto& test : kTestData) { |
| 312 TestExtensionAPI api; |
| 313 api.RegisterDependencyProvider("api", &api_feature_provider); |
| 314 for (const auto& key : kSessionTypeTestFeatures) |
| 315 api.add_fake_schema(key); |
| 316 ExtensionAPI::OverrideSharedInstanceForTest scope(&api); |
| 317 |
| 318 std::unique_ptr<base::AutoReset<FeatureSessionType>> current_session( |
| 319 ScopedCurrentFeatureSessionType(test.current_session_type)); |
| 320 EXPECT_EQ(test.expect_available, |
| 321 api.IsAvailable(test.api_name, nullptr, |
| 322 Feature::BLESSED_EXTENSION_CONTEXT, GURL()) |
| 323 .is_available()) |
| 324 << "Test case (" << test.api_name << ", " |
| 325 << static_cast<int>(test.current_session_type) << ")."; |
| 326 } |
| 327 } |
| 328 |
284 TEST(ExtensionAPITest, LazyGetSchema) { | 329 TEST(ExtensionAPITest, LazyGetSchema) { |
285 std::unique_ptr<ExtensionAPI> apis( | 330 std::unique_ptr<ExtensionAPI> apis( |
286 ExtensionAPI::CreateWithDefaultConfiguration()); | 331 ExtensionAPI::CreateWithDefaultConfiguration()); |
287 | 332 |
288 EXPECT_EQ(NULL, apis->GetSchema(std::string())); | 333 EXPECT_EQ(NULL, apis->GetSchema(std::string())); |
289 EXPECT_EQ(NULL, apis->GetSchema(std::string())); | 334 EXPECT_EQ(NULL, apis->GetSchema(std::string())); |
290 EXPECT_EQ(NULL, apis->GetSchema("experimental")); | 335 EXPECT_EQ(NULL, apis->GetSchema("experimental")); |
291 EXPECT_EQ(NULL, apis->GetSchema("experimental")); | 336 EXPECT_EQ(NULL, apis->GetSchema("experimental")); |
292 EXPECT_EQ(NULL, apis->GetSchema("foo")); | 337 EXPECT_EQ(NULL, apis->GetSchema("foo")); |
293 EXPECT_EQ(NULL, apis->GetSchema("foo")); | 338 EXPECT_EQ(NULL, apis->GetSchema("foo")); |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 extension.get(), | 884 extension.get(), |
840 Feature::BLESSED_EXTENSION_CONTEXT, | 885 Feature::BLESSED_EXTENSION_CONTEXT, |
841 GURL()).is_available()); | 886 GURL()).is_available()); |
842 EXPECT_FALSE(extension_api->IsAvailable("pageAction", | 887 EXPECT_FALSE(extension_api->IsAvailable("pageAction", |
843 extension.get(), | 888 extension.get(), |
844 Feature::BLESSED_EXTENSION_CONTEXT, | 889 Feature::BLESSED_EXTENSION_CONTEXT, |
845 GURL()).is_available()); | 890 GURL()).is_available()); |
846 } | 891 } |
847 | 892 |
848 } // namespace extensions | 893 } // namespace extensions |
OLD | NEW |