OLD | NEW |
---|---|
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 Loading... | |
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 = new base::DictionaryValue; |
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 = new base::ListValue; | |
141 base::DictionaryValue* spdy_setting_dict = new base::DictionaryValue; | |
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 = new base::DictionaryValue; | |
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 new base::DictionaryValue; | |
158 http_server_properties_dict->SetWithoutPathExpansion( | |
159 "www.google.com:80", server_pref_dict); | |
160 | |
161 // Set the preference for mail.google.com server. | |
162 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | |
163 | |
164 // Set supports_spdy for mail.google.com:80 | |
165 server_pref_dict1->SetBoolean("supports_spdy", true); | |
166 | |
167 // Set up the SpdySettings for mail.google.com:80 | |
168 base::ListValue* spdy_settings_list1 = new base::ListValue; | |
169 base::DictionaryValue* spdy_setting_dict1 = new base::DictionaryValue; | |
170 spdy_setting_dict1->SetInteger("flags", spdy::SETTINGS_FLAG_PERSISTED); | |
171 spdy_setting_dict1->SetInteger("id", 5678); | |
172 spdy_setting_dict1->SetInteger("value", 62667); | |
173 spdy_settings_list1->Append(spdy_setting_dict1); | |
174 server_pref_dict1->Set("settings", spdy_settings_list1); | |
175 | |
176 // Set up alternate_protocol for mail.google.com:80 | |
177 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; | |
178 alternate_protocol1->SetInteger("port", 444); | |
179 alternate_protocol1->SetInteger( | |
180 "protocol", static_cast<int>(net::NPN_SPDY_2)); | |
181 server_pref_dict1->SetWithoutPathExpansion( | |
182 "alternate_protocol", alternate_protocol1); | |
183 | |
184 // Set the server preference for mail.google.com:80. | |
185 http_server_properties_dict->SetWithoutPathExpansion( | |
186 "mail.google.com:80", server_pref_dict1); | |
187 | |
188 // Set the same value for kHttpServerProperties multiple times. | |
189 pref_service_.SetManagedPref(prefs::kHttpServerProperties, | |
190 http_server_properties_dict); | |
191 base::DictionaryValue* http_server_properties_dict2 = | |
192 http_server_properties_dict->DeepCopy(); | |
193 pref_service_.SetManagedPref(prefs::kHttpServerProperties, | |
194 http_server_properties_dict2); | |
195 | |
184 loop_.RunAllPending(); | 196 loop_.RunAllPending(); |
185 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 197 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
186 | 198 |
199 // Verify SupportsSpdy. | |
187 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy( | 200 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy( |
188 net::HostPortPair::FromString("www.google.com:443"))); | 201 net::HostPortPair::FromString("www.google.com:80"))); |
189 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy( | 202 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy( |
190 net::HostPortPair::FromString("mail.google.com:443"))); | 203 net::HostPortPair::FromString("mail.google.com:80"))); |
191 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( | 204 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( |
192 net::HostPortPair::FromString("foo.google.com:1337"))); | 205 net::HostPortPair::FromString("foo.google.com:1337"))); |
206 | |
207 // Verify SpdySettings. | |
208 spdy::SpdySettings spdy_settings_ret = | |
209 http_server_props_manager_->GetSpdySettings( | |
210 net::HostPortPair::FromString("www.google.com:80")); | |
211 EXPECT_EQ(1U, spdy_settings_ret.size()); | |
212 spdy::SpdySetting spdy_setting1_ret = spdy_settings_ret.front(); | |
213 spdy::SettingsFlagsAndId id1_ret(spdy_setting1_ret.first); | |
214 EXPECT_EQ(1234U, id1_ret.id()); | |
215 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, id1_ret.flags()); | |
216 EXPECT_EQ(31337u, spdy_setting1_ret.second); | |
217 spdy_settings_ret = http_server_props_manager_->GetSpdySettings( | |
218 net::HostPortPair::FromString("mail.google.com:80")); | |
219 EXPECT_EQ(1U, spdy_settings_ret.size()); | |
willchan no longer on Chromium
2011/11/11 23:00:01
ASSERT_EQ
ramant (doing other things)
2011/11/12 07:08:42
Done.
| |
220 spdy_setting1_ret = spdy_settings_ret.front(); | |
221 id1_ret = spdy_setting1_ret.first; | |
222 EXPECT_EQ(5678U, id1_ret.id()); | |
223 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, id1_ret.flags()); | |
224 EXPECT_EQ(62667u, spdy_setting1_ret.second); | |
225 | |
226 // Verify AlternateProtocol. | |
227 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( | |
228 net::HostPortPair::FromString("www.google.com:80"))); | |
229 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( | |
230 net::HostPortPair::FromString("mail.google.com:80"))); | |
231 net::PortAlternateProtocolPair port_alternate_protocol = | |
232 http_server_props_manager_->GetAlternateProtocol( | |
233 net::HostPortPair::FromString("www.google.com:80")); | |
234 EXPECT_EQ(443, port_alternate_protocol.port); | |
235 EXPECT_EQ(net::NPN_SPDY_1, port_alternate_protocol.protocol); | |
236 port_alternate_protocol = | |
237 http_server_props_manager_->GetAlternateProtocol( | |
238 net::HostPortPair::FromString("mail.google.com:80")); | |
239 EXPECT_EQ(444, port_alternate_protocol.port); | |
240 EXPECT_EQ(net::NPN_SPDY_2, port_alternate_protocol.protocol); | |
193 } | 241 } |
194 | 242 |
195 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { | 243 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { |
196 ExpectSpdyPrefsUpdate(); | 244 ExpectPrefsUpdate(); |
197 | 245 |
198 // Post an update task to the IO thread. SetSupportsSpdy calls | 246 // Post an update task to the IO thread. SetSupportsSpdy calls |
199 // ScheduleUpdateSpdyPrefsOnIO. | 247 // ScheduleUpdatePrefsOnIO. |
200 | 248 |
201 // Add mail.google.com:443 as a supporting spdy server. | 249 // Add mail.google.com:443 as a supporting spdy server. |
202 net::HostPortPair spdy_server_mail("mail.google.com", 443); | 250 net::HostPortPair spdy_server_mail("mail.google.com", 443); |
203 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 251 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); |
204 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 252 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
205 | 253 |
206 // Run the task. | 254 // Run the task. |
207 loop_.RunAllPending(); | 255 loop_.RunAllPending(); |
208 | 256 |
209 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 257 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); |
210 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 258 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
211 } | 259 } |
212 | 260 |
213 TEST_F(HttpServerPropertiesManagerTest, Clear) { | 261 TEST_F(HttpServerPropertiesManagerTest, SetSpdySettings) { |
214 ExpectSpdyPrefsUpdate(); | 262 ExpectPrefsUpdate(); |
215 ExpectAlternateProtocolPrefsUpdate(); | |
216 | 263 |
264 // Add SpdySettings for mail.google.com:443. | |
217 net::HostPortPair spdy_server_mail("mail.google.com", 443); | 265 net::HostPortPair spdy_server_mail("mail.google.com", 443); |
218 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 266 spdy::SpdySettings spdy_settings; |
219 http_server_props_manager_->SetAlternateProtocol( | 267 spdy::SettingsFlagsAndId id1(0); |
220 spdy_server_mail, 443, net::NPN_SPDY_2); | 268 id1.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST); |
269 id1.set_id(1234); | |
270 spdy_settings.push_back(std::make_pair(id1, 31337)); | |
271 http_server_props_manager_->SetSpdySettings(spdy_server_mail, spdy_settings); | |
221 | 272 |
222 // Run the task. | 273 // Run the task. |
223 loop_.RunAllPending(); | 274 loop_.RunAllPending(); |
224 | 275 |
225 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 276 spdy::SpdySettings spdy_settings_ret = |
226 EXPECT_TRUE( | 277 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
227 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 278 EXPECT_EQ(1U, spdy_settings_ret.size()); |
willchan no longer on Chromium
2011/11/11 23:00:01
ASSERT_EQ, otherwise the next line may crash.
ramant (doing other things)
2011/11/12 07:08:42
Done.
| |
228 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 279 spdy::SpdySetting spdy_setting1_ret = spdy_settings_ret.front(); |
280 spdy::SettingsFlagsAndId id1_ret(spdy_setting1_ret.first); | |
281 EXPECT_EQ(1234U, id1_ret.id()); | |
282 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, id1_ret.flags()); | |
283 EXPECT_EQ(31337U, spdy_setting1_ret.second); | |
229 | 284 |
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()); | 285 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
242 } | 286 } |
243 | 287 |
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) { | 288 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { |
357 ExpectAlternateProtocolPrefsUpdate(); | 289 ExpectPrefsUpdate(); |
358 | 290 |
359 net::HostPortPair spdy_server_mail("mail.google.com", 80); | 291 net::HostPortPair spdy_server_mail("mail.google.com", 80); |
360 EXPECT_FALSE( | 292 EXPECT_FALSE( |
361 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 293 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
362 http_server_props_manager_->SetAlternateProtocol( | 294 http_server_props_manager_->SetAlternateProtocol( |
363 spdy_server_mail, 443, net::NPN_SPDY_2); | 295 spdy_server_mail, 443, net::NPN_SPDY_2); |
364 | 296 |
365 // Run the task. | 297 // Run the task. |
366 loop_.RunAllPending(); | 298 loop_.RunAllPending(); |
367 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 299 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
368 | 300 |
369 ASSERT_TRUE( | 301 ASSERT_TRUE( |
370 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 302 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
371 net::PortAlternateProtocolPair port_alternate_protocol = | 303 net::PortAlternateProtocolPair port_alternate_protocol = |
372 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); | 304 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); |
373 EXPECT_EQ(443, port_alternate_protocol.port); | 305 EXPECT_EQ(443, port_alternate_protocol.port); |
374 EXPECT_EQ(net::NPN_SPDY_2, port_alternate_protocol.protocol); | 306 EXPECT_EQ(net::NPN_SPDY_2, port_alternate_protocol.protocol); |
375 } | 307 } |
376 | 308 |
377 TEST_F(HttpServerPropertiesManagerTest, | 309 TEST_F(HttpServerPropertiesManagerTest, Clear) { |
378 ShutdownWithPendingUpdateAlternateProtocolCache0) { | 310 ExpectPrefsUpdate(); |
311 | |
312 net::HostPortPair spdy_server_mail("mail.google.com", 443); | |
313 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | |
314 http_server_props_manager_->SetAlternateProtocol( | |
315 spdy_server_mail, 443, net::NPN_SPDY_2); | |
316 | |
317 spdy::SpdySettings spdy_settings; | |
318 spdy::SettingsFlagsAndId id1(0); | |
319 id1.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST); | |
320 id1.set_id(1234); | |
321 spdy_settings.push_back(std::make_pair(id1, 31337)); | |
322 http_server_props_manager_->SetSpdySettings(spdy_server_mail, spdy_settings); | |
323 | |
324 // Run the task. | |
325 loop_.RunAllPending(); | |
326 | |
327 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | |
328 EXPECT_TRUE( | |
329 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | |
330 | |
331 spdy::SpdySettings spdy_settings_ret = | |
332 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | |
333 EXPECT_EQ(1U, spdy_settings_ret.size()); | |
334 spdy::SpdySetting spdy_setting1_ret = spdy_settings_ret.front(); | |
335 spdy::SettingsFlagsAndId id1_ret(spdy_setting1_ret.first); | |
336 EXPECT_EQ(1234U, id1_ret.id()); | |
337 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, id1_ret.flags()); | |
338 EXPECT_EQ(31337U, spdy_setting1_ret.second); | |
339 | |
340 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | |
341 | |
342 ExpectPrefsUpdate(); | |
343 // Clear http server data. | |
344 http_server_props_manager_->Clear(); | |
345 | |
346 // Run the task. | |
347 loop_.RunAllPending(); | |
348 | |
349 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | |
350 EXPECT_FALSE( | |
351 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | |
352 | |
353 spdy::SpdySettings spdy_settings1_ret = | |
354 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | |
355 EXPECT_EQ(0U, spdy_settings1_ret.size()); | |
356 | |
357 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | |
358 } | |
359 | |
360 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { | |
379 // Post an update task to the UI thread. | 361 // Post an update task to the UI thread. |
380 http_server_props_manager_->ScheduleUpdateAlternateProtocolCacheOnUI(); | 362 http_server_props_manager_->ScheduleUpdateCacheOnUI(); |
381 // Shutdown comes before the task is executed. | 363 // Shutdown comes before the task is executed. |
382 http_server_props_manager_->ShutdownOnUIThread(); | 364 http_server_props_manager_->ShutdownOnUIThread(); |
383 http_server_props_manager_.reset(); | 365 http_server_props_manager_.reset(); |
384 // Run the task after shutdown and deletion. | 366 // Run the task after shutdown and deletion. |
385 loop_.RunAllPending(); | 367 loop_.RunAllPending(); |
386 } | 368 } |
387 | 369 |
388 TEST_F(HttpServerPropertiesManagerTest, | 370 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache1) { |
389 ShutdownWithPendingUpdateAlternateProtocolCache1) { | |
390 // Post an update task. | 371 // Post an update task. |
391 http_server_props_manager_->ScheduleUpdateAlternateProtocolCacheOnUI(); | 372 http_server_props_manager_->ScheduleUpdateCacheOnUI(); |
392 // Shutdown comes before the task is executed. | 373 // Shutdown comes before the task is executed. |
393 http_server_props_manager_->ShutdownOnUIThread(); | 374 http_server_props_manager_->ShutdownOnUIThread(); |
394 // Run the task after shutdown, but before deletion. | 375 // Run the task after shutdown, but before deletion. |
395 loop_.RunAllPending(); | 376 loop_.RunAllPending(); |
396 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 377 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
397 http_server_props_manager_.reset(); | 378 http_server_props_manager_.reset(); |
398 loop_.RunAllPending(); | 379 loop_.RunAllPending(); |
399 } | 380 } |
400 | 381 |
401 TEST_F(HttpServerPropertiesManagerTest, | 382 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache2) { |
402 ShutdownWithPendingUpdateAlternateProtocolCache2) { | 383 http_server_props_manager_->UpdateCacheFromPrefsOnUIConcrete(); |
403 http_server_props_manager_->UpdateAlternateProtocolCacheFromPrefsConcrete(); | |
404 // Shutdown comes before the task is executed. | 384 // Shutdown comes before the task is executed. |
405 http_server_props_manager_->ShutdownOnUIThread(); | 385 http_server_props_manager_->ShutdownOnUIThread(); |
406 // Run the task after shutdown, but before deletion. | 386 // Run the task after shutdown, but before deletion. |
407 loop_.RunAllPending(); | 387 loop_.RunAllPending(); |
408 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 388 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
409 http_server_props_manager_.reset(); | 389 http_server_props_manager_.reset(); |
410 loop_.RunAllPending(); | 390 loop_.RunAllPending(); |
411 } | 391 } |
412 | 392 |
413 // | 393 // |
414 // Tests for shutdown when updating prefs. | 394 // Tests for shutdown when updating prefs. |
415 // | 395 // |
416 TEST_F(HttpServerPropertiesManagerTest, | 396 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs0) { |
417 ShutdownWithPendingUpdateAlternateProtocolPrefs0) { | |
418 // Post an update task to the IO thread. | 397 // Post an update task to the IO thread. |
419 http_server_props_manager_->ScheduleUpdateAlternateProtocolPrefsOnIO(); | 398 http_server_props_manager_->ScheduleUpdatePrefsOnIO(); |
420 // Shutdown comes before the task is executed. | 399 // Shutdown comes before the task is executed. |
421 http_server_props_manager_->ShutdownOnUIThread(); | 400 http_server_props_manager_->ShutdownOnUIThread(); |
422 http_server_props_manager_.reset(); | 401 http_server_props_manager_.reset(); |
423 // Run the task after shutdown and deletion. | 402 // Run the task after shutdown and deletion. |
424 loop_.RunAllPending(); | 403 loop_.RunAllPending(); |
425 } | 404 } |
426 | 405 |
427 TEST_F(HttpServerPropertiesManagerTest, | 406 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs1) { |
428 ShutdownWithPendingUpdateAlternateProtocolPrefs1) { | 407 ExpectPrefsUpdate(); |
429 ExpectAlternateProtocolPrefsUpdate(); | |
430 // Post an update task. | 408 // Post an update task. |
431 http_server_props_manager_->ScheduleUpdateAlternateProtocolPrefsOnIO(); | 409 http_server_props_manager_->ScheduleUpdatePrefsOnIO(); |
432 // Shutdown comes before the task is executed. | 410 // Shutdown comes before the task is executed. |
433 http_server_props_manager_->ShutdownOnUIThread(); | 411 http_server_props_manager_->ShutdownOnUIThread(); |
434 // Run the task after shutdown, but before deletion. | 412 // Run the task after shutdown, but before deletion. |
435 loop_.RunAllPending(); | 413 loop_.RunAllPending(); |
436 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 414 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
437 http_server_props_manager_.reset(); | 415 http_server_props_manager_.reset(); |
438 loop_.RunAllPending(); | 416 loop_.RunAllPending(); |
439 } | 417 } |
440 | 418 |
441 TEST_F(HttpServerPropertiesManagerTest, | 419 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs2) { |
442 ShutdownWithPendingUpdateAlternateProtocolPrefs2) { | |
443 // This posts a task to the UI thread. | 420 // This posts a task to the UI thread. |
444 http_server_props_manager_->UpdateAlternateProtocolPrefsFromCacheConcrete(); | 421 http_server_props_manager_->UpdatePrefsFromCacheOnIOConcrete(); |
445 // Shutdown comes before the task is executed. | 422 // Shutdown comes before the task is executed. |
446 http_server_props_manager_->ShutdownOnUIThread(); | 423 http_server_props_manager_->ShutdownOnUIThread(); |
447 // Run the task after shutdown, but before deletion. | 424 // Run the task after shutdown, but before deletion. |
448 loop_.RunAllPending(); | 425 loop_.RunAllPending(); |
449 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 426 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
450 http_server_props_manager_.reset(); | 427 http_server_props_manager_.reset(); |
451 loop_.RunAllPending(); | 428 loop_.RunAllPending(); |
452 } | 429 } |
453 | 430 |
454 } // namespace | 431 } // namespace |
455 | 432 |
456 } // namespace chrome_browser_net | 433 } // namespace chrome_browser_net |
OLD | NEW |