OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/browsing_data/hosted_apps_counter.h" | 5 #include "chrome/browser/browsing_data/hosted_apps_counter.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 17 matching lines...) Expand all Loading... |
28 using extensions::DictionaryBuilder; | 28 using extensions::DictionaryBuilder; |
29 using extensions::ListBuilder; | 29 using extensions::ListBuilder; |
30 | 30 |
31 class HostedAppsCounterTest : public testing::Test { | 31 class HostedAppsCounterTest : public testing::Test { |
32 public: | 32 public: |
33 void SetUp() override { | 33 void SetUp() override { |
34 profile_.reset(new TestingProfile()); | 34 profile_.reset(new TestingProfile()); |
35 extension_registry_ = extensions::ExtensionRegistry::Get(profile_.get()); | 35 extension_registry_ = extensions::ExtensionRegistry::Get(profile_.get()); |
36 | 36 |
37 SetHostedAppsDeletionPref(true); | 37 SetHostedAppsDeletionPref(true); |
38 SetDeletionPeriodPref(browsing_data::ALL_TIME); | 38 SetDeletionPeriodPref(browsing_data::TimePeriod::ALL_TIME); |
39 } | 39 } |
40 | 40 |
41 // Adding and removing apps and extensions. ---------------------------------- | 41 // Adding and removing apps and extensions. ---------------------------------- |
42 | 42 |
43 std::string AddExtension() { | 43 std::string AddExtension() { |
44 return AddItem( | 44 return AddItem( |
45 base::GenerateGUID(), | 45 base::GenerateGUID(), |
46 std::unique_ptr<base::DictionaryValue>()); | 46 std::unique_ptr<base::DictionaryValue>()); |
47 } | 47 } |
48 | 48 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 145 |
146 bool finished_; | 146 bool finished_; |
147 browsing_data::BrowsingDataCounter::ResultInt num_apps_; | 147 browsing_data::BrowsingDataCounter::ResultInt num_apps_; |
148 std::vector<std::string> examples_; | 148 std::vector<std::string> examples_; |
149 }; | 149 }; |
150 | 150 |
151 // Tests that we count the total number of hosted apps correctly. | 151 // Tests that we count the total number of hosted apps correctly. |
152 TEST_F(HostedAppsCounterTest, Count) { | 152 TEST_F(HostedAppsCounterTest, Count) { |
153 Profile* profile = GetProfile(); | 153 Profile* profile = GetProfile(); |
154 HostedAppsCounter counter(profile); | 154 HostedAppsCounter counter(profile); |
155 counter.Init(profile->GetPrefs(), base::Bind(&HostedAppsCounterTest::Callback, | 155 counter.Init( |
156 base::Unretained(this))); | 156 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, |
| 157 base::Bind(&HostedAppsCounterTest::Callback, base::Unretained(this))); |
157 counter.Restart(); | 158 counter.Restart(); |
158 EXPECT_EQ(0u, GetNumHostedApps()); | 159 EXPECT_EQ(0u, GetNumHostedApps()); |
159 | 160 |
160 std::string first_app = AddHostedApp(); | 161 std::string first_app = AddHostedApp(); |
161 AddHostedApp(); | 162 AddHostedApp(); |
162 std::string last_app = AddHostedApp(); | 163 std::string last_app = AddHostedApp(); |
163 | 164 |
164 counter.Restart(); | 165 counter.Restart(); |
165 EXPECT_EQ(3u, GetNumHostedApps()); | 166 EXPECT_EQ(3u, GetNumHostedApps()); |
166 | 167 |
167 RemoveItem(last_app); | 168 RemoveItem(last_app); |
168 RemoveItem(first_app); | 169 RemoveItem(first_app); |
169 counter.Restart(); | 170 counter.Restart(); |
170 EXPECT_EQ(1u, GetNumHostedApps()); | 171 EXPECT_EQ(1u, GetNumHostedApps()); |
171 | 172 |
172 AddHostedApp(); | 173 AddHostedApp(); |
173 counter.Restart(); | 174 counter.Restart(); |
174 EXPECT_EQ(2u, GetNumHostedApps()); | 175 EXPECT_EQ(2u, GetNumHostedApps()); |
175 } | 176 } |
176 | 177 |
177 // Tests that we only count hosted apps, not packaged apps or extensions. | 178 // Tests that we only count hosted apps, not packaged apps or extensions. |
178 TEST_F(HostedAppsCounterTest, OnlyHostedApps) { | 179 TEST_F(HostedAppsCounterTest, OnlyHostedApps) { |
179 Profile* profile = GetProfile(); | 180 Profile* profile = GetProfile(); |
180 HostedAppsCounter counter(profile); | 181 HostedAppsCounter counter(profile); |
181 counter.Init(profile->GetPrefs(), base::Bind(&HostedAppsCounterTest::Callback, | 182 counter.Init( |
182 base::Unretained(this))); | 183 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, |
| 184 base::Bind(&HostedAppsCounterTest::Callback, base::Unretained(this))); |
183 | 185 |
184 AddHostedApp(); // 1 | 186 AddHostedApp(); // 1 |
185 AddExtension(); | 187 AddExtension(); |
186 AddPackagedApp(); | 188 AddPackagedApp(); |
187 AddExtension(); | 189 AddExtension(); |
188 counter.Restart(); | 190 counter.Restart(); |
189 EXPECT_EQ(1u, GetNumHostedApps()); | 191 EXPECT_EQ(1u, GetNumHostedApps()); |
190 | 192 |
191 AddHostedApp(); // 2 | 193 AddHostedApp(); // 2 |
192 AddHostedApp(); // 3 | 194 AddHostedApp(); // 3 |
(...skipping 15 matching lines...) Expand all Loading... |
208 AddPackagedApp(); | 210 AddPackagedApp(); |
209 counter.Restart(); | 211 counter.Restart(); |
210 EXPECT_EQ(5u, GetNumHostedApps()); | 212 EXPECT_EQ(5u, GetNumHostedApps()); |
211 } | 213 } |
212 | 214 |
213 // Tests that the counter results contain names of the first two hosted apps | 215 // Tests that the counter results contain names of the first two hosted apps |
214 // in lexicographic ordering. | 216 // in lexicographic ordering. |
215 TEST_F(HostedAppsCounterTest, Examples) { | 217 TEST_F(HostedAppsCounterTest, Examples) { |
216 Profile* profile = GetProfile(); | 218 Profile* profile = GetProfile(); |
217 HostedAppsCounter counter(profile); | 219 HostedAppsCounter counter(profile); |
218 counter.Init(profile->GetPrefs(), base::Bind(&HostedAppsCounterTest::Callback, | 220 counter.Init( |
219 base::Unretained(this))); | 221 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, |
| 222 base::Bind(&HostedAppsCounterTest::Callback, base::Unretained(this))); |
220 counter.Restart(); | 223 counter.Restart(); |
221 EXPECT_EQ(0u, GetExamples().size()); | 224 EXPECT_EQ(0u, GetExamples().size()); |
222 | 225 |
223 AddHostedAppWithName("App 1"); | 226 AddHostedAppWithName("App 1"); |
224 counter.Restart(); | 227 counter.Restart(); |
225 EXPECT_EQ(1u, GetExamples().size()); | 228 EXPECT_EQ(1u, GetExamples().size()); |
226 EXPECT_EQ("App 1", GetExamples().front()); | 229 EXPECT_EQ("App 1", GetExamples().front()); |
227 | 230 |
228 AddHostedAppWithName("App 2"); | 231 AddHostedAppWithName("App 2"); |
229 counter.Restart(); | 232 counter.Restart(); |
230 EXPECT_EQ(2u, GetExamples().size()); | 233 EXPECT_EQ(2u, GetExamples().size()); |
231 EXPECT_EQ("App 1", GetExamples().front()); | 234 EXPECT_EQ("App 1", GetExamples().front()); |
232 EXPECT_EQ("App 2", GetExamples().back()); | 235 EXPECT_EQ("App 2", GetExamples().back()); |
233 | 236 |
234 AddHostedAppWithName("App 3"); | 237 AddHostedAppWithName("App 3"); |
235 counter.Restart(); | 238 counter.Restart(); |
236 EXPECT_EQ(2u, GetExamples().size()); | 239 EXPECT_EQ(2u, GetExamples().size()); |
237 EXPECT_EQ("App 1", GetExamples().front()); | 240 EXPECT_EQ("App 1", GetExamples().front()); |
238 EXPECT_EQ("App 2", GetExamples().back()); | 241 EXPECT_EQ("App 2", GetExamples().back()); |
239 } | 242 } |
240 | 243 |
241 } // namespace | 244 } // namespace |
OLD | NEW |