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

Side by Side Diff: net/http/disk_cache_based_quic_server_info_unittest.cc

Issue 154933003: Persist server's crypto config data to disk cache for 0-RTT (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comments for Patch Set 4 Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
6
5 #include "base/bind.h" 7 #include "base/bind.h"
6 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
7 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
8 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
9 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
10 #include "net/http/disk_cache_based_quic_server_info.h"
11 #include "net/http/mock_http_cache.h" 12 #include "net/http/mock_http_cache.h"
12 #include "net/quic/crypto/quic_server_info.h" 13 #include "net/quic/crypto/quic_server_info.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace { 16 namespace {
16 17
17 // 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.
18 const MockTransaction kHostInfoTransaction = { 19 const MockTransaction kHostInfoTransaction = {
19 "quicserverinfo:https://www.google.com", 20 "quicserverinfo:https://www.google.com",
20 "", 21 "",
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 net::TestCompletionCallback callback; 57 net::TestCompletionCallback callback;
57 58
58 scoped_ptr<net::QuicServerInfo> quic_server_info( 59 scoped_ptr<net::QuicServerInfo> quic_server_info(
59 new net::DiskCacheBasedQuicServerInfo("https://www.google.com", 60 new net::DiskCacheBasedQuicServerInfo("https://www.google.com",
60 cache.http_cache())); 61 cache.http_cache()));
61 quic_server_info->Start(); 62 quic_server_info->Start();
62 int rv = quic_server_info->WaitForDataReady(callback.callback()); 63 int rv = quic_server_info->WaitForDataReady(callback.callback());
63 EXPECT_EQ(net::OK, callback.GetResult(rv)); 64 EXPECT_EQ(net::OK, callback.GetResult(rv));
64 65
65 net::QuicServerInfo::State* state = quic_server_info->mutable_state(); 66 net::QuicServerInfo::State* state = quic_server_info->mutable_state();
66 // TODO(rtenneti): Flesh out details of net::QuicServerInfo::State. 67 EXPECT_TRUE(state->certs.empty());
67 EXPECT_TRUE(state->data.empty()); 68 const string server_config_a = "server_config_a";
68 state->data.push_back(std::string("foo")); 69 const string source_address_token_a = "source_address_token_a";
70 const string server_config_sig_a = "server_config_sig_a";
71 const string cert_a = "cert_a";
72 const string cert_b = "cert_b";
73
74 state->server_config = server_config_a;
75 state->source_address_token = source_address_token_a;
76 state->server_config_sig = server_config_sig_a;
77 state->certs.push_back(cert_a);
69 quic_server_info->Persist(); 78 quic_server_info->Persist();
70 79
71 // Wait until Persist() does the work. 80 // Wait until Persist() does the work.
72 base::MessageLoop::current()->RunUntilIdle(); 81 base::MessageLoop::current()->RunUntilIdle();
73 82
74 // Open the stored net::QuicCryptoClientConfig::CachedState. 83 // Open the stored QuicServerInfo.
75 quic_server_info.reset( 84 quic_server_info.reset(
76 new net::DiskCacheBasedQuicServerInfo("https://www.google.com", 85 new net::DiskCacheBasedQuicServerInfo("https://www.google.com",
77 cache.http_cache())); 86 cache.http_cache()));
78 quic_server_info->Start(); 87 quic_server_info->Start();
79 rv = quic_server_info->WaitForDataReady(callback.callback()); 88 rv = quic_server_info->WaitForDataReady(callback.callback());
80 EXPECT_EQ(net::OK, callback.GetResult(rv)); 89 EXPECT_EQ(net::OK, callback.GetResult(rv));
81 90
82 // And now update the data. 91 // And now update the data.
83 state = quic_server_info->mutable_state(); 92 state = quic_server_info->mutable_state();
84 // TODO(rtenneti): Flesh out details of net::QuicServerInfo::State. 93 state->certs.push_back(cert_b);
85 // Verify the data after we implement save and restore of the data.
86 state->data.push_back(std::string("bar"));
87 94
88 // Fail instead of DCHECKing double creates. 95 // Fail instead of DCHECKing double creates.
89 cache.disk_cache()->set_double_create_check(false); 96 cache.disk_cache()->set_double_create_check(false);
90 quic_server_info->Persist(); 97 quic_server_info->Persist();
91 base::MessageLoop::current()->RunUntilIdle(); 98 base::MessageLoop::current()->RunUntilIdle();
92 99
93 // Verify that the state was updated. 100 // Verify that the state was updated.
94 quic_server_info.reset( 101 quic_server_info.reset(
95 new net::DiskCacheBasedQuicServerInfo("https://www.google.com", 102 new net::DiskCacheBasedQuicServerInfo("https://www.google.com",
96 cache.http_cache())); 103 cache.http_cache()));
97 quic_server_info->Start(); 104 quic_server_info->Start();
98 rv = quic_server_info->WaitForDataReady(callback.callback()); 105 rv = quic_server_info->WaitForDataReady(callback.callback());
99 EXPECT_EQ(net::OK, callback.GetResult(rv)); 106 EXPECT_EQ(net::OK, callback.GetResult(rv));
100 107
101 state = quic_server_info->mutable_state(); 108 const net::QuicServerInfo::State& state1 = quic_server_info->state();
102 // TODO(rtenneti): Flesh out details of net::QuicServerInfo::State. 109 EXPECT_TRUE(quic_server_info->IsDataReady());
103 // Verify the data after we implement save and restore of the data. 110 EXPECT_EQ(server_config_a, state1.server_config);
111 EXPECT_EQ(source_address_token_a, state1.source_address_token);
112 EXPECT_EQ(server_config_sig_a, state1.server_config_sig);
113 EXPECT_EQ(2U, state1.certs.size());
114 EXPECT_EQ(cert_a, state1.certs[0]);
115 EXPECT_EQ(cert_b, state1.certs[1]);
104 116
105 RemoveMockTransaction(&kHostInfoTransaction); 117 RemoveMockTransaction(&kHostInfoTransaction);
106 } 118 }
107 119
108 } // namespace 120 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698