| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profile_dependency_manager.h" | 7 #include "chrome/browser/profiles/profile_dependency_manager.h" |
| 8 #include "chrome/browser/profiles/profile_keyed_service_factory.h" | 8 #include "chrome/browser/profiles/profile_keyed_service_factory.h" |
| 9 #include "chrome/test/testing_profile.h" |
| 9 | 10 |
| 10 class ProfileDependencyManagerUnittests : public ::testing::Test { | 11 class ProfileDependencyManagerUnittests : public ::testing::Test { |
| 11 protected: | 12 protected: |
| 12 virtual ~ProfileDependencyManagerUnittests() { | 13 virtual ~ProfileDependencyManagerUnittests() { |
| 13 EXPECT_TRUE(dependency_manager_.all_components_.empty()); | 14 EXPECT_TRUE(dependency_manager_.all_components_.empty()); |
| 14 EXPECT_TRUE(dependency_manager_.edges_.empty()); | 15 EXPECT_TRUE(dependency_manager_.edges_.empty()); |
| 15 EXPECT_TRUE(dependency_manager_.destruction_order_.empty()); | 16 EXPECT_TRUE(dependency_manager_.destruction_order_.empty()); |
| 16 } | 17 } |
| 17 | 18 |
| 18 // To get around class access: | 19 // To get around class access: |
| 19 void DependOn(ProfileKeyedServiceFactory* child, | 20 void DependOn(ProfileKeyedServiceFactory* child, |
| 20 ProfileKeyedServiceFactory* parent) { | 21 ProfileKeyedServiceFactory* parent) { |
| 21 child->DependsOn(parent); | 22 child->DependsOn(parent); |
| 22 } | 23 } |
| 23 | 24 |
| 25 void CreateAndDestroyTestProfile() { |
| 26 TestingProfile profile; |
| 27 profile.SetProfileDependencyManager(&dependency_manager_); |
| 28 } |
| 29 |
| 24 ProfileDependencyManager* manager() { return &dependency_manager_; } | 30 ProfileDependencyManager* manager() { return &dependency_manager_; } |
| 25 | 31 |
| 26 std::vector<std::string>* shutdown_order() { return &shutdown_order_; } | 32 std::vector<std::string>* shutdown_order() { return &shutdown_order_; } |
| 27 | 33 |
| 28 private: | 34 private: |
| 29 ProfileDependencyManager dependency_manager_; | 35 ProfileDependencyManager dependency_manager_; |
| 30 | 36 |
| 31 std::vector<std::string> shutdown_order_; | 37 std::vector<std::string> shutdown_order_; |
| 32 }; | 38 }; |
| 33 | 39 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 53 | 59 |
| 54 private: | 60 private: |
| 55 const std::string name_; | 61 const std::string name_; |
| 56 std::vector<std::string>* fill_on_shutdown_; | 62 std::vector<std::string>* fill_on_shutdown_; |
| 57 }; | 63 }; |
| 58 | 64 |
| 59 // Tests that we can deal with a single component. | 65 // Tests that we can deal with a single component. |
| 60 TEST_F(ProfileDependencyManagerUnittests, SingleCase) { | 66 TEST_F(ProfileDependencyManagerUnittests, SingleCase) { |
| 61 TestService service("service", shutdown_order(), manager()); | 67 TestService service("service", shutdown_order(), manager()); |
| 62 | 68 |
| 63 manager()->DestroyProfileServices(NULL); | 69 CreateAndDestroyTestProfile(); |
| 64 | 70 |
| 65 ASSERT_EQ(1U, shutdown_order()->size()); | 71 ASSERT_EQ(1U, shutdown_order()->size()); |
| 66 EXPECT_STREQ("service", (*shutdown_order())[0].c_str()); | 72 EXPECT_STREQ("service", (*shutdown_order())[0].c_str()); |
| 67 } | 73 } |
| 68 | 74 |
| 69 // Tests that we get a simple one component depends on the other case. | 75 // Tests that we get a simple one component depends on the other case. |
| 70 TEST_F(ProfileDependencyManagerUnittests, SimpleDependency) { | 76 TEST_F(ProfileDependencyManagerUnittests, SimpleDependency) { |
| 71 TestService parent("parent", shutdown_order(), manager()); | 77 TestService parent("parent", shutdown_order(), manager()); |
| 72 TestService child("child", shutdown_order(), manager()); | 78 TestService child("child", shutdown_order(), manager()); |
| 73 DependOn(&child, &parent); | 79 DependOn(&child, &parent); |
| 74 | 80 |
| 75 manager()->DestroyProfileServices(NULL); | 81 CreateAndDestroyTestProfile(); |
| 76 | 82 |
| 77 ASSERT_EQ(2U, shutdown_order()->size()); | 83 ASSERT_EQ(2U, shutdown_order()->size()); |
| 78 EXPECT_STREQ("child", (*shutdown_order())[0].c_str()); | 84 EXPECT_STREQ("child", (*shutdown_order())[0].c_str()); |
| 79 EXPECT_STREQ("parent", (*shutdown_order())[1].c_str()); | 85 EXPECT_STREQ("parent", (*shutdown_order())[1].c_str()); |
| 80 } | 86 } |
| 81 | 87 |
| 82 // Tests two children, one parent | 88 // Tests two children, one parent |
| 83 TEST_F(ProfileDependencyManagerUnittests, TwoChildrenOneParent) { | 89 TEST_F(ProfileDependencyManagerUnittests, TwoChildrenOneParent) { |
| 84 TestService parent("parent", shutdown_order(), manager()); | 90 TestService parent("parent", shutdown_order(), manager()); |
| 85 TestService child1("child1", shutdown_order(), manager()); | 91 TestService child1("child1", shutdown_order(), manager()); |
| 86 TestService child2("child2", shutdown_order(), manager()); | 92 TestService child2("child2", shutdown_order(), manager()); |
| 87 DependOn(&child1, &parent); | 93 DependOn(&child1, &parent); |
| 88 DependOn(&child2, &parent); | 94 DependOn(&child2, &parent); |
| 89 | 95 |
| 90 manager()->DestroyProfileServices(NULL); | 96 CreateAndDestroyTestProfile(); |
| 91 | 97 |
| 92 ASSERT_EQ(3U, shutdown_order()->size()); | 98 ASSERT_EQ(3U, shutdown_order()->size()); |
| 93 EXPECT_STREQ("child2", (*shutdown_order())[0].c_str()); | 99 EXPECT_STREQ("child2", (*shutdown_order())[0].c_str()); |
| 94 EXPECT_STREQ("child1", (*shutdown_order())[1].c_str()); | 100 EXPECT_STREQ("child1", (*shutdown_order())[1].c_str()); |
| 95 EXPECT_STREQ("parent", (*shutdown_order())[2].c_str()); | 101 EXPECT_STREQ("parent", (*shutdown_order())[2].c_str()); |
| 96 } | 102 } |
| 97 | 103 |
| 98 // Tests an M configuration | 104 // Tests an M configuration |
| 99 TEST_F(ProfileDependencyManagerUnittests, MConfiguration) { | 105 TEST_F(ProfileDependencyManagerUnittests, MConfiguration) { |
| 100 TestService parent1("parent1", shutdown_order(), manager()); | 106 TestService parent1("parent1", shutdown_order(), manager()); |
| 101 TestService parent2("parent2", shutdown_order(), manager()); | 107 TestService parent2("parent2", shutdown_order(), manager()); |
| 102 | 108 |
| 103 TestService child_of_1("child_of_1", shutdown_order(), manager()); | 109 TestService child_of_1("child_of_1", shutdown_order(), manager()); |
| 104 DependOn(&child_of_1, &parent1); | 110 DependOn(&child_of_1, &parent1); |
| 105 | 111 |
| 106 TestService child_of_12("child_of_12", shutdown_order(), manager()); | 112 TestService child_of_12("child_of_12", shutdown_order(), manager()); |
| 107 DependOn(&child_of_12, &parent1); | 113 DependOn(&child_of_12, &parent1); |
| 108 DependOn(&child_of_12, &parent2); | 114 DependOn(&child_of_12, &parent2); |
| 109 | 115 |
| 110 TestService child_of_2("child_of_2", shutdown_order(), manager()); | 116 TestService child_of_2("child_of_2", shutdown_order(), manager()); |
| 111 DependOn(&child_of_2, &parent2); | 117 DependOn(&child_of_2, &parent2); |
| 112 | 118 |
| 113 manager()->DestroyProfileServices(NULL); | 119 CreateAndDestroyTestProfile(); |
| 114 | 120 |
| 115 ASSERT_EQ(5U, shutdown_order()->size()); | 121 ASSERT_EQ(5U, shutdown_order()->size()); |
| 116 EXPECT_STREQ("child_of_2", (*shutdown_order())[0].c_str()); | 122 EXPECT_STREQ("child_of_2", (*shutdown_order())[0].c_str()); |
| 117 EXPECT_STREQ("child_of_12", (*shutdown_order())[1].c_str()); | 123 EXPECT_STREQ("child_of_12", (*shutdown_order())[1].c_str()); |
| 118 EXPECT_STREQ("child_of_1", (*shutdown_order())[2].c_str()); | 124 EXPECT_STREQ("child_of_1", (*shutdown_order())[2].c_str()); |
| 119 EXPECT_STREQ("parent2", (*shutdown_order())[3].c_str()); | 125 EXPECT_STREQ("parent2", (*shutdown_order())[3].c_str()); |
| 120 EXPECT_STREQ("parent1", (*shutdown_order())[4].c_str()); | 126 EXPECT_STREQ("parent1", (*shutdown_order())[4].c_str()); |
| 121 } | 127 } |
| 122 | 128 |
| 123 // Tests that it can deal with a simple diamond. | 129 // Tests that it can deal with a simple diamond. |
| 124 TEST_F(ProfileDependencyManagerUnittests, DiamondConfiguration) { | 130 TEST_F(ProfileDependencyManagerUnittests, DiamondConfiguration) { |
| 125 TestService parent("parent", shutdown_order(), manager()); | 131 TestService parent("parent", shutdown_order(), manager()); |
| 126 | 132 |
| 127 TestService middle_row_1("middle_row_1", shutdown_order(), manager()); | 133 TestService middle_row_1("middle_row_1", shutdown_order(), manager()); |
| 128 DependOn(&middle_row_1, &parent); | 134 DependOn(&middle_row_1, &parent); |
| 129 | 135 |
| 130 TestService middle_row_2("middle_row_2", shutdown_order(), manager()); | 136 TestService middle_row_2("middle_row_2", shutdown_order(), manager()); |
| 131 DependOn(&middle_row_2, &parent); | 137 DependOn(&middle_row_2, &parent); |
| 132 | 138 |
| 133 TestService bottom("bottom", shutdown_order(), manager()); | 139 TestService bottom("bottom", shutdown_order(), manager()); |
| 134 DependOn(&bottom, &middle_row_1); | 140 DependOn(&bottom, &middle_row_1); |
| 135 DependOn(&bottom, &middle_row_2); | 141 DependOn(&bottom, &middle_row_2); |
| 136 | 142 |
| 137 manager()->DestroyProfileServices(NULL); | 143 CreateAndDestroyTestProfile(); |
| 138 | 144 |
| 139 ASSERT_EQ(4U, shutdown_order()->size()); | 145 ASSERT_EQ(4U, shutdown_order()->size()); |
| 140 EXPECT_STREQ("bottom", (*shutdown_order())[0].c_str()); | 146 EXPECT_STREQ("bottom", (*shutdown_order())[0].c_str()); |
| 141 EXPECT_STREQ("middle_row_2", (*shutdown_order())[1].c_str()); | 147 EXPECT_STREQ("middle_row_2", (*shutdown_order())[1].c_str()); |
| 142 EXPECT_STREQ("middle_row_1", (*shutdown_order())[2].c_str()); | 148 EXPECT_STREQ("middle_row_1", (*shutdown_order())[2].c_str()); |
| 143 EXPECT_STREQ("parent", (*shutdown_order())[3].c_str()); | 149 EXPECT_STREQ("parent", (*shutdown_order())[3].c_str()); |
| 144 } | 150 } |
| 145 | 151 |
| 146 // A final test that works with a more complex graph. | 152 // A final test that works with a more complex graph. |
| 147 TEST_F(ProfileDependencyManagerUnittests, ComplexGraph) { | 153 TEST_F(ProfileDependencyManagerUnittests, ComplexGraph) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 160 TestService other_root("other_root", shutdown_order(), manager()); | 166 TestService other_root("other_root", shutdown_order(), manager()); |
| 161 | 167 |
| 162 TestService other_intermediary("other_intermediary", | 168 TestService other_intermediary("other_intermediary", |
| 163 shutdown_order(), manager()); | 169 shutdown_order(), manager()); |
| 164 DependOn(&other_intermediary, &other_root); | 170 DependOn(&other_intermediary, &other_root); |
| 165 | 171 |
| 166 TestService bottom("bottom", shutdown_order(), manager()); | 172 TestService bottom("bottom", shutdown_order(), manager()); |
| 167 DependOn(&bottom, &specialized_service); | 173 DependOn(&bottom, &specialized_service); |
| 168 DependOn(&bottom, &other_intermediary); | 174 DependOn(&bottom, &other_intermediary); |
| 169 | 175 |
| 170 manager()->DestroyProfileServices(NULL); | 176 CreateAndDestroyTestProfile(); |
| 171 | 177 |
| 172 ASSERT_EQ(6U, shutdown_order()->size()); | 178 ASSERT_EQ(6U, shutdown_order()->size()); |
| 173 EXPECT_STREQ("bottom", (*shutdown_order())[0].c_str()); | 179 EXPECT_STREQ("bottom", (*shutdown_order())[0].c_str()); |
| 174 EXPECT_STREQ("specialized_service", (*shutdown_order())[1].c_str()); | 180 EXPECT_STREQ("specialized_service", (*shutdown_order())[1].c_str()); |
| 175 EXPECT_STREQ("other_intermediary", (*shutdown_order())[2].c_str()); | 181 EXPECT_STREQ("other_intermediary", (*shutdown_order())[2].c_str()); |
| 176 EXPECT_STREQ("intermediary_service", (*shutdown_order())[3].c_str()); | 182 EXPECT_STREQ("intermediary_service", (*shutdown_order())[3].c_str()); |
| 177 EXPECT_STREQ("other_root", (*shutdown_order())[4].c_str()); | 183 EXPECT_STREQ("other_root", (*shutdown_order())[4].c_str()); |
| 178 EXPECT_STREQ("everything_depends_on_me", (*shutdown_order())[5].c_str()); | 184 EXPECT_STREQ("everything_depends_on_me", (*shutdown_order())[5].c_str()); |
| 179 } | 185 } |
| OLD | NEW |