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

Side by Side Diff: net/ftp/ftp_auth_cache_unittest.cc

Issue 179028: Revert "Fix a ton of compiler warnings." (Closed)
Patch Set: Created 11 years, 3 months 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "net/ftp/ftp_auth_cache.h" 5 #include "net/ftp/ftp_auth_cache.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "googleurl/src/gurl.h" 8 #include "googleurl/src/gurl.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 using net::AuthData; 11 using net::AuthData;
12 using net::FtpAuthCache; 12 using net::FtpAuthCache;
13 13
14 TEST(FtpAuthCacheTest, LookupAddRemove) { 14 TEST(FtpAuthCacheTest, LookupAddRemove) {
15 FtpAuthCache cache; 15 FtpAuthCache cache;
16 16
17 GURL origin1("ftp://foo1"); 17 GURL origin1("ftp://foo1");
18 scoped_refptr<AuthData> data1(new AuthData()); 18 scoped_refptr<AuthData> data1(new AuthData());
19 19
20 GURL origin2("ftp://foo2"); 20 GURL origin2("ftp://foo2");
21 scoped_refptr<AuthData> data2(new AuthData()); 21 scoped_refptr<AuthData> data2(new AuthData());
22 22
23 GURL origin3("ftp://foo3"); 23 GURL origin3("ftp://foo3");
24 scoped_refptr<AuthData> data3(new AuthData()); 24 scoped_refptr<AuthData> data3(new AuthData());
25 25
26 // Lookup non-existent entry. 26 // Lookup non-existent entry.
27 EXPECT_TRUE(NULL == cache.Lookup(origin1)); 27 EXPECT_EQ(NULL, cache.Lookup(origin1));
28 28
29 // Add entry for origin1. 29 // Add entry for origin1.
30 cache.Add(origin1, data1.get()); 30 cache.Add(origin1, data1.get());
31 EXPECT_EQ(data1.get(), cache.Lookup(origin1)); 31 EXPECT_EQ(data1.get(), cache.Lookup(origin1));
32 32
33 // Add an entry for origin2. 33 // Add an entry for origin2.
34 cache.Add(origin2, data2.get()); 34 cache.Add(origin2, data2.get());
35 EXPECT_EQ(data1.get(), cache.Lookup(origin1)); 35 EXPECT_EQ(data1.get(), cache.Lookup(origin1));
36 EXPECT_EQ(data2.get(), cache.Lookup(origin2)); 36 EXPECT_EQ(data2.get(), cache.Lookup(origin2));
37 37
38 // Overwrite the entry for origin1. 38 // Overwrite the entry for origin1.
39 cache.Add(origin1, data3.get()); 39 cache.Add(origin1, data3.get());
40 EXPECT_EQ(data3.get(), cache.Lookup(origin1)); 40 EXPECT_EQ(data3.get(), cache.Lookup(origin1));
41 EXPECT_EQ(data2.get(), cache.Lookup(origin2)); 41 EXPECT_EQ(data2.get(), cache.Lookup(origin2));
42 42
43 // Remove entry of origin1. 43 // Remove entry of origin1.
44 cache.Remove(origin1); 44 cache.Remove(origin1);
45 EXPECT_TRUE(NULL == cache.Lookup(origin1)); 45 EXPECT_EQ(NULL, cache.Lookup(origin1));
46 EXPECT_EQ(data2.get(), cache.Lookup(origin2)); 46 EXPECT_EQ(data2.get(), cache.Lookup(origin2));
47 47
48 // Remove non-existent entry 48 // Remove non-existent entry
49 cache.Remove(origin1); 49 cache.Remove(origin1);
50 EXPECT_TRUE(NULL == cache.Lookup(origin1)); 50 EXPECT_EQ(NULL, cache.Lookup(origin1));
51 EXPECT_EQ(data2.get(), cache.Lookup(origin2)); 51 EXPECT_EQ(data2.get(), cache.Lookup(origin2));
52 } 52 }
53 53
54 // Check that if the origin differs only by port number, it is considered 54 // Check that if the origin differs only by port number, it is considered
55 // a separate origin. 55 // a separate origin.
56 TEST(FtpAuthCacheTest, LookupWithPort) { 56 TEST(FtpAuthCacheTest, LookupWithPort) {
57 FtpAuthCache cache; 57 FtpAuthCache cache;
58 58
59 GURL origin1("ftp://foo:80"); 59 GURL origin1("ftp://foo:80");
60 scoped_refptr<AuthData> data1(new AuthData()); 60 scoped_refptr<AuthData> data1(new AuthData());
(...skipping 25 matching lines...) Expand all
86 EXPECT_EQ(data1.get(), cache.Lookup(GURL("ftp://HoSt:21"))); 86 EXPECT_EQ(data1.get(), cache.Lookup(GURL("ftp://HoSt:21")));
87 EXPECT_EQ(data1.get(), cache.Lookup(GURL("ftp://host:21"))); 87 EXPECT_EQ(data1.get(), cache.Lookup(GURL("ftp://host:21")));
88 EXPECT_EQ(data1.get(), cache.Lookup(GURL("ftp://host"))); 88 EXPECT_EQ(data1.get(), cache.Lookup(GURL("ftp://host")));
89 89
90 // Overwrite. 90 // Overwrite.
91 cache.Add(GURL("ftp://host"), data2.get()); 91 cache.Add(GURL("ftp://host"), data2.get());
92 EXPECT_EQ(data2.get(), cache.Lookup(GURL("ftp://HoSt:21"))); 92 EXPECT_EQ(data2.get(), cache.Lookup(GURL("ftp://HoSt:21")));
93 93
94 // Remove 94 // Remove
95 cache.Remove(GURL("ftp://HOsT")); 95 cache.Remove(GURL("ftp://HOsT"));
96 EXPECT_TRUE(NULL == cache.Lookup(GURL("ftp://host"))); 96 EXPECT_EQ(NULL, cache.Lookup(GURL("ftp://host")));
97 } 97 }
98 98
99 TEST(FtpAuthCacheTest, EvictOldEntries) { 99 TEST(FtpAuthCacheTest, EvictOldEntries) {
100 FtpAuthCache cache; 100 FtpAuthCache cache;
101 101
102 scoped_refptr<AuthData> auth_data(new AuthData()); 102 scoped_refptr<AuthData> auth_data(new AuthData());
103 103
104 for (size_t i = 0; i < FtpAuthCache::kMaxEntries; i++) 104 for (size_t i = 0; i < FtpAuthCache::kMaxEntries; i++)
105 cache.Add(GURL("ftp://host" + IntToString(i)), auth_data.get()); 105 cache.Add(GURL("ftp://host" + IntToString(i)), auth_data.get());
106 106
107 // No entries should be evicted before reaching the limit. 107 // No entries should be evicted before reaching the limit.
108 for (size_t i = 0; i < FtpAuthCache::kMaxEntries; i++) { 108 for (size_t i = 0; i < FtpAuthCache::kMaxEntries; i++) {
109 EXPECT_EQ(auth_data.get(), 109 EXPECT_EQ(auth_data.get(),
110 cache.Lookup(GURL("ftp://host" + IntToString(i)))); 110 cache.Lookup(GURL("ftp://host" + IntToString(i))));
111 } 111 }
112 112
113 // Adding one entry should cause eviction of the first entry. 113 // Adding one entry should cause eviction of the first entry.
114 cache.Add(GURL("ftp://last_host"), auth_data.get()); 114 cache.Add(GURL("ftp://last_host"), auth_data.get());
115 EXPECT_TRUE(NULL == cache.Lookup(GURL("ftp://host0"))); 115 EXPECT_EQ(NULL, cache.Lookup(GURL("ftp://host0")));
116 116
117 // Remaining entries should not get evicted. 117 // Remaining entries should not get evicted.
118 for (size_t i = 1; i < FtpAuthCache::kMaxEntries; i++) { 118 for (size_t i = 1; i < FtpAuthCache::kMaxEntries; i++) {
119 EXPECT_EQ(auth_data.get(), 119 EXPECT_EQ(auth_data.get(),
120 cache.Lookup(GURL("ftp://host" + IntToString(i)))); 120 cache.Lookup(GURL("ftp://host" + IntToString(i))));
121 } 121 }
122 EXPECT_EQ(auth_data.get(), cache.Lookup(GURL("ftp://last_host"))); 122 EXPECT_EQ(auth_data.get(), cache.Lookup(GURL("ftp://last_host")));
123 } 123 }
OLDNEW
« no previous file with comments | « net/base/ssl_client_auth_cache_unittest.cc ('k') | net/http/http_network_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698