Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(890)

Side by Side Diff: net/base/cookie_monster_unittest.cc

Issue 4192012: Convert implicit scoped_refptr constructor calls to explicit ones, part 1 (Closed) Base URL: http://git.chromium.org/git/chromium.git
Patch Set: fix presubmit Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/cookie_monster_perftest.cc ('k') | net/base/directory_lister_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 1834 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 {"https://www.google.com", "b", "2", ".google.com", "/path/from/cookie", 1845 {"https://www.google.com", "b", "2", ".google.com", "/path/from/cookie",
1846 expires + TimeDelta::FromSeconds(10), true, true}, 1846 expires + TimeDelta::FromSeconds(10), true, true},
1847 {"https://google.com", "c", "3", "", "/another/path/to/cookie", 1847 {"https://google.com", "c", "3", "", "/another/path/to/cookie",
1848 base::Time::Now() + base::TimeDelta::FromSeconds(100), 1848 base::Time::Now() + base::TimeDelta::FromSeconds(100),
1849 true, false} 1849 true, false}
1850 }; 1850 };
1851 const int INPUT_DELETE = 1; 1851 const int INPUT_DELETE = 1;
1852 1852
1853 // Create new cookies and flush them to the store. 1853 // Create new cookies and flush them to the store.
1854 { 1854 {
1855 scoped_refptr<net::CookieMonster> cmout = new CookieMonster(store, NULL); 1855 scoped_refptr<net::CookieMonster> cmout(new CookieMonster(store, NULL));
1856 for (const CookiesInputInfo* p = input_info; 1856 for (const CookiesInputInfo* p = input_info;
1857 p < &input_info[ARRAYSIZE_UNSAFE(input_info)]; p++) { 1857 p < &input_info[ARRAYSIZE_UNSAFE(input_info)]; p++) {
1858 EXPECT_TRUE(cmout->SetCookieWithDetails(GURL(p->gurl), p->name, p->value, 1858 EXPECT_TRUE(cmout->SetCookieWithDetails(GURL(p->gurl), p->name, p->value,
1859 p->domain, p->path, p->expires, 1859 p->domain, p->path, p->expires,
1860 p->secure, p->http_only)); 1860 p->secure, p->http_only));
1861 } 1861 }
1862 cmout->DeleteCookie(GURL(std::string(input_info[INPUT_DELETE].gurl) + 1862 cmout->DeleteCookie(GURL(std::string(input_info[INPUT_DELETE].gurl) +
1863 input_info[INPUT_DELETE].path), 1863 input_info[INPUT_DELETE].path),
1864 input_info[INPUT_DELETE].name); 1864 input_info[INPUT_DELETE].name);
1865 } 1865 }
1866 1866
1867 // Create a new cookie monster and make sure that everything is correct 1867 // Create a new cookie monster and make sure that everything is correct
1868 { 1868 {
1869 scoped_refptr<net::CookieMonster> cmin = new CookieMonster(store, NULL); 1869 scoped_refptr<net::CookieMonster> cmin(new CookieMonster(store, NULL));
1870 CookieMonster::CookieList cookies(cmin->GetAllCookies()); 1870 CookieMonster::CookieList cookies(cmin->GetAllCookies());
1871 ASSERT_EQ(2u, cookies.size()); 1871 ASSERT_EQ(2u, cookies.size());
1872 // Ordering is path length, then creation time. So second cookie 1872 // Ordering is path length, then creation time. So second cookie
1873 // will come first, and we need to swap them. 1873 // will come first, and we need to swap them.
1874 std::swap(cookies[0], cookies[1]); 1874 std::swap(cookies[0], cookies[1]);
1875 for (int output_index = 0; output_index < 2; output_index++) { 1875 for (int output_index = 0; output_index < 2; output_index++) {
1876 int input_index = output_index * 2; 1876 int input_index = output_index * 2;
1877 const CookiesInputInfo* input = &input_info[input_index]; 1877 const CookiesInputInfo* input = &input_info[input_index];
1878 const CookieMonster::CanonicalCookie* output = &cookies[output_index]; 1878 const CookieMonster::CanonicalCookie* output = &cookies[output_index];
1879 1879
1880 EXPECT_EQ(input->name, output->Name()); 1880 EXPECT_EQ(input->name, output->Name());
1881 EXPECT_EQ(input->value, output->Value()); 1881 EXPECT_EQ(input->value, output->Value());
1882 EXPECT_EQ(GURL(input->gurl).host(), output->Domain()); 1882 EXPECT_EQ(GURL(input->gurl).host(), output->Domain());
1883 EXPECT_EQ(input->path, output->Path()); 1883 EXPECT_EQ(input->path, output->Path());
1884 EXPECT_LE(current.ToInternalValue(), 1884 EXPECT_LE(current.ToInternalValue(),
1885 output->CreationDate().ToInternalValue()); 1885 output->CreationDate().ToInternalValue());
1886 EXPECT_EQ(input->secure, output->IsSecure()); 1886 EXPECT_EQ(input->secure, output->IsSecure());
1887 EXPECT_EQ(input->http_only, output->IsHttpOnly()); 1887 EXPECT_EQ(input->http_only, output->IsHttpOnly());
1888 EXPECT_TRUE(output->IsPersistent()); 1888 EXPECT_TRUE(output->IsPersistent());
1889 EXPECT_EQ(input->expires.ToInternalValue(), 1889 EXPECT_EQ(input->expires.ToInternalValue(),
1890 output->ExpiryDate().ToInternalValue()); 1890 output->ExpiryDate().ToInternalValue());
1891 } 1891 }
1892 } 1892 }
1893 } 1893 }
1894 1894
1895 TEST(CookieMonsterTest, CookieOrdering) { 1895 TEST(CookieMonsterTest, CookieOrdering) {
1896 // Put a random set of cookies into a monster and make sure 1896 // Put a random set of cookies into a monster and make sure
1897 // they're returned in the right order. 1897 // they're returned in the right order.
1898 scoped_refptr<net::CookieMonster> cm = new CookieMonster(NULL, NULL); 1898 scoped_refptr<net::CookieMonster> cm(new CookieMonster(NULL, NULL));
1899 EXPECT_TRUE(cm->SetCookie(GURL("http://d.c.b.a.google.com/aa/x.html"), 1899 EXPECT_TRUE(cm->SetCookie(GURL("http://d.c.b.a.google.com/aa/x.html"),
1900 "c=1")); 1900 "c=1"));
1901 EXPECT_TRUE(cm->SetCookie(GURL("http://b.a.google.com/aa/bb/cc/x.html"), 1901 EXPECT_TRUE(cm->SetCookie(GURL("http://b.a.google.com/aa/bb/cc/x.html"),
1902 "d=1; domain=b.a.google.com")); 1902 "d=1; domain=b.a.google.com"));
1903 EXPECT_TRUE(cm->SetCookie(GURL("http://b.a.google.com/aa/bb/cc/x.html"), 1903 EXPECT_TRUE(cm->SetCookie(GURL("http://b.a.google.com/aa/bb/cc/x.html"),
1904 "a=4; domain=b.a.google.com")); 1904 "a=4; domain=b.a.google.com"));
1905 EXPECT_TRUE(cm->SetCookie(GURL("http://c.b.a.google.com/aa/bb/cc/x.html"), 1905 EXPECT_TRUE(cm->SetCookie(GURL("http://c.b.a.google.com/aa/bb/cc/x.html"),
1906 "e=1; domain=c.b.a.google.com")); 1906 "e=1; domain=c.b.a.google.com"));
1907 EXPECT_TRUE(cm->SetCookie(GURL("http://d.c.b.a.google.com/aa/bb/x.html"), 1907 EXPECT_TRUE(cm->SetCookie(GURL("http://d.c.b.a.google.com/aa/bb/x.html"),
1908 "b=1")); 1908 "b=1"));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1950 // This test and CookieMonstertest.TestGCTimes (in cookie_monster_perftest.cc) 1950 // This test and CookieMonstertest.TestGCTimes (in cookie_monster_perftest.cc)
1951 // are somewhat complementary twins. This test is probing for whether 1951 // are somewhat complementary twins. This test is probing for whether
1952 // garbage collection always happens when it should (i.e. that we actually 1952 // garbage collection always happens when it should (i.e. that we actually
1953 // get rid of cookies when we should). The perftest is probing for 1953 // get rid of cookies when we should). The perftest is probing for
1954 // whether garbage collection happens when it shouldn't. See comments 1954 // whether garbage collection happens when it shouldn't. See comments
1955 // before that test for more details. 1955 // before that test for more details.
1956 TEST(CookieMonsterTest, GarbageCollectionTriggers) { 1956 TEST(CookieMonsterTest, GarbageCollectionTriggers) {
1957 // First we check to make sure that a whole lot of recent cookies 1957 // First we check to make sure that a whole lot of recent cookies
1958 // doesn't get rid of anything after garbage collection is checked for. 1958 // doesn't get rid of anything after garbage collection is checked for.
1959 { 1959 {
1960 scoped_refptr<net::CookieMonster> cm = 1960 scoped_refptr<net::CookieMonster> cm(
1961 CreateMonsterForGC(CookieMonster::kMaxCookies * 2); 1961 CreateMonsterForGC(CookieMonster::kMaxCookies * 2));
1962 EXPECT_EQ(CookieMonster::kMaxCookies * 2, cm->GetAllCookies().size()); 1962 EXPECT_EQ(CookieMonster::kMaxCookies * 2, cm->GetAllCookies().size());
1963 cm->SetCookie(GURL("http://newdomain.com"), "b=2"); 1963 cm->SetCookie(GURL("http://newdomain.com"), "b=2");
1964 EXPECT_EQ(CookieMonster::kMaxCookies * 2 + 1, cm->GetAllCookies().size()); 1964 EXPECT_EQ(CookieMonster::kMaxCookies * 2 + 1, cm->GetAllCookies().size());
1965 } 1965 }
1966 1966
1967 // Now we explore a series of relationships between cookie last access 1967 // Now we explore a series of relationships between cookie last access
1968 // time and size of store to make sure we only get rid of cookies when 1968 // time and size of store to make sure we only get rid of cookies when
1969 // we really should. 1969 // we really should.
1970 const struct TestCase { 1970 const struct TestCase {
1971 int num_cookies; 1971 int num_cookies;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2009 CookieMonster::EKS_KEEP_RECENT_AND_PURGE_ETLDP1, 2009 CookieMonster::EKS_KEEP_RECENT_AND_PURGE_ETLDP1,
2010 CookieMonster::EKS_DISCARD_RECENT_AND_PURGE_DOMAIN, 2010 CookieMonster::EKS_DISCARD_RECENT_AND_PURGE_DOMAIN,
2011 }; 2011 };
2012 2012
2013 for (int ci = 0; ci < static_cast<int>(ARRAYSIZE_UNSAFE(test_cases)); ++ci) { 2013 for (int ci = 0; ci < static_cast<int>(ARRAYSIZE_UNSAFE(test_cases)); ++ci) {
2014 // Test both old and new key and expiry schemes. 2014 // Test both old and new key and expiry schemes.
2015 for (int recent_scheme = 0; 2015 for (int recent_scheme = 0;
2016 recent_scheme < static_cast<int>(ARRAYSIZE_UNSAFE(schemes)); 2016 recent_scheme < static_cast<int>(ARRAYSIZE_UNSAFE(schemes));
2017 recent_scheme++) { 2017 recent_scheme++) {
2018 const TestCase *test_case = &test_cases[ci]; 2018 const TestCase *test_case = &test_cases[ci];
2019 scoped_refptr<net::CookieMonster> cm = 2019 scoped_refptr<net::CookieMonster> cm(
2020 CreateMonsterFromStoreForGC( 2020 CreateMonsterFromStoreForGC(
2021 test_case->num_cookies, test_case->num_old_cookies, 2021 test_case->num_cookies, test_case->num_old_cookies,
2022 CookieMonster::kSafeFromGlobalPurgeDays * 2); 2022 CookieMonster::kSafeFromGlobalPurgeDays * 2));
2023 cm->SetExpiryAndKeyScheme(schemes[recent_scheme]); 2023 cm->SetExpiryAndKeyScheme(schemes[recent_scheme]);
2024 EXPECT_EQ(test_case->expected_initial_cookies, 2024 EXPECT_EQ(test_case->expected_initial_cookies,
2025 static_cast<int>(cm->GetAllCookies().size())) 2025 static_cast<int>(cm->GetAllCookies().size()))
2026 << "For test case " << ci; 2026 << "For test case " << ci;
2027 // Will trigger GC 2027 // Will trigger GC
2028 cm->SetCookie(GURL("http://newdomain.com"), "b=2"); 2028 cm->SetCookie(GURL("http://newdomain.com"), "b=2");
2029 EXPECT_EQ(test_case->expected_cookies_after_set[recent_scheme], 2029 EXPECT_EQ(test_case->expected_cookies_after_set[recent_scheme],
2030 static_cast<int>((cm->GetAllCookies().size()))) 2030 static_cast<int>((cm->GetAllCookies().size())))
2031 << "For test case (" << ci << ", " << recent_scheme << ")"; 2031 << "For test case (" << ci << ", " << recent_scheme << ")";
2032 } 2032 }
2033 } 2033 }
2034 } 2034 }
2035 2035
2036 } // namespace 2036 } // namespace
OLDNEW
« no previous file with comments | « net/base/cookie_monster_perftest.cc ('k') | net/base/directory_lister_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698