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

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

Issue 1908953003: Convert //extensions/{common,shell} from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase? Created 4 years, 8 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/complex_feature.h" 5 #include "extensions/common/features/complex_feature.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "extensions/common/features/simple_feature.h" 10 #include "extensions/common/features/simple_feature.h"
11 #include "extensions/common/manifest.h" 11 #include "extensions/common/manifest.h"
12 #include "extensions/common/value_builder.h" 12 #include "extensions/common/value_builder.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace extensions { 15 namespace extensions {
16 16
17 TEST(ComplexFeatureTest, MultipleRulesWhitelist) { 17 TEST(ComplexFeatureTest, MultipleRulesWhitelist) {
18 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); 18 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh");
19 const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh"); 19 const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh");
20 scoped_ptr<ComplexFeature::FeatureList> features( 20 std::unique_ptr<ComplexFeature::FeatureList> features(
21 new ComplexFeature::FeatureList()); 21 new ComplexFeature::FeatureList());
22 22
23 // Rule: "extension", whitelist "foo". 23 // Rule: "extension", whitelist "foo".
24 scoped_ptr<SimpleFeature> simple_feature(new SimpleFeature); 24 std::unique_ptr<SimpleFeature> simple_feature(new SimpleFeature);
25 scoped_ptr<base::DictionaryValue> rule( 25 std::unique_ptr<base::DictionaryValue> rule(
26 DictionaryBuilder() 26 DictionaryBuilder()
27 .Set("whitelist", ListBuilder().Append(kIdFoo).Build()) 27 .Set("whitelist", ListBuilder().Append(kIdFoo).Build())
28 .Set("extension_types", ListBuilder().Append("extension").Build()) 28 .Set("extension_types", ListBuilder().Append("extension").Build())
29 .Build()); 29 .Build());
30 simple_feature->Parse(rule.get()); 30 simple_feature->Parse(rule.get());
31 features->push_back(std::move(simple_feature)); 31 features->push_back(std::move(simple_feature));
32 32
33 // Rule: "legacy_packaged_app", whitelist "bar". 33 // Rule: "legacy_packaged_app", whitelist "bar".
34 simple_feature.reset(new SimpleFeature); 34 simple_feature.reset(new SimpleFeature);
35 rule = DictionaryBuilder() 35 rule = DictionaryBuilder()
36 .Set("whitelist", ListBuilder().Append(kIdBar).Build()) 36 .Set("whitelist", ListBuilder().Append(kIdBar).Build())
37 .Set("extension_types", 37 .Set("extension_types",
38 ListBuilder().Append("legacy_packaged_app").Build()) 38 ListBuilder().Append("legacy_packaged_app").Build())
39 .Build(); 39 .Build();
40 simple_feature->Parse(rule.get()); 40 simple_feature->Parse(rule.get());
41 features->push_back(std::move(simple_feature)); 41 features->push_back(std::move(simple_feature));
42 42
43 scoped_ptr<ComplexFeature> feature(new ComplexFeature(std::move(features))); 43 std::unique_ptr<ComplexFeature> feature(
44 new ComplexFeature(std::move(features)));
44 45
45 // Test match 1st rule. 46 // Test match 1st rule.
46 EXPECT_EQ( 47 EXPECT_EQ(
47 Feature::IS_AVAILABLE, 48 Feature::IS_AVAILABLE,
48 feature->IsAvailableToManifest(kIdFoo, 49 feature->IsAvailableToManifest(kIdFoo,
49 Manifest::TYPE_EXTENSION, 50 Manifest::TYPE_EXTENSION,
50 Manifest::INVALID_LOCATION, 51 Manifest::INVALID_LOCATION,
51 Feature::UNSPECIFIED_PLATFORM, 52 Feature::UNSPECIFIED_PLATFORM,
52 Feature::GetCurrentPlatform()).result()); 53 Feature::GetCurrentPlatform()).result());
53 54
(...skipping 18 matching lines...) Expand all
72 Feature::IS_AVAILABLE, 73 Feature::IS_AVAILABLE,
73 feature->IsAvailableToManifest(kIdFoo, 74 feature->IsAvailableToManifest(kIdFoo,
74 Manifest::TYPE_LEGACY_PACKAGED_APP, 75 Manifest::TYPE_LEGACY_PACKAGED_APP,
75 Manifest::INVALID_LOCATION, 76 Manifest::INVALID_LOCATION,
76 Feature::UNSPECIFIED_PLATFORM, 77 Feature::UNSPECIFIED_PLATFORM,
77 Feature::GetCurrentPlatform()).result()); 78 Feature::GetCurrentPlatform()).result());
78 } 79 }
79 80
80 // Tests that dependencies are correctly checked. 81 // Tests that dependencies are correctly checked.
81 TEST(ComplexFeatureTest, Dependencies) { 82 TEST(ComplexFeatureTest, Dependencies) {
82 scoped_ptr<ComplexFeature::FeatureList> features( 83 std::unique_ptr<ComplexFeature::FeatureList> features(
83 new ComplexFeature::FeatureList()); 84 new ComplexFeature::FeatureList());
84 85
85 // Rule which depends on an extension-only feature (content_security_policy). 86 // Rule which depends on an extension-only feature (content_security_policy).
86 scoped_ptr<SimpleFeature> simple_feature(new SimpleFeature); 87 std::unique_ptr<SimpleFeature> simple_feature(new SimpleFeature);
87 scoped_ptr<base::DictionaryValue> rule = 88 std::unique_ptr<base::DictionaryValue> rule =
88 DictionaryBuilder() 89 DictionaryBuilder()
89 .Set("dependencies", 90 .Set("dependencies",
90 ListBuilder().Append("manifest:content_security_policy").Build()) 91 ListBuilder().Append("manifest:content_security_policy").Build())
91 .Build(); 92 .Build();
92 simple_feature->Parse(rule.get()); 93 simple_feature->Parse(rule.get());
93 features->push_back(std::move(simple_feature)); 94 features->push_back(std::move(simple_feature));
94 95
95 // Rule which depends on an platform-app-only feature (serial). 96 // Rule which depends on an platform-app-only feature (serial).
96 simple_feature.reset(new SimpleFeature); 97 simple_feature.reset(new SimpleFeature);
97 rule = DictionaryBuilder() 98 rule = DictionaryBuilder()
98 .Set("dependencies", 99 .Set("dependencies",
99 ListBuilder().Append("permission:serial").Build()) 100 ListBuilder().Append("permission:serial").Build())
100 .Build(); 101 .Build();
101 simple_feature->Parse(rule.get()); 102 simple_feature->Parse(rule.get());
102 features->push_back(std::move(simple_feature)); 103 features->push_back(std::move(simple_feature));
103 104
104 scoped_ptr<ComplexFeature> feature(new ComplexFeature(std::move(features))); 105 std::unique_ptr<ComplexFeature> feature(
106 new ComplexFeature(std::move(features)));
105 107
106 // Available to extensions because of the content_security_policy rule. 108 // Available to extensions because of the content_security_policy rule.
107 EXPECT_EQ( 109 EXPECT_EQ(
108 Feature::IS_AVAILABLE, 110 Feature::IS_AVAILABLE,
109 feature->IsAvailableToManifest("extensionid", 111 feature->IsAvailableToManifest("extensionid",
110 Manifest::TYPE_EXTENSION, 112 Manifest::TYPE_EXTENSION,
111 Manifest::INVALID_LOCATION, 113 Manifest::INVALID_LOCATION,
112 Feature::UNSPECIFIED_PLATFORM, 114 Feature::UNSPECIFIED_PLATFORM,
113 Feature::GetCurrentPlatform()).result()); 115 Feature::GetCurrentPlatform()).result());
114 116
(...skipping 10 matching lines...) Expand all
125 EXPECT_EQ( 127 EXPECT_EQ(
126 Feature::INVALID_TYPE, 128 Feature::INVALID_TYPE,
127 feature->IsAvailableToManifest("hostedappid", 129 feature->IsAvailableToManifest("hostedappid",
128 Manifest::TYPE_HOSTED_APP, 130 Manifest::TYPE_HOSTED_APP,
129 Manifest::INVALID_LOCATION, 131 Manifest::INVALID_LOCATION,
130 Feature::UNSPECIFIED_PLATFORM, 132 Feature::UNSPECIFIED_PLATFORM,
131 Feature::GetCurrentPlatform()).result()); 133 Feature::GetCurrentPlatform()).result());
132 } 134 }
133 135
134 } // namespace extensions 136 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/features/complex_feature.cc ('k') | extensions/common/features/feature_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698