This source file includes following definitions.
- SetDelta
- GetNetworkTime
- TEST
#include "chrome/browser/network_time/navigation_time_helper.h"
#include "content/public/browser/navigation_entry.h"
#include "testing/gtest/include/gtest/gtest.h"
class TestNavigationTimeHelper : public NavigationTimeHelper {
public:
void SetDelta(base::TimeDelta delta) {
delta_ = delta;
}
virtual base::Time GetNetworkTime(base::Time t) OVERRIDE {
return t + delta_;
}
private:
base::TimeDelta delta_;
};
TEST(NavigationTimeHelperTest, QueryNavigationTime) {
TestNavigationTimeHelper time_helper;
time_helper.SetDelta(base::TimeDelta::FromHours(1));
scoped_ptr<content::NavigationEntry> entry1(
content::NavigationEntry::Create());
entry1->SetTimestamp(base::Time::Now());
EXPECT_EQ(entry1->GetTimestamp() + base::TimeDelta::FromHours(1),
time_helper.GetNavigationTime(entry1.get()));
time_helper.SetDelta(base::TimeDelta::FromHours(2));
EXPECT_EQ(entry1->GetTimestamp() + base::TimeDelta::FromHours(1),
time_helper.GetNavigationTime(entry1.get()));
scoped_ptr<content::NavigationEntry> entry2(
content::NavigationEntry::Create(*entry1));
EXPECT_EQ(entry2->GetTimestamp() + base::TimeDelta::FromHours(2),
time_helper.GetNavigationTime(entry2.get()));
entry1->SetTimestamp(
entry1->GetTimestamp() + base::TimeDelta::FromSeconds(1));
EXPECT_EQ(entry1->GetTimestamp() + base::TimeDelta::FromHours(2),
time_helper.GetNavigationTime(entry1.get()));
}