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

Side by Side Diff: components/google/core/browser/google_url_tracker_unittest.cc

Issue 263023002: Force usage of HTTPS for Google services. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add test Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « components/google/core/browser/google_url_tracker.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "components/google/core/browser/google_url_tracker.h" 5 #include "components/google/core/browser/google_url_tracker.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 base::MessageLoop::current()->RunUntilIdle(); 200 base::MessageLoop::current()->RunUntilIdle();
201 } 201 }
202 202
203 // Tests ---------------------------------------------------------------------- 203 // Tests ----------------------------------------------------------------------
204 204
205 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { 205 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) {
206 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 206 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
207 FinishSleep(); 207 FinishSleep();
208 // No one called RequestServerCheck() so nothing should have happened. 208 // No one called RequestServerCheck() so nothing should have happened.
209 EXPECT_FALSE(GetFetcher()); 209 EXPECT_FALSE(GetFetcher());
210 MockSearchDomainCheckResponse("http://www.google.co.uk/"); 210 MockSearchDomainCheckResponse(".google.co.uk");
211 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 211 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
212 EXPECT_FALSE(listener_notified()); 212 EXPECT_FALSE(listener_notified());
213 } 213 }
214 214
215 TEST_F(GoogleURLTrackerTest, Update) { 215 TEST_F(GoogleURLTrackerTest, Update) {
216 RequestServerCheck(); 216 RequestServerCheck();
217 EXPECT_FALSE(GetFetcher()); 217 EXPECT_FALSE(GetFetcher());
218 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 218 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
219 EXPECT_FALSE(listener_notified()); 219 EXPECT_FALSE(listener_notified());
220 220
221 FinishSleep(); 221 FinishSleep();
222 MockSearchDomainCheckResponse("http://www.google.co.uk/"); 222 MockSearchDomainCheckResponse(".google.co.uk");
223 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); 223 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url());
224 EXPECT_TRUE(listener_notified()); 224 EXPECT_TRUE(listener_notified());
225 } 225 }
226 226
227 TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { 227 TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) {
228 GURL original_google_url("http://www.google.co.uk/"); 228 GURL original_google_url("https://www.google.co.uk/");
229 set_google_url(original_google_url); 229 set_google_url(original_google_url);
230 230
231 RequestServerCheck(); 231 RequestServerCheck();
232 EXPECT_FALSE(GetFetcher()); 232 EXPECT_FALSE(GetFetcher());
233 EXPECT_EQ(original_google_url, google_url()); 233 EXPECT_EQ(original_google_url, google_url());
234 EXPECT_FALSE(listener_notified()); 234 EXPECT_FALSE(listener_notified());
235 235
236 FinishSleep(); 236 FinishSleep();
237 MockSearchDomainCheckResponse(original_google_url.spec()); 237 MockSearchDomainCheckResponse(".google.co.uk");
238 EXPECT_EQ(original_google_url, google_url()); 238 EXPECT_EQ(original_google_url, google_url());
239 // No one should be notified, because the new URL matches the old. 239 // No one should be notified, because the new URL matches the old.
240 EXPECT_FALSE(listener_notified()); 240 EXPECT_FALSE(listener_notified());
241 } 241 }
242 242
243 TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) { 243 TEST_F(GoogleURLTrackerTest, DontUpdateOnBadReplies) {
244 GURL original_google_url("http://www.google.co.uk/"); 244 GURL original_google_url("https://www.google.co.uk/");
245 set_google_url(original_google_url); 245 set_google_url(original_google_url);
246 246
247 RequestServerCheck(); 247 RequestServerCheck();
248 EXPECT_FALSE(GetFetcher()); 248 EXPECT_FALSE(GetFetcher());
249 EXPECT_EQ(original_google_url, google_url()); 249 EXPECT_EQ(original_google_url, google_url());
250 EXPECT_FALSE(listener_notified()); 250 EXPECT_FALSE(listener_notified());
251 251
252 // Old-style domain string. 252 // Old-style URL string.
253 FinishSleep(); 253 FinishSleep();
254 MockSearchDomainCheckResponse(".google.co.in"); 254 MockSearchDomainCheckResponse("https://www.google.com/");
255 EXPECT_EQ(original_google_url, google_url()); 255 EXPECT_EQ(original_google_url, google_url());
256 EXPECT_FALSE(listener_notified()); 256 EXPECT_FALSE(listener_notified());
257 257
258 // Bad subdomain. 258 // Not a Google domain.
259 FinishSleep();
260 MockSearchDomainCheckResponse(".google.evil.com");
261 EXPECT_EQ(original_google_url, google_url());
262 EXPECT_FALSE(listener_notified());
263
264 // Doesn't start with .google.
259 NotifyNetworkChanged(); 265 NotifyNetworkChanged();
260 MockSearchDomainCheckResponse("http://mail.google.com/"); 266 MockSearchDomainCheckResponse(".mail.google.com");
261 EXPECT_EQ(original_google_url, google_url()); 267 EXPECT_EQ(original_google_url, google_url());
262 EXPECT_FALSE(listener_notified()); 268 EXPECT_FALSE(listener_notified());
263 269
264 // Non-empty path. 270 // Non-empty path.
265 NotifyNetworkChanged(); 271 NotifyNetworkChanged();
266 MockSearchDomainCheckResponse("http://www.google.com/search"); 272 MockSearchDomainCheckResponse(".google.com/search");
267 EXPECT_EQ(original_google_url, google_url()); 273 EXPECT_EQ(original_google_url, google_url());
268 EXPECT_FALSE(listener_notified()); 274 EXPECT_FALSE(listener_notified());
269 275
270 // Non-empty query. 276 // Non-empty query.
271 NotifyNetworkChanged(); 277 NotifyNetworkChanged();
272 MockSearchDomainCheckResponse("http://www.google.com/?q=foo"); 278 MockSearchDomainCheckResponse(".google.com/?q=foo");
273 EXPECT_EQ(original_google_url, google_url()); 279 EXPECT_EQ(original_google_url, google_url());
274 EXPECT_FALSE(listener_notified()); 280 EXPECT_FALSE(listener_notified());
275 281
276 // Non-empty ref. 282 // Non-empty ref.
277 NotifyNetworkChanged(); 283 NotifyNetworkChanged();
278 MockSearchDomainCheckResponse("http://www.google.com/#anchor"); 284 MockSearchDomainCheckResponse(".google.com/#anchor");
279 EXPECT_EQ(original_google_url, google_url()); 285 EXPECT_EQ(original_google_url, google_url());
280 EXPECT_FALSE(listener_notified()); 286 EXPECT_FALSE(listener_notified());
281 287
282 // Complete garbage. 288 // Complete garbage.
283 NotifyNetworkChanged(); 289 NotifyNetworkChanged();
284 MockSearchDomainCheckResponse("HJ)*qF)_*&@f1"); 290 MockSearchDomainCheckResponse("HJ)*qF)_*&@f1");
285 EXPECT_EQ(original_google_url, google_url()); 291 EXPECT_EQ(original_google_url, google_url());
286 EXPECT_FALSE(listener_notified()); 292 EXPECT_FALSE(listener_notified());
287 } 293 }
288 294
289 TEST_F(GoogleURLTrackerTest, RefetchOnNetworkChange) { 295 TEST_F(GoogleURLTrackerTest, RefetchOnNetworkChange) {
290 RequestServerCheck(); 296 RequestServerCheck();
291 FinishSleep(); 297 FinishSleep();
292 MockSearchDomainCheckResponse("http://www.google.co.uk/"); 298 MockSearchDomainCheckResponse(".google.co.uk");
293 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); 299 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url());
294 EXPECT_TRUE(listener_notified()); 300 EXPECT_TRUE(listener_notified());
295 clear_listener_notified(); 301 clear_listener_notified();
296 302
297 NotifyNetworkChanged(); 303 NotifyNetworkChanged();
298 MockSearchDomainCheckResponse("http://www.google.co.in/"); 304 MockSearchDomainCheckResponse(".google.co.in");
299 EXPECT_EQ(GURL("http://www.google.co.in/"), google_url()); 305 EXPECT_EQ(GURL("https://www.google.co.in/"), google_url());
300 EXPECT_TRUE(listener_notified()); 306 EXPECT_TRUE(listener_notified());
301 } 307 }
302 308
303 TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { 309 TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) {
304 FinishSleep(); 310 FinishSleep();
305 NotifyNetworkChanged(); 311 NotifyNetworkChanged();
306 // No one called RequestServerCheck() so nothing should have happened. 312 // No one called RequestServerCheck() so nothing should have happened.
307 EXPECT_FALSE(GetFetcher()); 313 EXPECT_FALSE(GetFetcher());
308 MockSearchDomainCheckResponse("http://www.google.co.uk/"); 314 MockSearchDomainCheckResponse(".google.co.uk");
309 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 315 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
310 EXPECT_FALSE(listener_notified()); 316 EXPECT_FALSE(listener_notified());
311 } 317 }
312 318
313 TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { 319 TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) {
314 FinishSleep(); 320 FinishSleep();
315 NotifyNetworkChanged(); 321 NotifyNetworkChanged();
316 MockSearchDomainCheckResponse("http://www.google.co.jp/"); 322 MockSearchDomainCheckResponse(".google.co.jp");
317 323
318 RequestServerCheck(); 324 RequestServerCheck();
319 // The first request for a check should trigger a fetch if it hasn't happened 325 // The first request for a check should trigger a fetch if it hasn't happened
320 // already. 326 // already.
321 MockSearchDomainCheckResponse("http://www.google.co.uk/"); 327 MockSearchDomainCheckResponse(".google.co.uk");
322 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); 328 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url());
323 EXPECT_TRUE(listener_notified()); 329 EXPECT_TRUE(listener_notified());
324 } 330 }
325 331
326 TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) { 332 TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) {
327 FinishSleep(); 333 FinishSleep();
328 NotifyNetworkChanged(); 334 NotifyNetworkChanged();
329 MockSearchDomainCheckResponse("http://www.google.co.jp/"); 335 MockSearchDomainCheckResponse(".google.co.jp");
330 336
331 RequestServerCheck(); 337 RequestServerCheck();
332 // The first request for a check should trigger a fetch if it hasn't happened 338 // The first request for a check should trigger a fetch if it hasn't happened
333 // already. 339 // already.
334 MockSearchDomainCheckResponse("http://www.google.co.uk/"); 340 MockSearchDomainCheckResponse(".google.co.uk");
335 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); 341 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url());
336 EXPECT_TRUE(listener_notified()); 342 EXPECT_TRUE(listener_notified());
337 clear_listener_notified(); 343 clear_listener_notified();
338 344
339 RequestServerCheck(); 345 RequestServerCheck();
340 // The second request should be ignored. 346 // The second request should be ignored.
341 EXPECT_FALSE(GetFetcher()); 347 EXPECT_FALSE(GetFetcher());
342 MockSearchDomainCheckResponse("http://www.google.co.in/"); 348 MockSearchDomainCheckResponse(".google.co.in");
343 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); 349 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url());
344 EXPECT_FALSE(listener_notified()); 350 EXPECT_FALSE(listener_notified());
345 } 351 }
OLDNEW
« no previous file with comments | « components/google/core/browser/google_url_tracker.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698