OLD | NEW |
---|---|
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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 | 418 |
419 TEST_F(VisitDatabaseTest, GetHistoryCount) { | 419 TEST_F(VisitDatabaseTest, GetHistoryCount) { |
420 Time today = Time::Now().LocalMidnight(); | 420 Time today = Time::Now().LocalMidnight(); |
421 // Find the beginning of yesterday and the day before yesterday. We cannot use | 421 // Find the beginning of yesterday and the day before yesterday. We cannot use |
422 // TimeDelta::FromDays(1), as this simply removes 24 hours and thus does not | 422 // TimeDelta::FromDays(1), as this simply removes 24 hours and thus does not |
423 // work correctly with DST shifts. Instead, we'll jump 36 hours (i.e. | 423 // work correctly with DST shifts. Instead, we'll jump 36 hours (i.e. |
424 // somewhere in the middle of the previous day), and use |LocalMidnight()| to | 424 // somewhere in the middle of the previous day), and use |LocalMidnight()| to |
425 // round down to the beginning of the day in the local time, taking timezones | 425 // round down to the beginning of the day in the local time, taking timezones |
426 // and DST into account. This is necessary to achieve the same equivalence | 426 // and DST into account. This is necessary to achieve the same equivalence |
427 // class on days as the DATE(..., 'localtime') function in SQL. | 427 // class on days as the DATE(..., 'localtime') function in SQL. |
428 Time yesterday = (today - TimeDelta::FromHours(36)).LocalMidnight(); | 428 Time yesterday = (today - TimeDelta::FromSeconds(1)).LocalMidnight(); |
sdefresne
2015/10/06 17:14:32
Will this work around day light saving change? Why
lwchkg
2015/10/07 04:59:37
Thanks for a good point. DST is simply very hard a
sdefresne
2015/10/07 07:42:54
Or you could fix that initial date instead of usin
sdefresne
2015/10/07 13:55:36
I was thinking of using a date known not to cause
msramek
2015/10/13 18:10:05
Ok, I fixed the date in the middle of the summer t
| |
429 Time two_days_ago = (yesterday - TimeDelta::FromHours(36)).LocalMidnight(); | 429 Time two_days_ago = (yesterday - TimeDelta::FromSeconds(1)).LocalMidnight(); |
430 Time now = two_days_ago; | 430 Time now = two_days_ago; |
431 | 431 |
432 ui::PageTransition standard_transition = ui::PageTransitionFromInt( | 432 ui::PageTransition standard_transition = ui::PageTransitionFromInt( |
433 ui::PAGE_TRANSITION_TYPED | | 433 ui::PAGE_TRANSITION_TYPED | |
434 ui::PAGE_TRANSITION_CHAIN_START | | 434 ui::PAGE_TRANSITION_CHAIN_START | |
435 ui::PAGE_TRANSITION_CHAIN_END); | 435 ui::PAGE_TRANSITION_CHAIN_END); |
436 | 436 |
437 // Add 5 visits (3 distinct URLs) for the day before yesterday. | 437 // 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. | 438 // Whether the URL was browsed on this machine or synced has no effect. |
439 VisitRow first_day_1(1, now, 0, standard_transition, 0); | 439 VisitRow first_day_1(1, now, 0, standard_transition, 0); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 AddVisit(&forward_2, SOURCE_BROWSED); | 582 AddVisit(&forward_2, SOURCE_BROWSED); |
583 | 583 |
584 EXPECT_TRUE(GetHistoryCount(shift_forward, | 584 EXPECT_TRUE(GetHistoryCount(shift_forward, |
585 shift_forward + TimeDelta::FromHours(24), | 585 shift_forward + TimeDelta::FromHours(24), |
586 &result)); | 586 &result)); |
587 EXPECT_EQ(2, result); | 587 EXPECT_EQ(2, result); |
588 } | 588 } |
589 } | 589 } |
590 | 590 |
591 } // namespace history | 591 } // namespace history |
OLD | NEW |