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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc

Issue 1136553005: Revert of Classify navigations without page id in parallel to the existing classifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 <list> 5 #include <list>
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/safe_browsing/malware_details.h" 10 #include "chrome/browser/safe_browsing/malware_details.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 ChromeRenderViewHostTestHarness::TearDown(); 113 ChromeRenderViewHostTestHarness::TearDown();
114 } 114 }
115 115
116 void OnBlockingPageComplete(bool proceed) { 116 void OnBlockingPageComplete(bool proceed) {
117 if (proceed) 117 if (proceed)
118 user_response_ = OK; 118 user_response_ = OK;
119 else 119 else
120 user_response_ = CANCEL; 120 user_response_ = CANCEL;
121 } 121 }
122 122
123 void Navigate(const char* url, 123 void Navigate(const char* url, int page_id) {
124 int page_id, 124 WebContentsTester::For(web_contents())->TestDidNavigate(
125 int nav_entry_id, 125 web_contents()->GetMainFrame(), page_id, GURL(url),
126 bool did_create_new_entry) { 126 ui::PAGE_TRANSITION_TYPED);
127 NavigateInternal(url, page_id, nav_entry_id, did_create_new_entry, false);
128 }
129
130 void NavigateCrossSite(const char* url,
131 int page_id,
132 int nav_entry_id,
133 bool did_create_new_entry) {
134 NavigateInternal(url, page_id, nav_entry_id, did_create_new_entry, true);
135 }
136
137 void NavigateInternal(const char* url,
138 int page_id,
139 int nav_entry_id,
140 bool did_create_new_entry,
141 bool is_cross_site) {
142 // The pending RVH should commit for cross-site navigations.
143 content::RenderFrameHost* render_frame_host =
144 is_cross_site
145 ? content::WebContentsTester::For(web_contents())
146 ->GetPendingMainFrame()
147 : web_contents()->GetMainFrame();
148
149 content::WebContentsTester::For(web_contents())
150 ->TestDidNavigate(render_frame_host, page_id, nav_entry_id,
151 did_create_new_entry, GURL(url),
152 ui::PAGE_TRANSITION_TYPED);
153 } 127 }
154 128
155 void GoBack(bool is_cross_site) { 129 void GoBack(bool is_cross_site) {
156 NavigationEntry* entry = 130 NavigationEntry* entry =
157 web_contents()->GetController().GetEntryAtOffset(-1); 131 web_contents()->GetController().GetEntryAtOffset(-1);
158 ASSERT_TRUE(entry); 132 ASSERT_TRUE(entry);
159 web_contents()->GetController().GoBack(); 133 web_contents()->GetController().GoBack();
160 134
161 // The pending RVH should commit for cross-site navigations. 135 // The pending RVH should commit for cross-site navigations.
162 content::RenderFrameHost* rfh = is_cross_site ? 136 content::RenderFrameHost* rfh = is_cross_site ?
163 WebContentsTester::For(web_contents())->GetPendingMainFrame() : 137 WebContentsTester::For(web_contents())->GetPendingMainFrame() :
164 web_contents()->GetMainFrame(); 138 web_contents()->GetMainFrame();
165 WebContentsTester::For(web_contents())->TestDidNavigate( 139 WebContentsTester::For(web_contents())->TestDidNavigate(
166 rfh, 140 rfh,
167 entry->GetPageID(), 141 entry->GetPageID(),
168 entry->GetUniqueID(), 142 GURL(entry->GetURL()),
169 false,
170 entry->GetURL(),
171 ui::PAGE_TRANSITION_TYPED); 143 ui::PAGE_TRANSITION_TYPED);
172 } 144 }
173 145
174 void ShowInterstitial(bool is_subresource, const char* url) { 146 void ShowInterstitial(bool is_subresource, const char* url) {
175 SafeBrowsingUIManager::UnsafeResource resource; 147 SafeBrowsingUIManager::UnsafeResource resource;
176 InitResource(&resource, is_subresource, GURL(url)); 148 InitResource(&resource, is_subresource, GURL(url));
177 SafeBrowsingBlockingPage::ShowBlockingPage(ui_manager_.get(), resource); 149 SafeBrowsingBlockingPage::ShowBlockingPage(ui_manager_.get(), resource);
178 } 150 }
179 151
180 // Returns the SafeBrowsingBlockingPage currently showing or NULL if none is 152 // Returns the SafeBrowsingBlockingPage currently showing or NULL if none is
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 profile->GetPrefs()->SetBoolean( 217 profile->GetPrefs()->SetBoolean(
246 prefs::kSafeBrowsingExtendedReportingEnabled, true); 218 prefs::kSafeBrowsingExtendedReportingEnabled, true);
247 219
248 // Start a load. 220 // Start a load.
249 controller().LoadURL(GURL(kBadURL), content::Referrer(), 221 controller().LoadURL(GURL(kBadURL), content::Referrer(),
250 ui::PAGE_TRANSITION_TYPED, std::string()); 222 ui::PAGE_TRANSITION_TYPED, std::string());
251 223
252 224
253 // Simulate the load causing a safe browsing interstitial to be shown. 225 // Simulate the load causing a safe browsing interstitial to be shown.
254 ShowInterstitial(false, kBadURL); 226 ShowInterstitial(false, kBadURL);
255 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 227 SafeBrowsingBlockingPage* sb_interstitial =
228 GetSafeBrowsingBlockingPage();
256 ASSERT_TRUE(sb_interstitial); 229 ASSERT_TRUE(sb_interstitial);
257 230
258 base::RunLoop().RunUntilIdle(); 231 base::RunLoop().RunUntilIdle();
259 232
260 // Simulate the user clicking "don't proceed". 233 // Simulate the user clicking "don't proceed".
261 DontProceedThroughInterstitial(sb_interstitial); 234 DontProceedThroughInterstitial(sb_interstitial);
262 235
263 // The interstitial should be gone. 236 // The interstitial should be gone.
264 EXPECT_EQ(CANCEL, user_response()); 237 EXPECT_EQ(CANCEL, user_response());
265 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 238 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
(...skipping 10 matching lines...) Expand all
276 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageProceed) { 249 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageProceed) {
277 // Enable malware reports. 250 // Enable malware reports.
278 Profile* profile = Profile::FromBrowserContext( 251 Profile* profile = Profile::FromBrowserContext(
279 web_contents()->GetBrowserContext()); 252 web_contents()->GetBrowserContext());
280 profile->GetPrefs()->SetBoolean( 253 profile->GetPrefs()->SetBoolean(
281 prefs::kSafeBrowsingExtendedReportingEnabled, true); 254 prefs::kSafeBrowsingExtendedReportingEnabled, true);
282 255
283 // Start a load. 256 // Start a load.
284 controller().LoadURL(GURL(kBadURL), content::Referrer(), 257 controller().LoadURL(GURL(kBadURL), content::Referrer(),
285 ui::PAGE_TRANSITION_TYPED, std::string()); 258 ui::PAGE_TRANSITION_TYPED, std::string());
286 int pending_id = controller().GetPendingEntry()->GetUniqueID();
287 259
288 // Simulate the load causing a safe browsing interstitial to be shown. 260 // Simulate the load causing a safe browsing interstitial to be shown.
289 ShowInterstitial(false, kBadURL); 261 ShowInterstitial(false, kBadURL);
290 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 262 SafeBrowsingBlockingPage* sb_interstitial =
263 GetSafeBrowsingBlockingPage();
291 ASSERT_TRUE(sb_interstitial); 264 ASSERT_TRUE(sb_interstitial);
292 265
293 // Simulate the user clicking "proceed". 266 // Simulate the user clicking "proceed".
294 ProceedThroughInterstitial(sb_interstitial); 267 ProceedThroughInterstitial(sb_interstitial);
295 268
296 // The interstitial is shown until the navigation commits. 269 // The interstitial is shown until the navigation commits.
297 ASSERT_TRUE(InterstitialPage::GetInterstitialPage(web_contents())); 270 ASSERT_TRUE(InterstitialPage::GetInterstitialPage(web_contents()));
298 // Commit the navigation. 271 // Commit the navigation.
299 Navigate(kBadURL, 1, pending_id, true); 272 Navigate(kBadURL, 1);
300 // The interstitial should be gone now. 273 // The interstitial should be gone now.
301 ASSERT_FALSE(InterstitialPage::GetInterstitialPage(web_contents())); 274 ASSERT_FALSE(InterstitialPage::GetInterstitialPage(web_contents()));
302 275
303 // A report should have been sent. 276 // A report should have been sent.
304 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); 277 EXPECT_EQ(1u, ui_manager_->GetDetails()->size());
305 ui_manager_->GetDetails()->clear(); 278 ui_manager_->GetDetails()->clear();
306 } 279 }
307 280
308 // Tests showing a blocking page for a page that contains malware subresources 281 // Tests showing a blocking page for a page that contains malware subresources
309 // and not proceeding. 282 // and not proceeding.
310 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceDontProceed) { 283 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceDontProceed) {
311 // Enable malware reports. 284 // Enable malware reports.
312 Profile* profile = Profile::FromBrowserContext( 285 Profile* profile = Profile::FromBrowserContext(
313 web_contents()->GetBrowserContext()); 286 web_contents()->GetBrowserContext());
314 profile->GetPrefs()->SetBoolean( 287 profile->GetPrefs()->SetBoolean(
315 prefs::kSafeBrowsingExtendedReportingEnabled, true); 288 prefs::kSafeBrowsingExtendedReportingEnabled, true);
316 289
317 // Navigate somewhere. 290 // Navigate somewhere.
318 Navigate(kGoogleURL, 1, 0, true); 291 Navigate(kGoogleURL, 1);
319 292
320 // Navigate somewhere else. 293 // Navigate somewhere else.
321 Navigate(kGoodURL, 2, 0, true); 294 Navigate(kGoodURL, 2);
322 295
323 // Simulate that page loading a bad-resource triggering an interstitial. 296 // Simulate that page loading a bad-resource triggering an interstitial.
324 ShowInterstitial(true, kBadURL); 297 ShowInterstitial(true, kBadURL);
325 298
326 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 299 SafeBrowsingBlockingPage* sb_interstitial =
300 GetSafeBrowsingBlockingPage();
327 ASSERT_TRUE(sb_interstitial); 301 ASSERT_TRUE(sb_interstitial);
328 302
329 // Simulate the user clicking "don't proceed". 303 // Simulate the user clicking "don't proceed".
330 DontProceedThroughSubresourceInterstitial(sb_interstitial); 304 DontProceedThroughSubresourceInterstitial(sb_interstitial);
331 EXPECT_EQ(CANCEL, user_response()); 305 EXPECT_EQ(CANCEL, user_response());
332 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 306 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
333 307
334 // We did not proceed, we should be back to the first page, the 2nd one should 308 // We did not proceed, we should be back to the first page, the 2nd one should
335 // have been removed from the navigation controller. 309 // have been removed from the navigation controller.
336 ASSERT_EQ(1, controller().GetEntryCount()); 310 ASSERT_EQ(1, controller().GetEntryCount());
337 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec()); 311 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec());
338 312
339 // A report should have been sent. 313 // A report should have been sent.
340 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); 314 EXPECT_EQ(1u, ui_manager_->GetDetails()->size());
341 ui_manager_->GetDetails()->clear(); 315 ui_manager_->GetDetails()->clear();
342 } 316 }
343 317
344 // Tests showing a blocking page for a page that contains malware subresources 318 // Tests showing a blocking page for a page that contains malware subresources
345 // and proceeding. 319 // and proceeding.
346 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceProceed) { 320 TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceProceed) {
347 // Enable malware reports. 321 // Enable malware reports.
348 Profile* profile = Profile::FromBrowserContext( 322 Profile* profile = Profile::FromBrowserContext(
349 web_contents()->GetBrowserContext()); 323 web_contents()->GetBrowserContext());
350 profile->GetPrefs()->SetBoolean( 324 profile->GetPrefs()->SetBoolean(
351 prefs::kSafeBrowsingExtendedReportingEnabled, true); 325 prefs::kSafeBrowsingExtendedReportingEnabled, true);
352 326
353 // Navigate somewhere. 327 // Navigate somewhere.
354 Navigate(kGoodURL, 1, 0, true); 328 Navigate(kGoodURL, 1);
355 329
356 // Simulate that page loading a bad-resource triggering an interstitial. 330 // Simulate that page loading a bad-resource triggering an interstitial.
357 ShowInterstitial(true, kBadURL); 331 ShowInterstitial(true, kBadURL);
358 332
359 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 333 SafeBrowsingBlockingPage* sb_interstitial =
334 GetSafeBrowsingBlockingPage();
360 ASSERT_TRUE(sb_interstitial); 335 ASSERT_TRUE(sb_interstitial);
361 336
362 // Simulate the user clicking "proceed". 337 // Simulate the user clicking "proceed".
363 ProceedThroughInterstitial(sb_interstitial); 338 ProceedThroughInterstitial(sb_interstitial);
364 EXPECT_EQ(OK, user_response()); 339 EXPECT_EQ(OK, user_response());
365 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 340 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
366 341
367 // We did proceed, we should be back to showing the page. 342 // We did proceed, we should be back to showing the page.
368 ASSERT_EQ(1, controller().GetEntryCount()); 343 ASSERT_EQ(1, controller().GetEntryCount());
369 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->GetURL().spec()); 344 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->GetURL().spec());
370 345
371 // A report should have been sent. 346 // A report should have been sent.
372 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); 347 EXPECT_EQ(1u, ui_manager_->GetDetails()->size());
373 ui_manager_->GetDetails()->clear(); 348 ui_manager_->GetDetails()->clear();
374 } 349 }
375 350
376 // Tests showing a blocking page for a page that contains multiple malware 351 // Tests showing a blocking page for a page that contains multiple malware
377 // subresources and not proceeding. This just tests that the extra malware 352 // subresources and not proceeding. This just tests that the extra malware
378 // subresources (which trigger queued interstitial pages) do not break anything. 353 // subresources (which trigger queued interstitial pages) do not break anything.
379 TEST_F(SafeBrowsingBlockingPageTest, 354 TEST_F(SafeBrowsingBlockingPageTest,
380 PageWithMultipleMalwareResourceDontProceed) { 355 PageWithMultipleMalwareResourceDontProceed) {
381 // Enable malware reports. 356 // Enable malware reports.
382 Profile* profile = Profile::FromBrowserContext( 357 Profile* profile = Profile::FromBrowserContext(
383 web_contents()->GetBrowserContext()); 358 web_contents()->GetBrowserContext());
384 profile->GetPrefs()->SetBoolean( 359 profile->GetPrefs()->SetBoolean(
385 prefs::kSafeBrowsingExtendedReportingEnabled, true); 360 prefs::kSafeBrowsingExtendedReportingEnabled, true);
386 361
387 // Navigate somewhere. 362 // Navigate somewhere.
388 Navigate(kGoogleURL, 1, 0, true); 363 Navigate(kGoogleURL, 1);
389 364
390 // Navigate somewhere else. 365 // Navigate somewhere else.
391 Navigate(kGoodURL, 2, 0, true); 366 Navigate(kGoodURL, 2);
392 367
393 // Simulate that page loading a bad-resource triggering an interstitial. 368 // Simulate that page loading a bad-resource triggering an interstitial.
394 ShowInterstitial(true, kBadURL); 369 ShowInterstitial(true, kBadURL);
395 370
396 // More bad resources loading causing more interstitials. The new 371 // More bad resources loading causing more interstitials. The new
397 // interstitials should be queued. 372 // interstitials should be queued.
398 ShowInterstitial(true, kBadURL2); 373 ShowInterstitial(true, kBadURL2);
399 ShowInterstitial(true, kBadURL3); 374 ShowInterstitial(true, kBadURL3);
400 375
401 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 376 SafeBrowsingBlockingPage* sb_interstitial =
377 GetSafeBrowsingBlockingPage();
402 ASSERT_TRUE(sb_interstitial); 378 ASSERT_TRUE(sb_interstitial);
403 379
404 // Simulate the user clicking "don't proceed". 380 // Simulate the user clicking "don't proceed".
405 DontProceedThroughSubresourceInterstitial(sb_interstitial); 381 DontProceedThroughSubresourceInterstitial(sb_interstitial);
406 EXPECT_EQ(CANCEL, user_response()); 382 EXPECT_EQ(CANCEL, user_response());
407 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 383 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
408 384
409 // We did not proceed, we should be back to the first page, the 2nd one should 385 // We did not proceed, we should be back to the first page, the 2nd one should
410 // have been removed from the navigation controller. 386 // have been removed from the navigation controller.
411 ASSERT_EQ(1, controller().GetEntryCount()); 387 ASSERT_EQ(1, controller().GetEntryCount());
412 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec()); 388 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec());
413 389
414 // A report should have been sent. 390 // A report should have been sent.
415 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); 391 EXPECT_EQ(1u, ui_manager_->GetDetails()->size());
416 ui_manager_->GetDetails()->clear(); 392 ui_manager_->GetDetails()->clear();
417 } 393 }
418 394
419 // Tests showing a blocking page for a page that contains multiple malware 395 // Tests showing a blocking page for a page that contains multiple malware
420 // subresources and proceeding through the first interstitial, but not the next. 396 // subresources and proceeding through the first interstitial, but not the next.
421 TEST_F(SafeBrowsingBlockingPageTest, 397 TEST_F(SafeBrowsingBlockingPageTest,
422 PageWithMultipleMalwareResourceProceedThenDontProceed) { 398 PageWithMultipleMalwareResourceProceedThenDontProceed) {
423 // Enable malware reports. 399 // Enable malware reports.
424 Profile* profile = Profile::FromBrowserContext( 400 Profile* profile = Profile::FromBrowserContext(
425 web_contents()->GetBrowserContext()); 401 web_contents()->GetBrowserContext());
426 profile->GetPrefs()->SetBoolean( 402 profile->GetPrefs()->SetBoolean(
427 prefs::kSafeBrowsingExtendedReportingEnabled, true); 403 prefs::kSafeBrowsingExtendedReportingEnabled, true);
428 404
429 // Navigate somewhere. 405 // Navigate somewhere.
430 Navigate(kGoogleURL, 1, 0, true); 406 Navigate(kGoogleURL, 1);
431 407
432 // Navigate somewhere else. 408 // Navigate somewhere else.
433 Navigate(kGoodURL, 2, 0, true); 409 Navigate(kGoodURL, 2);
434 410
435 // Simulate that page loading a bad-resource triggering an interstitial. 411 // Simulate that page loading a bad-resource triggering an interstitial.
436 ShowInterstitial(true, kBadURL); 412 ShowInterstitial(true, kBadURL);
437 413
438 // More bad resources loading causing more interstitials. The new 414 // More bad resources loading causing more interstitials. The new
439 // interstitials should be queued. 415 // interstitials should be queued.
440 ShowInterstitial(true, kBadURL2); 416 ShowInterstitial(true, kBadURL2);
441 ShowInterstitial(true, kBadURL3); 417 ShowInterstitial(true, kBadURL3);
442 418
443 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 419 SafeBrowsingBlockingPage* sb_interstitial =
420 GetSafeBrowsingBlockingPage();
444 ASSERT_TRUE(sb_interstitial); 421 ASSERT_TRUE(sb_interstitial);
445 422
446 // Proceed through the 1st interstitial. 423 // Proceed through the 1st interstitial.
447 ProceedThroughInterstitial(sb_interstitial); 424 ProceedThroughInterstitial(sb_interstitial);
448 EXPECT_EQ(OK, user_response()); 425 EXPECT_EQ(OK, user_response());
449 426
450 // A report should have been sent. 427 // A report should have been sent.
451 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); 428 EXPECT_EQ(1u, ui_manager_->GetDetails()->size());
452 ui_manager_->GetDetails()->clear(); 429 ui_manager_->GetDetails()->clear();
453 430
(...skipping 15 matching lines...) Expand all
469 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec()); 446 EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec());
470 447
471 // No report should have been sent -- we don't create a report the 448 // No report should have been sent -- we don't create a report the
472 // second time. 449 // second time.
473 EXPECT_EQ(0u, ui_manager_->GetDetails()->size()); 450 EXPECT_EQ(0u, ui_manager_->GetDetails()->size());
474 ui_manager_->GetDetails()->clear(); 451 ui_manager_->GetDetails()->clear();
475 } 452 }
476 453
477 // Tests showing a blocking page for a page that contains multiple malware 454 // Tests showing a blocking page for a page that contains multiple malware
478 // subresources and proceeding through the multiple interstitials. 455 // subresources and proceeding through the multiple interstitials.
479 TEST_F(SafeBrowsingBlockingPageTest, PageWithMultipleMalwareResourceProceed) { 456 TEST_F(SafeBrowsingBlockingPageTest,
457 PageWithMultipleMalwareResourceProceed) {
480 // Enable malware reports. 458 // Enable malware reports.
481 Profile* profile = Profile::FromBrowserContext( 459 Profile* profile = Profile::FromBrowserContext(
482 web_contents()->GetBrowserContext()); 460 web_contents()->GetBrowserContext());
483 profile->GetPrefs()->SetBoolean( 461 profile->GetPrefs()->SetBoolean(
484 prefs::kSafeBrowsingExtendedReportingEnabled, true); 462 prefs::kSafeBrowsingExtendedReportingEnabled, true);
485 463
486 // Navigate somewhere else. 464 // Navigate somewhere else.
487 Navigate(kGoodURL, 1, 0, true); 465 Navigate(kGoodURL, 1);
488 466
489 // Simulate that page loading a bad-resource triggering an interstitial. 467 // Simulate that page loading a bad-resource triggering an interstitial.
490 ShowInterstitial(true, kBadURL); 468 ShowInterstitial(true, kBadURL);
491 469
492 // More bad resources loading causing more interstitials. The new 470 // More bad resources loading causing more interstitials. The new
493 // interstitials should be queued. 471 // interstitials should be queued.
494 ShowInterstitial(true, kBadURL2); 472 ShowInterstitial(true, kBadURL2);
495 ShowInterstitial(true, kBadURL3); 473 ShowInterstitial(true, kBadURL3);
496 474
497 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 475 SafeBrowsingBlockingPage* sb_interstitial =
476 GetSafeBrowsingBlockingPage();
498 ASSERT_TRUE(sb_interstitial); 477 ASSERT_TRUE(sb_interstitial);
499 478
500 // Proceed through the 1st interstitial. 479 // Proceed through the 1st interstitial.
501 ProceedThroughInterstitial(sb_interstitial); 480 ProceedThroughInterstitial(sb_interstitial);
502 EXPECT_EQ(OK, user_response()); 481 EXPECT_EQ(OK, user_response());
503 482
504 // A report should have been sent. 483 // A report should have been sent.
505 EXPECT_EQ(1u, ui_manager_->GetDetails()->size()); 484 EXPECT_EQ(1u, ui_manager_->GetDetails()->size());
506 ui_manager_->GetDetails()->clear(); 485 ui_manager_->GetDetails()->clear();
507 486
(...skipping 21 matching lines...) Expand all
529 // Tests showing a blocking page then navigating back and forth to make sure the 508 // Tests showing a blocking page then navigating back and forth to make sure the
530 // controller entries are OK. http://crbug.com/17627 509 // controller entries are OK. http://crbug.com/17627
531 TEST_F(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) { 510 TEST_F(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) {
532 // Enable malware reports. 511 // Enable malware reports.
533 Profile* profile = Profile::FromBrowserContext( 512 Profile* profile = Profile::FromBrowserContext(
534 web_contents()->GetBrowserContext()); 513 web_contents()->GetBrowserContext());
535 profile->GetPrefs()->SetBoolean( 514 profile->GetPrefs()->SetBoolean(
536 prefs::kSafeBrowsingExtendedReportingEnabled, true); 515 prefs::kSafeBrowsingExtendedReportingEnabled, true);
537 516
538 // Navigate somewhere. 517 // Navigate somewhere.
539 Navigate(kGoodURL, 1, 0, true); 518 Navigate(kGoodURL, 1);
540 519
541 // Now navigate to a bad page triggerring an interstitial. 520 // Now navigate to a bad page triggerring an interstitial.
542 controller().LoadURL(GURL(kBadURL), content::Referrer(), 521 controller().LoadURL(GURL(kBadURL), content::Referrer(),
543 ui::PAGE_TRANSITION_TYPED, std::string()); 522 ui::PAGE_TRANSITION_TYPED, std::string());
544 int pending_id = controller().GetPendingEntry()->GetUniqueID();
545 ShowInterstitial(false, kBadURL); 523 ShowInterstitial(false, kBadURL);
546 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 524 SafeBrowsingBlockingPage* sb_interstitial =
525 GetSafeBrowsingBlockingPage();
547 ASSERT_TRUE(sb_interstitial); 526 ASSERT_TRUE(sb_interstitial);
548 527
549 // Proceed, then navigate back. 528 // Proceed, then navigate back.
550 ProceedThroughInterstitial(sb_interstitial); 529 ProceedThroughInterstitial(sb_interstitial);
551 Navigate(kBadURL, 2, pending_id, true); // Commit the navigation. 530 Navigate(kBadURL, 2); // Commit the navigation.
552 GoBack(true); 531 GoBack(true);
553 532
554 // We are back on the good page. 533 // We are back on the good page.
555 sb_interstitial = GetSafeBrowsingBlockingPage(); 534 sb_interstitial = GetSafeBrowsingBlockingPage();
556 ASSERT_FALSE(sb_interstitial); 535 ASSERT_FALSE(sb_interstitial);
557 ASSERT_EQ(2, controller().GetEntryCount()); 536 ASSERT_EQ(2, controller().GetEntryCount());
558 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->GetURL().spec()); 537 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->GetURL().spec());
559 538
560 // Navigate forward to the malware URL. 539 // Navigate forward to the malware URL.
561 web_contents()->GetController().GoForward(); 540 web_contents()->GetController().GoForward();
562 pending_id = controller().GetPendingEntry()->GetUniqueID();
563 ShowInterstitial(false, kBadURL); 541 ShowInterstitial(false, kBadURL);
564 sb_interstitial = GetSafeBrowsingBlockingPage(); 542 sb_interstitial = GetSafeBrowsingBlockingPage();
565 ASSERT_TRUE(sb_interstitial); 543 ASSERT_TRUE(sb_interstitial);
566 544
567 // Let's proceed and make sure everything is OK (bug 17627). 545 // Let's proceed and make sure everything is OK (bug 17627).
568 ProceedThroughInterstitial(sb_interstitial); 546 ProceedThroughInterstitial(sb_interstitial);
569 // Commit the navigation. 547 Navigate(kBadURL, 2); // Commit the navigation.
570 NavigateCrossSite(kBadURL, 2, pending_id, false);
571 sb_interstitial = GetSafeBrowsingBlockingPage(); 548 sb_interstitial = GetSafeBrowsingBlockingPage();
572 ASSERT_FALSE(sb_interstitial); 549 ASSERT_FALSE(sb_interstitial);
573 ASSERT_EQ(2, controller().GetEntryCount()); 550 ASSERT_EQ(2, controller().GetEntryCount());
574 EXPECT_EQ(kBadURL, controller().GetActiveEntry()->GetURL().spec()); 551 EXPECT_EQ(kBadURL, controller().GetActiveEntry()->GetURL().spec());
575 552
576 // Two reports should have been sent. 553 // Two reports should have been sent.
577 EXPECT_EQ(2u, ui_manager_->GetDetails()->size()); 554 EXPECT_EQ(2u, ui_manager_->GetDetails()->size());
578 ui_manager_->GetDetails()->clear(); 555 ui_manager_->GetDetails()->clear();
579 } 556 }
580 557
581 // Tests that calling "don't proceed" after "proceed" has been called doesn't 558 // Tests that calling "don't proceed" after "proceed" has been called doesn't
582 // cause problems. http://crbug.com/30079 559 // cause problems. http://crbug.com/30079
583 TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { 560 TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) {
584 // Enable malware reports. 561 // Enable malware reports.
585 Profile* profile = Profile::FromBrowserContext( 562 Profile* profile = Profile::FromBrowserContext(
586 web_contents()->GetBrowserContext()); 563 web_contents()->GetBrowserContext());
587 profile->GetPrefs()->SetBoolean( 564 profile->GetPrefs()->SetBoolean(
588 prefs::kSafeBrowsingExtendedReportingEnabled, true); 565 prefs::kSafeBrowsingExtendedReportingEnabled, true);
589 566
590 // Start a load. 567 // Start a load.
591 controller().LoadURL(GURL(kBadURL), content::Referrer(), 568 controller().LoadURL(GURL(kBadURL), content::Referrer(),
592 ui::PAGE_TRANSITION_TYPED, std::string()); 569 ui::PAGE_TRANSITION_TYPED, std::string());
593 570
594 // Simulate the load causing a safe browsing interstitial to be shown. 571 // Simulate the load causing a safe browsing interstitial to be shown.
595 ShowInterstitial(false, kBadURL); 572 ShowInterstitial(false, kBadURL);
596 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 573 SafeBrowsingBlockingPage* sb_interstitial =
574 GetSafeBrowsingBlockingPage();
597 ASSERT_TRUE(sb_interstitial); 575 ASSERT_TRUE(sb_interstitial);
598 576
599 base::RunLoop().RunUntilIdle(); 577 base::RunLoop().RunUntilIdle();
600 578
601 // Simulate the user clicking "proceed" then "don't proceed" (before the 579 // Simulate the user clicking "proceed" then "don't proceed" (before the
602 // interstitial is shown). 580 // interstitial is shown).
603 sb_interstitial->interstitial_page()->Proceed(); 581 sb_interstitial->interstitial_page()->Proceed();
604 sb_interstitial->interstitial_page()->DontProceed(); 582 sb_interstitial->interstitial_page()->DontProceed();
605 // Proceed() and DontProceed() post a task to update the 583 // Proceed() and DontProceed() post a task to update the
606 // SafeBrowsingService::Client. 584 // SafeBrowsingService::Client.
(...skipping 15 matching lines...) Expand all
622 web_contents()->GetBrowserContext()); 600 web_contents()->GetBrowserContext());
623 profile->GetPrefs()->SetBoolean( 601 profile->GetPrefs()->SetBoolean(
624 prefs::kSafeBrowsingExtendedReportingEnabled, false); 602 prefs::kSafeBrowsingExtendedReportingEnabled, false);
625 603
626 // Start a load. 604 // Start a load.
627 controller().LoadURL(GURL(kBadURL), content::Referrer(), 605 controller().LoadURL(GURL(kBadURL), content::Referrer(),
628 ui::PAGE_TRANSITION_TYPED, std::string()); 606 ui::PAGE_TRANSITION_TYPED, std::string());
629 607
630 // Simulate the load causing a safe browsing interstitial to be shown. 608 // Simulate the load causing a safe browsing interstitial to be shown.
631 ShowInterstitial(false, kBadURL); 609 ShowInterstitial(false, kBadURL);
632 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 610 SafeBrowsingBlockingPage* sb_interstitial =
611 GetSafeBrowsingBlockingPage();
633 ASSERT_TRUE(sb_interstitial); 612 ASSERT_TRUE(sb_interstitial);
634 613
635 base::RunLoop().RunUntilIdle(); 614 base::RunLoop().RunUntilIdle();
636 615
637 // Simulate the user clicking "don't proceed". 616 // Simulate the user clicking "don't proceed".
638 DontProceedThroughInterstitial(sb_interstitial); 617 DontProceedThroughInterstitial(sb_interstitial);
639 618
640 // The interstitial should be gone. 619 // The interstitial should be gone.
641 EXPECT_EQ(CANCEL, user_response()); 620 EXPECT_EQ(CANCEL, user_response());
642 EXPECT_FALSE(GetSafeBrowsingBlockingPage()); 621 EXPECT_FALSE(GetSafeBrowsingBlockingPage());
(...skipping 13 matching lines...) Expand all
656 web_contents()->GetBrowserContext()); 635 web_contents()->GetBrowserContext());
657 profile->GetPrefs()->SetBoolean( 636 profile->GetPrefs()->SetBoolean(
658 prefs::kSafeBrowsingExtendedReportingEnabled, false); 637 prefs::kSafeBrowsingExtendedReportingEnabled, false);
659 638
660 // Start a load. 639 // Start a load.
661 controller().LoadURL(GURL(kBadURL), content::Referrer(), 640 controller().LoadURL(GURL(kBadURL), content::Referrer(),
662 ui::PAGE_TRANSITION_TYPED, std::string()); 641 ui::PAGE_TRANSITION_TYPED, std::string());
663 642
664 // Simulate the load causing a safe browsing interstitial to be shown. 643 // Simulate the load causing a safe browsing interstitial to be shown.
665 ShowInterstitial(false, kBadURL); 644 ShowInterstitial(false, kBadURL);
666 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 645 SafeBrowsingBlockingPage* sb_interstitial =
646 GetSafeBrowsingBlockingPage();
667 ASSERT_TRUE(sb_interstitial); 647 ASSERT_TRUE(sb_interstitial);
668 648
669 base::RunLoop().RunUntilIdle(); 649 base::RunLoop().RunUntilIdle();
670 650
671 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( 651 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(
672 prefs::kSafeBrowsingExtendedReportingEnabled)); 652 prefs::kSafeBrowsingExtendedReportingEnabled));
673 653
674 // Simulate the user check the report agreement checkbox. 654 // Simulate the user check the report agreement checkbox.
675 sb_interstitial->SetReportingPreference(true); 655 sb_interstitial->SetReportingPreference(true);
676 656
677 EXPECT_TRUE(profile->GetPrefs()->GetBoolean( 657 EXPECT_TRUE(profile->GetPrefs()->GetBoolean(
678 prefs::kSafeBrowsingExtendedReportingEnabled)); 658 prefs::kSafeBrowsingExtendedReportingEnabled));
679 659
680 // Simulate the user uncheck the report agreement checkbox. 660 // Simulate the user uncheck the report agreement checkbox.
681 sb_interstitial->SetReportingPreference(false); 661 sb_interstitial->SetReportingPreference(false);
682 662
683 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( 663 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(
684 prefs::kSafeBrowsingExtendedReportingEnabled)); 664 prefs::kSafeBrowsingExtendedReportingEnabled));
685 } 665 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698