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

Side by Side Diff: chrome/browser/browsing_data/history_counter_browsertest.cc

Issue 2671743002: Separate state of basic and advanced tab in CBD dialog (Closed)
Patch Set: rebase and fix compilation Created 3 years, 9 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
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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 "components/browsing_data/core/counters/history_counter.h" 5 #include "components/browsing_data/core/counters/history_counter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "chrome/browser/history/history_service_factory.h" 10 #include "chrome/browser/history/history_service_factory.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 void SetUpOnMainThread() override { 42 void SetUpOnMainThread() override {
43 time_ = base::Time::Now(); 43 time_ = base::Time::Now();
44 history_service_ = HistoryServiceFactory::GetForProfileWithoutCreating( 44 history_service_ = HistoryServiceFactory::GetForProfileWithoutCreating(
45 browser()->profile()); 45 browser()->profile());
46 fake_web_history_service_.reset(new history::FakeWebHistoryService( 46 fake_web_history_service_.reset(new history::FakeWebHistoryService(
47 ProfileOAuth2TokenServiceFactory::GetForProfile(browser()->profile()), 47 ProfileOAuth2TokenServiceFactory::GetForProfile(browser()->profile()),
48 SigninManagerFactory::GetForProfile(browser()->profile()), 48 SigninManagerFactory::GetForProfile(browser()->profile()),
49 browser()->profile()->GetRequestContext())); 49 browser()->profile()->GetRequestContext()));
50 50
51 SetHistoryDeletionPref(true); 51 SetHistoryDeletionPref(true);
52 SetDeletionPeriodPref(browsing_data::ALL_TIME); 52 SetDeletionPeriodPref(browsing_data::TimePeriod::ALL_TIME);
53 } 53 }
54 54
55 void AddVisit(const std::string url) { 55 void AddVisit(const std::string url) {
56 history_service_->AddPage(GURL(url), time_, history::SOURCE_BROWSED); 56 history_service_->AddPage(GURL(url), time_, history::SOURCE_BROWSED);
57 } 57 }
58 58
59 const base::Time& GetCurrentTime() { 59 const base::Time& GetCurrentTime() {
60 return time_; 60 return time_;
61 } 61 }
62 62
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 Profile* profile = browser()->profile(); 175 Profile* profile = browser()->profile();
176 176
177 browsing_data::HistoryCounter counter( 177 browsing_data::HistoryCounter counter(
178 GetHistoryService(), 178 GetHistoryService(),
179 base::Bind(&HistoryCounterTest::GetRealWebHistoryService, 179 base::Bind(&HistoryCounterTest::GetRealWebHistoryService,
180 base::Unretained(this), 180 base::Unretained(this),
181 base::Unretained(profile)), 181 base::Unretained(profile)),
182 ProfileSyncServiceFactory::GetForProfile(profile)); 182 ProfileSyncServiceFactory::GetForProfile(profile));
183 183
184 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, 184 counter.Init(
185 base::Unretained(this))); 185 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
186 base::Bind(&HistoryCounterTest::Callback, base::Unretained(this)));
186 counter.Restart(); 187 counter.Restart();
187 188
188 WaitForCounting(); 189 WaitForCounting();
189 EXPECT_EQ(7u, GetLocalResult()); 190 EXPECT_EQ(7u, GetLocalResult());
190 } 191 }
191 192
192 // Tests that the counter starts counting automatically when the deletion 193 // Tests that the counter starts counting automatically when the deletion
193 // pref changes to true. 194 // pref changes to true.
194 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PrefChanged) { 195 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PrefChanged) {
195 SetHistoryDeletionPref(false); 196 SetHistoryDeletionPref(false);
196 AddVisit("https://www.google.com"); 197 AddVisit("https://www.google.com");
197 AddVisit("https://www.chrome.com"); 198 AddVisit("https://www.chrome.com");
198 199
199 Profile* profile = browser()->profile(); 200 Profile* profile = browser()->profile();
200 201
201 browsing_data::HistoryCounter counter( 202 browsing_data::HistoryCounter counter(
202 GetHistoryService(), 203 GetHistoryService(),
203 base::Bind(&HistoryCounterTest::GetRealWebHistoryService, 204 base::Bind(&HistoryCounterTest::GetRealWebHistoryService,
204 base::Unretained(this), 205 base::Unretained(this),
205 base::Unretained(profile)), 206 base::Unretained(profile)),
206 ProfileSyncServiceFactory::GetForProfile(profile)); 207 ProfileSyncServiceFactory::GetForProfile(profile));
207 208
208 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, 209 counter.Init(
209 base::Unretained(this))); 210 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
211 base::Bind(&HistoryCounterTest::Callback, base::Unretained(this)));
210 SetHistoryDeletionPref(true); 212 SetHistoryDeletionPref(true);
211 213
212 WaitForCounting(); 214 WaitForCounting();
213 EXPECT_EQ(2u, GetLocalResult()); 215 EXPECT_EQ(2u, GetLocalResult());
214 } 216 }
215 217
216 // Tests that changing the deletion period restarts the counting, and that 218 // Tests that changing the deletion period restarts the counting, and that
217 // the result takes visit dates into account. 219 // the result takes visit dates into account.
218 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PeriodChanged) { 220 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PeriodChanged) {
219 AddVisit("https://www.google.com"); 221 AddVisit("https://www.google.com");
(...skipping 19 matching lines...) Expand all
239 241
240 Profile* profile = browser()->profile(); 242 Profile* profile = browser()->profile();
241 243
242 browsing_data::HistoryCounter counter( 244 browsing_data::HistoryCounter counter(
243 GetHistoryService(), 245 GetHistoryService(),
244 base::Bind(&HistoryCounterTest::GetRealWebHistoryService, 246 base::Bind(&HistoryCounterTest::GetRealWebHistoryService,
245 base::Unretained(this), 247 base::Unretained(this),
246 base::Unretained(profile)), 248 base::Unretained(profile)),
247 ProfileSyncServiceFactory::GetForProfile(profile)); 249 ProfileSyncServiceFactory::GetForProfile(profile));
248 250
249 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, 251 counter.Init(
250 base::Unretained(this))); 252 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
253 base::Bind(&HistoryCounterTest::Callback, base::Unretained(this)));
251 254
252 SetDeletionPeriodPref(browsing_data::LAST_HOUR); 255 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_HOUR);
253 WaitForCounting(); 256 WaitForCounting();
254 EXPECT_EQ(1u, GetLocalResult()); 257 EXPECT_EQ(1u, GetLocalResult());
255 258
256 SetDeletionPeriodPref(browsing_data::LAST_DAY); 259 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_DAY);
257 WaitForCounting(); 260 WaitForCounting();
258 EXPECT_EQ(1u, GetLocalResult()); 261 EXPECT_EQ(1u, GetLocalResult());
259 262
260 SetDeletionPeriodPref(browsing_data::LAST_WEEK); 263 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_WEEK);
261 WaitForCounting(); 264 WaitForCounting();
262 EXPECT_EQ(5u, GetLocalResult()); 265 EXPECT_EQ(5u, GetLocalResult());
263 266
264 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); 267 SetDeletionPeriodPref(browsing_data::TimePeriod::FOUR_WEEKS);
265 WaitForCounting(); 268 WaitForCounting();
266 EXPECT_EQ(8u, GetLocalResult()); 269 EXPECT_EQ(8u, GetLocalResult());
267 270
268 SetDeletionPeriodPref(browsing_data::ALL_TIME); 271 SetDeletionPeriodPref(browsing_data::TimePeriod::ALL_TIME);
269 WaitForCounting(); 272 WaitForCounting();
270 EXPECT_EQ(9u, GetLocalResult()); 273 EXPECT_EQ(9u, GetLocalResult());
271 } 274 }
272 275
273 // Test the behavior for a profile that syncs history. 276 // Test the behavior for a profile that syncs history.
274 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, Synced) { 277 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, Synced) {
275 // WebHistoryService makes network requests, so we need to use a fake one 278 // WebHistoryService makes network requests, so we need to use a fake one
276 // for testing. 279 // for testing.
277 Profile* profile = browser()->profile(); 280 Profile* profile = browser()->profile();
278 281
279 browsing_data::HistoryCounter counter( 282 browsing_data::HistoryCounter counter(
280 GetHistoryService(), 283 GetHistoryService(),
281 base::Bind(&HistoryCounterTest::GetFakeWebHistoryService, 284 base::Bind(&HistoryCounterTest::GetFakeWebHistoryService,
282 base::Unretained(this), 285 base::Unretained(this),
283 base::Unretained(profile), 286 base::Unretained(profile),
284 false), 287 false),
285 ProfileSyncServiceFactory::GetForProfile(profile)); 288 ProfileSyncServiceFactory::GetForProfile(profile));
286 289
287 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, 290 counter.Init(
288 base::Unretained(this))); 291 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
292 base::Bind(&HistoryCounterTest::Callback, base::Unretained(this)));
289 293
290 history::FakeWebHistoryService* service = 294 history::FakeWebHistoryService* service =
291 static_cast<history::FakeWebHistoryService*>(GetFakeWebHistoryService( 295 static_cast<history::FakeWebHistoryService*>(GetFakeWebHistoryService(
292 profile, false)); 296 profile, false));
293 297
294 // No entries locally and no entries in Sync. 298 // No entries locally and no entries in Sync.
295 service->SetupFakeResponse(true /* success */, net::HTTP_OK); 299 service->SetupFakeResponse(true /* success */, net::HTTP_OK);
296 counter.Restart(); 300 counter.Restart();
297 WaitForCounting(); 301 WaitForCounting();
298 EXPECT_EQ(0u, GetLocalResult()); 302 EXPECT_EQ(0u, GetLocalResult());
299 EXPECT_FALSE(HasSyncedVisits()); 303 EXPECT_FALSE(HasSyncedVisits());
300 304
301 // No entries locally. There are some entries in Sync, but they are out of the 305 // No entries locally. There are some entries in Sync, but they are out of the
302 // time range. 306 // time range.
303 SetDeletionPeriodPref(browsing_data::LAST_HOUR); 307 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_HOUR);
304 service->AddSyncedVisit( 308 service->AddSyncedVisit(
305 "www.google.com", GetCurrentTime() - base::TimeDelta::FromHours(2)); 309 "www.google.com", GetCurrentTime() - base::TimeDelta::FromHours(2));
306 service->AddSyncedVisit( 310 service->AddSyncedVisit(
307 "www.chrome.com", GetCurrentTime() - base::TimeDelta::FromHours(2)); 311 "www.chrome.com", GetCurrentTime() - base::TimeDelta::FromHours(2));
308 service->SetupFakeResponse(true /* success */, net::HTTP_OK); 312 service->SetupFakeResponse(true /* success */, net::HTTP_OK);
309 counter.Restart(); 313 counter.Restart();
310 WaitForCounting(); 314 WaitForCounting();
311 EXPECT_EQ(0u, GetLocalResult()); 315 EXPECT_EQ(0u, GetLocalResult());
312 EXPECT_FALSE(HasSyncedVisits()); 316 EXPECT_FALSE(HasSyncedVisits());
313 317
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 // Set up the fake web history service and the counter. 372 // Set up the fake web history service and the counter.
369 373
370 browsing_data::HistoryCounter counter( 374 browsing_data::HistoryCounter counter(
371 GetHistoryService(), 375 GetHistoryService(),
372 base::Bind(&HistoryCounterTest::GetFakeWebHistoryService, 376 base::Bind(&HistoryCounterTest::GetFakeWebHistoryService,
373 base::Unretained(this), 377 base::Unretained(this),
374 base::Unretained(profile), 378 base::Unretained(profile),
375 true), 379 true),
376 sync_service); 380 sync_service);
377 381
378 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, 382 counter.Init(
379 base::Unretained(this))); 383 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
384 base::Bind(&HistoryCounterTest::Callback, base::Unretained(this)));
380 385
381 // Note that some Sync operations notify observers immediately (and thus there 386 // Note that some Sync operations notify observers immediately (and thus there
382 // is no need to call |WaitForCounting()|; in fact, it would block the test), 387 // is no need to call |WaitForCounting()|; in fact, it would block the test),
383 // while other operations only post the task on UI thread's message loop 388 // while other operations only post the task on UI thread's message loop
384 // (which requires calling |WaitForCounting()| for them to run). Therefore, 389 // (which requires calling |WaitForCounting()| for them to run). Therefore,
385 // this test always checks if the callback has already run and only waits 390 // this test always checks if the callback has already run and only waits
386 // if it has not. 391 // if it has not.
387 392
388 // We sync all datatypes by default, so starting Sync means that we start 393 // We sync all datatypes by default, so starting Sync means that we start
389 // syncing history deletion, and this should restart the counter. 394 // syncing history deletion, and this should restart the counter.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 // history deletion did not change. However, in reality we can get two 435 // history deletion did not change. However, in reality we can get two
431 // notifications, one that history sync has stopped and another that it is 436 // notifications, one that history sync has stopped and another that it is
432 // active again. 437 // active again.
433 438
434 // Stopping the Sync service triggers a restart. 439 // Stopping the Sync service triggers a restart.
435 sync_service->RequestStop(syncer::SyncService::CLEAR_DATA); 440 sync_service->RequestStop(syncer::SyncService::CLEAR_DATA);
436 WaitForCountingOrConfirmFinished(); 441 WaitForCountingOrConfirmFinished();
437 } 442 }
438 443
439 } // namespace 444 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698