This source file includes following definitions.
- TEST
- TEST
#include <time.h>
#include <string>
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "chrome/browser/net/url_info.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::TimeDelta;
using base::TimeTicks;
namespace {
class UrlHostInfoTest : public testing::Test {
};
typedef chrome_browser_net::UrlInfo UrlInfo;
TEST(UrlHostInfoTest, StateChangeTest) {
UrlInfo info_practice, info;
GURL url1("http://domain1.com:80"), url2("https://domain2.com:443");
info_practice.SetUrl(url2);
info_practice.SetQueuedState(UrlInfo::UNIT_TEST_MOTIVATED);
info_practice.SetAssignedState();
info_practice.SetFoundState();
info.SetUrl(url1);
EXPECT_TRUE(info.NeedsDnsUpdate()) << "error in construction state";
info.SetQueuedState(UrlInfo::UNIT_TEST_MOTIVATED);
EXPECT_FALSE(info.NeedsDnsUpdate()) << "update needed after being queued";
info.SetAssignedState();
EXPECT_FALSE(info.NeedsDnsUpdate()) << "update needed during resolution";
base::TimeTicks before_resolution_complete = TimeTicks::Now();
info.SetFoundState();
if (info.NeedsDnsUpdate()) {
EXPECT_GT((TimeTicks::Now() - before_resolution_complete).InMilliseconds(),
UrlInfo::get_cache_expiration().InMilliseconds());
return;
}
const TimeDelta kMockExpirationTime = TimeDelta::FromMilliseconds(300);
info.set_cache_expiration(kMockExpirationTime);
info.SetQueuedState(UrlInfo::UNIT_TEST_MOTIVATED);
EXPECT_FALSE(info.NeedsDnsUpdate());
info.SetAssignedState();
EXPECT_FALSE(info.NeedsDnsUpdate());
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(25));
before_resolution_complete = TimeTicks::Now();
info.SetNoSuchNameState();
if (info.NeedsDnsUpdate()) {
EXPECT_GT((TimeTicks::Now() - before_resolution_complete),
kMockExpirationTime);
return;
}
base::PlatformThread::Sleep(kMockExpirationTime +
TimeDelta::FromMilliseconds(20));
EXPECT_TRUE(info.NeedsDnsUpdate()) << "expiration time not honored";
}
TEST(UrlHostInfoTest, CongestionResetStateTest) {
UrlInfo info;
GURL url("http://domain1.com:80");
info.SetUrl(url);
info.SetQueuedState(UrlInfo::UNIT_TEST_MOTIVATED);
info.SetAssignedState();
EXPECT_TRUE(info.is_assigned());
info.RemoveFromQueue();
EXPECT_FALSE(info.is_assigned());
EXPECT_FALSE(info.was_found());
EXPECT_FALSE(info.was_nonexistent());
info.SetQueuedState(UrlInfo::UNIT_TEST_MOTIVATED);
info.SetAssignedState();
info.SetFoundState();
EXPECT_TRUE(info.was_found());
info.SetQueuedState(UrlInfo::UNIT_TEST_MOTIVATED);
info.SetAssignedState();
info.RemoveFromQueue();
EXPECT_FALSE(info.is_assigned());
EXPECT_TRUE(info.was_found());
}
}