[ExtensionToolbarMac] Restrict action button drags to the container's bounds
[chromium-blink-merge.git] / chrome / browser / net / connect_interceptor_unittest.cc
blobc13e9591fe64af6f5313cc405dc1409a0c3e2ed4
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
3 // found in the LICENSE file.
5 #include "chrome/browser/net/connect_interceptor.h"
7 #include "base/threading/platform_thread.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace chrome_browser_net {
12 // These tests are all focused ConnectInterceptor::TimedCache.
13 TEST(ConnectInterceptorTest, TimedCacheRecall) {
14 // Creat a cache that has a long expiration so that we can test basic recall.
15 ConnectInterceptor::TimedCache cache(base::TimeDelta::FromHours(1));
17 GURL url("http://google.com/anypath");
18 GURL ssl_url("https://ssl_google.com/anypath");
19 EXPECT_FALSE(cache.WasRecentlySeen(url));
20 EXPECT_FALSE(cache.WasRecentlySeen(ssl_url));
22 cache.SetRecentlySeen(url);
24 EXPECT_TRUE(cache.WasRecentlySeen(url));
25 EXPECT_FALSE(cache.WasRecentlySeen(ssl_url));
27 cache.SetRecentlySeen(ssl_url);
29 EXPECT_TRUE(cache.WasRecentlySeen(url));
30 EXPECT_TRUE(cache.WasRecentlySeen(ssl_url));
32 // Check that port defaults correctly in canonicalization.
33 GURL url_with_port("http://google.com:80/anypath");
34 GURL ssl_url_with_port("https://ssl_google.com:443/anypath");
35 EXPECT_TRUE(cache.WasRecentlySeen(url_with_port));
36 EXPECT_TRUE(cache.WasRecentlySeen(ssl_url_with_port));
38 // Check for similar urls, to verify canonicalization isn't too generous.
39 GURL ssl_url_wrong_host("https://google.com/otherpath");
40 GURL ssl_url_wrong_path("https://ssl_google.com/otherpath");
41 GURL ssl_url_wrong_port("https://ssl_google.com:666/anypath");
42 GURL url_wrong_scheme("ftp://google.com/anypath");
43 GURL url_wrong_host("http://DOODLE.com/otherpath");
44 GURL url_wrong_path("http://google.com/otherpath");
45 GURL url_wrong_port("http://google.com:81/anypath");
47 EXPECT_FALSE(cache.WasRecentlySeen(ssl_url_wrong_host));
48 EXPECT_FALSE(cache.WasRecentlySeen(ssl_url_wrong_path));
49 EXPECT_FALSE(cache.WasRecentlySeen(ssl_url_wrong_port));
51 EXPECT_FALSE(cache.WasRecentlySeen(url_wrong_scheme));
53 EXPECT_FALSE(cache.WasRecentlySeen(url_wrong_host));
54 EXPECT_FALSE(cache.WasRecentlySeen(url_wrong_path));
55 EXPECT_FALSE(cache.WasRecentlySeen(url_wrong_port));
58 TEST(ConnectInterceptorTest, TimedCacheEviction) {
59 // Creat a cache that has a short expiration so that we can force evictions.
60 ConnectInterceptor::TimedCache cache(base::TimeDelta::FromMilliseconds(1));
62 GURL url("http://google.com/anypath");
63 EXPECT_FALSE(cache.WasRecentlySeen(url));
65 cache.SetRecentlySeen(url);
67 // Sleep at least long enough to cause an eviction.
68 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(30));
70 EXPECT_FALSE(cache.WasRecentlySeen(url));
73 } // namespace chrome_browser_net.