Index: net/http/http_cache_unittest.cc |
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc |
index 017334302a3114862ae04bf5562e4badac113230..d1a289e7121821a7c7e30d3229fa01cb3a239107 100644 |
--- a/net/http/http_cache_unittest.cc |
+++ b/net/http/http_cache_unittest.cc |
@@ -2972,6 +2972,133 @@ TEST(HttpCache, SimplePOST_Invalidate_205) { |
RemoveMockTransaction(&transaction); |
} |
+// The Origin of the Content-Location value must match |
+// the origin of kTypicalGET_Transaction. |
+const MockTransaction kContentLocationPOST_Transaction = { |
+ "http://www.example.com/edit", |
+ "POST", |
+ base::Time(), |
+ "", |
+ net::LOAD_NORMAL, |
+ "HTTP/1.1 200 OK", |
+ "Content-Location: http://www.example.com/~foo/bar.html" |
+ "", |
+ base::Time(), |
+ "<html><body>Google Blah Blah</body></html>", |
+ TEST_MODE_NORMAL, |
+ NULL, |
+ 0, |
+ net::OK |
+}; |
+ |
+// Test that a successful POST invalidates the url with a matching hostname |
+// given in the Content-Location header. |
+TEST(HttpCache, SimplePOST_InvalidateContentLocation) { |
+ MockHttpCache cache; |
+ |
+ // Attempt to populate the cache. |
+ RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction); |
+ |
+ EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
+ EXPECT_EQ(0, cache.disk_cache()->open_count()); |
+ EXPECT_EQ(1, cache.disk_cache()->create_count()); |
+ |
+ ScopedVector<net::UploadElementReader> element_readers; |
+ element_readers.push_back(new net::UploadBytesElementReader("hello", 5)); |
+ net::ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 1); |
+ |
+ // Send a post request with url of kTypicalGET_Transaction set in the |
+ // Content-Location header. |
+ ScopedMockTransaction transaction2(kContentLocationPOST_Transaction); |
+ |
+ MockHttpRequest req2(transaction2); |
+ req2.upload_data_stream = &upload_data_stream; |
+ |
+ RunTransactionTestWithRequest(cache.http_cache(), transaction2, req2, NULL); |
+ |
+ EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
+ EXPECT_EQ(0, cache.disk_cache()->open_count()); |
+ EXPECT_EQ(2, cache.disk_cache()->create_count()); |
+ |
+ // Check that the cache entry from kTypicalGET_Transaction is invalidated. |
+ RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction); |
+ |
+ EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
+ EXPECT_EQ(0, cache.disk_cache()->open_count()); |
+ EXPECT_EQ(3, cache.disk_cache()->create_count()); |
+} |
+ |
+// Tests that a successful POST does not invalidate the url given in the |
+// Content-Location header if the hostname does not match. |
+TEST(HttpCache, SimplePOST_DoNotInvalidateUnmatchingContentLocationHostname) { |
+ MockHttpCache cache; |
+ |
+ // Attempt to populate the cache. |
+ RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
+ |
+ EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
+ EXPECT_EQ(0, cache.disk_cache()->open_count()); |
+ EXPECT_EQ(1, cache.disk_cache()->create_count()); |
+ |
+ ScopedVector<net::UploadElementReader> element_readers; |
+ element_readers.push_back(new net::UploadBytesElementReader("hello", 5)); |
+ net::ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 1); |
+ |
+ // Send a post request with url of kSimpleGET_Transaction set in the |
+ // Content-Location header. The hostname of kSimpleGET_Transaction does not |
+ // match the hostname of kContentLocationPOST_Transaction. |
+ ScopedMockTransaction transaction2(kContentLocationPOST_Transaction); |
+ transaction2.response_headers = "Content-Location: http://www.google.com/"; |
+ |
+ MockHttpRequest req2(transaction2); |
+ req2.upload_data_stream = &upload_data_stream; |
+ |
+ RunTransactionTestWithRequest(cache.http_cache(), transaction2, req2, NULL); |
+ |
+ EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
+ EXPECT_EQ(0, cache.disk_cache()->open_count()); |
+ EXPECT_EQ(2, cache.disk_cache()->create_count()); |
+ |
+ // Check that the cache entry from kSimpleGET_Transaction is still valid. |
+ RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
+ |
+ EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
+ EXPECT_EQ(1, cache.disk_cache()->open_count()); |
+ EXPECT_EQ(2, cache.disk_cache()->create_count()); |
+} |
+ |
+// Tests that a successful GET does not invalidate the url given in the |
+// Content-Location header. |
+TEST(HttpCache, SimpleGET_DoNotInvalidateContentLocation) { |
+ MockHttpCache cache; |
+ |
+ // Attempt to populate the cache. |
+ RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction); |
+ |
+ EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
+ EXPECT_EQ(0, cache.disk_cache()->open_count()); |
+ EXPECT_EQ(1, cache.disk_cache()->create_count()); |
+ |
+ // Send a GET request with the url of kTypicalGET_Transaction set in the |
+ // Content-Location header. |
+ ScopedMockTransaction transaction2(kContentLocationPOST_Transaction); |
+ transaction2.method = "GET"; |
+ MockHttpRequest req2(transaction2); |
+ RunTransactionTestWithRequest(cache.http_cache(), transaction2, req2, NULL); |
+ |
+ EXPECT_EQ(2, cache.network_layer()->transaction_count()); |
+ EXPECT_EQ(0, cache.disk_cache()->open_count()); |
+ EXPECT_EQ(2, cache.disk_cache()->create_count()); |
+ |
+ // Check that the cache entry from kTypicalGET_Transaction is not invalidated. |
+ RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction); |
+ |
+ // If-modified-since triggers a network transaction |
+ EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
+ EXPECT_EQ(1, cache.disk_cache()->open_count()); |
+ EXPECT_EQ(2, cache.disk_cache()->create_count()); |
+} |
+ |
// Tests that a successful POST invalidates a previously cached GET, even when |
// there is no upload identifier. |
TEST(HttpCache, SimplePOST_NoUploadId_Invalidate_205) { |