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

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

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

Powered by Google App Engine
This is Rietveld 408576698