| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <time.h> | 5 #include <time.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/platform_thread.h" | 10 #include "base/platform_thread.h" |
| (...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 EXPECT_TRUE(cookies.find(cookie) != std::string::npos); | 847 EXPECT_TRUE(cookies.find(cookie) != std::string::npos); |
| 848 // Count the number of cookies. | 848 // Count the number of cookies. |
| 849 EXPECT_LE(CountInString(cookies, '='), 70); | 849 EXPECT_LE(CountInString(cookies, '='), 70); |
| 850 } | 850 } |
| 851 } | 851 } |
| 852 | 852 |
| 853 TEST(CookieMonsterTest, TestTotalGarbageCollection) { | 853 TEST(CookieMonsterTest, TestTotalGarbageCollection) { |
| 854 net::CookieMonster cm(kLastAccessThresholdSeconds); | 854 net::CookieMonster cm(kLastAccessThresholdSeconds); |
| 855 // Add a bunch of cookies on a bunch of host, some should get purged. | 855 // Add a bunch of cookies on a bunch of host, some should get purged. |
| 856 const GURL sticky_cookie("http://a0000.izzle"); | 856 const GURL sticky_cookie("http://a0000.izzle"); |
| 857 for (int i = 0; i < 2000; ++i) { | 857 for (int i = 0; i < 4000; ++i) { |
| 858 GURL url(StringPrintf("http://a%04d.izzle", i)); | 858 GURL url(StringPrintf("http://a%04d.izzle", i)); |
| 859 EXPECT_TRUE(cm.SetCookie(url, "a=b")); | 859 EXPECT_TRUE(cm.SetCookie(url, "a=b")); |
| 860 EXPECT_EQ("a=b", cm.GetCookies(url)); | 860 EXPECT_EQ("a=b", cm.GetCookies(url)); |
| 861 | 861 |
| 862 // Keep touching the first cookie to ensure it's not purged (since it will | 862 // Keep touching the first cookie to ensure it's not purged (since it will |
| 863 // always have the most recent access time). | 863 // always have the most recent access time). |
| 864 if (!(i % 500)) { | 864 if (!(i % 500)) { |
| 865 PlatformThread::Sleep(1500); // Ensure the timestamps will be different | 865 PlatformThread::Sleep(1500); // Ensure the timestamps will be different |
| 866 // enough to update. | 866 // enough to update. |
| 867 EXPECT_EQ("a=b", cm.GetCookies(sticky_cookie)); | 867 EXPECT_EQ("a=b", cm.GetCookies(sticky_cookie)); |
| 868 } | 868 } |
| 869 } | 869 } |
| 870 | 870 |
| 871 // Check that cookies that still exist. | 871 // Check that cookies that still exist. |
| 872 for (int i = 0; i < 2000; ++i) { | 872 for (int i = 0; i < 4000; ++i) { |
| 873 GURL url(StringPrintf("http://a%04d.izzle", i)); | 873 GURL url(StringPrintf("http://a%04d.izzle", i)); |
| 874 if ((i == 0) || (i > 1101)) { | 874 if ((i == 0) || (i > 1001)) { |
| 875 // Cookies should still be around. | 875 // Cookies should still be around. |
| 876 EXPECT_FALSE(cm.GetCookies(url).empty()); | 876 EXPECT_FALSE(cm.GetCookies(url).empty()); |
| 877 } else if (i < 901) { | 877 } else if (i < 701) { |
| 878 // Cookies should have gotten purged. | 878 // Cookies should have gotten purged. |
| 879 EXPECT_TRUE(cm.GetCookies(url).empty()); | 879 EXPECT_TRUE(cm.GetCookies(url).empty()); |
| 880 } | 880 } |
| 881 } | 881 } |
| 882 } | 882 } |
| 883 | 883 |
| 884 // Formerly NetUtilTest.CookieTest back when we used wininet's cookie handling. | 884 // Formerly NetUtilTest.CookieTest back when we used wininet's cookie handling. |
| 885 TEST(CookieMonsterTest, NetUtilCookieTest) { | 885 TEST(CookieMonsterTest, NetUtilCookieTest) { |
| 886 const GURL test_url("http://mojo.jojo.google.izzle/"); | 886 const GURL test_url("http://mojo.jojo.google.izzle/"); |
| 887 | 887 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 GURL foo_url("foo://host/path"); | 939 GURL foo_url("foo://host/path"); |
| 940 GURL http_url("http://host/path"); | 940 GURL http_url("http://host/path"); |
| 941 | 941 |
| 942 EXPECT_TRUE(cm.SetCookie(http_url, "x=1")); | 942 EXPECT_TRUE(cm.SetCookie(http_url, "x=1")); |
| 943 EXPECT_FALSE(cm.SetCookie(foo_url, "x=1")); | 943 EXPECT_FALSE(cm.SetCookie(foo_url, "x=1")); |
| 944 EXPECT_TRUE(cm_foo.SetCookie(foo_url, "x=1")); | 944 EXPECT_TRUE(cm_foo.SetCookie(foo_url, "x=1")); |
| 945 EXPECT_FALSE(cm_foo.SetCookie(http_url, "x=1")); | 945 EXPECT_FALSE(cm_foo.SetCookie(http_url, "x=1")); |
| 946 } | 946 } |
| 947 | 947 |
| 948 // TODO test overwrite cookie | 948 // TODO test overwrite cookie |
| OLD | NEW |