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

Side by Side Diff: components/history/core/browser/visit_database_unittest.cc

Issue 1370493002: Enable history counting for time ranges. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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) 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 <set> 5 #include <set>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 409
410 // Now try without de-duping, expect to see all visible visits to url id 1. 410 // Now try without de-duping, expect to see all visible visits to url id 1.
411 options.duplicate_policy = QueryOptions::KEEP_ALL_DUPLICATES; 411 options.duplicate_policy = QueryOptions::KEEP_ALL_DUPLICATES;
412 GetVisibleVisitsForURL(url_id, options, &results); 412 GetVisibleVisitsForURL(url_id, options, &results);
413 ASSERT_EQ(static_cast<size_t>(3), results.size()); 413 ASSERT_EQ(static_cast<size_t>(3), results.size());
414 EXPECT_TRUE(IsVisitInfoEqual(results[0], test_visit_rows[5])); 414 EXPECT_TRUE(IsVisitInfoEqual(results[0], test_visit_rows[5]));
415 EXPECT_TRUE(IsVisitInfoEqual(results[1], test_visit_rows[1])); 415 EXPECT_TRUE(IsVisitInfoEqual(results[1], test_visit_rows[1]));
416 EXPECT_TRUE(IsVisitInfoEqual(results[2], test_visit_rows[0])); 416 EXPECT_TRUE(IsVisitInfoEqual(results[2], test_visit_rows[0]));
417 } 417 }
418 418
419 TEST_F(VisitDatabaseTest, GetHistoryCount) {
420 Time today = Time::Now().LocalMidnight();
421 Time tomorrow = today + TimeDelta::FromDays(1);
422 Time after_tomorrow = today + TimeDelta::FromDays(2);
423 Time now = today;
lwchkg 2015/09/25 04:06:35 The test will fail when the day is near DST switch
msramek 2015/09/25 10:44:35 Done. Thanks for reminding me, I forgot about DST
424
lwchkg 2015/09/25 04:06:35 Anyway, any plans to test time zone and DST handli
msramek 2015/09/25 10:44:35 I've added DST-specific tests at the end. This is
425 ui::PageTransition standard_transition = ui::PageTransitionFromInt(
426 ui::PAGE_TRANSITION_TYPED |
427 ui::PAGE_TRANSITION_CHAIN_START |
428 ui::PAGE_TRANSITION_CHAIN_END);
429
430 // Add 5 visits (3 distinct URLs) for today. Whether the URL was browsed
431 // on this machine or synced has no effect.
432 VisitRow today_1(1, now, 0, standard_transition, 0);
433 today_1.visit_id = 1;
434 AddVisit(&today_1, SOURCE_BROWSED);
435 now += TimeDelta::FromHours(1);
436
437 VisitRow today_2(2, now, 0, standard_transition, 0);
438 today_2.visit_id = 2;
439 AddVisit(&today_2, SOURCE_BROWSED);
440 now += TimeDelta::FromHours(1);
441
442 VisitRow today_3(1, now, 0, standard_transition, 0);
443 today_3.visit_id = 3;
444 AddVisit(&today_3, SOURCE_SYNCED);
445 now += TimeDelta::FromHours(1);
446
447 VisitRow today_4(3, now, 0, standard_transition, 0);
448 today_4.visit_id = 4;
449 AddVisit(&today_4, SOURCE_SYNCED);
450 now += TimeDelta::FromHours(1);
451
452 VisitRow today_5(2, now, 0, standard_transition, 0);
453 today_5.visit_id = 5;
454 AddVisit(&today_5, SOURCE_BROWSED);
455 now += TimeDelta::FromHours(1);
456
457 // Add 4 more visits for tomorrow. One of them is invalid, as it's not
458 // a user-visible navigation. Of the remaining 3, only 2 are unique.
459 now = tomorrow;
460
461 VisitRow tomorrow_1(1, now, 0, standard_transition, 0);
462 tomorrow_1.visit_id = 6;
463 AddVisit(&tomorrow_1, SOURCE_BROWSED);
464 now += TimeDelta::FromHours(1);
465
466 VisitRow tomorrow_2(1, now, 0, standard_transition, 0);
467 tomorrow_2.visit_id = 7;
468 AddVisit(&tomorrow_2, SOURCE_BROWSED);
469 now += TimeDelta::FromHours(1);
470
471 VisitRow tomorrow_3(2, now, 0, ui::PAGE_TRANSITION_AUTO_SUBFRAME, 0);
472 tomorrow_3.visit_id = 8;
473 AddVisit(&tomorrow_3, SOURCE_BROWSED);
474 now += TimeDelta::FromHours(1);
475
476 VisitRow tomorrow_4(3, now, 0, standard_transition, 0);
477 tomorrow_4.visit_id = 9;
478 AddVisit(&tomorrow_4, SOURCE_BROWSED);
479 now += TimeDelta::FromHours(1);
480
481 int result;
482
483 // There are 3 distinct URLs today.
484 EXPECT_TRUE(GetHistoryCount(today, tomorrow, &result));
485 EXPECT_EQ(3, result);
486
487 // For today and tomorrow, there should be 5 per-day unique URLs.
488 EXPECT_TRUE(GetHistoryCount(today, after_tomorrow, &result));
489 EXPECT_EQ(5, result);
490
491 // Since we only have entries for today and tomorrow, the infinite time
492 // range should yield the same result.
493 EXPECT_TRUE(GetHistoryCount(Time(), Time::Max(), &result));
494 EXPECT_EQ(5, result);
495
496 // Narrowing the range to exclude |today_1| will still return 5,
497 // because |today_1| is not unique.
498 EXPECT_TRUE(GetHistoryCount(
499 today + TimeDelta::FromHours(2), after_tomorrow, &result));
500 EXPECT_EQ(5, result);
501
502 // Narrowing the range to exclude |tomorrow_4| will return 4,
503 // because |tomorrow_4| is unique.
504 EXPECT_TRUE(GetHistoryCount(
505 today, tomorrow + TimeDelta::FromHours(3), &result));
506 EXPECT_EQ(4, result);
507
508 // Narrowing the range to exclude both |today_1| and |tomorrow_4| will
509 // still return 4.
510 EXPECT_TRUE(GetHistoryCount(today + TimeDelta::FromHours(2),
511 tomorrow + TimeDelta::FromHours(3),
512 &result));
513 EXPECT_EQ(4, result);
514
515 // A range that contains no visits will return 0.
516 EXPECT_TRUE(GetHistoryCount(today + TimeDelta::FromMicroseconds(1),
517 today + TimeDelta::FromHours(1),
518 &result));
519 EXPECT_EQ(0, result);
520 }
521
419 } // namespace history 522 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698