[safe-browsing] Database full hash matches like prefix match.
[chromium-blink-merge.git] / chrome / browser / network_time / navigation_time_helper_unittest.cc
blobab7ac8e5cc5163b8e809640b38c3b643e0efd944
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/network_time/navigation_time_helper.h"
7 #include "content/public/browser/navigation_entry.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 class TestNavigationTimeHelper : public NavigationTimeHelper {
11 public:
12 void SetDelta(base::TimeDelta delta) {
13 delta_ = delta;
15 virtual base::Time GetNetworkTime(base::Time t) OVERRIDE {
16 return t + delta_;
19 private:
20 base::TimeDelta delta_;
23 TEST(NavigationTimeHelperTest, QueryNavigationTime) {
24 TestNavigationTimeHelper time_helper;
25 time_helper.SetDelta(base::TimeDelta::FromHours(1));
27 scoped_ptr<content::NavigationEntry> entry1(
28 content::NavigationEntry::Create());
29 entry1->SetTimestamp(base::Time::Now());
31 EXPECT_EQ(entry1->GetTimestamp() + base::TimeDelta::FromHours(1),
32 time_helper.GetNavigationTime(entry1.get()));
34 // Adjusting delta shouldn't affect navigation time of unchanged entry.
35 time_helper.SetDelta(base::TimeDelta::FromHours(2));
36 EXPECT_EQ(entry1->GetTimestamp() + base::TimeDelta::FromHours(1),
37 time_helper.GetNavigationTime(entry1.get()));
39 // New delta is applied to new entry even if it has same local time.
40 scoped_ptr<content::NavigationEntry> entry2(
41 content::NavigationEntry::Create(*entry1));
42 EXPECT_EQ(entry2->GetTimestamp() + base::TimeDelta::FromHours(2),
43 time_helper.GetNavigationTime(entry2.get()));
45 // New delta is applied if existing entry has new navigation.
46 entry1->SetTimestamp(
47 entry1->GetTimestamp() + base::TimeDelta::FromSeconds(1));
48 EXPECT_EQ(entry1->GetTimestamp() + base::TimeDelta::FromHours(2),
49 time_helper.GetNavigationTime(entry1.get()));