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

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

Issue 1739183003: Make extensions::DictionaryBuilder and extensions::ListValue unmovable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 scoped_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 scoped_ptr<SimpleFeature> simple_feature(new SimpleFeature);
25 scoped_ptr<base::DictionaryValue> rule( 25 scoped_ptr<base::DictionaryValue> rule(
26 DictionaryBuilder() 26 DictionaryBuilder()
27 .Set("whitelist", std::move(ListBuilder().Append(kIdFoo))) 27 .Set("whitelist", ListBuilder().Append(kIdFoo).Build())
28 .Set("extension_types", std::move(ListBuilder().Append("extension"))) 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", std::move(ListBuilder().Append(kIdBar))) 36 .Set("whitelist", ListBuilder().Append(kIdBar).Build())
37 .Set("extension_types", 37 .Set("extension_types",
38 std::move(ListBuilder().Append("legacy_packaged_app"))) 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 scoped_ptr<ComplexFeature> feature(new ComplexFeature(std::move(features)));
44 44
45 // Test match 1st rule. 45 // Test match 1st rule.
46 EXPECT_EQ( 46 EXPECT_EQ(
47 Feature::IS_AVAILABLE, 47 Feature::IS_AVAILABLE,
48 feature->IsAvailableToManifest(kIdFoo, 48 feature->IsAvailableToManifest(kIdFoo,
(...skipping 30 matching lines...) Expand all
79 79
80 // Tests that dependencies are correctly checked. 80 // Tests that dependencies are correctly checked.
81 TEST(ComplexFeatureTest, Dependencies) { 81 TEST(ComplexFeatureTest, Dependencies) {
82 scoped_ptr<ComplexFeature::FeatureList> features( 82 scoped_ptr<ComplexFeature::FeatureList> features(
83 new ComplexFeature::FeatureList()); 83 new ComplexFeature::FeatureList());
84 84
85 // Rule which depends on an extension-only feature (content_security_policy). 85 // Rule which depends on an extension-only feature (content_security_policy).
86 scoped_ptr<SimpleFeature> simple_feature(new SimpleFeature); 86 scoped_ptr<SimpleFeature> simple_feature(new SimpleFeature);
87 scoped_ptr<base::DictionaryValue> rule = 87 scoped_ptr<base::DictionaryValue> rule =
88 DictionaryBuilder() 88 DictionaryBuilder()
89 .Set("dependencies", std::move(ListBuilder().Append( 89 .Set("dependencies",
90 "manifest:content_security_policy"))) 90 ListBuilder().Append("manifest:content_security_policy").Build())
91 .Build(); 91 .Build();
92 simple_feature->Parse(rule.get()); 92 simple_feature->Parse(rule.get());
93 features->push_back(std::move(simple_feature)); 93 features->push_back(std::move(simple_feature));
94 94
95 // Rule which depends on an platform-app-only feature (serial). 95 // Rule which depends on an platform-app-only feature (serial).
96 simple_feature.reset(new SimpleFeature); 96 simple_feature.reset(new SimpleFeature);
97 rule = DictionaryBuilder() 97 rule = DictionaryBuilder()
98 .Set("dependencies", 98 .Set("dependencies",
99 std::move(ListBuilder().Append("permission:serial"))) 99 ListBuilder().Append("permission:serial").Build())
100 .Build(); 100 .Build();
101 simple_feature->Parse(rule.get()); 101 simple_feature->Parse(rule.get());
102 features->push_back(std::move(simple_feature)); 102 features->push_back(std::move(simple_feature));
103 103
104 scoped_ptr<ComplexFeature> feature(new ComplexFeature(std::move(features))); 104 scoped_ptr<ComplexFeature> feature(new ComplexFeature(std::move(features)));
105 105
106 // Available to extensions because of the content_security_policy rule. 106 // Available to extensions because of the content_security_policy rule.
107 EXPECT_EQ( 107 EXPECT_EQ(
108 Feature::IS_AVAILABLE, 108 Feature::IS_AVAILABLE,
109 feature->IsAvailableToManifest("extensionid", 109 feature->IsAvailableToManifest("extensionid",
(...skipping 15 matching lines...) Expand all
125 EXPECT_EQ( 125 EXPECT_EQ(
126 Feature::INVALID_TYPE, 126 Feature::INVALID_TYPE,
127 feature->IsAvailableToManifest("hostedappid", 127 feature->IsAvailableToManifest("hostedappid",
128 Manifest::TYPE_HOSTED_APP, 128 Manifest::TYPE_HOSTED_APP,
129 Manifest::INVALID_LOCATION, 129 Manifest::INVALID_LOCATION,
130 Feature::UNSPECIFIED_PLATFORM, 130 Feature::UNSPECIFIED_PLATFORM,
131 Feature::GetCurrentPlatform()).result()); 131 Feature::GetCurrentPlatform()).result());
132 } 132 }
133 133
134 } // namespace extensions 134 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698