| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | 7 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
| 8 #include "components/browser_context_keyed_service/browser_context_keyed_service
_factory.h" | 8 #include "components/browser_context_keyed_service/browser_context_keyed_service
_factory.h" |
| 9 | 9 |
| 10 class ProfileDependencyManagerUnittests : public ::testing::Test { | 10 class BrowserContextDependencyManagerUnittests : public ::testing::Test { |
| 11 protected: | 11 protected: |
| 12 // To get around class access: | 12 // To get around class access: |
| 13 void DependOn(ProfileKeyedServiceFactory* child, | 13 void DependOn(BrowserContextKeyedServiceFactory* child, |
| 14 ProfileKeyedServiceFactory* parent) { | 14 BrowserContextKeyedServiceFactory* parent) { |
| 15 child->DependsOn(parent); | 15 child->DependsOn(parent); |
| 16 } | 16 } |
| 17 | 17 |
| 18 ProfileDependencyManager* manager() { return &dependency_manager_; } | 18 BrowserContextDependencyManager* manager() { return &dependency_manager_; } |
| 19 | 19 |
| 20 std::vector<std::string>* shutdown_order() { return &shutdown_order_; } | 20 std::vector<std::string>* shutdown_order() { return &shutdown_order_; } |
| 21 | 21 |
| 22 private: | 22 private: |
| 23 ProfileDependencyManager dependency_manager_; | 23 BrowserContextDependencyManager dependency_manager_; |
| 24 | 24 |
| 25 std::vector<std::string> shutdown_order_; | 25 std::vector<std::string> shutdown_order_; |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 class TestService : public ProfileKeyedServiceFactory { | 28 class TestService : public BrowserContextKeyedServiceFactory { |
| 29 public: | 29 public: |
| 30 TestService(const std::string& name, | 30 TestService(const std::string& name, |
| 31 std::vector<std::string>* fill_on_shutdown, | 31 std::vector<std::string>* fill_on_shutdown, |
| 32 ProfileDependencyManager* manager) | 32 BrowserContextDependencyManager* manager) |
| 33 : ProfileKeyedServiceFactory("TestService", manager), | 33 : BrowserContextKeyedServiceFactory("TestService", manager), |
| 34 name_(name), | 34 name_(name), |
| 35 fill_on_shutdown_(fill_on_shutdown) { | 35 fill_on_shutdown_(fill_on_shutdown) { |
| 36 } | 36 } |
| 37 | 37 |
| 38 virtual ProfileKeyedService* BuildServiceInstanceFor( | 38 virtual BrowserContextKeyedService* BuildServiceInstanceFor( |
| 39 content::BrowserContext* profile) const OVERRIDE { | 39 content::BrowserContext* context) const OVERRIDE { |
| 40 ADD_FAILURE() << "This isn't part of the tests!"; | 40 ADD_FAILURE() << "This isn't part of the tests!"; |
| 41 return NULL; | 41 return NULL; |
| 42 } | 42 } |
| 43 | 43 |
| 44 virtual void ProfileShutdown(content::BrowserContext* profile) OVERRIDE { | 44 virtual void BrowserContextShutdown( |
| 45 content::BrowserContext* context) OVERRIDE { |
| 45 fill_on_shutdown_->push_back(name_); | 46 fill_on_shutdown_->push_back(name_); |
| 46 } | 47 } |
| 47 | 48 |
| 48 private: | 49 private: |
| 49 const std::string name_; | 50 const std::string name_; |
| 50 std::vector<std::string>* fill_on_shutdown_; | 51 std::vector<std::string>* fill_on_shutdown_; |
| 51 }; | 52 }; |
| 52 | 53 |
| 53 // Tests that we can deal with a single component. | 54 // Tests that we can deal with a single component. |
| 54 TEST_F(ProfileDependencyManagerUnittests, SingleCase) { | 55 TEST_F(BrowserContextDependencyManagerUnittests, SingleCase) { |
| 55 TestService service("service", shutdown_order(), manager()); | 56 TestService service("service", shutdown_order(), manager()); |
| 56 | 57 |
| 57 manager()->DestroyProfileServices(NULL); | 58 manager()->DestroyBrowserContextServices(NULL); |
| 58 | 59 |
| 59 ASSERT_EQ(1U, shutdown_order()->size()); | 60 ASSERT_EQ(1U, shutdown_order()->size()); |
| 60 EXPECT_STREQ("service", (*shutdown_order())[0].c_str()); | 61 EXPECT_STREQ("service", (*shutdown_order())[0].c_str()); |
| 61 } | 62 } |
| 62 | 63 |
| 63 // Tests that we get a simple one component depends on the other case. | 64 // Tests that we get a simple one component depends on the other case. |
| 64 TEST_F(ProfileDependencyManagerUnittests, SimpleDependency) { | 65 TEST_F(BrowserContextDependencyManagerUnittests, SimpleDependency) { |
| 65 TestService parent("parent", shutdown_order(), manager()); | 66 TestService parent("parent", shutdown_order(), manager()); |
| 66 TestService child("child", shutdown_order(), manager()); | 67 TestService child("child", shutdown_order(), manager()); |
| 67 DependOn(&child, &parent); | 68 DependOn(&child, &parent); |
| 68 | 69 |
| 69 manager()->DestroyProfileServices(NULL); | 70 manager()->DestroyBrowserContextServices(NULL); |
| 70 | 71 |
| 71 ASSERT_EQ(2U, shutdown_order()->size()); | 72 ASSERT_EQ(2U, shutdown_order()->size()); |
| 72 EXPECT_STREQ("child", (*shutdown_order())[0].c_str()); | 73 EXPECT_STREQ("child", (*shutdown_order())[0].c_str()); |
| 73 EXPECT_STREQ("parent", (*shutdown_order())[1].c_str()); | 74 EXPECT_STREQ("parent", (*shutdown_order())[1].c_str()); |
| 74 } | 75 } |
| 75 | 76 |
| 76 // Tests two children, one parent | 77 // Tests two children, one parent |
| 77 TEST_F(ProfileDependencyManagerUnittests, TwoChildrenOneParent) { | 78 TEST_F(BrowserContextDependencyManagerUnittests, TwoChildrenOneParent) { |
| 78 TestService parent("parent", shutdown_order(), manager()); | 79 TestService parent("parent", shutdown_order(), manager()); |
| 79 TestService child1("child1", shutdown_order(), manager()); | 80 TestService child1("child1", shutdown_order(), manager()); |
| 80 TestService child2("child2", shutdown_order(), manager()); | 81 TestService child2("child2", shutdown_order(), manager()); |
| 81 DependOn(&child1, &parent); | 82 DependOn(&child1, &parent); |
| 82 DependOn(&child2, &parent); | 83 DependOn(&child2, &parent); |
| 83 | 84 |
| 84 manager()->DestroyProfileServices(NULL); | 85 manager()->DestroyBrowserContextServices(NULL); |
| 85 | 86 |
| 86 ASSERT_EQ(3U, shutdown_order()->size()); | 87 ASSERT_EQ(3U, shutdown_order()->size()); |
| 87 EXPECT_STREQ("child2", (*shutdown_order())[0].c_str()); | 88 EXPECT_STREQ("child2", (*shutdown_order())[0].c_str()); |
| 88 EXPECT_STREQ("child1", (*shutdown_order())[1].c_str()); | 89 EXPECT_STREQ("child1", (*shutdown_order())[1].c_str()); |
| 89 EXPECT_STREQ("parent", (*shutdown_order())[2].c_str()); | 90 EXPECT_STREQ("parent", (*shutdown_order())[2].c_str()); |
| 90 } | 91 } |
| 91 | 92 |
| 92 // Tests an M configuration | 93 // Tests an M configuration |
| 93 TEST_F(ProfileDependencyManagerUnittests, MConfiguration) { | 94 TEST_F(BrowserContextDependencyManagerUnittests, MConfiguration) { |
| 94 TestService parent1("parent1", shutdown_order(), manager()); | 95 TestService parent1("parent1", shutdown_order(), manager()); |
| 95 TestService parent2("parent2", shutdown_order(), manager()); | 96 TestService parent2("parent2", shutdown_order(), manager()); |
| 96 | 97 |
| 97 TestService child_of_1("child_of_1", shutdown_order(), manager()); | 98 TestService child_of_1("child_of_1", shutdown_order(), manager()); |
| 98 DependOn(&child_of_1, &parent1); | 99 DependOn(&child_of_1, &parent1); |
| 99 | 100 |
| 100 TestService child_of_12("child_of_12", shutdown_order(), manager()); | 101 TestService child_of_12("child_of_12", shutdown_order(), manager()); |
| 101 DependOn(&child_of_12, &parent1); | 102 DependOn(&child_of_12, &parent1); |
| 102 DependOn(&child_of_12, &parent2); | 103 DependOn(&child_of_12, &parent2); |
| 103 | 104 |
| 104 TestService child_of_2("child_of_2", shutdown_order(), manager()); | 105 TestService child_of_2("child_of_2", shutdown_order(), manager()); |
| 105 DependOn(&child_of_2, &parent2); | 106 DependOn(&child_of_2, &parent2); |
| 106 | 107 |
| 107 manager()->DestroyProfileServices(NULL); | 108 manager()->DestroyBrowserContextServices(NULL); |
| 108 | 109 |
| 109 ASSERT_EQ(5U, shutdown_order()->size()); | 110 ASSERT_EQ(5U, shutdown_order()->size()); |
| 110 EXPECT_STREQ("child_of_2", (*shutdown_order())[0].c_str()); | 111 EXPECT_STREQ("child_of_2", (*shutdown_order())[0].c_str()); |
| 111 EXPECT_STREQ("child_of_12", (*shutdown_order())[1].c_str()); | 112 EXPECT_STREQ("child_of_12", (*shutdown_order())[1].c_str()); |
| 112 EXPECT_STREQ("child_of_1", (*shutdown_order())[2].c_str()); | 113 EXPECT_STREQ("child_of_1", (*shutdown_order())[2].c_str()); |
| 113 EXPECT_STREQ("parent2", (*shutdown_order())[3].c_str()); | 114 EXPECT_STREQ("parent2", (*shutdown_order())[3].c_str()); |
| 114 EXPECT_STREQ("parent1", (*shutdown_order())[4].c_str()); | 115 EXPECT_STREQ("parent1", (*shutdown_order())[4].c_str()); |
| 115 } | 116 } |
| 116 | 117 |
| 117 // Tests that it can deal with a simple diamond. | 118 // Tests that it can deal with a simple diamond. |
| 118 TEST_F(ProfileDependencyManagerUnittests, DiamondConfiguration) { | 119 TEST_F(BrowserContextDependencyManagerUnittests, DiamondConfiguration) { |
| 119 TestService parent("parent", shutdown_order(), manager()); | 120 TestService parent("parent", shutdown_order(), manager()); |
| 120 | 121 |
| 121 TestService middle_row_1("middle_row_1", shutdown_order(), manager()); | 122 TestService middle_row_1("middle_row_1", shutdown_order(), manager()); |
| 122 DependOn(&middle_row_1, &parent); | 123 DependOn(&middle_row_1, &parent); |
| 123 | 124 |
| 124 TestService middle_row_2("middle_row_2", shutdown_order(), manager()); | 125 TestService middle_row_2("middle_row_2", shutdown_order(), manager()); |
| 125 DependOn(&middle_row_2, &parent); | 126 DependOn(&middle_row_2, &parent); |
| 126 | 127 |
| 127 TestService bottom("bottom", shutdown_order(), manager()); | 128 TestService bottom("bottom", shutdown_order(), manager()); |
| 128 DependOn(&bottom, &middle_row_1); | 129 DependOn(&bottom, &middle_row_1); |
| 129 DependOn(&bottom, &middle_row_2); | 130 DependOn(&bottom, &middle_row_2); |
| 130 | 131 |
| 131 manager()->DestroyProfileServices(NULL); | 132 manager()->DestroyBrowserContextServices(NULL); |
| 132 | 133 |
| 133 ASSERT_EQ(4U, shutdown_order()->size()); | 134 ASSERT_EQ(4U, shutdown_order()->size()); |
| 134 EXPECT_STREQ("bottom", (*shutdown_order())[0].c_str()); | 135 EXPECT_STREQ("bottom", (*shutdown_order())[0].c_str()); |
| 135 EXPECT_STREQ("middle_row_2", (*shutdown_order())[1].c_str()); | 136 EXPECT_STREQ("middle_row_2", (*shutdown_order())[1].c_str()); |
| 136 EXPECT_STREQ("middle_row_1", (*shutdown_order())[2].c_str()); | 137 EXPECT_STREQ("middle_row_1", (*shutdown_order())[2].c_str()); |
| 137 EXPECT_STREQ("parent", (*shutdown_order())[3].c_str()); | 138 EXPECT_STREQ("parent", (*shutdown_order())[3].c_str()); |
| 138 } | 139 } |
| 139 | 140 |
| 140 // A final test that works with a more complex graph. | 141 // A final test that works with a more complex graph. |
| 141 TEST_F(ProfileDependencyManagerUnittests, ComplexGraph) { | 142 TEST_F(BrowserContextDependencyManagerUnittests, ComplexGraph) { |
| 142 TestService everything_depends_on_me("everything_depends_on_me", | 143 TestService everything_depends_on_me("everything_depends_on_me", |
| 143 shutdown_order(), manager()); | 144 shutdown_order(), manager()); |
| 144 | 145 |
| 145 TestService intermediary_service("intermediary_service", | 146 TestService intermediary_service("intermediary_service", |
| 146 shutdown_order(), manager()); | 147 shutdown_order(), manager()); |
| 147 DependOn(&intermediary_service, &everything_depends_on_me); | 148 DependOn(&intermediary_service, &everything_depends_on_me); |
| 148 | 149 |
| 149 TestService specialized_service("specialized_service", | 150 TestService specialized_service("specialized_service", |
| 150 shutdown_order(), manager()); | 151 shutdown_order(), manager()); |
| 151 DependOn(&specialized_service, &everything_depends_on_me); | 152 DependOn(&specialized_service, &everything_depends_on_me); |
| 152 DependOn(&specialized_service, &intermediary_service); | 153 DependOn(&specialized_service, &intermediary_service); |
| 153 | 154 |
| 154 TestService other_root("other_root", shutdown_order(), manager()); | 155 TestService other_root("other_root", shutdown_order(), manager()); |
| 155 | 156 |
| 156 TestService other_intermediary("other_intermediary", | 157 TestService other_intermediary("other_intermediary", |
| 157 shutdown_order(), manager()); | 158 shutdown_order(), manager()); |
| 158 DependOn(&other_intermediary, &other_root); | 159 DependOn(&other_intermediary, &other_root); |
| 159 | 160 |
| 160 TestService bottom("bottom", shutdown_order(), manager()); | 161 TestService bottom("bottom", shutdown_order(), manager()); |
| 161 DependOn(&bottom, &specialized_service); | 162 DependOn(&bottom, &specialized_service); |
| 162 DependOn(&bottom, &other_intermediary); | 163 DependOn(&bottom, &other_intermediary); |
| 163 | 164 |
| 164 manager()->DestroyProfileServices(NULL); | 165 manager()->DestroyBrowserContextServices(NULL); |
| 165 | 166 |
| 166 ASSERT_EQ(6U, shutdown_order()->size()); | 167 ASSERT_EQ(6U, shutdown_order()->size()); |
| 167 EXPECT_STREQ("bottom", (*shutdown_order())[0].c_str()); | 168 EXPECT_STREQ("bottom", (*shutdown_order())[0].c_str()); |
| 168 EXPECT_STREQ("specialized_service", (*shutdown_order())[1].c_str()); | 169 EXPECT_STREQ("specialized_service", (*shutdown_order())[1].c_str()); |
| 169 EXPECT_STREQ("other_intermediary", (*shutdown_order())[2].c_str()); | 170 EXPECT_STREQ("other_intermediary", (*shutdown_order())[2].c_str()); |
| 170 EXPECT_STREQ("intermediary_service", (*shutdown_order())[3].c_str()); | 171 EXPECT_STREQ("intermediary_service", (*shutdown_order())[3].c_str()); |
| 171 EXPECT_STREQ("other_root", (*shutdown_order())[4].c_str()); | 172 EXPECT_STREQ("other_root", (*shutdown_order())[4].c_str()); |
| 172 EXPECT_STREQ("everything_depends_on_me", (*shutdown_order())[5].c_str()); | 173 EXPECT_STREQ("everything_depends_on_me", (*shutdown_order())[5].c_str()); |
| 173 } | 174 } |
| OLD | NEW |