| 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/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> |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 ASSERT_TRUE(parent); | 173 ASSERT_TRUE(parent); |
| 174 std::vector<Feature*> children = provider.GetChildren(*parent); | 174 std::vector<Feature*> children = provider.GetChildren(*parent); |
| 175 std::set<std::string> children_names; | 175 std::set<std::string> children_names; |
| 176 for (const Feature* child : children) | 176 for (const Feature* child : children) |
| 177 children_names.insert(child->name()); | 177 children_names.insert(child->name()); |
| 178 EXPECT_THAT(children_names, testing::UnorderedElementsAre( | 178 EXPECT_THAT(children_names, testing::UnorderedElementsAre( |
| 179 "parent.child", "parent.child.grandchild", | 179 "parent.child", "parent.child.grandchild", |
| 180 "parent.other_child.other_grandchild")); | 180 "parent.other_child.other_grandchild")); |
| 181 } | 181 } |
| 182 | 182 |
| 183 TEST(FeatureProviderTest, GetParent) { |
| 184 FeatureProvider provider; |
| 185 |
| 186 auto add_feature = [&provider](base::StringPiece name, |
| 187 bool no_parent = false) { |
| 188 auto feature = base::MakeUnique<SimpleFeature>(); |
| 189 feature->set_name(name); |
| 190 feature->set_noparent(no_parent); |
| 191 provider.AddFeature(name, std::move(feature)); |
| 192 }; |
| 193 |
| 194 add_feature("parent"); |
| 195 add_feature("parent.child"); |
| 196 add_feature("parent.child.grandchild"); |
| 197 add_feature("parent.other_child.other_grandchild"); |
| 198 add_feature("parent.unparented_child", true); |
| 199 |
| 200 auto is_parent = [&provider](base::StringPiece child_name, |
| 201 base::StringPiece parent_name) { |
| 202 Feature* child = provider.GetFeature(child_name.as_string()); |
| 203 ASSERT_TRUE(child) << child_name; |
| 204 Feature* parent = provider.GetParent(child); |
| 205 ASSERT_TRUE(parent) << parent_name; |
| 206 EXPECT_EQ(parent_name.as_string(), parent->name()); |
| 207 }; |
| 208 |
| 209 is_parent("parent.child", "parent"); |
| 210 is_parent("parent.child.grandchild", "parent.child"); |
| 211 is_parent("parent.other_child.other_grandchild", "parent"); |
| 212 |
| 213 { |
| 214 Feature* no_parent = provider.GetFeature("parent.unparented_child"); |
| 215 ASSERT_TRUE(no_parent); |
| 216 EXPECT_TRUE(no_parent->no_parent()); |
| 217 } |
| 218 } |
| 219 |
| 183 } // namespace extensions | 220 } // namespace extensions |
| OLD | NEW |