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: components/history/core/browser/visit_database_unittest.cc

Issue 1389923004: Fix the incorrectly named time points in VisitDatabaseTest.GetHistoryCount. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed the date. Created 5 years, 2 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
« no previous file with comments | « no previous file | no next file » | 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) 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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) { 419 TEST_F(VisitDatabaseTest, GetHistoryCount) {
420 Time today = Time::Now().LocalMidnight(); 420 // Start with a day in the middle of summer, so that we are nowhere near
421 // Find the beginning of yesterday and the day before yesterday. We cannot use 421 // DST shifts.
422 // TimeDelta::FromDays(1), as this simply removes 24 hours and thus does not 422 Time today;
423 // work correctly with DST shifts. Instead, we'll jump 36 hours (i.e. 423 ASSERT_TRUE(Time::FromUTCString("2015-07-07", &today));
lwchkg 2015/10/14 16:06:11 Should be Time::FromString to return a local time.
msramek 2015/10/15 08:57:55 Changed to FromString.
424 // somewhere in the middle of the previous day), and use |LocalMidnight()| to 424 Time yesterday = today - TimeDelta::FromDays(1);
425 // round down to the beginning of the day in the local time, taking timezones 425 Time two_days_ago = yesterday - TimeDelta::FromDays(1);
426 // and DST into account. This is necessary to achieve the same equivalence
427 // class on days as the DATE(..., 'localtime') function in SQL.
428 Time yesterday = (today - TimeDelta::FromHours(36)).LocalMidnight();
429 Time two_days_ago = (yesterday - TimeDelta::FromHours(36)).LocalMidnight();
430 Time now = two_days_ago; 426 Time now = two_days_ago;
431 427
432 ui::PageTransition standard_transition = ui::PageTransitionFromInt( 428 ui::PageTransition standard_transition = ui::PageTransitionFromInt(
433 ui::PAGE_TRANSITION_TYPED | 429 ui::PAGE_TRANSITION_TYPED |
434 ui::PAGE_TRANSITION_CHAIN_START | 430 ui::PAGE_TRANSITION_CHAIN_START |
435 ui::PAGE_TRANSITION_CHAIN_END); 431 ui::PAGE_TRANSITION_CHAIN_END);
436 432
437 // Add 5 visits (3 distinct URLs) for the day before yesterday. 433 // Add 5 visits (3 distinct URLs) for the day before yesterday.
438 // Whether the URL was browsed on this machine or synced has no effect. 434 // Whether the URL was browsed on this machine or synced has no effect.
439 VisitRow first_day_1(1, now, 0, standard_transition, 0); 435 VisitRow first_day_1(1, now, 0, standard_transition, 0);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 &result)); 515 &result));
520 EXPECT_EQ(4, result); 516 EXPECT_EQ(4, result);
521 517
522 // A range that contains no visits will return 0. 518 // A range that contains no visits will return 0.
523 EXPECT_TRUE(GetHistoryCount(two_days_ago + TimeDelta::FromMicroseconds(1), 519 EXPECT_TRUE(GetHistoryCount(two_days_ago + TimeDelta::FromMicroseconds(1),
524 two_days_ago + TimeDelta::FromHours(1), 520 two_days_ago + TimeDelta::FromHours(1),
525 &result)); 521 &result));
526 EXPECT_EQ(0, result); 522 EXPECT_EQ(0, result);
527 523
528 // If this timezone uses DST, test the behavior on days when the time 524 // If this timezone uses DST, test the behavior on days when the time
529 // is shifted forward and backward. 525 // is shifted forward and backward. Note that in this case we cannot use
526 // TimeDelta::FromDays(1) to move one day, as this simply removes 24 hours and
527 // thus does not work correctly with DST shifts. Instead, we'll go back
528 // 1 second (i.e. somewhere in the middle of the previous day), and use
529 // |LocalMidnight()| to round down to the beginning of the day in the local
530 // time, taking timezones and DST into account. This is necessary to achieve
531 // the same equivalence class on days as the DATE(..., 'localtime') function
532 // in SQL.
530 Time shift_forward; 533 Time shift_forward;
531 Time shift_backward; 534 Time shift_backward;
532 Time current_day = (two_days_ago - TimeDelta::FromSeconds(1)).LocalMidnight(); 535 Time current_day = (two_days_ago - TimeDelta::FromSeconds(1)).LocalMidnight();
533 for (int i = 0; i < 366; i++) { 536 for (int i = 0; i < 366; i++) {
534 current_day = (current_day - TimeDelta::FromSeconds(1)).LocalMidnight(); 537 current_day = (current_day - TimeDelta::FromSeconds(1)).LocalMidnight();
535 Time after_24_hours = current_day + TimeDelta::FromHours(24); 538 Time after_24_hours = current_day + TimeDelta::FromHours(24);
536 539
537 if (current_day == after_24_hours.LocalMidnight()) { 540 if (current_day == after_24_hours.LocalMidnight()) {
538 // More than 24 hours. Shift backward. 541 // More than 24 hours. Shift backward.
539 shift_backward = current_day; 542 shift_backward = current_day;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 AddVisit(&forward_2, SOURCE_BROWSED); 585 AddVisit(&forward_2, SOURCE_BROWSED);
583 586
584 EXPECT_TRUE(GetHistoryCount(shift_forward, 587 EXPECT_TRUE(GetHistoryCount(shift_forward,
585 shift_forward + TimeDelta::FromHours(24), 588 shift_forward + TimeDelta::FromHours(24),
586 &result)); 589 &result));
587 EXPECT_EQ(2, result); 590 EXPECT_EQ(2, result);
588 } 591 }
589 } 592 }
590 593
591 } // namespace history 594 } // namespace history
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698