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

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

Issue 2945383002: [Extensions] Fix FeatureProvider::GetChildren() (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « extensions/common/features/feature_provider.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/feature_provider.h" 5 #include "extensions/common/features/feature_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/memory/ptr_util.h"
12 #include "base/stl_util.h" 13 #include "base/stl_util.h"
13 #include "extensions/common/extension_builder.h" 14 #include "extensions/common/extension_builder.h"
14 #include "extensions/common/features/feature.h" 15 #include "extensions/common/features/feature.h"
15 #include "extensions/common/features/simple_feature.h" 16 #include "extensions/common/features/simple_feature.h"
16 #include "extensions/common/manifest.h" 17 #include "extensions/common/manifest.h"
17 #include "extensions/common/value_builder.h" 18 #include "extensions/common/value_builder.h"
19 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
19 21
20 namespace extensions { 22 namespace extensions {
21 23
22 // Tests that a real manifest feature is available for the correct types of 24 // Tests that a real manifest feature is available for the correct types of
23 // extensions and apps. 25 // extensions and apps.
24 TEST(FeatureProviderTest, ManifestFeatureTypes) { 26 TEST(FeatureProviderTest, ManifestFeatureTypes) {
25 // NOTE: This feature cannot have multiple rules, otherwise it is not a 27 // NOTE: This feature cannot have multiple rules, otherwise it is not a
26 // SimpleFeature. 28 // SimpleFeature.
27 const SimpleFeature* feature = static_cast<const SimpleFeature*>( 29 const SimpleFeature* feature = static_cast<const SimpleFeature*>(
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // A permission that isn't part of the manifest returns NOT_PRESENT. 145 // A permission that isn't part of the manifest returns NOT_PRESENT.
144 feature = provider->GetFeature("serial"); 146 feature = provider->GetFeature("serial");
145 ASSERT_TRUE(feature); 147 ASSERT_TRUE(feature);
146 EXPECT_EQ(Feature::NOT_PRESENT, 148 EXPECT_EQ(Feature::NOT_PRESENT,
147 feature 149 feature
148 ->IsAvailableToContext(app.get(), Feature::UNSPECIFIED_CONTEXT, 150 ->IsAvailableToContext(app.get(), Feature::UNSPECIFIED_CONTEXT,
149 GURL()) 151 GURL())
150 .result()); 152 .result());
151 } 153 }
152 154
155 TEST(FeatureProviderTest, GetChildren) {
156 FeatureProvider provider;
157
158 auto add_feature = [&provider](base::StringPiece name,
159 bool no_parent = false) {
160 auto feature = base::MakeUnique<SimpleFeature>();
161 feature->set_name(name);
162 feature->set_noparent(no_parent);
163 provider.AddFeature(name, std::move(feature));
164 };
165
166 add_feature("parent");
167 add_feature("parent.child");
168 add_feature("parent.child.grandchild");
169 add_feature("parent.other_child.other_grandchild");
170 add_feature("parent.unparented_child", true);
171
172 Feature* parent = provider.GetFeature("parent");
173 ASSERT_TRUE(parent);
174 std::vector<Feature*> children = provider.GetChildren(*parent);
175 std::set<std::string> children_names;
176 for (const Feature* child : children)
177 children_names.insert(child->name());
178 EXPECT_THAT(children_names, testing::UnorderedElementsAre(
179 "parent.child", "parent.child.grandchild",
180 "parent.other_child.other_grandchild"));
181 }
182
153 } // namespace extensions 183 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/features/feature_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698