This source file includes following definitions.
- TEST
- TEST
#include "chrome/browser/net/connect_interceptor.h"
#include "base/threading/platform_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chrome_browser_net {
TEST(ConnectInterceptorTest, TimedCacheRecall) {
ConnectInterceptor::TimedCache cache(base::TimeDelta::FromHours(1));
GURL url("http://google.com/anypath");
GURL ssl_url("https://ssl_google.com/anypath");
EXPECT_FALSE(cache.WasRecentlySeen(url));
EXPECT_FALSE(cache.WasRecentlySeen(ssl_url));
cache.SetRecentlySeen(url);
EXPECT_TRUE(cache.WasRecentlySeen(url));
EXPECT_FALSE(cache.WasRecentlySeen(ssl_url));
cache.SetRecentlySeen(ssl_url);
EXPECT_TRUE(cache.WasRecentlySeen(url));
EXPECT_TRUE(cache.WasRecentlySeen(ssl_url));
GURL url_with_port("http://google.com:80/anypath");
GURL ssl_url_with_port("https://ssl_google.com:443/anypath");
EXPECT_TRUE(cache.WasRecentlySeen(url_with_port));
EXPECT_TRUE(cache.WasRecentlySeen(ssl_url_with_port));
GURL ssl_url_wrong_host("https://google.com/otherpath");
GURL ssl_url_wrong_path("https://ssl_google.com/otherpath");
GURL ssl_url_wrong_port("https://ssl_google.com:666/anypath");
GURL url_wrong_scheme("ftp://google.com/anypath");
GURL url_wrong_host("http://DOODLE.com/otherpath");
GURL url_wrong_path("http://google.com/otherpath");
GURL url_wrong_port("http://google.com:81/anypath");
EXPECT_FALSE(cache.WasRecentlySeen(ssl_url_wrong_host));
EXPECT_FALSE(cache.WasRecentlySeen(ssl_url_wrong_path));
EXPECT_FALSE(cache.WasRecentlySeen(ssl_url_wrong_port));
EXPECT_FALSE(cache.WasRecentlySeen(url_wrong_scheme));
EXPECT_FALSE(cache.WasRecentlySeen(url_wrong_host));
EXPECT_FALSE(cache.WasRecentlySeen(url_wrong_path));
EXPECT_FALSE(cache.WasRecentlySeen(url_wrong_port));
}
TEST(ConnectInterceptorTest, TimedCacheEviction) {
ConnectInterceptor::TimedCache cache(base::TimeDelta::FromMilliseconds(1));
GURL url("http://google.com/anypath");
EXPECT_FALSE(cache.WasRecentlySeen(url));
cache.SetRecentlySeen(url);
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(30));
EXPECT_FALSE(cache.WasRecentlySeen(url));
}
}