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

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

Issue 273022: Fixing a bug with interstitial pages triggered with malware.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/renderer_host/test/test_render_view_host.h" 5 #include "chrome/browser/renderer_host/test/test_render_view_host.h"
6 6
7 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" 7 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
8 #include "chrome/browser/tab_contents/navigation_entry.h" 8 #include "chrome/browser/tab_contents/navigation_entry.h"
9 #include "chrome/common/render_messages.h" 9 #include "chrome/common/render_messages.h"
10 10
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 else 95 else
96 user_response_ = CANCEL; 96 user_response_ = CANCEL;
97 } 97 }
98 98
99 void Navigate(const char* url, int page_id) { 99 void Navigate(const char* url, int page_id) {
100 ViewHostMsg_FrameNavigate_Params params; 100 ViewHostMsg_FrameNavigate_Params params;
101 InitNavigateParams(&params, page_id, GURL(url)); 101 InitNavigateParams(&params, page_id, GURL(url));
102 contents()->TestDidNavigate(contents_->render_view_host(), params); 102 contents()->TestDidNavigate(contents_->render_view_host(), params);
103 } 103 }
104 104
105 void GoBack() {
106 NavigationEntry* entry = contents()->controller().GetEntryAtOffset(-1);
107 ASSERT_TRUE(entry);
108 contents()->controller().GoBack();
109 Navigate(entry->url().spec().c_str(), entry->page_id());
110 }
111
105 void ShowInterstitial(ResourceType::Type resource_type, 112 void ShowInterstitial(ResourceType::Type resource_type,
106 const char* url) { 113 const char* url) {
107 SafeBrowsingService::UnsafeResource resource; 114 SafeBrowsingService::UnsafeResource resource;
108 InitResource(&resource, resource_type, GURL(url)); 115 InitResource(&resource, resource_type, GURL(url));
109 SafeBrowsingBlockingPage::ShowBlockingPage(service_, resource); 116 SafeBrowsingBlockingPage::ShowBlockingPage(service_, resource);
110 } 117 }
111 118
112 // Returns the SafeBrowsingBlockingPage currently showing or NULL if none is 119 // Returns the SafeBrowsingBlockingPage currently showing or NULL if none is
113 // showing. 120 // showing.
114 SafeBrowsingBlockingPage* GetSafeBrowsingBlockingPage() { 121 SafeBrowsingBlockingPage* GetSafeBrowsingBlockingPage() {
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 ASSERT_TRUE(sb_interstitial); 355 ASSERT_TRUE(sb_interstitial);
349 356
350 // Proceed through the 2nd interstitial. 357 // Proceed through the 2nd interstitial.
351 ProceedThroughInterstitial(sb_interstitial); 358 ProceedThroughInterstitial(sb_interstitial);
352 EXPECT_EQ(OK, user_response()); 359 EXPECT_EQ(OK, user_response());
353 360
354 // We did proceed, we should be back to the initial page. 361 // We did proceed, we should be back to the initial page.
355 ASSERT_EQ(1, controller().entry_count()); 362 ASSERT_EQ(1, controller().entry_count());
356 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->url().spec()); 363 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->url().spec());
357 } 364 }
365
366 // Tests showing a blocking page then navigating back and forth to make sure the
367 // controller entries are OK. http://crbug.com/17627
368 TEST_F(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) {
369 // Navigate somewhere.
370 Navigate(kGoodURL, 1);
371
372 // Now navigate to a bad page triggerring an interstitial.
373 controller().LoadURL(GURL(kBadURL), GURL(), PageTransition::TYPED);
374 ShowInterstitial(ResourceType::MAIN_FRAME, kBadURL);
375 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
376 ASSERT_TRUE(sb_interstitial);
377
378 // Proceed, then navigate back.
379 ProceedThroughInterstitial(sb_interstitial);
380 Navigate(kBadURL, 2); // Commit the navigation.
381 GoBack();
382
383 // We are back on the good page.
384 sb_interstitial = GetSafeBrowsingBlockingPage();
385 ASSERT_FALSE(sb_interstitial);
386 ASSERT_EQ(2, controller().entry_count());
387 EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->url().spec());
388
389 // Navigate forward to the malware URL.
390 contents()->controller().GoForward();
391 ShowInterstitial(ResourceType::MAIN_FRAME, kBadURL);
392 sb_interstitial = GetSafeBrowsingBlockingPage();
393 ASSERT_TRUE(sb_interstitial);
394
395 // Let's proceed and make sure everything is OK (bug 17627).
396 ProceedThroughInterstitial(sb_interstitial);
397 Navigate(kBadURL, 2); // Commit the navigation.
398 sb_interstitial = GetSafeBrowsingBlockingPage();
399 ASSERT_FALSE(sb_interstitial);
400 ASSERT_EQ(2, controller().entry_count());
401 EXPECT_EQ(kBadURL, controller().GetActiveEntry()->url().spec());
402 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698