Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: extensions/common/features/simple_feature_unittest.cc

Issue 2255613003: Introduce session type parameter to extension features (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Introduce session type parameter to extension features Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
29 struct IsAvailableTestData { 31 struct IsAvailableTestData {
30 std::string extension_id; 32 std::string extension_id;
31 Manifest::Type extension_type; 33 Manifest::Type extension_type;
32 Manifest::Location location; 34 Manifest::Location location;
33 Feature::Platform platform; 35 Feature::Platform platform;
34 int manifest_version; 36 int manifest_version;
35 Feature::AvailabilityResult expected_result; 37 Feature::AvailabilityResult expected_result;
36 }; 38 };
37 39
40 struct FeatureSessionTypeTestData {
41 std::string desc;
42 Feature::AvailabilityResult expected_availability;
43 FeatureSessionType current_session_type;
44 std::initializer_list<FeatureSessionType> feature_session_types;
45 bool ignore_session_types;
Devlin 2016/08/23 20:49:06 Why do we need this? It seems like we should neve
tbarzic 2016/09/08 18:48:55 it was named a bit poorly, but it's used to distin
46 };
47
38 template <class FeatureClass> 48 template <class FeatureClass>
39 SimpleFeature* CreateFeature() { 49 SimpleFeature* CreateFeature() {
40 return new FeatureClass(); 50 return new FeatureClass();
41 } 51 }
42 52
43 Feature::AvailabilityResult IsAvailableInChannel( 53 Feature::AvailabilityResult IsAvailableInChannel(
44 const std::string& channel, 54 const std::string& channel,
45 version_info::Channel channel_for_testing) { 55 version_info::Channel channel_for_testing) {
46 ScopedCurrentChannel current_channel(channel_for_testing); 56 ScopedCurrentChannel current_channel(channel_for_testing);
47 57
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 Feature::CHROMEOS_PLATFORM).result()); 405 Feature::CHROMEOS_PLATFORM).result());
396 feature.set_min_manifest_version(21); 406 feature.set_min_manifest_version(21);
397 407
398 feature.set_max_manifest_version(18); 408 feature.set_max_manifest_version(18);
399 EXPECT_EQ(Feature::INVALID_MAX_MANIFEST_VERSION, feature.IsAvailableToContext( 409 EXPECT_EQ(Feature::INVALID_MAX_MANIFEST_VERSION, feature.IsAvailableToContext(
400 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, 410 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT,
401 Feature::CHROMEOS_PLATFORM).result()); 411 Feature::CHROMEOS_PLATFORM).result());
402 feature.set_max_manifest_version(25); 412 feature.set_max_manifest_version(25);
403 } 413 }
404 414
415 TEST_F(SimpleFeatureTest, SessionType) {
416 base::DictionaryValue manifest;
417 manifest.SetString("name", "test");
418 manifest.SetString("version", "1");
419 manifest.SetInteger("manifest_version", 21);
Devlin 2016/08/23 20:49:06 ? This didn't throw an error?
tbarzic 2016/09/08 18:48:55 no
420 manifest.SetString("app.launch.local_path", "foo.html");
421
422 std::string error;
423 scoped_refptr<const Extension> extension(
424 Extension::Create(base::FilePath(), Manifest::INTERNAL, manifest,
425 Extension::NO_FLAGS, &error));
426 EXPECT_EQ("", error);
427 ASSERT_TRUE(extension.get());
428
429 const std::vector<FeatureSessionTypeTestData> kTestData(
430 {{"kiosk_feature in kiosk session",
431 Feature::IS_AVAILABLE,
432 FeatureSessionType::KIOSK,
433 {FeatureSessionType::KIOSK},
434 false /* ignore_session_types */},
435 {"kiosk feature in regular session",
436 Feature::INVALID_SESSION_TYPE,
437 FeatureSessionType::REGULAR,
438 {FeatureSessionType::KIOSK},
439 false /* ignore_session_types */},
440 {"kiosk feature in unknown session",
441 Feature::INVALID_SESSION_TYPE,
442 FeatureSessionType::UNKNOWN,
443 {FeatureSessionType::KIOSK},
444 false /* ignore_session_types */},
445 {"kiosk feature in initial session",
446 Feature::INVALID_SESSION_TYPE,
447 FeatureSessionType::INITIAL,
448 {FeatureSessionType::KIOSK},
449 false /* ignore_session_types */},
450 {"non kiosk feature in kiosk session",
451 Feature::INVALID_SESSION_TYPE,
452 FeatureSessionType::KIOSK,
453 {FeatureSessionType::REGULAR},
454 false /* ignore_session_types */},
455 {"non kiosk feature in regular session",
456 Feature::IS_AVAILABLE,
457 FeatureSessionType::REGULAR,
458 {FeatureSessionType::REGULAR},
459 false /* ignore_session_types */},
460 {"non kiosk feature in unknown session",
461 Feature::INVALID_SESSION_TYPE,
462 FeatureSessionType::UNKNOWN,
463 {FeatureSessionType::REGULAR},
464 false /* ignore_session_types */},
465 {"non kiosk feature in initial session",
466 Feature::INVALID_SESSION_TYPE,
467 FeatureSessionType::INITIAL,
468 {FeatureSessionType::REGULAR},
469 false /* ignore_session_types */},
470
471 {"empty session types in kiosk session",
472 Feature::INVALID_SESSION_TYPE,
473 FeatureSessionType::KIOSK,
474 {},
475 false /* ignore_session_types */},
476 {"empty session types in regular session",
477 Feature::INVALID_SESSION_TYPE,
478 FeatureSessionType::REGULAR,
479 {},
480 false /* ignore_session_types */},
481 {"empty session types in unknown session",
482 Feature::INVALID_SESSION_TYPE,
483 FeatureSessionType::UNKNOWN,
484 {},
485 false /* ignore_session_types */},
486 {"empty session types in unknown session",
487 Feature::INVALID_SESSION_TYPE,
488 FeatureSessionType::INITIAL,
489 {},
490 false /* ignore_session_types */},
491
492 {"session agnostic feature in kiosk session",
493 Feature::IS_AVAILABLE,
494 FeatureSessionType::KIOSK,
495 {},
496 true /* ignore_session_types */},
497 {"session agnostic feature in regular session",
498 Feature::IS_AVAILABLE,
499 FeatureSessionType::REGULAR,
500 {},
501 true /* ignore_session_types */},
502 {"session agnostic feature in unknown session",
503 Feature::IS_AVAILABLE,
504 FeatureSessionType::UNKNOWN,
505 {},
506 true /* ignore_session_types */},
507 {"feature with multiple session types",
508 Feature::IS_AVAILABLE,
509 FeatureSessionType::REGULAR,
510 {FeatureSessionType::REGULAR, FeatureSessionType::KIOSK},
511 false /* ignore_session_types */},
512 {"feature with multiple session types in unknown session",
513 Feature::INVALID_SESSION_TYPE,
514 FeatureSessionType::UNKNOWN,
515 {FeatureSessionType::REGULAR, FeatureSessionType::KIOSK},
516 false /* ignore_session_types */},
517 {"feature with multiple session types in initial session",
518 Feature::INVALID_SESSION_TYPE,
519 FeatureSessionType::INITIAL,
520 {FeatureSessionType::REGULAR, FeatureSessionType::KIOSK},
521 false /* ignore_session_types */}});
522
523 for (const auto& test : kTestData) {
524 std::unique_ptr<base::AutoReset<FeatureSessionType>> current_session(
525 ScopedCurrentFeatureSessionType(test.current_session_type));
526
527 SimpleFeature feature;
528 if (!test.ignore_session_types)
529 feature.set_session_types(test.feature_session_types);
530
531 EXPECT_EQ(test.expected_availability,
532 feature
533 .IsAvailableToContext(extension.get(),
534 Feature::BLESSED_EXTENSION_CONTEXT,
535 Feature::CHROMEOS_PLATFORM)
536 .result())
537 << "Failed test '" << test.desc << "'.";
538
539 EXPECT_EQ(
540 test.expected_availability,
541 feature
542 .IsAvailableToManifest(extension->id(), Manifest::TYPE_UNKNOWN,
543 Manifest::INVALID_LOCATION, -1,
544 Feature::CHROMEOS_PLATFORM)
545 .result())
546 << "Failed test '" << test.desc << "'.";
547 }
548 }
549
405 TEST_F(SimpleFeatureTest, Location) { 550 TEST_F(SimpleFeatureTest, Location) {
406 // Component extensions can access any location. 551 // Component extensions can access any location.
407 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION, 552 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION,
408 Manifest::COMPONENT)); 553 Manifest::COMPONENT));
409 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::EXTERNAL_COMPONENT_LOCATION, 554 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::EXTERNAL_COMPONENT_LOCATION,
410 Manifest::COMPONENT)); 555 Manifest::COMPONENT));
411 EXPECT_TRUE( 556 EXPECT_TRUE(
412 LocationIsAvailable(SimpleFeature::POLICY_LOCATION, Manifest::COMPONENT)); 557 LocationIsAvailable(SimpleFeature::POLICY_LOCATION, Manifest::COMPONENT));
413 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::UNSPECIFIED_LOCATION, 558 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::UNSPECIFIED_LOCATION,
414 Manifest::COMPONENT)); 559 Manifest::COMPONENT));
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 EXPECT_NE(Feature::IS_AVAILABLE, 1115 EXPECT_NE(Feature::IS_AVAILABLE,
971 feature 1116 feature
972 ->IsAvailableToManifest("1", Manifest::TYPE_EXTENSION, 1117 ->IsAvailableToManifest("1", Manifest::TYPE_EXTENSION,
973 Manifest::INVALID_LOCATION, 1118 Manifest::INVALID_LOCATION,
974 Feature::UNSPECIFIED_PLATFORM) 1119 Feature::UNSPECIFIED_PLATFORM)
975 .result()); 1120 .result());
976 } 1121 }
977 } 1122 }
978 1123
979 } // namespace extensions 1124 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698