Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/features/simple_feature.h" | 5 #include "extensions/common/features/simple_feature.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | |
| 10 | 11 |
| 11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 14 #include "base/test/scoped_command_line.h" | 15 #include "base/test/scoped_command_line.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "extensions/common/features/api_feature.h" | 17 #include "extensions/common/features/api_feature.h" |
| 17 #include "extensions/common/features/complex_feature.h" | 18 #include "extensions/common/features/complex_feature.h" |
| 18 #include "extensions/common/features/feature_channel.h" | 19 #include "extensions/common/features/feature_channel.h" |
| 20 #include "extensions/common/features/feature_session_type.h" | |
| 19 #include "extensions/common/features/json_feature_provider.h" | 21 #include "extensions/common/features/json_feature_provider.h" |
| 20 #include "extensions/common/features/permission_feature.h" | 22 #include "extensions/common/features/permission_feature.h" |
| 21 #include "extensions/common/manifest.h" | 23 #include "extensions/common/manifest.h" |
| 22 #include "extensions/common/value_builder.h" | 24 #include "extensions/common/value_builder.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 26 |
| 25 namespace extensions { | 27 namespace extensions { |
| 26 | 28 |
| 27 namespace { | 29 namespace { |
| 28 | 30 |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 Feature::CHROMEOS_PLATFORM).result()); | 397 Feature::CHROMEOS_PLATFORM).result()); |
| 396 feature.set_min_manifest_version(21); | 398 feature.set_min_manifest_version(21); |
| 397 | 399 |
| 398 feature.set_max_manifest_version(18); | 400 feature.set_max_manifest_version(18); |
| 399 EXPECT_EQ(Feature::INVALID_MAX_MANIFEST_VERSION, feature.IsAvailableToContext( | 401 EXPECT_EQ(Feature::INVALID_MAX_MANIFEST_VERSION, feature.IsAvailableToContext( |
| 400 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, | 402 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, |
| 401 Feature::CHROMEOS_PLATFORM).result()); | 403 Feature::CHROMEOS_PLATFORM).result()); |
| 402 feature.set_max_manifest_version(25); | 404 feature.set_max_manifest_version(25); |
| 403 } | 405 } |
| 404 | 406 |
| 407 TEST_F(SimpleFeatureTest, SessionType) { | |
| 408 base::DictionaryValue manifest; | |
| 409 manifest.SetString("name", "test"); | |
| 410 manifest.SetString("version", "1"); | |
| 411 manifest.SetInteger("manifest_version", 21); | |
| 412 manifest.SetString("app.launch.local_path", "foo.html"); | |
| 413 | |
| 414 std::string error; | |
| 415 scoped_refptr<const Extension> extension( | |
| 416 Extension::Create(base::FilePath(), Manifest::INTERNAL, manifest, | |
| 417 Extension::NO_FLAGS, &error)); | |
| 418 EXPECT_EQ("", error); | |
| 419 ASSERT_TRUE(extension.get()); | |
| 420 | |
| 421 struct { | |
|
xiyuan
2016/08/18 21:24:00
nit: const
tbarzic
2016/08/18 22:18:56
Done.
| |
| 422 std::string desc; | |
| 423 Feature::AvailabilityResult expected_availability; | |
| 424 FeatureSessionType current_session_type; | |
| 425 std::initializer_list<FeatureSessionType> feature_session_types; | |
| 426 } 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.
| |
| 427 Feature::IS_AVAILABLE, | |
| 428 FeatureSessionType::KIOSK, | |
| 429 {FeatureSessionType::KIOSK}}, | |
| 430 {"kiosk feature in regular session", | |
| 431 Feature::INVALID_SESSION_TYPE, | |
| 432 FeatureSessionType::REGULAR, | |
| 433 {FeatureSessionType::KIOSK}}, | |
| 434 {"kiosk feature in unknown session", | |
| 435 Feature::INVALID_SESSION_TYPE, | |
| 436 FeatureSessionType::UNKNOWN, | |
| 437 {FeatureSessionType::KIOSK}}, | |
| 438 {"non kiosk feature in kiosk session", | |
| 439 Feature::INVALID_SESSION_TYPE, | |
| 440 FeatureSessionType::KIOSK, | |
| 441 {FeatureSessionType::REGULAR}}, | |
| 442 {"non kiosk feature in regular session", | |
| 443 Feature::IS_AVAILABLE, | |
| 444 FeatureSessionType::REGULAR, | |
| 445 {FeatureSessionType::REGULAR}}, | |
| 446 {"non kiosk feature in unknown session", | |
| 447 Feature::INVALID_SESSION_TYPE, | |
| 448 FeatureSessionType::UNKNOWN, | |
| 449 {FeatureSessionType::REGULAR}}, | |
| 450 {"session agnostic feature in kiosk session", | |
| 451 Feature::IS_AVAILABLE, | |
| 452 FeatureSessionType::KIOSK, | |
| 453 {}}, | |
| 454 {"session_agnostic feature in regular session", | |
| 455 Feature::IS_AVAILABLE, | |
| 456 FeatureSessionType::REGULAR, | |
| 457 {}}, | |
| 458 {"session agnostic feature in unknown session", | |
| 459 Feature::IS_AVAILABLE, | |
| 460 FeatureSessionType::UNKNOWN, | |
| 461 {}}, | |
| 462 {"feature with multiple session types", | |
| 463 Feature::IS_AVAILABLE, | |
| 464 FeatureSessionType::REGULAR, | |
| 465 {FeatureSessionType::REGULAR, FeatureSessionType::KIOSK}}, | |
| 466 {"feature with multiple session types in unknown session", | |
| 467 Feature::INVALID_SESSION_TYPE, | |
| 468 FeatureSessionType::UNKNOWN, | |
| 469 {FeatureSessionType::REGULAR, FeatureSessionType::KIOSK}}}; | |
| 470 | |
| 471 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.
| |
| 472 std::unique_ptr<base::AutoReset<FeatureSessionType>> current_session( | |
| 473 ScopedCurrentFeatureSessionType(test_data[i].current_session_type)); | |
| 474 | |
| 475 SimpleFeature feature; | |
| 476 feature.set_session_types(test_data[i].feature_session_types); | |
| 477 | |
| 478 EXPECT_EQ(test_data[i].expected_availability, | |
| 479 feature | |
| 480 .IsAvailableToContext(extension.get(), | |
| 481 Feature::BLESSED_EXTENSION_CONTEXT, | |
| 482 Feature::CHROMEOS_PLATFORM) | |
| 483 .result()) | |
| 484 << "Failed test " << i << " (" << test_data[i].desc << ")."; | |
| 485 | |
| 486 EXPECT_EQ( | |
| 487 Feature::IS_AVAILABLE, | |
| 488 feature | |
| 489 .IsAvailableToManifest(extension->id(), Manifest::TYPE_UNKNOWN, | |
| 490 Manifest::INVALID_LOCATION, -1, | |
| 491 Feature::CHROMEOS_PLATFORM) | |
| 492 .result()) | |
| 493 << "Failed test " << i << " (" << test_data[i].desc << ")."; | |
| 494 } | |
| 495 } | |
| 496 | |
| 405 TEST_F(SimpleFeatureTest, Location) { | 497 TEST_F(SimpleFeatureTest, Location) { |
| 406 // Component extensions can access any location. | 498 // Component extensions can access any location. |
| 407 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION, | 499 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION, |
| 408 Manifest::COMPONENT)); | 500 Manifest::COMPONENT)); |
| 409 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::EXTERNAL_COMPONENT_LOCATION, | 501 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::EXTERNAL_COMPONENT_LOCATION, |
| 410 Manifest::COMPONENT)); | 502 Manifest::COMPONENT)); |
| 411 EXPECT_TRUE( | 503 EXPECT_TRUE( |
| 412 LocationIsAvailable(SimpleFeature::POLICY_LOCATION, Manifest::COMPONENT)); | 504 LocationIsAvailable(SimpleFeature::POLICY_LOCATION, Manifest::COMPONENT)); |
| 413 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::UNSPECIFIED_LOCATION, | 505 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::UNSPECIFIED_LOCATION, |
| 414 Manifest::COMPONENT)); | 506 Manifest::COMPONENT)); |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 970 EXPECT_NE(Feature::IS_AVAILABLE, | 1062 EXPECT_NE(Feature::IS_AVAILABLE, |
| 971 feature | 1063 feature |
| 972 ->IsAvailableToManifest("1", Manifest::TYPE_EXTENSION, | 1064 ->IsAvailableToManifest("1", Manifest::TYPE_EXTENSION, |
| 973 Manifest::INVALID_LOCATION, | 1065 Manifest::INVALID_LOCATION, |
| 974 Feature::UNSPECIFIED_PLATFORM) | 1066 Feature::UNSPECIFIED_PLATFORM) |
| 975 .result()); | 1067 .result()); |
| 976 } | 1068 } |
| 977 } | 1069 } |
| 978 | 1070 |
| 979 } // namespace extensions | 1071 } // namespace extensions |
| OLD | NEW |