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

Side by Side Diff: chrome/browser/profiles/profile_dependency_manager_unittest.cc

Issue 6766004: Create a ProfileDependencyManager to order ProfileKeyedService destruction. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "testing/gtest/include/gtest/gtest.h"
6
7 #include "chrome/browser/profiles/profile_dependency_manager.h"
8 #include "chrome/browser/profiles/profile_keyed_service_factory.h"
9 #include "chrome/test/testing_profile.h"
10
11 class ProfileDependencyManagerUnittests : public ::testing::Test {
12 protected:
13 virtual ~ProfileDependencyManagerUnittests() {
14 EXPECT_TRUE(dependency_manager_.all_components_.empty());
15 EXPECT_TRUE(dependency_manager_.edges_.empty());
16 EXPECT_TRUE(dependency_manager_.destruction_order_.empty());
17 }
18
19 // To get around class access:
20 void DependOn(ProfileKeyedServiceFactory* child,
21 ProfileKeyedServiceFactory* parent) {
22 child->DependsOn(parent);
23 }
24
25 ProfileDependencyManager* manager() { return &dependency_manager_; }
26
27 std::vector<std::string>* shutdown_order() { return &shutdown_order_; }
28
29 private:
30 ProfileDependencyManager dependency_manager_;
31
32 std::vector<std::string> shutdown_order_;
33 };
34
35 class TestService : public ProfileKeyedServiceFactory {
36 public:
37 TestService(const std::string& name,
38 std::vector<std::string>* fill_on_shutdown,
39 ProfileDependencyManager* manager)
40 : ProfileKeyedServiceFactory(manager),
41 name_(name),
42 fill_on_shutdown_(fill_on_shutdown) {
43 }
44
45 virtual ProfileKeyedService* BuildServiceInstanceFor(
46 Profile* profile) const {
47 NOTREACHED() << "This isn't part of the tests!";
Paweł Hajdan Jr. 2011/03/29 19:10:28 nit: NOTREACHED() will fire only for the Debug bui
48 return NULL;
49 }
50
51 virtual void ProfileShutdown(Profile* profile) {
52 fill_on_shutdown_->push_back(name_);
53 }
54
55 private:
56 const std::string name_;
57 std::vector<std::string>* fill_on_shutdown_;
58 };
59
60 // Tests that we can deal with a single component.
61 TEST_F(ProfileDependencyManagerUnittests, SingleCase) {
62 TestService service("service", shutdown_order(), manager());
63
64 {
65 TestingProfile profile;
66 }
67
68 ASSERT_EQ(1U, shutdown_order()->size());
69 EXPECT_STREQ("service", (*shutdown_order())[0].c_str());
70 }
71
72 // Tests that we get a simple one component depends on the other case.
73 TEST_F(ProfileDependencyManagerUnittests, SimpleDependency) {
74 TestService parent("parent", shutdown_order(), manager());
75 TestService child("child", shutdown_order(), manager());
76 DependOn(&child, &parent);
77
78 {
79 TestingProfile profile;
80 }
81
82 ASSERT_EQ(2U, shutdown_order()->size());
83 EXPECT_STREQ("child", (*shutdown_order())[0].c_str());
84 EXPECT_STREQ("parent", (*shutdown_order())[1].c_str());
85 }
86
87 // Tests two children, one parent
88 TEST_F(ProfileDependencyManagerUnittests, TwoChildrenOneParent) {
89 TestService parent("parent", shutdown_order(), manager());
90 TestService child1("child1", shutdown_order(), manager());
91 TestService child2("child2", shutdown_order(), manager());
92 DependOn(&child1, &parent);
93 DependOn(&child2, &parent);
94
95 {
96 TestingProfile profile;
97 }
98
99 ASSERT_EQ(3U, shutdown_order()->size());
100 EXPECT_STREQ("child2", (*shutdown_order())[0].c_str());
101 EXPECT_STREQ("child1", (*shutdown_order())[1].c_str());
102 EXPECT_STREQ("parent", (*shutdown_order())[2].c_str());
103 }
104
105 // Tests an M configuration
106 TEST_F(ProfileDependencyManagerUnittests, MConfiguration) {
107 TestService parent1("parent1", shutdown_order(), manager());
108 TestService parent2("parent2", shutdown_order(), manager());
109
110 TestService child_of_1("child_of_1", shutdown_order(), manager());
111 DependOn(&child_of_1, &parent1);
112
113 TestService child_of_12("child_of_12", shutdown_order(), manager());
114 DependOn(&child_of_12, &parent1);
115 DependOn(&child_of_12, &parent2);
116
117 TestService child_of_2("child_of_2", shutdown_order(), manager());
118 DependOn(&child_of_2, &parent2);
119
120 {
121 TestingProfile profile;
122 }
123
124 ASSERT_EQ(5U, shutdown_order()->size());
125 EXPECT_STREQ("child_of_2", (*shutdown_order())[0].c_str());
126 EXPECT_STREQ("child_of_12", (*shutdown_order())[1].c_str());
127 EXPECT_STREQ("child_of_1", (*shutdown_order())[2].c_str());
128 EXPECT_STREQ("parent2", (*shutdown_order())[3].c_str());
129 EXPECT_STREQ("parent1", (*shutdown_order())[4].c_str());
130 }
131
132 // Tests that it can deal with a simple diamond.
133 TEST_F(ProfileDependencyManagerUnittests, DiamondConfiguration) {
134 TestService parent("parent", shutdown_order(), manager());
135
136 TestService middle_row_1("middle_row_1", shutdown_order(), manager());
137 DependOn(&middle_row_1, &parent);
138
139 TestService middle_row_2("middle_row_2", shutdown_order(), manager());
140 DependOn(&middle_row_2, &parent);
141
142 TestService bottom("bottom", shutdown_order(), manager());
143 DependOn(&bottom, &middle_row_1);
144 DependOn(&bottom, &middle_row_2);
145
146 {
147 TestingProfile profile;
148 }
149
150 ASSERT_EQ(4U, shutdown_order()->size());
151 EXPECT_STREQ("bottom", (*shutdown_order())[0].c_str());
152 EXPECT_STREQ("middle_row_2", (*shutdown_order())[1].c_str());
153 EXPECT_STREQ("middle_row_1", (*shutdown_order())[2].c_str());
154 EXPECT_STREQ("parent", (*shutdown_order())[3].c_str());
155 }
156
157 // A final test that works with a more complex graph.
158 TEST_F(ProfileDependencyManagerUnittests, ComplexGraph) {
159 TestService everything_depends_on_me("everything_depends_on_me",
160 shutdown_order(), manager());
161
162 TestService intermediary_service("intermediary_service",
163 shutdown_order(), manager());
164 DependOn(&intermediary_service, &everything_depends_on_me);
165
166 TestService specialized_service("specialized_service",
167 shutdown_order(), manager());
168 DependOn(&specialized_service, &everything_depends_on_me);
169 DependOn(&specialized_service, &intermediary_service);
170
171 TestService other_root("other_root", shutdown_order(), manager());
172
173 TestService other_intermediary("other_intermediary",
174 shutdown_order(), manager());
175 DependOn(&other_intermediary, &other_root);
176
177 TestService bottom("bottom", shutdown_order(), manager());
178 DependOn(&bottom, &specialized_service);
179 DependOn(&bottom, &other_intermediary);
180
181 {
182 TestingProfile profile;
183 }
184
185 ASSERT_EQ(6U, shutdown_order()->size());
186 EXPECT_STREQ("bottom", (*shutdown_order())[0].c_str());
187 EXPECT_STREQ("specialized_service", (*shutdown_order())[1].c_str());
188 EXPECT_STREQ("other_intermediary", (*shutdown_order())[2].c_str());
189 EXPECT_STREQ("intermediary_service", (*shutdown_order())[3].c_str());
190 EXPECT_STREQ("other_root", (*shutdown_order())[4].c_str());
191 EXPECT_STREQ("everything_depends_on_me", (*shutdown_order())[5].c_str());
192 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698