Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/disk_cache_based_quic_server_info.h" | 5 #include "net/http/disk_cache_based_quic_server_info.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 12 #include "net/http/mock_http_cache.h" | 12 #include "net/http/mock_http_cache.h" |
| 13 #include "net/quic/crypto/quic_server_info.h" | 13 #include "net/quic/crypto/quic_server_info.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // This is an empty transaction, needed to register the URL and the test mode. | 18 // This is an empty transaction, needed to register the URL and the test mode. |
| 19 const MockTransaction kHostInfoTransaction = { | 19 const MockTransaction kHostInfoTransaction = { |
| 20 "quicserverinfo:https://www.google.com", | 20 "quicserverinfo:https://www.google.com/443", |
| 21 "", | 21 "", |
| 22 base::Time(), | 22 base::Time(), |
| 23 "", | 23 "", |
| 24 net::LOAD_NORMAL, | 24 net::LOAD_NORMAL, |
| 25 "", | 25 "", |
| 26 "", | 26 "", |
| 27 base::Time(), | 27 base::Time(), |
| 28 "", | 28 "", |
| 29 TEST_MODE_NORMAL, | 29 TEST_MODE_NORMAL, |
| 30 NULL, | 30 NULL, |
| 31 0 | 31 0 |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 // Tests that we can delete a DiskCacheBasedQuicServerInfo object in a | 34 // Tests that we can delete a DiskCacheBasedQuicServerInfo object in a |
| 35 // completion callback for DiskCacheBasedQuicServerInfo::WaitForDataReady. | 35 // completion callback for DiskCacheBasedQuicServerInfo::WaitForDataReady. |
| 36 TEST(DiskCacheBasedQuicServerInfo, DeleteInCallback) { | 36 TEST(DiskCacheBasedQuicServerInfo, DeleteInCallback) { |
| 37 // Use the blocking mock backend factory to force asynchronous completion | 37 // Use the blocking mock backend factory to force asynchronous completion |
| 38 // of quic_server_info->WaitForDataReady(), so that the callback will run. | 38 // of quic_server_info->WaitForDataReady(), so that the callback will run. |
| 39 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); | 39 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); |
| 40 MockHttpCache cache(factory); | 40 MockHttpCache cache(factory); |
| 41 scoped_ptr<net::QuicServerInfo> quic_server_info( | 41 scoped_ptr<net::QuicServerInfo> quic_server_info( |
| 42 new net::DiskCacheBasedQuicServerInfo("https://www.verisign.com", | 42 new net::DiskCacheBasedQuicServerInfo("https://www.verisign.com", |
| 43 443, | |
|
Ryan Hamilton
2014/03/10 20:57:33
Should we have any test which demonstrates differe
ramant (doing other things)
2014/03/11 00:48:50
Done.
| |
| 43 cache.http_cache())); | 44 cache.http_cache())); |
| 44 quic_server_info->Start(); | 45 quic_server_info->Start(); |
| 45 net::TestCompletionCallback callback; | 46 net::TestCompletionCallback callback; |
| 46 int rv = quic_server_info->WaitForDataReady(callback.callback()); | 47 int rv = quic_server_info->WaitForDataReady(callback.callback()); |
| 47 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 48 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
| 48 // Now complete the backend creation and let the callback run. | 49 // Now complete the backend creation and let the callback run. |
| 49 factory->FinishCreation(); | 50 factory->FinishCreation(); |
| 50 EXPECT_EQ(net::OK, callback.GetResult(rv)); | 51 EXPECT_EQ(net::OK, callback.GetResult(rv)); |
| 51 } | 52 } |
| 52 | 53 |
| 53 // Tests the basic logic of storing, retrieving and updating data. | 54 // Tests the basic logic of storing, retrieving and updating data. |
| 54 TEST(DiskCacheBasedQuicServerInfo, Update) { | 55 TEST(DiskCacheBasedQuicServerInfo, Update) { |
| 55 MockHttpCache cache; | 56 MockHttpCache cache; |
| 56 AddMockTransaction(&kHostInfoTransaction); | 57 AddMockTransaction(&kHostInfoTransaction); |
| 57 net::TestCompletionCallback callback; | 58 net::TestCompletionCallback callback; |
| 58 | 59 |
| 59 scoped_ptr<net::QuicServerInfo> quic_server_info( | 60 scoped_ptr<net::QuicServerInfo> quic_server_info( |
| 60 new net::DiskCacheBasedQuicServerInfo("https://www.google.com", | 61 new net::DiskCacheBasedQuicServerInfo("https://www.google.com", |
| 62 443, | |
| 61 cache.http_cache())); | 63 cache.http_cache())); |
| 62 quic_server_info->Start(); | 64 quic_server_info->Start(); |
| 63 int rv = quic_server_info->WaitForDataReady(callback.callback()); | 65 int rv = quic_server_info->WaitForDataReady(callback.callback()); |
| 64 EXPECT_EQ(net::OK, callback.GetResult(rv)); | 66 EXPECT_EQ(net::OK, callback.GetResult(rv)); |
| 65 | 67 |
| 66 net::QuicServerInfo::State* state = quic_server_info->mutable_state(); | 68 net::QuicServerInfo::State* state = quic_server_info->mutable_state(); |
| 67 EXPECT_TRUE(state->certs.empty()); | 69 EXPECT_TRUE(state->certs.empty()); |
| 68 const string server_config_a = "server_config_a"; | 70 const string server_config_a = "server_config_a"; |
| 69 const string source_address_token_a = "source_address_token_a"; | 71 const string source_address_token_a = "source_address_token_a"; |
| 70 const string server_config_sig_a = "server_config_sig_a"; | 72 const string server_config_sig_a = "server_config_sig_a"; |
| 71 const string cert_a = "cert_a"; | 73 const string cert_a = "cert_a"; |
| 72 const string cert_b = "cert_b"; | 74 const string cert_b = "cert_b"; |
| 73 | 75 |
| 74 state->server_config = server_config_a; | 76 state->server_config = server_config_a; |
| 75 state->source_address_token = source_address_token_a; | 77 state->source_address_token = source_address_token_a; |
| 76 state->server_config_sig = server_config_sig_a; | 78 state->server_config_sig = server_config_sig_a; |
| 77 state->certs.push_back(cert_a); | 79 state->certs.push_back(cert_a); |
| 78 quic_server_info->Persist(); | 80 quic_server_info->Persist(); |
| 79 | 81 |
| 80 // Wait until Persist() does the work. | 82 // Wait until Persist() does the work. |
| 81 base::MessageLoop::current()->RunUntilIdle(); | 83 base::MessageLoop::current()->RunUntilIdle(); |
| 82 | 84 |
| 83 // Open the stored QuicServerInfo. | 85 // Open the stored QuicServerInfo. |
| 84 quic_server_info.reset( | 86 quic_server_info.reset( |
| 85 new net::DiskCacheBasedQuicServerInfo("https://www.google.com", | 87 new net::DiskCacheBasedQuicServerInfo("https://www.google.com", |
| 88 443, | |
| 86 cache.http_cache())); | 89 cache.http_cache())); |
| 87 quic_server_info->Start(); | 90 quic_server_info->Start(); |
| 88 rv = quic_server_info->WaitForDataReady(callback.callback()); | 91 rv = quic_server_info->WaitForDataReady(callback.callback()); |
| 89 EXPECT_EQ(net::OK, callback.GetResult(rv)); | 92 EXPECT_EQ(net::OK, callback.GetResult(rv)); |
| 90 | 93 |
| 91 // And now update the data. | 94 // And now update the data. |
| 92 state = quic_server_info->mutable_state(); | 95 state = quic_server_info->mutable_state(); |
| 93 state->certs.push_back(cert_b); | 96 state->certs.push_back(cert_b); |
| 94 | 97 |
| 95 // Fail instead of DCHECKing double creates. | 98 // Fail instead of DCHECKing double creates. |
| 96 cache.disk_cache()->set_double_create_check(false); | 99 cache.disk_cache()->set_double_create_check(false); |
| 97 quic_server_info->Persist(); | 100 quic_server_info->Persist(); |
| 98 base::MessageLoop::current()->RunUntilIdle(); | 101 base::MessageLoop::current()->RunUntilIdle(); |
| 99 | 102 |
| 100 // Verify that the state was updated. | 103 // Verify that the state was updated. |
| 101 quic_server_info.reset( | 104 quic_server_info.reset( |
| 102 new net::DiskCacheBasedQuicServerInfo("https://www.google.com", | 105 new net::DiskCacheBasedQuicServerInfo("https://www.google.com", |
| 106 443, | |
| 103 cache.http_cache())); | 107 cache.http_cache())); |
| 104 quic_server_info->Start(); | 108 quic_server_info->Start(); |
| 105 rv = quic_server_info->WaitForDataReady(callback.callback()); | 109 rv = quic_server_info->WaitForDataReady(callback.callback()); |
| 106 EXPECT_EQ(net::OK, callback.GetResult(rv)); | 110 EXPECT_EQ(net::OK, callback.GetResult(rv)); |
| 107 | 111 |
| 108 const net::QuicServerInfo::State& state1 = quic_server_info->state(); | 112 const net::QuicServerInfo::State& state1 = quic_server_info->state(); |
| 109 EXPECT_TRUE(quic_server_info->IsDataReady()); | 113 EXPECT_TRUE(quic_server_info->IsDataReady()); |
| 110 EXPECT_EQ(server_config_a, state1.server_config); | 114 EXPECT_EQ(server_config_a, state1.server_config); |
| 111 EXPECT_EQ(source_address_token_a, state1.source_address_token); | 115 EXPECT_EQ(source_address_token_a, state1.source_address_token); |
| 112 EXPECT_EQ(server_config_sig_a, state1.server_config_sig); | 116 EXPECT_EQ(server_config_sig_a, state1.server_config_sig); |
| 113 EXPECT_EQ(2U, state1.certs.size()); | 117 EXPECT_EQ(2U, state1.certs.size()); |
| 114 EXPECT_EQ(cert_a, state1.certs[0]); | 118 EXPECT_EQ(cert_a, state1.certs[0]); |
| 115 EXPECT_EQ(cert_b, state1.certs[1]); | 119 EXPECT_EQ(cert_b, state1.certs[1]); |
| 116 | 120 |
| 117 RemoveMockTransaction(&kHostInfoTransaction); | 121 RemoveMockTransaction(&kHostInfoTransaction); |
| 118 } | 122 } |
| 119 | 123 |
| 120 } // namespace | 124 } // namespace |
| OLD | NEW |