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

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

Issue 378823002: Move http_server_properties_manager from chrome/browser/net to net/http. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments. Created 6 years, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/http/http_server_properties_manager.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/prefs/pref_registry_simple.h" 9 #include "base/prefs/pref_registry_simple.h"
10 #include "base/prefs/testing_pref_service.h" 10 #include "base/prefs/testing_pref_service.h"
11 #include "base/test/test_simple_task_runner.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "chrome/common/pref_names.h"
13 #include "content/public/test/test_browser_thread.h"
14 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
16 #include "url/gurl.h" 15 #include "url/gurl.h"
17 16
18 namespace chrome_browser_net { 17 namespace net {
19 18
20 namespace { 19 namespace {
21 20
22 using ::testing::_; 21 using ::testing::_;
23 using ::testing::Invoke; 22 using ::testing::Invoke;
24 using ::testing::Mock; 23 using ::testing::Mock;
25 using ::testing::StrictMock; 24 using ::testing::StrictMock;
26 using content::BrowserThread; 25
26 const char kTestHttpServerProperties[] = "TestHttpServerProperties";
27 27
28 class TestingHttpServerPropertiesManager : public HttpServerPropertiesManager { 28 class TestingHttpServerPropertiesManager : public HttpServerPropertiesManager {
29 public: 29 public:
30 explicit TestingHttpServerPropertiesManager(PrefService* pref_service) 30 TestingHttpServerPropertiesManager(
31 : HttpServerPropertiesManager(pref_service) { 31 PrefService* pref_service,
32 const char* pref_path,
33 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
34 : HttpServerPropertiesManager(pref_service, pref_path, io_task_runner) {
32 InitializeOnIOThread(); 35 InitializeOnIOThread();
33 } 36 }
34 37
35 virtual ~TestingHttpServerPropertiesManager() { 38 virtual ~TestingHttpServerPropertiesManager() {}
36 }
37 39
38 // Make these methods public for testing. 40 // Make these methods public for testing.
39 using HttpServerPropertiesManager::ScheduleUpdateCacheOnUI; 41 using HttpServerPropertiesManager::ScheduleUpdateCacheOnPref;
40 using HttpServerPropertiesManager::ScheduleUpdatePrefsOnIO; 42 using HttpServerPropertiesManager::ScheduleUpdatePrefsOnIO;
41 43
42 // Post tasks without a delay during tests. 44 // Post tasks without a delay during tests.
43 virtual void StartPrefsUpdateTimerOnIO(base::TimeDelta delay) OVERRIDE { 45 virtual void StartPrefsUpdateTimerOnIO(base::TimeDelta delay) OVERRIDE {
44 HttpServerPropertiesManager::StartPrefsUpdateTimerOnIO( 46 HttpServerPropertiesManager::StartPrefsUpdateTimerOnIO(base::TimeDelta());
45 base::TimeDelta());
46 } 47 }
47 48
48 void UpdateCacheFromPrefsOnUIConcrete() { 49 void UpdateCacheFromPrefsOnUIConcrete() {
49 HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI(); 50 HttpServerPropertiesManager::UpdateCacheFromPrefsOnPref();
50 } 51 }
51 52
52 // Post tasks without a delay during tests. 53 // Post tasks without a delay during tests.
53 virtual void StartCacheUpdateTimerOnUI(base::TimeDelta delay) OVERRIDE { 54 virtual void StartCacheUpdateTimerOnPref(base::TimeDelta delay) OVERRIDE {
54 HttpServerPropertiesManager::StartCacheUpdateTimerOnUI( 55 HttpServerPropertiesManager::StartCacheUpdateTimerOnPref(base::TimeDelta());
55 base::TimeDelta());
56 } 56 }
57 57
58 void UpdatePrefsFromCacheOnIOConcrete(const base::Closure& callback) { 58 void UpdatePrefsFromCacheOnIOConcrete(const base::Closure& callback) {
59 HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO(callback); 59 HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO(callback);
60 } 60 }
61 61
62 MOCK_METHOD0(UpdateCacheFromPrefsOnUI, void()); 62 MOCK_METHOD0(UpdateCacheFromPrefsOnPref, void());
63 MOCK_METHOD1(UpdatePrefsFromCacheOnIO, void(const base::Closure&)); 63 MOCK_METHOD1(UpdatePrefsFromCacheOnIO, void(const base::Closure&));
64 MOCK_METHOD5(UpdateCacheFromPrefsOnIO, 64 MOCK_METHOD5(UpdateCacheFromPrefsOnIO,
65 void(std::vector<std::string>* spdy_servers, 65 void(std::vector<std::string>* spdy_servers,
66 net::SpdySettingsMap* spdy_settings_map, 66 net::SpdySettingsMap* spdy_settings_map,
67 net::AlternateProtocolMap* alternate_protocol_map, 67 net::AlternateProtocolMap* alternate_protocol_map,
68 net::AlternateProtocolExperiment experiment, 68 net::AlternateProtocolExperiment experiment,
69 bool detected_corrupted_prefs)); 69 bool detected_corrupted_prefs));
70 MOCK_METHOD3(UpdatePrefsOnUI, 70 MOCK_METHOD3(UpdatePrefsOnPref,
71 void(base::ListValue* spdy_server_list, 71 void(base::ListValue* spdy_server_list,
72 net::SpdySettingsMap* spdy_settings_map, 72 net::SpdySettingsMap* spdy_settings_map,
73 net::AlternateProtocolMap* alternate_protocol_map)); 73 net::AlternateProtocolMap* alternate_protocol_map));
74 74
75 private: 75 private:
76 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); 76 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager);
77 }; 77 };
78 78
79 class HttpServerPropertiesManagerTest : public testing::Test { 79 class HttpServerPropertiesManagerTest : public testing::Test {
80 protected: 80 protected:
81 HttpServerPropertiesManagerTest() 81 HttpServerPropertiesManagerTest() {}
82 : ui_thread_(BrowserThread::UI, &loop_),
83 io_thread_(BrowserThread::IO, &loop_) {
84 }
85 82
86 virtual void SetUp() OVERRIDE { 83 virtual void SetUp() OVERRIDE {
87 pref_service_.registry()->RegisterDictionaryPref( 84 pref_service_.registry()->RegisterDictionaryPref(kTestHttpServerProperties);
88 prefs::kHttpServerProperties);
89 http_server_props_manager_.reset( 85 http_server_props_manager_.reset(
90 new StrictMock<TestingHttpServerPropertiesManager>(&pref_service_)); 86 new StrictMock<TestingHttpServerPropertiesManager>(
87 &pref_service_,
88 kTestHttpServerProperties,
89 base::MessageLoop::current()->message_loop_proxy()));
91 ExpectCacheUpdate(); 90 ExpectCacheUpdate();
92 loop_.RunUntilIdle(); 91 base::MessageLoop::current()->RunUntilIdle();
93 } 92 }
94 93
95 virtual void TearDown() OVERRIDE { 94 virtual void TearDown() OVERRIDE {
96 if (http_server_props_manager_.get()) 95 if (http_server_props_manager_.get())
97 http_server_props_manager_->ShutdownOnUIThread(); 96 http_server_props_manager_->ShutdownOnPrefThread();
98 loop_.RunUntilIdle(); 97 base::MessageLoop::current()->RunUntilIdle();
99 // Delete |http_server_props_manager_| while |io_thread_| is mapping IO to
100 // |loop_|.
101 http_server_props_manager_.reset(); 98 http_server_props_manager_.reset();
102 } 99 }
103 100
104 void ExpectCacheUpdate() { 101 void ExpectCacheUpdate() {
105 EXPECT_CALL(*http_server_props_manager_, UpdateCacheFromPrefsOnUI()) 102 EXPECT_CALL(*http_server_props_manager_, UpdateCacheFromPrefsOnPref())
106 .WillOnce( 103 .WillOnce(Invoke(http_server_props_manager_.get(),
107 Invoke(http_server_props_manager_.get(), 104 &TestingHttpServerPropertiesManager::
108 &TestingHttpServerPropertiesManager:: 105 UpdateCacheFromPrefsOnUIConcrete));
109 UpdateCacheFromPrefsOnUIConcrete));
110 } 106 }
111 107
112 void ExpectPrefsUpdate() { 108 void ExpectPrefsUpdate() {
113 EXPECT_CALL(*http_server_props_manager_, UpdatePrefsFromCacheOnIO(_)) 109 EXPECT_CALL(*http_server_props_manager_, UpdatePrefsFromCacheOnIO(_))
114 .WillOnce( 110 .WillOnce(Invoke(http_server_props_manager_.get(),
115 Invoke(http_server_props_manager_.get(), 111 &TestingHttpServerPropertiesManager::
116 &TestingHttpServerPropertiesManager:: 112 UpdatePrefsFromCacheOnIOConcrete));
117 UpdatePrefsFromCacheOnIOConcrete));
118 } 113 }
119 114
120 void ExpectPrefsUpdateRepeatedly() { 115 void ExpectPrefsUpdateRepeatedly() {
121 EXPECT_CALL(*http_server_props_manager_, UpdatePrefsFromCacheOnIO(_)) 116 EXPECT_CALL(*http_server_props_manager_, UpdatePrefsFromCacheOnIO(_))
122 .WillRepeatedly( 117 .WillRepeatedly(Invoke(http_server_props_manager_.get(),
123 Invoke(http_server_props_manager_.get(), 118 &TestingHttpServerPropertiesManager::
124 &TestingHttpServerPropertiesManager:: 119 UpdatePrefsFromCacheOnIOConcrete));
125 UpdatePrefsFromCacheOnIOConcrete));
126 } 120 }
127 121
128 base::MessageLoop loop_;
129 TestingPrefServiceSimple pref_service_; 122 TestingPrefServiceSimple pref_service_;
130 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_; 123 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_;
131 124
132 private: 125 private:
133 content::TestBrowserThread ui_thread_;
134 content::TestBrowserThread io_thread_;
135
136 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); 126 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest);
137 }; 127 };
138 128
139 TEST_F(HttpServerPropertiesManagerTest, 129 TEST_F(HttpServerPropertiesManagerTest,
140 SingleUpdateForTwoSpdyServerPrefChanges) { 130 SingleUpdateForTwoSpdyServerPrefChanges) {
141 ExpectCacheUpdate(); 131 ExpectCacheUpdate();
142 132
143 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set 133 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set
144 // it twice. Only expect a single cache update. 134 // it twice. Only expect a single cache update.
145 135
146 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 136 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
147 137
148 // Set supports_spdy for www.google.com:80. 138 // Set supports_spdy for www.google.com:80.
149 server_pref_dict->SetBoolean("supports_spdy", true); 139 server_pref_dict->SetBoolean("supports_spdy", true);
150 140
151 // Set up alternate_protocol for www.google.com:80. 141 // Set up alternate_protocol for www.google.com:80.
152 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; 142 base::DictionaryValue* alternate_protocol = new base::DictionaryValue;
153 alternate_protocol->SetInteger("port", 443); 143 alternate_protocol->SetInteger("port", 443);
154 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); 144 alternate_protocol->SetString("protocol_str", "npn-spdy/3");
155 server_pref_dict->SetWithoutPathExpansion( 145 server_pref_dict->SetWithoutPathExpansion("alternate_protocol",
156 "alternate_protocol", alternate_protocol); 146 alternate_protocol);
157 147
158 // Set the server preference for www.google.com:80. 148 // Set the server preference for www.google.com:80.
159 base::DictionaryValue* servers_dict = new base::DictionaryValue; 149 base::DictionaryValue* servers_dict = new base::DictionaryValue;
160 servers_dict->SetWithoutPathExpansion( 150 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict);
161 "www.google.com:80", server_pref_dict);
162 151
163 // Set the preference for mail.google.com server. 152 // Set the preference for mail.google.com server.
164 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; 153 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue;
165 154
166 // Set supports_spdy for mail.google.com:80 155 // Set supports_spdy for mail.google.com:80
167 server_pref_dict1->SetBoolean("supports_spdy", true); 156 server_pref_dict1->SetBoolean("supports_spdy", true);
168 157
169 // Set up alternate_protocol for mail.google.com:80 158 // Set up alternate_protocol for mail.google.com:80
170 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; 159 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue;
171 alternate_protocol1->SetInteger("port", 444); 160 alternate_protocol1->SetInteger("port", 444);
172 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1"); 161 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1");
173 162
174 server_pref_dict1->SetWithoutPathExpansion( 163 server_pref_dict1->SetWithoutPathExpansion("alternate_protocol",
175 "alternate_protocol", alternate_protocol1); 164 alternate_protocol1);
176 165
177 // Set the server preference for mail.google.com:80. 166 // Set the server preference for mail.google.com:80.
178 servers_dict->SetWithoutPathExpansion( 167 servers_dict->SetWithoutPathExpansion("mail.google.com:80",
179 "mail.google.com:80", server_pref_dict1); 168 server_pref_dict1);
180 169
181 base::DictionaryValue* http_server_properties_dict = 170 base::DictionaryValue* http_server_properties_dict =
182 new base::DictionaryValue; 171 new base::DictionaryValue;
183 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); 172 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1);
184 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); 173 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict);
185 174
186 // Set the same value for kHttpServerProperties multiple times. 175 // Set the same value for kHttpServerProperties multiple times.
187 pref_service_.SetManagedPref(prefs::kHttpServerProperties, 176 pref_service_.SetManagedPref(kTestHttpServerProperties,
188 http_server_properties_dict); 177 http_server_properties_dict);
189 base::DictionaryValue* http_server_properties_dict2 = 178 base::DictionaryValue* http_server_properties_dict2 =
190 http_server_properties_dict->DeepCopy(); 179 http_server_properties_dict->DeepCopy();
191 pref_service_.SetManagedPref(prefs::kHttpServerProperties, 180 pref_service_.SetManagedPref(kTestHttpServerProperties,
192 http_server_properties_dict2); 181 http_server_properties_dict2);
193 182
194 loop_.RunUntilIdle(); 183 base::MessageLoop::current()->RunUntilIdle();
195 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 184 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
196 185
197 // Verify SupportsSpdy. 186 // Verify SupportsSpdy.
198 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy( 187 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(
199 net::HostPortPair::FromString("www.google.com:80"))); 188 net::HostPortPair::FromString("www.google.com:80")));
200 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy( 189 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(
201 net::HostPortPair::FromString("mail.google.com:80"))); 190 net::HostPortPair::FromString("mail.google.com:80")));
202 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( 191 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(
203 net::HostPortPair::FromString("foo.google.com:1337"))); 192 net::HostPortPair::FromString("foo.google.com:1337")));
204 193
205 // Verify AlternateProtocol. 194 // Verify AlternateProtocol.
206 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( 195 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(
207 net::HostPortPair::FromString("www.google.com:80"))); 196 net::HostPortPair::FromString("www.google.com:80")));
208 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( 197 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(
209 net::HostPortPair::FromString("mail.google.com:80"))); 198 net::HostPortPair::FromString("mail.google.com:80")));
210 net::PortAlternateProtocolPair port_alternate_protocol = 199 net::PortAlternateProtocolPair port_alternate_protocol =
211 http_server_props_manager_->GetAlternateProtocol( 200 http_server_props_manager_->GetAlternateProtocol(
212 net::HostPortPair::FromString("www.google.com:80")); 201 net::HostPortPair::FromString("www.google.com:80"));
213 EXPECT_EQ(443, port_alternate_protocol.port); 202 EXPECT_EQ(443, port_alternate_protocol.port);
214 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); 203 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol);
215 port_alternate_protocol = 204 port_alternate_protocol = http_server_props_manager_->GetAlternateProtocol(
216 http_server_props_manager_->GetAlternateProtocol( 205 net::HostPortPair::FromString("mail.google.com:80"));
217 net::HostPortPair::FromString("mail.google.com:80"));
218 EXPECT_EQ(444, port_alternate_protocol.port); 206 EXPECT_EQ(444, port_alternate_protocol.port);
219 EXPECT_EQ(net::NPN_SPDY_3_1, port_alternate_protocol.protocol); 207 EXPECT_EQ(net::NPN_SPDY_3_1, port_alternate_protocol.protocol);
220 } 208 }
221 209
222 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { 210 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) {
223 ExpectPrefsUpdate(); 211 ExpectPrefsUpdate();
224 212
225 // Post an update task to the IO thread. SetSupportsSpdy calls 213 // Post an update task to the IO thread. SetSupportsSpdy calls
226 // ScheduleUpdatePrefsOnIO. 214 // ScheduleUpdatePrefsOnIO.
227 215
228 // Add mail.google.com:443 as a supporting spdy server. 216 // Add mail.google.com:443 as a supporting spdy server.
229 net::HostPortPair spdy_server_mail("mail.google.com", 443); 217 net::HostPortPair spdy_server_mail("mail.google.com", 443);
230 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); 218 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail));
231 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); 219 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true);
232 220
233 // Run the task. 221 // Run the task.
234 loop_.RunUntilIdle(); 222 base::MessageLoop::current()->RunUntilIdle();
235 223
236 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); 224 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail));
237 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 225 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
238 } 226 }
239 227
240 TEST_F(HttpServerPropertiesManagerTest, SetSpdySetting) { 228 TEST_F(HttpServerPropertiesManagerTest, SetSpdySetting) {
241 ExpectPrefsUpdate(); 229 ExpectPrefsUpdate();
242 230
243 // Add SpdySetting for mail.google.com:443. 231 // Add SpdySetting for mail.google.com:443.
244 net::HostPortPair spdy_server_mail("mail.google.com", 443); 232 net::HostPortPair spdy_server_mail("mail.google.com", 443);
245 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH; 233 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH;
246 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST; 234 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST;
247 const uint32 value1 = 31337; 235 const uint32 value1 = 31337;
248 http_server_props_manager_->SetSpdySetting( 236 http_server_props_manager_->SetSpdySetting(
249 spdy_server_mail, id1, flags1, value1); 237 spdy_server_mail, id1, flags1, value1);
250 238
251 // Run the task. 239 // Run the task.
252 loop_.RunUntilIdle(); 240 base::MessageLoop::current()->RunUntilIdle();
253 241
254 const net::SettingsMap& settings_map1_ret = 242 const net::SettingsMap& settings_map1_ret =
255 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 243 http_server_props_manager_->GetSpdySettings(spdy_server_mail);
256 ASSERT_EQ(1U, settings_map1_ret.size()); 244 ASSERT_EQ(1U, settings_map1_ret.size());
257 net::SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); 245 net::SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1);
258 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); 246 EXPECT_TRUE(it1_ret != settings_map1_ret.end());
259 net::SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; 247 net::SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second;
260 EXPECT_EQ(net::SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); 248 EXPECT_EQ(net::SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first);
261 EXPECT_EQ(value1, flags_and_value1_ret.second); 249 EXPECT_EQ(value1, flags_and_value1_ret.second);
262 250
263 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 251 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
264 } 252 }
265 253
266 TEST_F(HttpServerPropertiesManagerTest, ClearSpdySetting) { 254 TEST_F(HttpServerPropertiesManagerTest, ClearSpdySetting) {
267 ExpectPrefsUpdateRepeatedly(); 255 ExpectPrefsUpdateRepeatedly();
268 256
269 // Add SpdySetting for mail.google.com:443. 257 // Add SpdySetting for mail.google.com:443.
270 net::HostPortPair spdy_server_mail("mail.google.com", 443); 258 net::HostPortPair spdy_server_mail("mail.google.com", 443);
271 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH; 259 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH;
272 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST; 260 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST;
273 const uint32 value1 = 31337; 261 const uint32 value1 = 31337;
274 http_server_props_manager_->SetSpdySetting( 262 http_server_props_manager_->SetSpdySetting(
275 spdy_server_mail, id1, flags1, value1); 263 spdy_server_mail, id1, flags1, value1);
276 264
277 // Run the task. 265 // Run the task.
278 loop_.RunUntilIdle(); 266 base::MessageLoop::current()->RunUntilIdle();
279 267
280 const net::SettingsMap& settings_map1_ret = 268 const net::SettingsMap& settings_map1_ret =
281 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 269 http_server_props_manager_->GetSpdySettings(spdy_server_mail);
282 ASSERT_EQ(1U, settings_map1_ret.size()); 270 ASSERT_EQ(1U, settings_map1_ret.size());
283 net::SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); 271 net::SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1);
284 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); 272 EXPECT_TRUE(it1_ret != settings_map1_ret.end());
285 net::SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; 273 net::SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second;
286 EXPECT_EQ(net::SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); 274 EXPECT_EQ(net::SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first);
287 EXPECT_EQ(value1, flags_and_value1_ret.second); 275 EXPECT_EQ(value1, flags_and_value1_ret.second);
288 276
289 // Clear SpdySetting for mail.google.com:443. 277 // Clear SpdySetting for mail.google.com:443.
290 http_server_props_manager_->ClearSpdySettings(spdy_server_mail); 278 http_server_props_manager_->ClearSpdySettings(spdy_server_mail);
291 279
292 // Run the task. 280 // Run the task.
293 loop_.RunUntilIdle(); 281 base::MessageLoop::current()->RunUntilIdle();
Ryan Sleevi 2014/07/08 18:19:27 These tests should be using RunLoop
mef 2014/07/09 12:12:04 Could you elaborate? Switching to RunLoop causes
Bernhard Bauer 2014/07/09 12:24:43 RunLoop is the prefered interface for running a me
mef 2014/07/09 12:44:50 Done.
294 282
295 // Verify that there are no entries in the settings map for 283 // Verify that there are no entries in the settings map for
296 // mail.google.com:443. 284 // mail.google.com:443.
297 const net::SettingsMap& settings_map2_ret = 285 const net::SettingsMap& settings_map2_ret =
298 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 286 http_server_props_manager_->GetSpdySettings(spdy_server_mail);
299 ASSERT_EQ(0U, settings_map2_ret.size()); 287 ASSERT_EQ(0U, settings_map2_ret.size());
300 288
301 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 289 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
302 } 290 }
303 291
304 TEST_F(HttpServerPropertiesManagerTest, ClearAllSpdySetting) { 292 TEST_F(HttpServerPropertiesManagerTest, ClearAllSpdySetting) {
305 ExpectPrefsUpdateRepeatedly(); 293 ExpectPrefsUpdateRepeatedly();
306 294
307 // Add SpdySetting for mail.google.com:443. 295 // Add SpdySetting for mail.google.com:443.
308 net::HostPortPair spdy_server_mail("mail.google.com", 443); 296 net::HostPortPair spdy_server_mail("mail.google.com", 443);
309 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH; 297 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH;
310 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST; 298 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST;
311 const uint32 value1 = 31337; 299 const uint32 value1 = 31337;
312 http_server_props_manager_->SetSpdySetting( 300 http_server_props_manager_->SetSpdySetting(
313 spdy_server_mail, id1, flags1, value1); 301 spdy_server_mail, id1, flags1, value1);
314 302
315 // Run the task. 303 // Run the task.
316 loop_.RunUntilIdle(); 304 base::MessageLoop::current()->RunUntilIdle();
317 305
318 const net::SettingsMap& settings_map1_ret = 306 const net::SettingsMap& settings_map1_ret =
319 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 307 http_server_props_manager_->GetSpdySettings(spdy_server_mail);
320 ASSERT_EQ(1U, settings_map1_ret.size()); 308 ASSERT_EQ(1U, settings_map1_ret.size());
321 net::SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); 309 net::SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1);
322 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); 310 EXPECT_TRUE(it1_ret != settings_map1_ret.end());
323 net::SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; 311 net::SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second;
324 EXPECT_EQ(net::SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); 312 EXPECT_EQ(net::SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first);
325 EXPECT_EQ(value1, flags_and_value1_ret.second); 313 EXPECT_EQ(value1, flags_and_value1_ret.second);
326 314
327 // Clear All SpdySettings. 315 // Clear All SpdySettings.
328 http_server_props_manager_->ClearAllSpdySettings(); 316 http_server_props_manager_->ClearAllSpdySettings();
329 317
330 // Run the task. 318 // Run the task.
331 loop_.RunUntilIdle(); 319 base::MessageLoop::current()->RunUntilIdle();
332 320
333 // Verify that there are no entries in the settings map. 321 // Verify that there are no entries in the settings map.
334 const net::SpdySettingsMap& spdy_settings_map2_ret = 322 const net::SpdySettingsMap& spdy_settings_map2_ret =
335 http_server_props_manager_->spdy_settings_map(); 323 http_server_props_manager_->spdy_settings_map();
336 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); 324 ASSERT_EQ(0U, spdy_settings_map2_ret.size());
337 325
338 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 326 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
339 } 327 }
340 328
341 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { 329 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) {
342 ExpectPrefsUpdate(); 330 ExpectPrefsUpdate();
343 331
344 net::HostPortPair spdy_server_mail("mail.google.com", 80); 332 net::HostPortPair spdy_server_mail("mail.google.com", 80);
345 EXPECT_FALSE( 333 EXPECT_FALSE(
346 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); 334 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
347 http_server_props_manager_->SetAlternateProtocol( 335 http_server_props_manager_->SetAlternateProtocol(
348 spdy_server_mail, 443, net::NPN_SPDY_3); 336 spdy_server_mail, 443, net::NPN_SPDY_3);
349 337
350 // Run the task. 338 // Run the task.
351 loop_.RunUntilIdle(); 339 base::MessageLoop::current()->RunUntilIdle();
352 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 340 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
353 341
354 ASSERT_TRUE( 342 ASSERT_TRUE(
355 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); 343 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
356 net::PortAlternateProtocolPair port_alternate_protocol = 344 net::PortAlternateProtocolPair port_alternate_protocol =
357 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); 345 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail);
358 EXPECT_EQ(443, port_alternate_protocol.port); 346 EXPECT_EQ(443, port_alternate_protocol.port);
359 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); 347 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol);
360 } 348 }
361 349
362 TEST_F(HttpServerPropertiesManagerTest, Clear) { 350 TEST_F(HttpServerPropertiesManagerTest, Clear) {
363 ExpectPrefsUpdate(); 351 ExpectPrefsUpdate();
364 352
365 net::HostPortPair spdy_server_mail("mail.google.com", 443); 353 net::HostPortPair spdy_server_mail("mail.google.com", 443);
366 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); 354 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true);
367 http_server_props_manager_->SetAlternateProtocol( 355 http_server_props_manager_->SetAlternateProtocol(
368 spdy_server_mail, 443, net::NPN_SPDY_3); 356 spdy_server_mail, 443, net::NPN_SPDY_3);
369 357
370 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH; 358 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH;
371 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST; 359 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST;
372 const uint32 value1 = 31337; 360 const uint32 value1 = 31337;
373 http_server_props_manager_->SetSpdySetting( 361 http_server_props_manager_->SetSpdySetting(
374 spdy_server_mail, id1, flags1, value1); 362 spdy_server_mail, id1, flags1, value1);
375 363
376 // Run the task. 364 // Run the task.
377 loop_.RunUntilIdle(); 365 base::MessageLoop::current()->RunUntilIdle();
378 366
379 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); 367 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail));
380 EXPECT_TRUE( 368 EXPECT_TRUE(
381 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); 369 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
382 370
383 // Check SPDY settings values. 371 // Check SPDY settings values.
384 const net::SettingsMap& settings_map1_ret = 372 const net::SettingsMap& settings_map1_ret =
385 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 373 http_server_props_manager_->GetSpdySettings(spdy_server_mail);
386 ASSERT_EQ(1U, settings_map1_ret.size()); 374 ASSERT_EQ(1U, settings_map1_ret.size());
387 net::SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); 375 net::SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1);
388 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); 376 EXPECT_TRUE(it1_ret != settings_map1_ret.end());
389 net::SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; 377 net::SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second;
390 EXPECT_EQ(net::SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); 378 EXPECT_EQ(net::SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first);
391 EXPECT_EQ(value1, flags_and_value1_ret.second); 379 EXPECT_EQ(value1, flags_and_value1_ret.second);
392 380
393 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 381 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
394 382
395 ExpectPrefsUpdate(); 383 ExpectPrefsUpdate();
396 384
397 // Clear http server data, time out if we do not get a completion callback. 385 // Clear http server data, time out if we do not get a completion callback.
398 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); 386 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure());
399 loop_.Run(); 387 base::MessageLoop::current()->Run();
400 388
401 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); 389 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail));
402 EXPECT_FALSE( 390 EXPECT_FALSE(
403 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); 391 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
404 392
405 const net::SettingsMap& settings_map2_ret = 393 const net::SettingsMap& settings_map2_ret =
406 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 394 http_server_props_manager_->GetSpdySettings(spdy_server_mail);
407 EXPECT_EQ(0U, settings_map2_ret.size()); 395 EXPECT_EQ(0U, settings_map2_ret.size());
408 396
409 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 397 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
410 } 398 }
411 399
412 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { 400 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) {
413 // Post an update task to the UI thread. 401 // Post an update task to the UI thread.
414 http_server_props_manager_->ScheduleUpdateCacheOnUI(); 402 http_server_props_manager_->ScheduleUpdateCacheOnPref();
415 // Shutdown comes before the task is executed. 403 // Shutdown comes before the task is executed.
416 http_server_props_manager_->ShutdownOnUIThread(); 404 http_server_props_manager_->ShutdownOnPrefThread();
417 http_server_props_manager_.reset(); 405 http_server_props_manager_.reset();
418 // Run the task after shutdown and deletion. 406 // Run the task after shutdown and deletion.
419 loop_.RunUntilIdle(); 407 base::MessageLoop::current()->RunUntilIdle();
420 } 408 }
421 409
422 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache1) { 410 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache1) {
423 // Post an update task. 411 // Post an update task.
424 http_server_props_manager_->ScheduleUpdateCacheOnUI(); 412 http_server_props_manager_->ScheduleUpdateCacheOnPref();
425 // Shutdown comes before the task is executed. 413 // Shutdown comes before the task is executed.
426 http_server_props_manager_->ShutdownOnUIThread(); 414 http_server_props_manager_->ShutdownOnPrefThread();
427 // Run the task after shutdown, but before deletion. 415 // Run the task after shutdown, but before deletion.
428 loop_.RunUntilIdle(); 416 base::MessageLoop::current()->RunUntilIdle();
429 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 417 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
430 http_server_props_manager_.reset(); 418 http_server_props_manager_.reset();
431 loop_.RunUntilIdle(); 419 base::MessageLoop::current()->RunUntilIdle();
432 } 420 }
433 421
434 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache2) { 422 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache2) {
435 http_server_props_manager_->UpdateCacheFromPrefsOnUIConcrete(); 423 http_server_props_manager_->UpdateCacheFromPrefsOnUIConcrete();
436 // Shutdown comes before the task is executed. 424 // Shutdown comes before the task is executed.
437 http_server_props_manager_->ShutdownOnUIThread(); 425 http_server_props_manager_->ShutdownOnPrefThread();
438 // Run the task after shutdown, but before deletion. 426 // Run the task after shutdown, but before deletion.
439 loop_.RunUntilIdle(); 427 base::MessageLoop::current()->RunUntilIdle();
440 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 428 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
441 http_server_props_manager_.reset(); 429 http_server_props_manager_.reset();
442 loop_.RunUntilIdle(); 430 base::MessageLoop::current()->RunUntilIdle();
443 } 431 }
444 432
445 // 433 //
446 // Tests for shutdown when updating prefs. 434 // Tests for shutdown when updating prefs.
447 // 435 //
448 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs0) { 436 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs0) {
449 // Post an update task to the IO thread. 437 // Post an update task to the IO thread.
450 http_server_props_manager_->ScheduleUpdatePrefsOnIO(); 438 http_server_props_manager_->ScheduleUpdatePrefsOnIO();
451 // Shutdown comes before the task is executed. 439 // Shutdown comes before the task is executed.
452 http_server_props_manager_->ShutdownOnUIThread(); 440 http_server_props_manager_->ShutdownOnPrefThread();
453 http_server_props_manager_.reset(); 441 http_server_props_manager_.reset();
454 // Run the task after shutdown and deletion. 442 // Run the task after shutdown and deletion.
455 loop_.RunUntilIdle(); 443 base::MessageLoop::current()->RunUntilIdle();
456 } 444 }
457 445
458 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs1) { 446 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs1) {
459 ExpectPrefsUpdate(); 447 ExpectPrefsUpdate();
460 // Post an update task. 448 // Post an update task.
461 http_server_props_manager_->ScheduleUpdatePrefsOnIO(); 449 http_server_props_manager_->ScheduleUpdatePrefsOnIO();
462 // Shutdown comes before the task is executed. 450 // Shutdown comes before the task is executed.
463 http_server_props_manager_->ShutdownOnUIThread(); 451 http_server_props_manager_->ShutdownOnPrefThread();
464 // Run the task after shutdown, but before deletion. 452 // Run the task after shutdown, but before deletion.
465 loop_.RunUntilIdle(); 453 base::MessageLoop::current()->RunUntilIdle();
466 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 454 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
467 http_server_props_manager_.reset(); 455 http_server_props_manager_.reset();
468 loop_.RunUntilIdle(); 456 base::MessageLoop::current()->RunUntilIdle();
469 } 457 }
470 458
471 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs2) { 459 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs2) {
472 // This posts a task to the UI thread. 460 // This posts a task to the UI thread.
473 http_server_props_manager_->UpdatePrefsFromCacheOnIOConcrete(base::Closure()); 461 http_server_props_manager_->UpdatePrefsFromCacheOnIOConcrete(base::Closure());
474 // Shutdown comes before the task is executed. 462 // Shutdown comes before the task is executed.
475 http_server_props_manager_->ShutdownOnUIThread(); 463 http_server_props_manager_->ShutdownOnPrefThread();
476 // Run the task after shutdown, but before deletion. 464 // Run the task after shutdown, but before deletion.
477 loop_.RunUntilIdle(); 465 base::MessageLoop::current()->RunUntilIdle();
478 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 466 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
479 http_server_props_manager_.reset(); 467 http_server_props_manager_.reset();
480 loop_.RunUntilIdle(); 468 base::MessageLoop::current()->RunUntilIdle();
481 } 469 }
482 470
483 } // namespace 471 } // namespace
484 472
485 } // namespace chrome_browser_net 473 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698