OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/http/http_cache.h" | 5 #include "net/http/http_cache.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 6426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6437 MockHttpCache cache; | 6437 MockHttpCache cache; |
6438 | 6438 |
6439 // Write to the cache | 6439 // Write to the cache |
6440 net::HttpResponseInfo response; | 6440 net::HttpResponseInfo response; |
6441 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, | 6441 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, |
6442 &response); | 6442 &response); |
6443 EXPECT_TRUE(response.metadata.get() == NULL); | 6443 EXPECT_TRUE(response.metadata.get() == NULL); |
6444 | 6444 |
6445 // Trivial call. | 6445 // Trivial call. |
6446 cache.http_cache()->WriteMetadata(GURL("foo"), net::DEFAULT_PRIORITY, | 6446 cache.http_cache()->WriteMetadata(GURL("foo"), net::DEFAULT_PRIORITY, |
6447 Time::Now().ToDoubleT(), NULL, 0); | 6447 Time::Now(), NULL, 0); |
6448 | 6448 |
6449 // Write meta data to the same entry. | 6449 // Write meta data to the same entry. |
6450 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(50)); | 6450 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(50)); |
6451 memset(buf->data(), 0, buf->size()); | 6451 memset(buf->data(), 0, buf->size()); |
6452 base::strlcpy(buf->data(), "Hi there", buf->size()); | 6452 base::strlcpy(buf->data(), "Hi there", buf->size()); |
6453 cache.http_cache()->WriteMetadata( | 6453 cache.http_cache()->WriteMetadata( |
6454 GURL(kSimpleGET_Transaction.url), net::DEFAULT_PRIORITY, | 6454 GURL(kSimpleGET_Transaction.url), net::DEFAULT_PRIORITY, |
6455 response.response_time.ToDoubleT(), buf.get(), buf->size()); | 6455 response.response_time, buf.get(), buf->size()); |
6456 | 6456 |
6457 // Release the buffer before the operation takes place. | 6457 // Release the buffer before the operation takes place. |
6458 buf = NULL; | 6458 buf = NULL; |
6459 | 6459 |
6460 // Makes sure we finish pending operations. | 6460 // Makes sure we finish pending operations. |
6461 base::MessageLoop::current()->RunUntilIdle(); | 6461 base::MessageLoop::current()->RunUntilIdle(); |
6462 | 6462 |
6463 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, | 6463 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, |
6464 &response); | 6464 &response); |
6465 ASSERT_TRUE(response.metadata.get() != NULL); | 6465 ASSERT_TRUE(response.metadata.get() != NULL); |
(...skipping 14 matching lines...) Expand all Loading... |
6480 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, | 6480 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, |
6481 &response); | 6481 &response); |
6482 EXPECT_TRUE(response.metadata.get() == NULL); | 6482 EXPECT_TRUE(response.metadata.get() == NULL); |
6483 | 6483 |
6484 // Attempt to write meta data to the same entry. | 6484 // Attempt to write meta data to the same entry. |
6485 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(50)); | 6485 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(50)); |
6486 memset(buf->data(), 0, buf->size()); | 6486 memset(buf->data(), 0, buf->size()); |
6487 base::strlcpy(buf->data(), "Hi there", buf->size()); | 6487 base::strlcpy(buf->data(), "Hi there", buf->size()); |
6488 base::Time expected_time = response.response_time - | 6488 base::Time expected_time = response.response_time - |
6489 base::TimeDelta::FromMilliseconds(20); | 6489 base::TimeDelta::FromMilliseconds(20); |
6490 cache.http_cache()->WriteMetadata( | 6490 cache.http_cache()->WriteMetadata(GURL(kSimpleGET_Transaction.url), |
6491 GURL(kSimpleGET_Transaction.url), net::DEFAULT_PRIORITY, | 6491 net::DEFAULT_PRIORITY, expected_time, |
6492 expected_time.ToDoubleT(), buf.get(), buf->size()); | 6492 buf.get(), buf->size()); |
6493 | 6493 |
6494 // Makes sure we finish pending operations. | 6494 // Makes sure we finish pending operations. |
6495 base::MessageLoop::current()->RunUntilIdle(); | 6495 base::MessageLoop::current()->RunUntilIdle(); |
6496 | 6496 |
6497 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, | 6497 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, |
6498 &response); | 6498 &response); |
6499 EXPECT_TRUE(response.metadata.get() == NULL); | 6499 EXPECT_TRUE(response.metadata.get() == NULL); |
6500 | 6500 |
6501 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 6501 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
6502 EXPECT_EQ(2, cache.disk_cache()->open_count()); | 6502 EXPECT_EQ(2, cache.disk_cache()->open_count()); |
(...skipping 10 matching lines...) Expand all Loading... |
6513 RunTransactionTestWithResponseInfo(cache.http_cache(), | 6513 RunTransactionTestWithResponseInfo(cache.http_cache(), |
6514 kTypicalGET_Transaction, &response); | 6514 kTypicalGET_Transaction, &response); |
6515 EXPECT_TRUE(response.metadata.get() == NULL); | 6515 EXPECT_TRUE(response.metadata.get() == NULL); |
6516 | 6516 |
6517 // Write meta data to the same entry. | 6517 // Write meta data to the same entry. |
6518 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(50)); | 6518 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(50)); |
6519 memset(buf->data(), 0, buf->size()); | 6519 memset(buf->data(), 0, buf->size()); |
6520 base::strlcpy(buf->data(), "Hi there", buf->size()); | 6520 base::strlcpy(buf->data(), "Hi there", buf->size()); |
6521 cache.http_cache()->WriteMetadata( | 6521 cache.http_cache()->WriteMetadata( |
6522 GURL(kTypicalGET_Transaction.url), net::DEFAULT_PRIORITY, | 6522 GURL(kTypicalGET_Transaction.url), net::DEFAULT_PRIORITY, |
6523 response.response_time.ToDoubleT(), buf.get(), buf->size()); | 6523 response.response_time, buf.get(), buf->size()); |
6524 | 6524 |
6525 // Makes sure we finish pending operations. | 6525 // Makes sure we finish pending operations. |
6526 base::MessageLoop::current()->RunUntilIdle(); | 6526 base::MessageLoop::current()->RunUntilIdle(); |
6527 | 6527 |
6528 // Start with a READ mode transaction. | 6528 // Start with a READ mode transaction. |
6529 MockTransaction trans1(kTypicalGET_Transaction); | 6529 MockTransaction trans1(kTypicalGET_Transaction); |
6530 trans1.load_flags = net::LOAD_ONLY_FROM_CACHE; | 6530 trans1.load_flags = net::LOAD_ONLY_FROM_CACHE; |
6531 | 6531 |
6532 RunTransactionTestWithResponseInfo(cache.http_cache(), trans1, &response); | 6532 RunTransactionTestWithResponseInfo(cache.http_cache(), trans1, &response); |
6533 ASSERT_TRUE(response.metadata.get() != NULL); | 6533 ASSERT_TRUE(response.metadata.get() != NULL); |
(...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7769 | 7769 |
7770 // Here the second transaction proceeds without reading the first body. | 7770 // Here the second transaction proceeds without reading the first body. |
7771 EXPECT_EQ(net::LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState()); | 7771 EXPECT_EQ(net::LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState()); |
7772 base::MessageLoop::current()->RunUntilIdle(); | 7772 base::MessageLoop::current()->RunUntilIdle(); |
7773 EXPECT_EQ(net::LOAD_STATE_IDLE, second->trans->GetLoadState()); | 7773 EXPECT_EQ(net::LOAD_STATE_IDLE, second->trans->GetLoadState()); |
7774 ASSERT_TRUE(second->trans->GetResponseInfo()); | 7774 ASSERT_TRUE(second->trans->GetResponseInfo()); |
7775 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue( | 7775 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue( |
7776 "Cache-Control", "no-store")); | 7776 "Cache-Control", "no-store")); |
7777 ReadAndVerifyTransaction(second->trans.get(), kSimpleGET_Transaction); | 7777 ReadAndVerifyTransaction(second->trans.get(), kSimpleGET_Transaction); |
7778 } | 7778 } |
OLD | NEW |