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

Unified Diff: net/http/http_cache_unittest.cc

Issue 155972: Strip embedded "#" in URLs when constructing HTTP cache key.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fix a typo from past change Created 11 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_cache.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_cache_unittest.cc
===================================================================
--- net/http/http_cache_unittest.cc (revision 21359)
+++ net/http/http_cache_unittest.cc (working copy)
@@ -33,7 +33,7 @@
: test_mode_(0), doomed_(false), sparse_(false) {
}
- MockDiskEntry(const std::string& key)
+ explicit MockDiskEntry(const std::string& key)
: key_(key), doomed_(false), sparse_(false) {
//
// 'key' is prefixed with an identifier if it corresponds to a cached POST.
@@ -1175,7 +1175,7 @@
EXPECT_EQ(0, cache.disk_cache()->open_count());
EXPECT_EQ(1, cache.disk_cache()->create_count());
- // Request |kUrl| a second first time. Now |kNetResponse1| it is in the HTTP
+ // Request |kUrl| a second time. Now |kNetResponse1| it is in the HTTP
// cache, so we don't hit the network.
kUnexpectedResponse.AssignTo(&mock_network_response); // Network mock.
@@ -1229,6 +1229,30 @@
RemoveMockTransaction(&mock_network_response);
}
+TEST(HttpCache, UrlContainingHash) {
+ MockHttpCache cache;
+
+ // Do a typical GET request -- should write an entry into our cache.
+ MockTransaction trans(kTypicalGET_Transaction);
+ RunTransactionTest(cache.http_cache(), trans);
+
+ EXPECT_EQ(1, cache.network_layer()->transaction_count());
+ EXPECT_EQ(0, cache.disk_cache()->open_count());
+ EXPECT_EQ(1, cache.disk_cache()->create_count());
+
+ // Request the same URL, but this time with a reference section (hash).
+ // Since the cache key strips the hash sections, this should be a cache hit.
+ std::string url_with_hash = std::string(trans.url) + "#multiple#hashes";
+ trans.url = url_with_hash.c_str();
+ trans.load_flags = net::LOAD_ONLY_FROM_CACHE;
+
+ RunTransactionTest(cache.http_cache(), trans);
+
+ EXPECT_EQ(1, cache.network_layer()->transaction_count());
+ EXPECT_EQ(1, cache.disk_cache()->open_count());
+ EXPECT_EQ(1, cache.disk_cache()->create_count());
+}
+
TEST(HttpCache, SimplePOST_LoadOnlyFromCache_Miss) {
MockHttpCache cache;
« no previous file with comments | « net/http/http_cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698