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

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

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

Powered by Google App Engine
This is Rietveld 408576698