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

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

Powered by Google App Engine
This is Rietveld 408576698