OLD | NEW |
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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 "base/hash_tables.h" | 7 #include "base/hash_tables.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/scoped_vector.h" | 9 #include "base/scoped_vector.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1394 | 1394 |
1395 std::vector<Context*> context_list; | 1395 std::vector<Context*> context_list; |
1396 const int kNumTransactions = 5; | 1396 const int kNumTransactions = 5; |
1397 | 1397 |
1398 for (int i = 0; i < kNumTransactions; ++i) { | 1398 for (int i = 0; i < kNumTransactions; ++i) { |
1399 context_list.push_back(new Context()); | 1399 context_list.push_back(new Context()); |
1400 Context* c = context_list[i]; | 1400 Context* c = context_list[i]; |
1401 | 1401 |
1402 c->result = cache.http_cache()->CreateTransaction(&c->trans); | 1402 c->result = cache.http_cache()->CreateTransaction(&c->trans); |
1403 EXPECT_EQ(net::OK, c->result); | 1403 EXPECT_EQ(net::OK, c->result); |
1404 EXPECT_EQ(net::LOAD_STATE_IDLE, c->trans->GetLoadState()); | |
1405 | 1404 |
1406 c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog()); | 1405 c->result = c->trans->Start(&request, &c->callback, net::BoundNetLog()); |
1407 } | 1406 } |
1408 | 1407 |
1409 // All requests are waiting for the active entry. | |
1410 for (int i = 0; i < kNumTransactions; ++i) { | |
1411 Context* c = context_list[i]; | |
1412 EXPECT_EQ(net::LOAD_STATE_WAITING_FOR_CACHE, c->trans->GetLoadState()); | |
1413 } | |
1414 | |
1415 // Allow all requests to move from the Create queue to the active entry. | 1408 // Allow all requests to move from the Create queue to the active entry. |
1416 MessageLoop::current()->RunAllPending(); | 1409 MessageLoop::current()->RunAllPending(); |
1417 | 1410 |
1418 // The first request should be a writer at this point, and the subsequent | 1411 // The first request should be a writer at this point, and the subsequent |
1419 // requests should be pending. | 1412 // requests should be pending. |
1420 | 1413 |
1421 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1414 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
1422 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 1415 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
1423 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 1416 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
1424 | 1417 |
1425 // All requests depend on the writer, and the writer is between Start and | |
1426 // Read, i.e. idle. | |
1427 for (int i = 0; i < kNumTransactions; ++i) { | |
1428 Context* c = context_list[i]; | |
1429 EXPECT_EQ(net::LOAD_STATE_IDLE, c->trans->GetLoadState()); | |
1430 } | |
1431 | |
1432 for (int i = 0; i < kNumTransactions; ++i) { | 1418 for (int i = 0; i < kNumTransactions; ++i) { |
1433 Context* c = context_list[i]; | 1419 Context* c = context_list[i]; |
1434 if (c->result == net::ERR_IO_PENDING) | 1420 if (c->result == net::ERR_IO_PENDING) |
1435 c->result = c->callback.WaitForResult(); | 1421 c->result = c->callback.WaitForResult(); |
1436 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); | 1422 ReadAndVerifyTransaction(c->trans.get(), kSimpleGET_Transaction); |
1437 } | 1423 } |
1438 | 1424 |
1439 // We should not have had to re-open the disk entry | 1425 // We should not have had to re-open the disk entry |
1440 | 1426 |
1441 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | 1427 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
(...skipping 3277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4719 // Now return 200 when validating the entry so the metadata will be lost. | 4705 // Now return 200 when validating the entry so the metadata will be lost. |
4720 MockTransaction trans2(kTypicalGET_Transaction); | 4706 MockTransaction trans2(kTypicalGET_Transaction); |
4721 trans2.load_flags = net::LOAD_VALIDATE_CACHE; | 4707 trans2.load_flags = net::LOAD_VALIDATE_CACHE; |
4722 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); | 4708 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); |
4723 EXPECT_TRUE(response.metadata.get() == NULL); | 4709 EXPECT_TRUE(response.metadata.get() == NULL); |
4724 | 4710 |
4725 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 4711 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
4726 EXPECT_EQ(4, cache.disk_cache()->open_count()); | 4712 EXPECT_EQ(4, cache.disk_cache()->open_count()); |
4727 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 4713 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
4728 } | 4714 } |
OLD | NEW |