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

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

Issue 8253002: Move PageTransition into content namespace. While I'm touching all these files, I've also updated... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 5
6 #include "chrome/browser/prefs/pref_service.h" 6 #include "chrome/browser/prefs/pref_service.h"
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/safe_browsing/malware_details.h" 8 #include "chrome/browser/safe_browsing/malware_details.h"
9 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" 9 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
10 #include "chrome/common/pref_names.h" 10 #include "chrome/common/pref_names.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 96 }
97 virtual void OnBlockingPageComplete(bool proceed) { 97 virtual void OnBlockingPageComplete(bool proceed) {
98 if (proceed) 98 if (proceed)
99 user_response_ = OK; 99 user_response_ = OK;
100 else 100 else
101 user_response_ = CANCEL; 101 user_response_ = CANCEL;
102 } 102 }
103 103
104 void Navigate(const char* url, int page_id) { 104 void Navigate(const char* url, int page_id) {
105 ViewHostMsg_FrameNavigate_Params params; 105 ViewHostMsg_FrameNavigate_Params params;
106 InitNavigateParams(&params, page_id, GURL(url), PageTransition::TYPED); 106 InitNavigateParams(
107 &params, page_id, GURL(url), content::PAGE_TRANSITION_TYPED);
107 contents()->TestDidNavigate(contents()->render_view_host(), params); 108 contents()->TestDidNavigate(contents()->render_view_host(), params);
108 } 109 }
109 110
110 void GoBackCrossSite() { 111 void GoBackCrossSite() {
111 NavigationEntry* entry = contents()->controller().GetEntryAtOffset(-1); 112 NavigationEntry* entry = contents()->controller().GetEntryAtOffset(-1);
112 ASSERT_TRUE(entry); 113 ASSERT_TRUE(entry);
113 contents()->controller().GoBack(); 114 contents()->controller().GoBack();
114 115
115 // The navigation should commit in the pending RVH. 116 // The navigation should commit in the pending RVH.
116 ViewHostMsg_FrameNavigate_Params params; 117 ViewHostMsg_FrameNavigate_Params params;
117 InitNavigateParams(&params, entry->page_id(), GURL(entry->url()), 118 InitNavigateParams(&params, entry->page_id(), GURL(entry->url()),
118 PageTransition::TYPED); 119 content::PAGE_TRANSITION_TYPED);
119 contents()->TestDidNavigate(contents()->pending_rvh(), params); 120 contents()->TestDidNavigate(contents()->pending_rvh(), params);
120 } 121 }
121 122
122 void ShowInterstitial(bool is_subresource, const char* url) { 123 void ShowInterstitial(bool is_subresource, const char* url) {
123 SafeBrowsingService::UnsafeResource resource; 124 SafeBrowsingService::UnsafeResource resource;
124 InitResource(&resource, is_subresource, GURL(url)); 125 InitResource(&resource, is_subresource, GURL(url));
125 SafeBrowsingBlockingPage::ShowBlockingPage(service_, resource); 126 SafeBrowsingBlockingPage::ShowBlockingPage(service_, resource);
126 } 127 }
127 128
128 // Returns the SafeBrowsingBlockingPage currently showing or NULL if none is 129 // Returns the SafeBrowsingBlockingPage currently showing or NULL if none is
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 BrowserThread io_thread_; 173 BrowserThread io_thread_;
173 }; 174 };
174 175
175 // Tests showing a blocking page for a malware page and not proceeding. 176 // Tests showing a blocking page for a malware page and not proceeding.
176 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageDontProceed) { 177 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageDontProceed) {
177 // Enable malware details. 178 // Enable malware details.
178 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); 179 Profile* profile = Profile::FromBrowserContext(contents()->browser_context());
179 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); 180 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true);
180 181
181 // Start a load. 182 // Start a load.
182 controller().LoadURL(GURL(kBadURL), GURL(), PageTransition::TYPED, 183 controller().LoadURL(GURL(kBadURL), GURL(), content::PAGE_TRANSITION_TYPED,
183 std::string()); 184 std::string());
184 185
185 186
186 // Simulate the load causing a safe browsing interstitial to be shown. 187 // Simulate the load causing a safe browsing interstitial to be shown.
187 ShowInterstitial(false, kBadURL); 188 ShowInterstitial(false, kBadURL);
188 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 189 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
189 ASSERT_TRUE(sb_interstitial); 190 ASSERT_TRUE(sb_interstitial);
190 191
191 MessageLoop::current()->RunAllPending(); 192 MessageLoop::current()->RunAllPending();
192 193
(...skipping 12 matching lines...) Expand all
205 service_->GetDetails()->clear(); 206 service_->GetDetails()->clear();
206 } 207 }
207 208
208 // Tests showing a blocking page for a malware page and then proceeding. 209 // Tests showing a blocking page for a malware page and then proceeding.
209 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageProceed) { 210 TEST_F(SafeBrowsingBlockingPageTest, MalwarePageProceed) {
210 // Enable malware reports. 211 // Enable malware reports.
211 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); 212 Profile* profile = Profile::FromBrowserContext(contents()->browser_context());
212 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); 213 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true);
213 214
214 // Start a load. 215 // Start a load.
215 controller().LoadURL(GURL(kBadURL), GURL(), PageTransition::TYPED, 216 controller().LoadURL(GURL(kBadURL), GURL(), content::PAGE_TRANSITION_TYPED,
216 std::string()); 217 std::string());
217 218
218 // Simulate the load causing a safe browsing interstitial to be shown. 219 // Simulate the load causing a safe browsing interstitial to be shown.
219 ShowInterstitial(false, kBadURL); 220 ShowInterstitial(false, kBadURL);
220 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 221 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
221 ASSERT_TRUE(sb_interstitial); 222 ASSERT_TRUE(sb_interstitial);
222 223
223 // Simulate the user clicking "proceed". 224 // Simulate the user clicking "proceed".
224 ProceedThroughInterstitial(sb_interstitial); 225 ProceedThroughInterstitial(sb_interstitial);
225 226
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 // controller entries are OK. http://crbug.com/17627 451 // controller entries are OK. http://crbug.com/17627
451 TEST_F(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) { 452 TEST_F(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) {
452 // Enable malware reports. 453 // Enable malware reports.
453 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); 454 Profile* profile = Profile::FromBrowserContext(contents()->browser_context());
454 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); 455 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true);
455 456
456 // Navigate somewhere. 457 // Navigate somewhere.
457 Navigate(kGoodURL, 1); 458 Navigate(kGoodURL, 1);
458 459
459 // Now navigate to a bad page triggerring an interstitial. 460 // Now navigate to a bad page triggerring an interstitial.
460 controller().LoadURL(GURL(kBadURL), GURL(), PageTransition::TYPED, 461 controller().LoadURL(GURL(kBadURL), GURL(), content::PAGE_TRANSITION_TYPED,
461 std::string()); 462 std::string());
462 ShowInterstitial(false, kBadURL); 463 ShowInterstitial(false, kBadURL);
463 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 464 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
464 ASSERT_TRUE(sb_interstitial); 465 ASSERT_TRUE(sb_interstitial);
465 466
466 // Proceed, then navigate back. 467 // Proceed, then navigate back.
467 ProceedThroughInterstitial(sb_interstitial); 468 ProceedThroughInterstitial(sb_interstitial);
468 Navigate(kBadURL, 2); // Commit the navigation. 469 Navigate(kBadURL, 2); // Commit the navigation.
469 GoBackCrossSite(); 470 GoBackCrossSite();
470 471
(...skipping 23 matching lines...) Expand all
494 } 495 }
495 496
496 // Tests that calling "don't proceed" after "proceed" has been called doesn't 497 // Tests that calling "don't proceed" after "proceed" has been called doesn't
497 // cause problems. http://crbug.com/30079 498 // cause problems. http://crbug.com/30079
498 TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) { 499 TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) {
499 // Enable malware reports. 500 // Enable malware reports.
500 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); 501 Profile* profile = Profile::FromBrowserContext(contents()->browser_context());
501 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true); 502 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true);
502 503
503 // Start a load. 504 // Start a load.
504 controller().LoadURL(GURL(kBadURL), GURL(), PageTransition::TYPED, 505 controller().LoadURL(GURL(kBadURL), GURL(), content::PAGE_TRANSITION_TYPED,
505 std::string()); 506 std::string());
506 507
507 // Simulate the load causing a safe browsing interstitial to be shown. 508 // Simulate the load causing a safe browsing interstitial to be shown.
508 ShowInterstitial(false, kBadURL); 509 ShowInterstitial(false, kBadURL);
509 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 510 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
510 ASSERT_TRUE(sb_interstitial); 511 ASSERT_TRUE(sb_interstitial);
511 512
512 MessageLoop::current()->RunAllPending(); 513 MessageLoop::current()->RunAllPending();
513 514
514 // Simulate the user clicking "proceed" then "don't proceed" (before the 515 // Simulate the user clicking "proceed" then "don't proceed" (before the
(...skipping 13 matching lines...) Expand all
528 service_->GetDetails()->clear(); 529 service_->GetDetails()->clear();
529 } 530 }
530 531
531 // Tests showing a blocking page for a malware page with reports disabled. 532 // Tests showing a blocking page for a malware page with reports disabled.
532 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) { 533 TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) {
533 // Disable malware reports. 534 // Disable malware reports.
534 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); 535 Profile* profile = Profile::FromBrowserContext(contents()->browser_context());
535 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false); 536 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false);
536 537
537 // Start a load. 538 // Start a load.
538 controller().LoadURL(GURL(kBadURL), GURL(), PageTransition::TYPED, 539 controller().LoadURL(GURL(kBadURL), GURL(), content::PAGE_TRANSITION_TYPED,
539 std::string()); 540 std::string());
540 541
541 // Simulate the load causing a safe browsing interstitial to be shown. 542 // Simulate the load causing a safe browsing interstitial to be shown.
542 ShowInterstitial(false, kBadURL); 543 ShowInterstitial(false, kBadURL);
543 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 544 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
544 ASSERT_TRUE(sb_interstitial); 545 ASSERT_TRUE(sb_interstitial);
545 546
546 MessageLoop::current()->RunAllPending(); 547 MessageLoop::current()->RunAllPending();
547 548
548 // Simulate the user clicking "don't proceed". 549 // Simulate the user clicking "don't proceed".
(...skipping 11 matching lines...) Expand all
560 service_->GetDetails()->clear(); 561 service_->GetDetails()->clear();
561 } 562 }
562 563
563 // Test setting the malware report preferance 564 // Test setting the malware report preferance
564 TEST_F(SafeBrowsingBlockingPageTest, MalwareReports) { 565 TEST_F(SafeBrowsingBlockingPageTest, MalwareReports) {
565 // Disable malware reports. 566 // Disable malware reports.
566 Profile* profile = Profile::FromBrowserContext(contents()->browser_context()); 567 Profile* profile = Profile::FromBrowserContext(contents()->browser_context());
567 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false); 568 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false);
568 569
569 // Start a load. 570 // Start a load.
570 controller().LoadURL(GURL(kBadURL), GURL(), PageTransition::TYPED, 571 controller().LoadURL(GURL(kBadURL), GURL(), content::PAGE_TRANSITION_TYPED,
571 std::string()); 572 std::string());
572 573
573 // Simulate the load causing a safe browsing interstitial to be shown. 574 // Simulate the load causing a safe browsing interstitial to be shown.
574 ShowInterstitial(false, kBadURL); 575 ShowInterstitial(false, kBadURL);
575 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage(); 576 SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
576 ASSERT_TRUE(sb_interstitial); 577 ASSERT_TRUE(sb_interstitial);
577 578
578 MessageLoop::current()->RunAllPending(); 579 MessageLoop::current()->RunAllPending();
579 580
580 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( 581 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(
581 prefs::kSafeBrowsingReportingEnabled)); 582 prefs::kSafeBrowsingReportingEnabled));
582 583
583 // Simulate the user check the report agreement checkbox. 584 // Simulate the user check the report agreement checkbox.
584 sb_interstitial->SetReportingPreference(true); 585 sb_interstitial->SetReportingPreference(true);
585 586
586 EXPECT_TRUE(profile->GetPrefs()->GetBoolean( 587 EXPECT_TRUE(profile->GetPrefs()->GetBoolean(
587 prefs::kSafeBrowsingReportingEnabled)); 588 prefs::kSafeBrowsingReportingEnabled));
588 589
589 // Simulate the user uncheck the report agreement checkbox. 590 // Simulate the user uncheck the report agreement checkbox.
590 sb_interstitial->SetReportingPreference(false); 591 sb_interstitial->SetReportingPreference(false);
591 592
592 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( 593 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(
593 prefs::kSafeBrowsingReportingEnabled)); 594 prefs::kSafeBrowsingReportingEnabled));
594 } 595 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_blocking_page.cc ('k') | chrome/browser/search_engines/template_url_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698