Index: net/http/http_auth_cache_unittest.cc |
diff --git a/net/http/http_auth_cache_unittest.cc b/net/http/http_auth_cache_unittest.cc |
index c0509ce1d50c1d323e8c45aca802e679bcdfa43a..f9588eb2f430956b39a542389b7721ba0c193f3c 100644 |
--- a/net/http/http_auth_cache_unittest.cc |
+++ b/net/http/http_auth_cache_unittest.cc |
@@ -4,10 +4,12 @@ |
#include <string> |
+#include "base/run_loop.h" |
#include "base/strings/string16.h" |
#include "base/strings/string_util.h" |
#include "base/strings/stringprintf.h" |
#include "base/strings/utf_string_conversions.h" |
+#include "base/threading/thread_task_runner_handle.h" |
#include "net/base/net_errors.h" |
#include "net/http/http_auth_cache.h" |
#include "net/http/http_auth_handler.h" |
@@ -76,6 +78,20 @@ AuthCredentials CreateASCIICredentials(const char* username, |
return AuthCredentials(ASCIIToUTF16(username), ASCIIToUTF16(password)); |
} |
+// Ensures that difference between TimeTicks of entering and leaving this |
+// function is non-zero. |
+void EnsureTimeDifference() { |
+ base::TimeTicks begin_time = base::TimeTicks::Now(); |
+ base::RunLoop run_loop; |
+ base::Closure quit_closure(run_loop.QuitClosure()); |
+ base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
+ FROM_HERE, quit_closure, |
+ base::TimeDelta::FromMilliseconds( |
+ base::TimeTicks::IsHighResolution() ? 1 : 20)); |
+ run_loop.Run(); |
+ ASSERT_FALSE((base::TimeTicks::Now() - begin_time).is_zero()); |
+} |
+ |
} // namespace |
// Test adding and looking-up cache entries (both by realm and by path). |
@@ -377,6 +393,42 @@ TEST(HttpAuthCacheTest, Remove) { |
EXPECT_FALSE(NULL == entry); |
} |
+TEST(HttpAuthCacheTest, ClearEntriesAddedWithin) { |
+ GURL origin("http://foobar.com"); |
+ |
+ HttpAuthCache cache; |
+ cache.Add(origin, kRealm1, HttpAuth::AUTH_SCHEME_BASIC, "basic realm=Realm1", |
+ AuthCredentials(kAlice, k123), "/"); |
+ cache.Add(origin, kRealm2, HttpAuth::AUTH_SCHEME_BASIC, "basic realm=Realm2", |
+ AuthCredentials(kRoot, kWileCoyote), "/"); |
+ |
+ EnsureTimeDifference(); |
+ base::TimeTicks start_time = base::TimeTicks::Now(); |
+ |
+ cache.Add(origin, kRealm3, HttpAuth::AUTH_SCHEME_BASIC, "basic realm=Realm3", |
+ AuthCredentials(kAlice2, k1234), "/"); |
+ cache.Add(origin, kRealm4, HttpAuth::AUTH_SCHEME_BASIC, "basic realm=Realm4", |
+ AuthCredentials(kUsername, kPassword), "/"); |
+ // Add path to existing entry. |
+ cache.Add(origin, kRealm2, HttpAuth::AUTH_SCHEME_BASIC, "basic realm=Realm2", |
+ AuthCredentials(kAdmin, kPassword), "/baz/"); |
+ |
+ EnsureTimeDifference(); |
+ cache.ClearEntriesAddedWithin(base::TimeTicks::Now() - start_time); |
mmenke
2016/08/25 19:28:02
I still don't think this works - ClearEntriesAdded
|
+ |
+ EXPECT_NE(nullptr, |
+ cache.Lookup(origin, kRealm1, HttpAuth::AUTH_SCHEME_BASIC)); |
+ EXPECT_NE(nullptr, |
+ cache.Lookup(origin, kRealm2, HttpAuth::AUTH_SCHEME_BASIC)); |
+ // Creation time is set for a whole entry rather than for a particular path. |
+ // Path added within the requested duration isn't be removed. |
+ EXPECT_NE(nullptr, cache.LookupByPath(origin, "/baz/")); |
+ EXPECT_EQ(nullptr, |
+ cache.Lookup(origin, kRealm3, HttpAuth::AUTH_SCHEME_BASIC)); |
+ EXPECT_EQ(nullptr, |
+ cache.Lookup(origin, kRealm4, HttpAuth::AUTH_SCHEME_BASIC)); |
+} |
+ |
TEST(HttpAuthCacheTest, UpdateStaleChallenge) { |
HttpAuthCache cache; |
GURL origin("http://foobar2.com"); |