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

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

Issue 9706012: Add abstractions that let embedders drive tests of WebContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove CONTENT_EXPORT on statically linked functions. Merge to head for commit. Created 8 years, 9 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) 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 "chrome/browser/prefs/pref_service.h" 5 #include "chrome/browser/prefs/pref_service.h"
6 #include "chrome/browser/profiles/profile.h" 6 #include "chrome/browser/profiles/profile.h"
7 #include "chrome/browser/safe_browsing/malware_details.h" 7 #include "chrome/browser/safe_browsing/malware_details.h"
8 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" 8 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
9 #include "chrome/common/pref_names.h" 9 #include "chrome/common/pref_names.h"
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
11 #include "content/browser/tab_contents/test_tab_contents.h"
12 #include "content/public/browser/interstitial_page.h" 11 #include "content/public/browser/interstitial_page.h"
13 #include "content/public/browser/navigation_entry.h" 12 #include "content/public/browser/navigation_entry.h"
13 #include "content/public/browser/render_process_host.h"
14 #include "content/public/browser/web_contents.h"
15 #include "content/public/browser/web_contents_view.h"
14 #include "content/test/test_browser_thread.h" 16 #include "content/test/test_browser_thread.h"
17 #include "content/test/web_contents_tester.h"
15 18
16 using content::BrowserThread; 19 using content::BrowserThread;
17 using content::InterstitialPage; 20 using content::InterstitialPage;
18 using content::NavigationEntry; 21 using content::NavigationEntry;
19 using content::WebContents; 22 using content::WebContents;
23 using content::WebContentsTester;
20 using content::WebContentsView; 24 using content::WebContentsView;
21 25
22 static const char* kGoogleURL = "http://www.google.com/"; 26 static const char* kGoogleURL = "http://www.google.com/";
23 static const char* kGoodURL = "http://www.goodguys.com/"; 27 static const char* kGoodURL = "http://www.goodguys.com/";
24 static const char* kBadURL = "http://www.badguys.com/"; 28 static const char* kBadURL = "http://www.badguys.com/";
25 static const char* kBadURL2 = "http://www.badguys2.com/"; 29 static const char* kBadURL2 = "http://www.badguys2.com/";
26 static const char* kBadURL3 = "http://www.badguys3.com/"; 30 static const char* kBadURL3 = "http://www.badguys3.com/";
27 31
28 // A SafeBrowingBlockingPage class that does not create windows. 32 // A SafeBrowingBlockingPage class that does not create windows.
29 class TestSafeBrowsingBlockingPage : public SafeBrowsingBlockingPage { 33 class TestSafeBrowsingBlockingPage : public SafeBrowsingBlockingPage {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 107 }
104 108
105 void OnBlockingPageComplete(bool proceed) { 109 void OnBlockingPageComplete(bool proceed) {
106 if (proceed) 110 if (proceed)
107 user_response_ = OK; 111 user_response_ = OK;
108 else 112 else
109 user_response_ = CANCEL; 113 user_response_ = CANCEL;
110 } 114 }
111 115
112 void Navigate(const char* url, int page_id) { 116 void Navigate(const char* url, int page_id) {
113 contents()->TestDidNavigate( 117 WebContentsTester::For(contents())->TestDidNavigate(
114 contents()->GetRenderViewHost(), page_id, GURL(url), 118 contents()->GetRenderViewHost(), page_id, GURL(url),
115 content::PAGE_TRANSITION_TYPED); 119 content::PAGE_TRANSITION_TYPED);
116 } 120 }
117 121
118 void GoBack(bool is_cross_site) { 122 void GoBack(bool is_cross_site) {
119 NavigationEntry* entry = contents()->GetController().GetEntryAtOffset(-1); 123 NavigationEntry* entry = contents()->GetController().GetEntryAtOffset(-1);
120 ASSERT_TRUE(entry); 124 ASSERT_TRUE(entry);
121 contents()->GetController().GoBack(); 125 contents()->GetController().GoBack();
122 126
123 // The pending RVH should commit for cross-site navigations. 127 // The pending RVH should commit for cross-site navigations.
124 content::RenderViewHost* rvh = is_cross_site ? 128 content::RenderViewHost* rvh = is_cross_site ?
125 contents()->pending_rvh() : 129 WebContentsTester::For(contents())->pending_rvh() :
126 contents()->GetRenderViewHost(); 130 contents()->GetRenderViewHost();
127 contents()->TestDidNavigate(rvh, entry->GetPageID(), GURL(entry->GetURL()), 131 WebContentsTester::For(contents())->TestDidNavigate(
128 content::PAGE_TRANSITION_TYPED); 132 rvh,
133 entry->GetPageID(),
134 GURL(entry->GetURL()),
135 content::PAGE_TRANSITION_TYPED);
129 } 136 }
130 137
131 void ShowInterstitial(bool is_subresource, const char* url) { 138 void ShowInterstitial(bool is_subresource, const char* url) {
132 SafeBrowsingService::UnsafeResource resource; 139 SafeBrowsingService::UnsafeResource resource;
133 InitResource(&resource, is_subresource, GURL(url)); 140 InitResource(&resource, is_subresource, GURL(url));
134 SafeBrowsingBlockingPage::ShowBlockingPage(service_, resource); 141 SafeBrowsingBlockingPage::ShowBlockingPage(service_, resource);
135 } 142 }
136 143
137 // Returns the SafeBrowsingBlockingPage currently showing or NULL if none is 144 // Returns the SafeBrowsingBlockingPage currently showing or NULL if none is
138 // showing. 145 // showing.
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 626
620 EXPECT_TRUE(profile->GetPrefs()->GetBoolean( 627 EXPECT_TRUE(profile->GetPrefs()->GetBoolean(
621 prefs::kSafeBrowsingReportingEnabled)); 628 prefs::kSafeBrowsingReportingEnabled));
622 629
623 // Simulate the user uncheck the report agreement checkbox. 630 // Simulate the user uncheck the report agreement checkbox.
624 sb_interstitial->SetReportingPreference(false); 631 sb_interstitial->SetReportingPreference(false);
625 632
626 EXPECT_FALSE(profile->GetPrefs()->GetBoolean( 633 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(
627 prefs::kSafeBrowsingReportingEnabled)); 634 prefs::kSafeBrowsingReportingEnabled));
628 } 635 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/malware_details_unittest.cc ('k') | chrome/browser/sessions/tab_restore_service_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698