summaryrefslogtreecommitdiffstats
path: root/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc')
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc102
1 files changed, 61 insertions, 41 deletions
diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc
index 536953a..cdc185a 100644
--- a/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc
@@ -120,10 +120,36 @@ class SafeBrowsingBlockingPageTest : public ChromeRenderViewHostTestHarness {
user_response_ = CANCEL;
}
- void Navigate(const char* url, int page_id) {
- WebContentsTester::For(web_contents())->TestDidNavigate(
- web_contents()->GetMainFrame(), page_id, GURL(url),
- ui::PAGE_TRANSITION_TYPED);
+ void Navigate(const char* url,
+ int page_id,
+ int nav_entry_id,
+ bool did_create_new_entry) {
+ NavigateInternal(url, page_id, nav_entry_id, did_create_new_entry, false);
+ }
+
+ void NavigateCrossSite(const char* url,
+ int page_id,
+ int nav_entry_id,
+ bool did_create_new_entry) {
+ NavigateInternal(url, page_id, nav_entry_id, did_create_new_entry, true);
+ }
+
+ void NavigateInternal(const char* url,
+ int page_id,
+ int nav_entry_id,
+ bool did_create_new_entry,
+ bool is_cross_site) {
+ // The pending RVH should commit for cross-site navigations.
+ content::RenderFrameHost* render_frame_host =
+ is_cross_site
+ ? content::WebContentsTester::For(web_contents())
+ ->GetPendingMainFrame()
+ : web_contents()->GetMainFrame();
+
+ content::WebContentsTester::For(web_contents())
+ ->TestDidNavigate(render_frame_host, page_id, nav_entry_id,
+ did_create_new_entry, GURL(url),
+ ui::PAGE_TRANSITION_TYPED);
}
void GoBack(bool is_cross_site) {
@@ -139,7 +165,9 @@ class SafeBrowsingBlockingPageTest : public ChromeRenderViewHostTestHarness {
WebContentsTester::For(web_contents())->TestDidNavigate(
rfh,
entry->GetPageID(),
- GURL(entry->GetURL()),
+ entry->GetUniqueID(),
+ false,
+ entry->GetURL(),
ui::PAGE_TRANSITION_TYPED);
}
@@ -224,8 +252,7 @@ TEST_F(SafeBrowsingBlockingPageTest, MalwarePageDontProceed) {
// Simulate the load causing a safe browsing interstitial to be shown.
ShowInterstitial(false, kBadURL);
- SafeBrowsingBlockingPage* sb_interstitial =
- GetSafeBrowsingBlockingPage();
+ SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
ASSERT_TRUE(sb_interstitial);
base::RunLoop().RunUntilIdle();
@@ -256,11 +283,11 @@ TEST_F(SafeBrowsingBlockingPageTest, MalwarePageProceed) {
// Start a load.
controller().LoadURL(GURL(kBadURL), content::Referrer(),
ui::PAGE_TRANSITION_TYPED, std::string());
+ int pending_id = controller().GetPendingEntry()->GetUniqueID();
// Simulate the load causing a safe browsing interstitial to be shown.
ShowInterstitial(false, kBadURL);
- SafeBrowsingBlockingPage* sb_interstitial =
- GetSafeBrowsingBlockingPage();
+ SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
ASSERT_TRUE(sb_interstitial);
// Simulate the user clicking "proceed".
@@ -269,7 +296,7 @@ TEST_F(SafeBrowsingBlockingPageTest, MalwarePageProceed) {
// The interstitial is shown until the navigation commits.
ASSERT_TRUE(InterstitialPage::GetInterstitialPage(web_contents()));
// Commit the navigation.
- Navigate(kBadURL, 1);
+ Navigate(kBadURL, 1, pending_id, true);
// The interstitial should be gone now.
ASSERT_FALSE(InterstitialPage::GetInterstitialPage(web_contents()));
@@ -288,16 +315,15 @@ TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceDontProceed) {
prefs::kSafeBrowsingExtendedReportingEnabled, true);
// Navigate somewhere.
- Navigate(kGoogleURL, 1);
+ Navigate(kGoogleURL, 1, 0, true);
// Navigate somewhere else.
- Navigate(kGoodURL, 2);
+ Navigate(kGoodURL, 2, 0, true);
// Simulate that page loading a bad-resource triggering an interstitial.
ShowInterstitial(true, kBadURL);
- SafeBrowsingBlockingPage* sb_interstitial =
- GetSafeBrowsingBlockingPage();
+ SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
ASSERT_TRUE(sb_interstitial);
// Simulate the user clicking "don't proceed".
@@ -325,13 +351,12 @@ TEST_F(SafeBrowsingBlockingPageTest, PageWithMalwareResourceProceed) {
prefs::kSafeBrowsingExtendedReportingEnabled, true);
// Navigate somewhere.
- Navigate(kGoodURL, 1);
+ Navigate(kGoodURL, 1, 0, true);
// Simulate that page loading a bad-resource triggering an interstitial.
ShowInterstitial(true, kBadURL);
- SafeBrowsingBlockingPage* sb_interstitial =
- GetSafeBrowsingBlockingPage();
+ SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
ASSERT_TRUE(sb_interstitial);
// Simulate the user clicking "proceed".
@@ -360,10 +385,10 @@ TEST_F(SafeBrowsingBlockingPageTest,
prefs::kSafeBrowsingExtendedReportingEnabled, true);
// Navigate somewhere.
- Navigate(kGoogleURL, 1);
+ Navigate(kGoogleURL, 1, 0, true);
// Navigate somewhere else.
- Navigate(kGoodURL, 2);
+ Navigate(kGoodURL, 2, 0, true);
// Simulate that page loading a bad-resource triggering an interstitial.
ShowInterstitial(true, kBadURL);
@@ -373,8 +398,7 @@ TEST_F(SafeBrowsingBlockingPageTest,
ShowInterstitial(true, kBadURL2);
ShowInterstitial(true, kBadURL3);
- SafeBrowsingBlockingPage* sb_interstitial =
- GetSafeBrowsingBlockingPage();
+ SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
ASSERT_TRUE(sb_interstitial);
// Simulate the user clicking "don't proceed".
@@ -403,10 +427,10 @@ TEST_F(SafeBrowsingBlockingPageTest,
prefs::kSafeBrowsingExtendedReportingEnabled, true);
// Navigate somewhere.
- Navigate(kGoogleURL, 1);
+ Navigate(kGoogleURL, 1, 0, true);
// Navigate somewhere else.
- Navigate(kGoodURL, 2);
+ Navigate(kGoodURL, 2, 0, true);
// Simulate that page loading a bad-resource triggering an interstitial.
ShowInterstitial(true, kBadURL);
@@ -416,8 +440,7 @@ TEST_F(SafeBrowsingBlockingPageTest,
ShowInterstitial(true, kBadURL2);
ShowInterstitial(true, kBadURL3);
- SafeBrowsingBlockingPage* sb_interstitial =
- GetSafeBrowsingBlockingPage();
+ SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
ASSERT_TRUE(sb_interstitial);
// Proceed through the 1st interstitial.
@@ -453,8 +476,7 @@ TEST_F(SafeBrowsingBlockingPageTest,
// Tests showing a blocking page for a page that contains multiple malware
// subresources and proceeding through the multiple interstitials.
-TEST_F(SafeBrowsingBlockingPageTest,
- PageWithMultipleMalwareResourceProceed) {
+TEST_F(SafeBrowsingBlockingPageTest, PageWithMultipleMalwareResourceProceed) {
// Enable malware reports.
Profile* profile = Profile::FromBrowserContext(
web_contents()->GetBrowserContext());
@@ -462,7 +484,7 @@ TEST_F(SafeBrowsingBlockingPageTest,
prefs::kSafeBrowsingExtendedReportingEnabled, true);
// Navigate somewhere else.
- Navigate(kGoodURL, 1);
+ Navigate(kGoodURL, 1, 0, true);
// Simulate that page loading a bad-resource triggering an interstitial.
ShowInterstitial(true, kBadURL);
@@ -472,8 +494,7 @@ TEST_F(SafeBrowsingBlockingPageTest,
ShowInterstitial(true, kBadURL2);
ShowInterstitial(true, kBadURL3);
- SafeBrowsingBlockingPage* sb_interstitial =
- GetSafeBrowsingBlockingPage();
+ SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
ASSERT_TRUE(sb_interstitial);
// Proceed through the 1st interstitial.
@@ -515,19 +536,19 @@ TEST_F(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) {
prefs::kSafeBrowsingExtendedReportingEnabled, true);
// Navigate somewhere.
- Navigate(kGoodURL, 1);
+ Navigate(kGoodURL, 1, 0, true);
// Now navigate to a bad page triggerring an interstitial.
controller().LoadURL(GURL(kBadURL), content::Referrer(),
ui::PAGE_TRANSITION_TYPED, std::string());
+ int pending_id = controller().GetPendingEntry()->GetUniqueID();
ShowInterstitial(false, kBadURL);
- SafeBrowsingBlockingPage* sb_interstitial =
- GetSafeBrowsingBlockingPage();
+ SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
ASSERT_TRUE(sb_interstitial);
// Proceed, then navigate back.
ProceedThroughInterstitial(sb_interstitial);
- Navigate(kBadURL, 2); // Commit the navigation.
+ Navigate(kBadURL, 2, pending_id, true); // Commit the navigation.
GoBack(true);
// We are back on the good page.
@@ -538,13 +559,15 @@ TEST_F(SafeBrowsingBlockingPageTest, NavigatingBackAndForth) {
// Navigate forward to the malware URL.
web_contents()->GetController().GoForward();
+ pending_id = controller().GetPendingEntry()->GetUniqueID();
ShowInterstitial(false, kBadURL);
sb_interstitial = GetSafeBrowsingBlockingPage();
ASSERT_TRUE(sb_interstitial);
// Let's proceed and make sure everything is OK (bug 17627).
ProceedThroughInterstitial(sb_interstitial);
- Navigate(kBadURL, 2); // Commit the navigation.
+ // Commit the navigation.
+ NavigateCrossSite(kBadURL, 2, pending_id, false);
sb_interstitial = GetSafeBrowsingBlockingPage();
ASSERT_FALSE(sb_interstitial);
ASSERT_EQ(2, controller().GetEntryCount());
@@ -570,8 +593,7 @@ TEST_F(SafeBrowsingBlockingPageTest, ProceedThenDontProceed) {
// Simulate the load causing a safe browsing interstitial to be shown.
ShowInterstitial(false, kBadURL);
- SafeBrowsingBlockingPage* sb_interstitial =
- GetSafeBrowsingBlockingPage();
+ SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
ASSERT_TRUE(sb_interstitial);
base::RunLoop().RunUntilIdle();
@@ -607,8 +629,7 @@ TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsDisabled) {
// Simulate the load causing a safe browsing interstitial to be shown.
ShowInterstitial(false, kBadURL);
- SafeBrowsingBlockingPage* sb_interstitial =
- GetSafeBrowsingBlockingPage();
+ SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
ASSERT_TRUE(sb_interstitial);
base::RunLoop().RunUntilIdle();
@@ -642,8 +663,7 @@ TEST_F(SafeBrowsingBlockingPageTest, MalwareReportsToggling) {
// Simulate the load causing a safe browsing interstitial to be shown.
ShowInterstitial(false, kBadURL);
- SafeBrowsingBlockingPage* sb_interstitial =
- GetSafeBrowsingBlockingPage();
+ SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
ASSERT_TRUE(sb_interstitial);
base::RunLoop().RunUntilIdle();