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

Side by Side Diff: chrome/browser/net/http_server_properties_manager_unittest.cc

Issue 8423028: Persist dynamically learned SPDY settings (like CWND). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/net/http_server_properties_manager.h" 5 #include "chrome/browser/net/http_server_properties_manager.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/common/pref_names.h" 10 #include "chrome/common/pref_names.h"
(...skipping 16 matching lines...) Expand all
27 class TestingHttpServerPropertiesManager : public HttpServerPropertiesManager { 27 class TestingHttpServerPropertiesManager : public HttpServerPropertiesManager {
28 public: 28 public:
29 explicit TestingHttpServerPropertiesManager(PrefService* pref_service) 29 explicit TestingHttpServerPropertiesManager(PrefService* pref_service)
30 : HttpServerPropertiesManager(pref_service) { 30 : HttpServerPropertiesManager(pref_service) {
31 InitializeOnIOThread(); 31 InitializeOnIOThread();
32 } 32 }
33 33
34 virtual ~TestingHttpServerPropertiesManager() { 34 virtual ~TestingHttpServerPropertiesManager() {
35 } 35 }
36 36
37 // Make these method public for testing. 37 // Make these methods public for testing.
38 using HttpServerPropertiesManager::ScheduleUpdateSpdyCacheOnUI; 38 using HttpServerPropertiesManager::ScheduleUpdateCacheOnUI;
39 using HttpServerPropertiesManager::ScheduleUpdateSpdyPrefsOnIO; 39 using HttpServerPropertiesManager::ScheduleUpdatePrefsOnIO;
40 using HttpServerPropertiesManager::ScheduleUpdateAlternateProtocolCacheOnUI;
41 using HttpServerPropertiesManager::ScheduleUpdateAlternateProtocolPrefsOnIO;
42 40
43 // Post tasks without a delay during tests. 41 // Post tasks without a delay during tests.
44 virtual void StartSpdyPrefsUpdateTimerOnIO(base::TimeDelta delay) OVERRIDE { 42 virtual void StartPrefsUpdateTimerOnIO(base::TimeDelta delay) OVERRIDE {
45 HttpServerPropertiesManager::StartSpdyPrefsUpdateTimerOnIO( 43 HttpServerPropertiesManager::StartPrefsUpdateTimerOnIO(
46 base::TimeDelta()); 44 base::TimeDelta());
47 } 45 }
48 46
47 void UpdateCacheFromPrefsOnUIConcrete() {
48 HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI();
49 }
50
49 // Post tasks without a delay during tests. 51 // Post tasks without a delay during tests.
50 virtual void StartAlternateProtocolPrefsUpdateTimerOnIO( 52 virtual void StartCacheUpdateTimerOnUI(base::TimeDelta delay) OVERRIDE {
51 base::TimeDelta delay) OVERRIDE { 53 HttpServerPropertiesManager::StartCacheUpdateTimerOnUI(
52 HttpServerPropertiesManager::StartAlternateProtocolPrefsUpdateTimerOnIO(
53 base::TimeDelta()); 54 base::TimeDelta());
54 } 55 }
55 56
56 void UpdateSpdyCacheFromPrefsConcrete() { 57 void UpdatePrefsFromCacheOnIOConcrete() {
57 HttpServerPropertiesManager::UpdateSpdyCacheFromPrefs(); 58 HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO();
58 } 59 }
59 60
60 void UpdateAlternateProtocolCacheFromPrefsConcrete() { 61 MOCK_METHOD0(UpdateCacheFromPrefsOnUI, void());
61 HttpServerPropertiesManager::UpdateAlternateProtocolCacheFromPrefs(); 62 MOCK_METHOD0(UpdatePrefsFromCacheOnIO, void());
62 } 63 MOCK_METHOD3(UpdateCacheFromPrefsOnIO,
63 64 void(std::vector<std::string>* spdy_servers,
64 // Post tasks without a delay during tests. 65 RefCountedSpdySettingsMap* spdy_settings_map,
65 virtual void StartSpdyCacheUpdateTimerOnUI(base::TimeDelta delay) OVERRIDE { 66 RefCountedAlternateProtocolMap* alternate_protocol_map));
66 HttpServerPropertiesManager::StartSpdyCacheUpdateTimerOnUI( 67 MOCK_METHOD3(UpdatePrefsOnUI,
67 base::TimeDelta()); 68 void(scoped_refptr<RefCountedListValue> spdy_server_list,
68 } 69 RefCountedSpdySettingsMap* spdy_settings_map,
69 70 RefCountedAlternateProtocolMap* alternate_protocol_map));
70 // Post tasks without a delay during tests.
71 virtual void StartAlternateProtocolCacheUpdateTimerOnUI(
72 base::TimeDelta delay) OVERRIDE {
73 HttpServerPropertiesManager::StartAlternateProtocolCacheUpdateTimerOnUI(
74 base::TimeDelta());
75 }
76
77 void UpdateSpdyPrefsFromCacheConcrete() {
78 HttpServerPropertiesManager::UpdateSpdyPrefsFromCache();
79 }
80
81 void UpdateAlternateProtocolPrefsFromCacheConcrete() {
82 HttpServerPropertiesManager::UpdateAlternateProtocolPrefsFromCache();
83 }
84
85 MOCK_METHOD0(UpdateSpdyCacheFromPrefs, void());
86 MOCK_METHOD0(UpdateSpdyPrefsFromCache, void());
87 MOCK_METHOD2(UpdateSpdyCacheFromPrefsOnIO,
88 void(std::vector<std::string>* spdy_servers, bool support_spdy));
89 MOCK_METHOD1(SetSpdyServersInPrefsOnUI,
90 void(scoped_refptr<RefCountedListValue> spdy_server_list));
91
92 MOCK_METHOD0(UpdateAlternateProtocolCacheFromPrefs, void());
93 MOCK_METHOD0(UpdateAlternateProtocolPrefsFromCache, void());
94 MOCK_METHOD1(UpdateAlternateProtocolCacheFromPrefsOnIO,
95 void(RefCountedAlternateProtocolMap*));
96 MOCK_METHOD1(SetAlternateProtocolServersInPrefsOnUI,
97 void(RefCountedAlternateProtocolMap*));
98 71
99 private: 72 private:
100 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); 73 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager);
101 }; 74 };
102 75
103 class HttpServerPropertiesManagerTest : public testing::Test { 76 class HttpServerPropertiesManagerTest : public testing::Test {
104 protected: 77 protected:
105 HttpServerPropertiesManagerTest() 78 HttpServerPropertiesManagerTest()
106 : ui_thread_(BrowserThread::UI, &loop_), 79 : ui_thread_(BrowserThread::UI, &loop_),
107 io_thread_(BrowserThread::IO, &loop_) { 80 io_thread_(BrowserThread::IO, &loop_) {
108 } 81 }
109 82
110 virtual void SetUp() OVERRIDE { 83 virtual void SetUp() OVERRIDE {
111 pref_service_.RegisterListPref(prefs::kSpdyServers); 84 pref_service_.RegisterDictionaryPref(prefs::kHttpServerProperties);
112 pref_service_.RegisterDictionaryPref(prefs::kAlternateProtocolServers);
113 http_server_props_manager_.reset( 85 http_server_props_manager_.reset(
114 new StrictMock<TestingHttpServerPropertiesManager>(&pref_service_)); 86 new StrictMock<TestingHttpServerPropertiesManager>(&pref_service_));
115 ExpectSpdyCacheUpdate(); 87 ExpectCacheUpdate();
116 ExpectAlternateProtocolCacheUpdate();
117 loop_.RunAllPending(); 88 loop_.RunAllPending();
118 } 89 }
119 90
120 virtual void TearDown() OVERRIDE { 91 virtual void TearDown() OVERRIDE {
121 if (http_server_props_manager_.get()) 92 if (http_server_props_manager_.get())
122 http_server_props_manager_->ShutdownOnUIThread(); 93 http_server_props_manager_->ShutdownOnUIThread();
123 loop_.RunAllPending(); 94 loop_.RunAllPending();
124 // Delete |http_server_props_manager_| while |io_thread_| is mapping IO to 95 // Delete |http_server_props_manager_| while |io_thread_| is mapping IO to
125 // |loop_|. 96 // |loop_|.
126 http_server_props_manager_.reset(); 97 http_server_props_manager_.reset();
127 } 98 }
128 99
129 void ExpectSpdyCacheUpdate() { 100 void ExpectCacheUpdate() {
130 EXPECT_CALL(*http_server_props_manager_, UpdateSpdyCacheFromPrefs()) 101 EXPECT_CALL(*http_server_props_manager_, UpdateCacheFromPrefsOnUI())
131 .WillOnce( 102 .WillOnce(
132 Invoke(http_server_props_manager_.get(), 103 Invoke(http_server_props_manager_.get(),
133 &TestingHttpServerPropertiesManager:: 104 &TestingHttpServerPropertiesManager::
134 UpdateSpdyCacheFromPrefsConcrete)); 105 UpdateCacheFromPrefsOnUIConcrete));
135 } 106 }
136 107
137 void ExpectSpdyPrefsUpdate() { 108 void ExpectPrefsUpdate() {
138 EXPECT_CALL(*http_server_props_manager_, UpdateSpdyPrefsFromCache()) 109 EXPECT_CALL(*http_server_props_manager_, UpdatePrefsFromCacheOnIO())
139 .WillOnce( 110 .WillOnce(
140 Invoke(http_server_props_manager_.get(), 111 Invoke(http_server_props_manager_.get(),
141 &TestingHttpServerPropertiesManager:: 112 &TestingHttpServerPropertiesManager::
142 UpdateSpdyPrefsFromCacheConcrete)); 113 UpdatePrefsFromCacheOnIOConcrete));
143 }
144
145 void ExpectAlternateProtocolCacheUpdate() {
146 EXPECT_CALL(*http_server_props_manager_,
147 UpdateAlternateProtocolCacheFromPrefs())
148 .WillOnce(
149 Invoke(http_server_props_manager_.get(),
150 &TestingHttpServerPropertiesManager::
151 UpdateAlternateProtocolCacheFromPrefsConcrete));
152 }
153
154 void ExpectAlternateProtocolPrefsUpdate() {
155 EXPECT_CALL(*http_server_props_manager_,
156 UpdateAlternateProtocolPrefsFromCache())
157 .WillOnce(
158 Invoke(http_server_props_manager_.get(),
159 &TestingHttpServerPropertiesManager::
160 UpdateAlternateProtocolPrefsFromCacheConcrete));
161 } 114 }
162 115
163 MessageLoop loop_; 116 MessageLoop loop_;
164 TestingPrefService pref_service_; 117 TestingPrefService pref_service_;
165 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_; 118 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_;
166 119
167 private: 120 private:
168 content::TestBrowserThread ui_thread_; 121 content::TestBrowserThread ui_thread_;
169 content::TestBrowserThread io_thread_; 122 content::TestBrowserThread io_thread_;
170 123
171 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); 124 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest);
172 }; 125 };
173 126
174 TEST_F(HttpServerPropertiesManagerTest, SingleUpdateForTwoSpdyPrefChanges) { 127 TEST_F(HttpServerPropertiesManagerTest,
175 ExpectSpdyCacheUpdate(); 128 SingleUpdateForTwoSpdyServerPrefChanges) {
129 ExpectCacheUpdate();
176 130
177 // Set up the pref and then set it twice. Only expect a single cache update. 131 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set
178 base::ListValue* http_server_props = new base::ListValue; 132 // it twice. Only expect a single cache update.
179 http_server_props->Append(new base::StringValue("www.google.com:443")); 133
180 pref_service_.SetManagedPref(prefs::kSpdyServers, http_server_props); 134 base::DictionaryValue server_pref_dict;
181 http_server_props = http_server_props->DeepCopy(); 135
182 http_server_props->Append(new base::StringValue("mail.google.com:443")); 136 // Set supports_spdy for www.google.com:80.
183 pref_service_.SetManagedPref(prefs::kSpdyServers, http_server_props); 137 server_pref_dict.SetBoolean("supports_spdy", true);
138
139 // Set up the SpdySettings for www.google.com:80.
140 base::ListValue spdy_settings_list;
141 base::DictionaryValue spdy_setting_dict;
142 spdy_setting_dict.SetInteger("flags", spdy::SETTINGS_FLAG_PERSISTED);
143 spdy_setting_dict.SetInteger("id", 1234);
144 spdy_setting_dict.SetInteger("value", 31337);
145 spdy_settings_list.Append(&spdy_setting_dict);
146 server_pref_dict.Set("settings", &spdy_settings_list);
147
148 // Set up alternate_protocol for www.google.com:80.
149 base::DictionaryValue alternate_protocol;
150 alternate_protocol.SetInteger("port", 443);
151 alternate_protocol.SetInteger("protocol", static_cast<int>(net::NPN_SPDY_1));
152 server_pref_dict.SetWithoutPathExpansion(
153 "alternate_protocol", &alternate_protocol);
154
155 // Set the server preference for www.google.com:80.
156 base::DictionaryValue http_server_properties_dict;
157 http_server_properties_dict.SetWithoutPathExpansion(
158 "www.google.com:80", &server_pref_dict);
159
160 // Set the preference for mail.google.com server.
161 base::DictionaryValue server_pref_dict1;
162
163 // Set supports_spdy for mail.google.com:80
164 server_pref_dict1.SetBoolean("supports_spdy", true);
165
166 // Set up the SpdySettings for mail.google.com:80
167 base::ListValue spdy_settings_list1;
168 base::DictionaryValue spdy_setting_dict1;
169 spdy_setting_dict1.SetInteger("flags", spdy::SETTINGS_FLAG_PERSISTED);
170 spdy_setting_dict1.SetInteger("id", 5678);
171 spdy_setting_dict1.SetInteger("value", 62667);
172 spdy_settings_list1.Append(&spdy_setting_dict1);
173 server_pref_dict1.Set("settings", &spdy_settings_list1);
174
175 // Set up alternate_protocol for mail.google.com:80
176 base::DictionaryValue alternate_protocol1;
177 alternate_protocol1.SetInteger("port", 444);
178 alternate_protocol1.SetInteger(
179 "protocol", static_cast<int>(net::NPN_SPDY_2));
180 server_pref_dict1.SetWithoutPathExpansion(
181 "alternate_protocol", &alternate_protocol1);
182
183 // Set the server preference for mail.google.com:80.
184 http_server_properties_dict.SetWithoutPathExpansion(
185 "mail.google.com:80", &server_pref_dict1);
186
187 // Set the preferences second time.
188 base::DictionaryValue* http_server_properties_dict2 =
189 http_server_properties_dict.DeepCopy();
190 pref_service_.SetManagedPref(prefs::kHttpServerProperties,
191 http_server_properties_dict2);
192
184 loop_.RunAllPending(); 193 loop_.RunAllPending();
185 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 194 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
186 195
196 // Verify SupportsSpdy.
187 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy( 197 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(
188 net::HostPortPair::FromString("www.google.com:443"))); 198 net::HostPortPair::FromString("www.google.com:80")));
189 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy( 199 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(
190 net::HostPortPair::FromString("mail.google.com:443"))); 200 net::HostPortPair::FromString("mail.google.com:80")));
191 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( 201 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(
192 net::HostPortPair::FromString("foo.google.com:1337"))); 202 net::HostPortPair::FromString("foo.google.com:1337")));
203
204 // Verify SpdySettings.
205 spdy::SpdySettings spdy_settings_ret =
206 http_server_props_manager_->GetSpdySettings(
207 net::HostPortPair::FromString("www.google.com:80"));
208 EXPECT_EQ(1U, spdy_settings_ret.size());
209 spdy::SpdySetting spdy_setting1_ret = spdy_settings_ret.front();
210 spdy::SettingsFlagsAndId id1_ret(spdy_setting1_ret.first);
211 EXPECT_EQ(1234U, id1_ret.id());
212 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, id1_ret.flags());
213 EXPECT_EQ(31337u, spdy_setting1_ret.second);
214 spdy_settings_ret = http_server_props_manager_->GetSpdySettings(
215 net::HostPortPair::FromString("mail.google.com:80"));
216 EXPECT_EQ(1U, spdy_settings_ret.size());
217 spdy_setting1_ret = spdy_settings_ret.front();
218 id1_ret = spdy_setting1_ret.first;
219 EXPECT_EQ(5678U, id1_ret.id());
220 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, id1_ret.flags());
221 EXPECT_EQ(62667u, spdy_setting1_ret.second);
222
223 // Verify AlternateProtocol.
224 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(
225 net::HostPortPair::FromString("www.google.com:80")));
226 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(
227 net::HostPortPair::FromString("mail.google.com:80")));
228 net::PortAlternateProtocolPair port_alternate_protocol =
229 http_server_props_manager_->GetAlternateProtocol(
230 net::HostPortPair::FromString("www.google.com:80"));
231 EXPECT_EQ(443, port_alternate_protocol.port);
232 EXPECT_EQ(net::NPN_SPDY_1, port_alternate_protocol.protocol);
233 port_alternate_protocol =
234 http_server_props_manager_->GetAlternateProtocol(
235 net::HostPortPair::FromString("mail.google.com:80"));
236 EXPECT_EQ(444, port_alternate_protocol.port);
237 EXPECT_EQ(net::NPN_SPDY_2, port_alternate_protocol.protocol);
193 } 238 }
194 239
195 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { 240 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) {
196 ExpectSpdyPrefsUpdate(); 241 ExpectPrefsUpdate();
197 242
198 // Post an update task to the IO thread. SetSupportsSpdy calls 243 // Post an update task to the IO thread. SetSupportsSpdy calls
199 // ScheduleUpdateSpdyPrefsOnIO. 244 // ScheduleUpdatePrefsOnIO.
200 245
201 // Add mail.google.com:443 as a supporting spdy server. 246 // Add mail.google.com:443 as a supporting spdy server.
202 net::HostPortPair spdy_server_mail("mail.google.com", 443); 247 net::HostPortPair spdy_server_mail("mail.google.com", 443);
203 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); 248 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail));
204 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); 249 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true);
205 250
206 // Run the task. 251 // Run the task.
207 loop_.RunAllPending(); 252 loop_.RunAllPending();
208 253
209 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); 254 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail));
210 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 255 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
211 } 256 }
212 257
213 TEST_F(HttpServerPropertiesManagerTest, Clear) { 258 TEST_F(HttpServerPropertiesManagerTest, SetSpdySettings) {
214 ExpectSpdyPrefsUpdate(); 259 ExpectPrefsUpdate();
215 ExpectAlternateProtocolPrefsUpdate();
216 260
261 // Add SpdySettings for mail.google.com:443.
217 net::HostPortPair spdy_server_mail("mail.google.com", 443); 262 net::HostPortPair spdy_server_mail("mail.google.com", 443);
218 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); 263 spdy::SpdySettings spdy_settings;
219 http_server_props_manager_->SetAlternateProtocol( 264 spdy::SettingsFlagsAndId id1(0);
220 spdy_server_mail, 443, net::NPN_SPDY_2); 265 id1.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST);
266 id1.set_id(1234);
267 spdy_settings.push_back(std::make_pair(id1, 31337));
268 http_server_props_manager_->SetSpdySettings(spdy_server_mail, spdy_settings);
221 269
222 // Run the task. 270 // Run the task.
223 loop_.RunAllPending(); 271 loop_.RunAllPending();
224 272
225 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); 273 spdy::SpdySettings spdy_settings_ret =
226 EXPECT_TRUE( 274 http_server_props_manager_->GetSpdySettings(spdy_server_mail);
227 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); 275 EXPECT_EQ(1U, spdy_settings_ret.size());
228 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 276 spdy::SpdySetting spdy_setting1_ret = spdy_settings_ret.front();
277 spdy::SettingsFlagsAndId id1_ret(spdy_setting1_ret.first);
278 EXPECT_EQ(1234U, id1_ret.id());
279 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, id1_ret.flags());
280 EXPECT_EQ(31337U, spdy_setting1_ret.second);
229 281
230 ExpectSpdyPrefsUpdate();
231 ExpectAlternateProtocolPrefsUpdate();
232 // Clear http server data.
233 http_server_props_manager_->Clear();
234
235 // Run the task.
236 loop_.RunAllPending();
237
238 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail));
239 EXPECT_FALSE(
240 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
241 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 282 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
242 } 283 }
243 284
244 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateSpdyCache0) {
245 // Post an update task to the UI thread.
246 http_server_props_manager_->ScheduleUpdateSpdyCacheOnUI();
247 // Shutdown comes before the task is executed.
248 http_server_props_manager_->ShutdownOnUIThread();
249 http_server_props_manager_.reset();
250 // Run the task after shutdown and deletion.
251 loop_.RunAllPending();
252 }
253
254 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateSpdyCache1) {
255 // Post an update task.
256 http_server_props_manager_->ScheduleUpdateSpdyCacheOnUI();
257 // Shutdown comes before the task is executed.
258 http_server_props_manager_->ShutdownOnUIThread();
259 // Run the task after shutdown, but before deletion.
260 loop_.RunAllPending();
261 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
262 http_server_props_manager_.reset();
263 loop_.RunAllPending();
264 }
265
266 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateSpdyCache2) {
267 http_server_props_manager_->UpdateSpdyCacheFromPrefsConcrete();
268 // Shutdown comes before the task is executed.
269 http_server_props_manager_->ShutdownOnUIThread();
270 // Run the task after shutdown, but before deletion.
271 loop_.RunAllPending();
272 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
273 http_server_props_manager_.reset();
274 loop_.RunAllPending();
275 }
276
277 //
278 // Tests for shutdown when updating prefs.
279 //
280 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateSpdyPrefs0) {
281 // Post an update task to the IO thread.
282 http_server_props_manager_->ScheduleUpdateSpdyPrefsOnIO();
283 // Shutdown comes before the task is executed.
284 http_server_props_manager_->ShutdownOnUIThread();
285 http_server_props_manager_.reset();
286 // Run the task after shutdown and deletion.
287 loop_.RunAllPending();
288 }
289
290 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateSpdyPrefs1) {
291 ExpectSpdyPrefsUpdate();
292 // Post an update task.
293 http_server_props_manager_->ScheduleUpdateSpdyPrefsOnIO();
294 // Shutdown comes before the task is executed.
295 http_server_props_manager_->ShutdownOnUIThread();
296 // Run the task after shutdown, but before deletion.
297 loop_.RunAllPending();
298 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
299 http_server_props_manager_.reset();
300 loop_.RunAllPending();
301 }
302
303 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateSpdyPrefs2) {
304 // This posts a task to the UI thread.
305 http_server_props_manager_->UpdateSpdyPrefsFromCacheConcrete();
306 // Shutdown comes before the task is executed.
307 http_server_props_manager_->ShutdownOnUIThread();
308 // Run the task after shutdown, but before deletion.
309 loop_.RunAllPending();
310 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
311 http_server_props_manager_.reset();
312 loop_.RunAllPending();
313 }
314
315 TEST_F(HttpServerPropertiesManagerTest,
316 SingleUpdateForTwoAlternateProtocolPrefChanges) {
317 ExpectAlternateProtocolCacheUpdate();
318
319 // Set up the pref and then set it twice. Only expect a single cache update.
320 base::DictionaryValue* alternate_protocol_servers = new base::DictionaryValue;
321 base::DictionaryValue* alternate_protocol = new base::DictionaryValue;
322 alternate_protocol->SetInteger("port", 443);
323 alternate_protocol->SetInteger("protocol", static_cast<int>(net::NPN_SPDY_1));
324 alternate_protocol_servers->SetWithoutPathExpansion(
325 "www.google.com:80", alternate_protocol);
326 alternate_protocol = new base::DictionaryValue;
327 alternate_protocol->SetInteger("port", 444);
328 alternate_protocol->SetInteger("protocol", static_cast<int>(net::NPN_SPDY_2));
329 alternate_protocol_servers->SetWithoutPathExpansion(
330 "mail.google.com:80", alternate_protocol);
331 pref_service_.SetManagedPref(prefs::kAlternateProtocolServers,
332 alternate_protocol_servers);
333 alternate_protocol_servers = alternate_protocol_servers->DeepCopy();
334 pref_service_.SetManagedPref(prefs::kAlternateProtocolServers,
335 alternate_protocol_servers);
336 loop_.RunAllPending();
337
338 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
339
340 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(
341 net::HostPortPair::FromString("www.google.com:80")));
342 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(
343 net::HostPortPair::FromString("mail.google.com:80")));
344 net::PortAlternateProtocolPair port_alternate_protocol =
345 http_server_props_manager_->GetAlternateProtocol(
346 net::HostPortPair::FromString("www.google.com:80"));
347 EXPECT_EQ(443, port_alternate_protocol.port);
348 EXPECT_EQ(net::NPN_SPDY_1, port_alternate_protocol.protocol);
349 port_alternate_protocol =
350 http_server_props_manager_->GetAlternateProtocol(
351 net::HostPortPair::FromString("mail.google.com:80"));
352 EXPECT_EQ(444, port_alternate_protocol.port);
353 EXPECT_EQ(net::NPN_SPDY_2, port_alternate_protocol.protocol);
354 }
355
356 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { 285 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) {
357 ExpectAlternateProtocolPrefsUpdate(); 286 ExpectPrefsUpdate();
358 287
359 net::HostPortPair spdy_server_mail("mail.google.com", 80); 288 net::HostPortPair spdy_server_mail("mail.google.com", 80);
360 EXPECT_FALSE( 289 EXPECT_FALSE(
361 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); 290 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
362 http_server_props_manager_->SetAlternateProtocol( 291 http_server_props_manager_->SetAlternateProtocol(
363 spdy_server_mail, 443, net::NPN_SPDY_2); 292 spdy_server_mail, 443, net::NPN_SPDY_2);
364 293
365 // Run the task. 294 // Run the task.
366 loop_.RunAllPending(); 295 loop_.RunAllPending();
367 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 296 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
368 297
369 ASSERT_TRUE( 298 ASSERT_TRUE(
370 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); 299 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
371 net::PortAlternateProtocolPair port_alternate_protocol = 300 net::PortAlternateProtocolPair port_alternate_protocol =
372 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); 301 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail);
373 EXPECT_EQ(443, port_alternate_protocol.port); 302 EXPECT_EQ(443, port_alternate_protocol.port);
374 EXPECT_EQ(net::NPN_SPDY_2, port_alternate_protocol.protocol); 303 EXPECT_EQ(net::NPN_SPDY_2, port_alternate_protocol.protocol);
375 } 304 }
376 305
377 TEST_F(HttpServerPropertiesManagerTest, 306 TEST_F(HttpServerPropertiesManagerTest, Clear) {
378 ShutdownWithPendingUpdateAlternateProtocolCache0) { 307 ExpectPrefsUpdate();
308
309 net::HostPortPair spdy_server_mail("mail.google.com", 443);
310 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true);
311 http_server_props_manager_->SetAlternateProtocol(
312 spdy_server_mail, 443, net::NPN_SPDY_2);
313
314 spdy::SpdySettings spdy_settings;
315 spdy::SettingsFlagsAndId id1(0);
316 id1.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST);
317 id1.set_id(1234);
318 spdy_settings.push_back(std::make_pair(id1, 31337));
319 http_server_props_manager_->SetSpdySettings(spdy_server_mail, spdy_settings);
320
321 // Run the task.
322 loop_.RunAllPending();
323
324 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail));
325 EXPECT_TRUE(
326 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
327
328 spdy::SpdySettings spdy_settings_ret =
329 http_server_props_manager_->GetSpdySettings(spdy_server_mail);
330 EXPECT_EQ(1U, spdy_settings_ret.size());
331 spdy::SpdySetting spdy_setting1_ret = spdy_settings_ret.front();
332 spdy::SettingsFlagsAndId id1_ret(spdy_setting1_ret.first);
333 EXPECT_EQ(1234U, id1_ret.id());
334 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, id1_ret.flags());
335 EXPECT_EQ(31337U, spdy_setting1_ret.second);
336
337 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
338
339 ExpectPrefsUpdate();
340 // Clear http server data.
341 http_server_props_manager_->Clear();
342
343 // Run the task.
344 loop_.RunAllPending();
345
346 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail));
347 EXPECT_FALSE(
348 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
349
350 spdy::SpdySettings spdy_settings1_ret =
351 http_server_props_manager_->GetSpdySettings(spdy_server_mail);
352 EXPECT_EQ(0U, spdy_settings1_ret.size());
353
354 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
355 }
356
357 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) {
379 // Post an update task to the UI thread. 358 // Post an update task to the UI thread.
380 http_server_props_manager_->ScheduleUpdateAlternateProtocolCacheOnUI(); 359 http_server_props_manager_->ScheduleUpdateCacheOnUI();
381 // Shutdown comes before the task is executed. 360 // Shutdown comes before the task is executed.
382 http_server_props_manager_->ShutdownOnUIThread(); 361 http_server_props_manager_->ShutdownOnUIThread();
383 http_server_props_manager_.reset(); 362 http_server_props_manager_.reset();
384 // Run the task after shutdown and deletion. 363 // Run the task after shutdown and deletion.
385 loop_.RunAllPending(); 364 loop_.RunAllPending();
386 } 365 }
387 366
388 TEST_F(HttpServerPropertiesManagerTest, 367 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache1) {
389 ShutdownWithPendingUpdateAlternateProtocolCache1) {
390 // Post an update task. 368 // Post an update task.
391 http_server_props_manager_->ScheduleUpdateAlternateProtocolCacheOnUI(); 369 http_server_props_manager_->ScheduleUpdateCacheOnUI();
392 // Shutdown comes before the task is executed. 370 // Shutdown comes before the task is executed.
393 http_server_props_manager_->ShutdownOnUIThread(); 371 http_server_props_manager_->ShutdownOnUIThread();
394 // Run the task after shutdown, but before deletion. 372 // Run the task after shutdown, but before deletion.
395 loop_.RunAllPending(); 373 loop_.RunAllPending();
396 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 374 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
397 http_server_props_manager_.reset(); 375 http_server_props_manager_.reset();
398 loop_.RunAllPending(); 376 loop_.RunAllPending();
399 } 377 }
400 378
401 TEST_F(HttpServerPropertiesManagerTest, 379 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache2) {
402 ShutdownWithPendingUpdateAlternateProtocolCache2) { 380 http_server_props_manager_->UpdateCacheFromPrefsOnUIConcrete();
403 http_server_props_manager_->UpdateAlternateProtocolCacheFromPrefsConcrete();
404 // Shutdown comes before the task is executed. 381 // Shutdown comes before the task is executed.
405 http_server_props_manager_->ShutdownOnUIThread(); 382 http_server_props_manager_->ShutdownOnUIThread();
406 // Run the task after shutdown, but before deletion. 383 // Run the task after shutdown, but before deletion.
407 loop_.RunAllPending(); 384 loop_.RunAllPending();
408 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 385 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
409 http_server_props_manager_.reset(); 386 http_server_props_manager_.reset();
410 loop_.RunAllPending(); 387 loop_.RunAllPending();
411 } 388 }
412 389
413 // 390 //
414 // Tests for shutdown when updating prefs. 391 // Tests for shutdown when updating prefs.
415 // 392 //
416 TEST_F(HttpServerPropertiesManagerTest, 393 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs0) {
417 ShutdownWithPendingUpdateAlternateProtocolPrefs0) {
418 // Post an update task to the IO thread. 394 // Post an update task to the IO thread.
419 http_server_props_manager_->ScheduleUpdateAlternateProtocolPrefsOnIO(); 395 http_server_props_manager_->ScheduleUpdatePrefsOnIO();
420 // Shutdown comes before the task is executed. 396 // Shutdown comes before the task is executed.
421 http_server_props_manager_->ShutdownOnUIThread(); 397 http_server_props_manager_->ShutdownOnUIThread();
422 http_server_props_manager_.reset(); 398 http_server_props_manager_.reset();
423 // Run the task after shutdown and deletion. 399 // Run the task after shutdown and deletion.
424 loop_.RunAllPending(); 400 loop_.RunAllPending();
425 } 401 }
426 402
427 TEST_F(HttpServerPropertiesManagerTest, 403 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs1) {
428 ShutdownWithPendingUpdateAlternateProtocolPrefs1) { 404 ExpectPrefsUpdate();
429 ExpectAlternateProtocolPrefsUpdate();
430 // Post an update task. 405 // Post an update task.
431 http_server_props_manager_->ScheduleUpdateAlternateProtocolPrefsOnIO(); 406 http_server_props_manager_->ScheduleUpdatePrefsOnIO();
432 // Shutdown comes before the task is executed. 407 // Shutdown comes before the task is executed.
433 http_server_props_manager_->ShutdownOnUIThread(); 408 http_server_props_manager_->ShutdownOnUIThread();
434 // Run the task after shutdown, but before deletion. 409 // Run the task after shutdown, but before deletion.
435 loop_.RunAllPending(); 410 loop_.RunAllPending();
436 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 411 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
437 http_server_props_manager_.reset(); 412 http_server_props_manager_.reset();
438 loop_.RunAllPending(); 413 loop_.RunAllPending();
439 } 414 }
440 415
441 TEST_F(HttpServerPropertiesManagerTest, 416 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs2) {
442 ShutdownWithPendingUpdateAlternateProtocolPrefs2) {
443 // This posts a task to the UI thread. 417 // This posts a task to the UI thread.
444 http_server_props_manager_->UpdateAlternateProtocolPrefsFromCacheConcrete(); 418 http_server_props_manager_->UpdatePrefsFromCacheOnIOConcrete();
445 // Shutdown comes before the task is executed. 419 // Shutdown comes before the task is executed.
446 http_server_props_manager_->ShutdownOnUIThread(); 420 http_server_props_manager_->ShutdownOnUIThread();
447 // Run the task after shutdown, but before deletion. 421 // Run the task after shutdown, but before deletion.
448 loop_.RunAllPending(); 422 loop_.RunAllPending();
449 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 423 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
450 http_server_props_manager_.reset(); 424 http_server_props_manager_.reset();
451 loop_.RunAllPending(); 425 loop_.RunAllPending();
452 } 426 }
453 427
454 } // namespace 428 } // namespace
455 429
456 } // namespace chrome_browser_net 430 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698