summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/browser_resources.grd2
-rw-r--r--chrome/browser/chrome_browser_field_trials.cc11
-rw-r--r--chrome/browser/chrome_browser_field_trials.h3
-rw-r--r--chrome/browser/resources/safe_browsing_malware_block.html186
-rw-r--r--chrome/browser/resources/safe_browsing_phishing_block.html150
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_blocking_page.cc144
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc382
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc35
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_blocking_page_v2_test.cc722
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_blocking_page_v2_unittest.cc537
-rw-r--r--chrome/chrome_tests.gypi2
-rwxr-xr-xchrome/tools/extract_actions.py3
-rw-r--r--tools/valgrind/gtest_exclude/browser_tests.gtest-drmemory_win32.txt1
13 files changed, 275 insertions, 1903 deletions
diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd
index 564eaa8..1c02d8f 100644
--- a/chrome/browser/browser_resources.grd
+++ b/chrome/browser/browser_resources.grd
@@ -184,9 +184,7 @@
</if>
<include name="IDR_PROFILER_HTML" file="resources\profiler\profiler.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" />
<include name="IDR_PROFILER_JS" file="resources\profiler\profiler.js" flattenhtml="true" type="BINDATA" />
- <include name="IDR_SAFE_BROWSING_MALWARE_BLOCK" file="resources\safe_browsing_malware_block.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_SAFE_BROWSING_MULTIPLE_THREAT_BLOCK" file="resources\safe_browsing_multiple_threat_block.html" flattenhtml="true" type="BINDATA" />
- <include name="IDR_SAFE_BROWSING_PHISHING_BLOCK" file="resources\safe_browsing_phishing_block.html" flattenhtml="true" type="BINDATA" />
<if expr="is_win">
<include name="IDR_SETTINGS_APP_MANIFEST" file="resources\settings_app\manifest.json" type="BINDATA" />
</if>
diff --git a/chrome/browser/chrome_browser_field_trials.cc b/chrome/browser/chrome_browser_field_trials.cc
index b1283ec..fad2078 100644
--- a/chrome/browser/chrome_browser_field_trials.cc
+++ b/chrome/browser/chrome_browser_field_trials.cc
@@ -133,7 +133,6 @@ void ChromeBrowserFieldTrials::SetupFieldTrials(
SetupUniformityFieldTrials(install_time);
AutocompleteFieldTrial::Activate();
DisableNewTabFieldTrialIfNecesssary();
- SetUpSafeBrowsingInterstitialFieldTrial();
SetUpInfiniteCacheFieldTrial();
SetUpCacheSensitivityAnalysisFieldTrial();
WindowsOverlappedTCPReadsFieldTrial();
@@ -284,16 +283,6 @@ void ChromeBrowserFieldTrials::DisableNewTabFieldTrialIfNecesssary() {
}
}
-void ChromeBrowserFieldTrials::SetUpSafeBrowsingInterstitialFieldTrial() {
- const base::FieldTrial::Probability kDivisor = 100;
- const base::FieldTrial::Probability kVersion2Probability = 50; // 50% prob.
- scoped_refptr<base::FieldTrial> trial(
- base::FieldTrialList::FactoryGetFieldTrial("SBInterstitial", kDivisor,
- "V1", 2012, 10, 23, NULL));
- trial->UseOneTimeRandomization();
- trial->AppendGroup("V2", kVersion2Probability);
-}
-
void ChromeBrowserFieldTrials::SetUpInfiniteCacheFieldTrial() {
const base::FieldTrial::Probability kDivisor = 100;
diff --git a/chrome/browser/chrome_browser_field_trials.h b/chrome/browser/chrome_browser_field_trials.h
index cc097a7..3d16f6a 100644
--- a/chrome/browser/chrome_browser_field_trials.h
+++ b/chrome/browser/chrome_browser_field_trials.h
@@ -49,9 +49,6 @@ class ChromeBrowserFieldTrials {
// Disables the new tab field trial if not running in desktop mode.
void DisableNewTabFieldTrialIfNecesssary();
- // Sets up the Safe Browsing interstitial redesign trial.
- void SetUpSafeBrowsingInterstitialFieldTrial();
-
// Sets up the InfiniteCache field trial.
void SetUpInfiniteCacheFieldTrial();
diff --git a/chrome/browser/resources/safe_browsing_malware_block.html b/chrome/browser/resources/safe_browsing_malware_block.html
deleted file mode 100644
index aa71348..0000000
--- a/chrome/browser/resources/safe_browsing_malware_block.html
+++ /dev/null
@@ -1,186 +0,0 @@
-<!DOCTYPE html>
-<html id="template_root" i18n-values="dir:textdirection">
-<head>
-<title i18n-content="title"></title>
-<style>
-body {
- background-color:#500;
- font-family:Helvetica,Arial,sans-serif;
- margin:0px;
-}
-.background {
- position:absolute;
- width:100%;
- height:100%;
-}
-.cell {
- padding:40px;
-}
-.box {
- width:80%;
- background-color:white;
- color:black;
- font-size:10pt;
- line-height:16pt;
- text-align:left;
- padding:20px;
- position:relative;
- -webkit-box-shadow:3px 3px 8px #200;
- border-radius:5px;
-}
-html[dir='rtl'] .box {
- text-align:right;
-}
-
-.icon {
- position:absolute;
-}
-.title {
- margin:0px 87px 0px;
- font-size:18pt;
- line-height: 140%;
- margin-bottom:6pt;
- font-weight:bold;
- color:#660000;
-}
-.main {
- margin:0px 90px 10px;
-}
-.footer {
- margin-top: 40px;
- padding-top: 10px;
- border-top: 1px solid #ddd;
-}
-.submission {
- margin:15px 5px 15px 0px;
- padding:0px;
-}
-input {
- margin:0px;
-}
-.helpbutton {
- float:right;
-}
-
-.example {
- margin: 30px 90px 0px;
- border-top:1px solid #ccc;
- padding-top:6px;
-}
-.moreinfotitle {
- margin-left:5px;
- margin-right:5px;
-}
-
-.green {
- background: -webkit-linear-gradient(#83c260, #71b44c 44%, #549d2c);
- border: 1px solid #4c7336;
- border-bottom: 1px solid #44692f;
- border-radius: 3px;
- -webkit-box-shadow: inset 0 1px 0 0 #a0d186, 0px 1px 2px rgba(0,0,0,0.2);
- color: #fff;
- font-family: arial, helvetica, sans-serif;
- font-size: 14px;
- font-weight: bold;
- line-height: 1;
- padding: 6px 16px 7px 16px;
- text-align: center;
- text-shadow: 0 -1px 0 #4865e4;
- cursor: pointer;
- text-decoration: none;
- display: inline-block;
-}
-
-.green:hover, .green:focus {
- background: -webkit-linear-gradient(#8bc968, #7bbc57 44%, #4f9727);
- border: 1px solid #456a2f;
- border-bottom: 1px solid #456a2f;
- -webkit-box-shadow: inset 0 1px 0 0 #a0d186, 0px 1px 2px rgba(0,0,0,0.3);;
-}
-
-.green:active {
- background: -webkit-linear-gradient(#83c260, #71b44c 44%, #549d2c);
- border: 1px solid #3e612a;
- border-top:1px solid #4c7336;
- border-bottom:1px solid #547b3f;
- -webkit-box-shadow: inset 1px 1px 1px 1px rgba(0, 0, 0, 0.1);
-}
-
-.green:focus {
- border: 1px solid #000;
-}
-
-label.checkbox {
- position: relative;
-}
-
-label.checkbox > input {
- margin-top: 3px;
- position: absolute;
-}
-
-label.checkbox > span {
- -webkit-margin-start: 20px;
- display: block;
-}
-</style>
-
-<script>
- function sendCommand(cmd) {
- window.domAutomationController.setAutomationId(1);
- window.domAutomationController.send(cmd);
- }
-
- function savePreference() {
- var checkBox = document.getElementById('checkreport');
- if (checkBox.checked) {
- sendCommand('doReport');
- } else {
- sendCommand('dontReport');
- }
- }
-</script>
-
-</head>
-<body oncontextmenu="return false;">
-<div class="background">
- <img src="ssl_roadblock_background.png" width="100%" height="100%"
- alt="background" onmousedown="return false;">
-</div>
-<table width="100%" cellspacing="0" cellpadding="0">
- <td class="cell" valign="middle" align="center">
- <div class="box">
- <div class="icon">
- <img src="shared/images/phishing_icon.png" alt="Malware Icon"
- onmousedown="return false;">
- </div>
- <div class="title" i18n-content="headLine"></div>
- <div class="main" i18n-values=".innerHTML:description1"></div>
- <div class="main" i18n-values=".innerHTML:description2"></div>
- <div id="detailinfo" class="main" i18n-values=".innerHTML:description5">
- </div>
-
- <div class="main">
- <form class="submission">
- <button id="back" class="green" i18n-content="back_button"
- onclick="sendCommand('takeMeBack')"></button>
- <br>
- </form>
- </div>
-
- <div class="main" i18n-values=".innerHTML:description3"
- jsdisplay="!proceedDisabled"></div>
-
- <div class="main footer" jsdisplay="displaycheckbox">
- <label class="checkbox" for="checkreport">
- <input id="checkreport" name="checked" type="checkbox"
- jsvalues=".checked:boxchecked" onclick="savePreference()">
- <span i18n-values=".innerHTML:confirm_text"></span>
- </label>
- </div>
-
- </div>
- </td>
-</table>
-</body>
-</html>
diff --git a/chrome/browser/resources/safe_browsing_phishing_block.html b/chrome/browser/resources/safe_browsing_phishing_block.html
deleted file mode 100644
index 62880b5..0000000
--- a/chrome/browser/resources/safe_browsing_phishing_block.html
+++ /dev/null
@@ -1,150 +0,0 @@
-<!DOCTYPE html>
-<html id="template_root" i18n-values="dir:textdirection">
-<head>
-<title i18n-content="title"></title>
-<style>
-body {
- background-color:#500;
- font-family:Helvetica,Arial,sans-serif;
- margin:0px;
-}
-.background {
- position:absolute;
- width:100%;
- height:100%;
-}
-.cell {
- padding:40px;
-}
-.box {
- width:80%;
- background-color:white;
- color:black;
- font-size:10pt;
- line-height:16pt;
- text-align:left;
- padding:20px;
- position:relative;
- -webkit-box-shadow:3px 3px 8px #200;
- border-radius:5px;
-}
-html[dir='rtl'] .box {
- text-align:right;
-}
-.icon {
- position:absolute;
-}
-.title {
- margin: 0px 87px 0px;
- font-size:18pt;
- line-height: 140%;
- margin-bottom:6pt;
- font-weight:bold;
- color:#660000;
-}
-.main {
- margin:0px 90px 0px;
-}
-.submission {
- margin:15px 5px 15px 0px;
- padding:0px;
-}
-input {
- margin:0px;
-}
-.proceedbutton {
-}
-.helpbutton {
- float:right;
-}
-html[dir='rtl'] .helpbutton {
- float:left;
-}
-.example {
- margin: 30px 90px 0px;
- border-top:1px solid #ccc;
- padding-top:6px;
-}
-
-.green {
- background: -webkit-linear-gradient(#83c260, #71b44c 44%, #549d2c);
- border: 1px solid #4c7336;
- border-bottom: 1px solid #44692f;
- border-radius: 3px;
- -webkit-box-shadow: inset 0 1px 0 0 #a0d186, 0px 1px 2px rgba(0,0,0,0.2);
- color: #fff;
- font-family: arial, helvetica, sans-serif;
- font-size: 14px;
- font-weight: bold;
- line-height: 1;
- padding: 6px 16px 7px 16px;
- text-align: center;
- text-shadow: 0 -1px 0 #4865e4;
- cursor:pointer;
- text-decoration:none;
- display:inline-block;
-}
-
-.green:hover, .green:focus {
- background: -webkit-linear-gradient(#8bc968, #7bbc57 44%, #4f9727);
- border: 1px solid #456a2f;
- border-bottom: 1px solid #456a2f;
- -webkit-box-shadow: inset 0 1px 0 0 #a0d186, 0px 1px 2px rgba(0,0,0,0.3);;
-}
-
-.green:active {
- background: -webkit-linear-gradient(#83c260, #71b44c 44%, #549d2c);
- border: 1px solid #3e612a;
- border-top:1px solid #4c7336;
- border-bottom:1px solid #547b3f;
- -webkit-box-shadow: inset 1px 1px 1px 1px rgba(0, 0, 0, 0.1);
-}
-
-.green:focus {
- border: 1px solid #000;
-}
-</style>
-
-<script>
- function sendCommand(cmd) {
- window.domAutomationController.setAutomationId(1);
- window.domAutomationController.send(cmd);
- }
-</script>
-
-</head>
-<body oncontextmenu="return false;">
-<div class="background">
- <img src="ssl_roadblock_background.png" width="100%" height="100%"
- alt="background" onmousedown="return false;">
-</div>
-<table width="100%" cellspacing="0" cellpadding="0">
- <td class="cell" valign="middle" align="center">
- <div class="box">
- <div class="icon">
- <img src="shared/images/phishing_icon.png" alt="Phishing Warning Icon"
- onmousedown="return false;">
- </div>
- <div class="title" i18n-content="headLine"></div>
- <div class="main" i18n-values=".innerHTML:description1"></div>
- <div class="main">
- <form class="submission">
- <button id="back" class="green" i18n-content="back_button"
- onclick="sendCommand('takeMeBack')"></button>
- </form>
- </div>
- <div class="main">
- <a href="" i18n-content="description2"
- onclick="sendCommand('learnMore'); return false;"></a>
- </div>
- <div class="main">
- <a href="" onclick="sendCommand('reportError'); return false;"
- onmousedown="return false;" i18n-content="report_error"></a>
- </div>
- <div class="main" i18n-values=".innerHTML:description3"
- jsdisplay="!proceedDisabled"></div>
- </div>
- </td>
-</table>
-</body>
-</html>
diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
index c050156..9856f17 100644
--- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
@@ -134,12 +134,8 @@ class SafeBrowsingBlockingPageFactoryImpl
if (unsafe_resources.size() == 1 &&
(unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE ||
unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_PHISHING)) {
- if (base::FieldTrialList::FindFullName("SBInterstitial") == "V2") {
- DVLOG(1) << "In V2 group.";
- return new SafeBrowsingBlockingPageV2(service, web_contents,
- unsafe_resources);
- }
- DVLOG(1) << "In V1 group.";
+ return new SafeBrowsingBlockingPageV2(service, web_contents,
+ unsafe_resources);
}
return new SafeBrowsingBlockingPageV1(service, web_contents,
unsafe_resources);
@@ -549,10 +545,6 @@ void SafeBrowsingBlockingPage::RecordUserAction(BlockingPageEvent event) {
} else {
UMA_HISTOGRAM_ENUMERATION("SB2.InterstitialAction", histogram_action,
MAX_ACTION);
- UMA_HISTOGRAM_ENUMERATION(
- base::FieldTrial::MakeName("SB2.InterstitialAction", "SBInterstitial"),
- histogram_action,
- MAX_ACTION);
}
// TODO(mattm): now that we've added the histogram above, should we remove
@@ -587,14 +579,7 @@ void SafeBrowsingBlockingPage::RecordUserAction(BlockingPageEvent event) {
NOTREACHED() << "Unexpected event: " << event;
}
- std::string field_trial_action;
- if (base::FieldTrialList::FindFullName("SBInterstitial") == "V2")
- field_trial_action = action + "_V2";
- else
- field_trial_action = action + "_V1";
-
content::RecordComputedAction(action);
- content::RecordComputedAction(field_trial_action);
}
void SafeBrowsingBlockingPage::RecordUserReactionTime(
@@ -614,30 +599,18 @@ void SafeBrowsingBlockingPage::RecordUserReactionTime(
// the big green button) are considered the same action.
if (command == kProceedCommand) {
UMA_HISTOGRAM_MEDIUM_TIMES("SB2.MalwareInterstitialTimeProceed", dt);
- UMA_HISTOGRAM_MEDIUM_TIMES(base::FieldTrial::MakeName(
- "SB2.MalwareInterstitialTimeProceed", "SBInterstitial"), dt);
} else if (command == kTakeMeBackCommand) {
UMA_HISTOGRAM_MEDIUM_TIMES("SB2.MalwareInterstitialTimeTakeMeBack", dt);
- UMA_HISTOGRAM_MEDIUM_TIMES(base::FieldTrial::MakeName(
- "SB2.MalwareInterstitialTimeTakeMeBack", "SBInterstitial"), dt);
} else if (command == kShowDiagnosticCommand) {
UMA_HISTOGRAM_MEDIUM_TIMES("SB2.MalwareInterstitialTimeDiagnostic", dt);
- UMA_HISTOGRAM_MEDIUM_TIMES(base::FieldTrial::MakeName(
- "SB2.MalwareInterstitialTimeDiagnostic", "SBInterstitial"), dt);
} else if (command == kShowPrivacyCommand) {
UMA_HISTOGRAM_MEDIUM_TIMES("SB2.MalwareInterstitialTimePrivacyPolicy",
dt);
- UMA_HISTOGRAM_MEDIUM_TIMES(base::FieldTrial::MakeName(
- "SB2.MalwareInterstitialTimePrivacyPolicy", "SBInterstitial"), dt);
} else if (command == kLearnMoreCommand || command == kLearnMoreCommandV2) {
UMA_HISTOGRAM_MEDIUM_TIMES("SB2.MalwareInterstitialLearnMore",
dt);
- UMA_HISTOGRAM_MEDIUM_TIMES(base::FieldTrial::MakeName(
- "SB2.MalwareInterstitialLearnMore", "SBInterstitial"), dt);
} else if (command == kNavigatedAwayMetaCommand) {
UMA_HISTOGRAM_MEDIUM_TIMES("SB2.MalwareInterstitialTimeClosed", dt);
- UMA_HISTOGRAM_MEDIUM_TIMES(base::FieldTrial::MakeName(
- "SB2.MalwareInterstitialTimeClosed", "SBInterstitial"), dt);
} else if (command == kExpandedSeeMore) {
// Only record the expanded histogram once per display of the
// interstitial.
@@ -791,24 +764,10 @@ std::string SafeBrowsingBlockingPageV1::GetHTMLContents() {
return std::string();
}
- if (unsafe_resources_.size() > 1) {
- PopulateMultipleThreatStringDictionary(&strings);
- html = rb.GetRawDataResource(
- IDR_SAFE_BROWSING_MULTIPLE_THREAT_BLOCK).as_string();
- } else {
- SBThreatType threat_type = unsafe_resources_[0].threat_type;
- if (threat_type == SB_THREAT_TYPE_URL_MALWARE) {
- PopulateMalwareStringDictionary(&strings);
- html = rb.GetRawDataResource(
- IDR_SAFE_BROWSING_MALWARE_BLOCK).as_string();
- } else { // Phishing.
- DCHECK(threat_type == SB_THREAT_TYPE_URL_PHISHING ||
- threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL);
- PopulatePhishingStringDictionary(&strings);
- html = rb.GetRawDataResource(
- IDR_SAFE_BROWSING_PHISHING_BLOCK).as_string();
- }
- }
+ DCHECK_GT(unsafe_resources_.size(), 1U);
+ PopulateMultipleThreatStringDictionary(&strings);
+ html = rb.GetRawDataResource(
+ IDR_SAFE_BROWSING_MULTIPLE_THREAT_BLOCK).as_string();
interstitial_show_time_ = base::TimeTicks::Now();
return jstemplate_builder::GetTemplatesHtml(html, &strings, "template_root");
}
@@ -916,97 +875,12 @@ void SafeBrowsingBlockingPageV1::PopulateMultipleThreatStringDictionary(
void SafeBrowsingBlockingPageV1::PopulateMalwareStringDictionary(
DictionaryValue* strings) {
- std::string diagnostic_link = base::StringPrintf(kSbDiagnosticHtml,
- l10n_util::GetStringUTF8(
- IDS_SAFE_BROWSING_MALWARE_DIAGNOSTIC_PAGE).c_str());
-
- // Check to see if we're blocking the main page, or a sub-resource on the
- // main page.
- string16 description1, description3, description5;
- if (is_main_frame_load_blocked_) {
- description1 = l10n_util::GetStringFUTF16(
- IDS_SAFE_BROWSING_MALWARE_DESCRIPTION1, UTF8ToUTF16(url_.host()));
- } else {
- description1 = l10n_util::GetStringFUTF16(
- IDS_SAFE_BROWSING_MALWARE_DESCRIPTION4,
- UTF8ToUTF16(web_contents_->GetURL().host()),
- UTF8ToUTF16(url_.host()));
- }
-
- std::string proceed_link = base::StringPrintf(kPLinkHtml,
- l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_MALWARE_PROCEED_LINK).c_str());
- description3 =
- l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION3,
- UTF8ToUTF16(proceed_link));
-
- PopulateStringDictionary(
- strings,
- l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_TITLE),
- l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_HEADLINE),
- description1,
- l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION2),
- description3);
-
- description5 =
- l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION5,
- UTF8ToUTF16(url_.host()),
- UTF8ToUTF16(url_.host()),
- UTF8ToUTF16(diagnostic_link));
-
- strings->SetString("description5", description5);
-
- strings->SetString("back_button",
- l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON));
- strings->SetString("proceed_link",
- l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_PROCEED_LINK));
- strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr");
-
- if (!CanShowMalwareDetailsOption()) {
- strings->SetBoolean(kDisplayCheckBox, false);
- } else {
- // Show the checkbox for sending malware details.
- strings->SetBoolean(kDisplayCheckBox, true);
-
- std::string privacy_link = base::StringPrintf(
- kPrivacyLinkHtml,
- l10n_util::GetStringUTF8(
- IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str());
-
- strings->SetString("confirm_text",
- l10n_util::GetStringFUTF16(
- IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE,
- UTF8ToUTF16(privacy_link)));
- if (IsPrefEnabled(prefs::kSafeBrowsingReportingEnabled))
- strings->SetString(kBoxChecked, "yes");
- else
- strings->SetString(kBoxChecked, "");
- }
+ NOTREACHED();
}
void SafeBrowsingBlockingPageV1::PopulatePhishingStringDictionary(
DictionaryValue* strings) {
- std::string proceed_link = base::StringPrintf(
- kPLinkHtml,
- l10n_util::GetStringUTF8(
- IDS_SAFE_BROWSING_PHISHING_PROCEED_LINK).c_str());
- string16 description3 = l10n_util::GetStringFUTF16(
- IDS_SAFE_BROWSING_PHISHING_DESCRIPTION3,
- UTF8ToUTF16(proceed_link));
-
- PopulateStringDictionary(
- strings,
- l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_TITLE),
- l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_HEADLINE),
- l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION1,
- UTF8ToUTF16(url_.host())),
- l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION2),
- description3);
-
- strings->SetString("back_button",
- l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_BACK_BUTTON));
- strings->SetString("report_error",
- l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_REPORT_ERROR));
- strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr");
+ NOTREACHED();
}
SafeBrowsingBlockingPageV2::SafeBrowsingBlockingPageV2(
@@ -1028,6 +902,8 @@ std::string SafeBrowsingBlockingPageV2::GetHTMLContents() {
}
if (unsafe_resources_.size() > 1) {
+ // TODO(mattm): Implement new multi-threat interstitial and remove
+ // SafeBrowsingBlockingPageV1 entirely. (http://crbug.com/160336)
NOTREACHED();
} else {
SBThreatType threat_type = unsafe_resources_[0].threat_type;
diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc
index 64abf80..833f675 100644
--- a/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc
@@ -38,6 +38,10 @@ using content::WebContents;
namespace {
+const char kEmptyPage[] = "files/empty.html";
+const char kMalwarePage[] = "files/safe_browsing/malware.html";
+const char kMalwareIframe[] = "files/safe_browsing/malware_iframe.html";
+
// A SafeBrowingService class that allows us to inject the malicious URLs.
class FakeSafeBrowsingService : public SafeBrowsingService {
public:
@@ -183,12 +187,12 @@ class TestMalwareDetailsFactory : public MalwareDetailsFactory {
};
// A SafeBrowingBlockingPage class that lets us wait until it's hidden.
-class TestSafeBrowsingBlockingPage : public SafeBrowsingBlockingPageV1 {
+class TestSafeBrowsingBlockingPage : public SafeBrowsingBlockingPageV2 {
public:
TestSafeBrowsingBlockingPage(SafeBrowsingService* service,
WebContents* web_contents,
const UnsafeResourceList& unsafe_resources)
- : SafeBrowsingBlockingPageV1(service, web_contents, unsafe_resources),
+ : SafeBrowsingBlockingPageV2(service, web_contents, unsafe_resources),
wait_for_delete_(false) {
// Don't wait the whole 3 seconds for the browser test.
malware_details_proceed_delay_ms_ = 100;
@@ -233,6 +237,12 @@ class TestSafeBrowsingBlockingPageFactory
// Tests the safe browsing blocking page in a browser.
class SafeBrowsingBlockingPageTest : public InProcessBrowserTest {
public:
+ enum Visibility {
+ VISIBILITY_ERROR = -1,
+ HIDDEN = 0,
+ VISIBLE = 1,
+ };
+
SafeBrowsingBlockingPageTest() {
}
@@ -263,6 +273,30 @@ class SafeBrowsingBlockingPageTest : public InProcessBrowserTest {
service->SetURLThreatType(url, threat_type);
}
+ // Adds a safebrowsing result of type |threat_type| to the fake safebrowsing
+ // service, navigates to that page, and returns the url.
+ GURL SetupWarningAndNavigate(SBThreatType threat_type) {
+ GURL url = test_server()->GetURL(kEmptyPage);
+ SetURLThreatType(url, threat_type);
+
+ ui_test_utils::NavigateToURL(browser(), url);
+ EXPECT_TRUE(WaitForReady());
+ return url;
+ }
+
+ // Adds a safebrowsing malware result to the fake safebrowsing service,
+ // navigates to a page with an iframe containing the malware site, and
+ // returns the url of the parent page.
+ GURL SetupMalwareIframeWarningAndNavigate() {
+ GURL url = test_server()->GetURL(kMalwarePage);
+ GURL iframe_url = test_server()->GetURL(kMalwareIframe);
+ SetURLThreatType(iframe_url, SB_THREAT_TYPE_URL_MALWARE);
+
+ ui_test_utils::NavigateToURL(browser(), url);
+ EXPECT_TRUE(WaitForReady());
+ return url;
+ }
+
void SendCommand(const std::string& command) {
WebContents* contents = chrome::GetActiveWebContents(browser());
// We use InterstitialPage::GetInterstitialPage(tab) instead of
@@ -367,16 +401,24 @@ class SafeBrowsingBlockingPageTest : public InProcessBrowserTest {
CURRENT_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
chrome::ActivateTabAt(browser(), 1, true);
- // Simulate the user clicking "proceed", there should be no crash.
+ // Simulate the user clicking "proceed", there should be no crash. Since
+ // clicking proceed may do nothing (see comment in MalwareRedirectCanceled
+ // below, and crbug.com/76460), we use SendCommand to trigger the callback
+ // directly rather than using ClickAndWaitForDetach since there might not
+ // be a notification to wait for.
SendCommand("\"proceed\"");
}
- bool GetProceedLinkIsHidden(bool* result) {
+ content::RenderViewHost* GetRenderViewHost() {
InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage(
chrome::GetActiveWebContents(browser()));
if (!interstitial)
- return false;
- content::RenderViewHost* rvh = interstitial->GetRenderViewHostForTesting();
+ return NULL;
+ return interstitial->GetRenderViewHostForTesting();
+ }
+
+ bool WaitForReady() {
+ content::RenderViewHost* rvh = GetRenderViewHost();
if (!rvh)
return false;
// Wait until all <script> tags have executed, including jstemplate.
@@ -390,19 +432,53 @@ class SafeBrowsingBlockingPageTest : public InProcessBrowserTest {
if (!value.get() || !value->GetAsString(&ready_state))
return false;
} while (ready_state != "complete");
- // Now get the display style for the "proceed anyway" <div>.
+ return true;
+ }
+
+ Visibility GetVisibility(const std::string& node_id) {
+ content::RenderViewHost* rvh = GetRenderViewHost();
+ if (!rvh)
+ return VISIBILITY_ERROR;
scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(
string16(),
ASCIIToUTF16(
- "var list = document.querySelectorAll("
- " 'div[jsdisplay=\"!proceedDisabled\"]');\n"
- "if (list.length == 1)\n"
- " list[0].style.display === 'none';\n"
+ "var node = document.getElementById('" + node_id + "');\n"
+ "if (node)\n"
+ " node.offsetWidth > 0 && node.offsetHeight > 0;"
"else\n"
- " 'Fail with non-boolean result value';\n")));
+ " 'node not found';\n")));
if (!value.get())
+ return VISIBILITY_ERROR;
+ bool result = false;
+ if (!value->GetAsBoolean(&result))
+ return VISIBILITY_ERROR;
+ return result ? VISIBLE : HIDDEN;
+ }
+
+ bool Click(const std::string& node_id) {
+ content::RenderViewHost* rvh = GetRenderViewHost();
+ if (!rvh)
+ return false;
+ // We don't use ExecuteJavascriptAndGetValue for this one, since clicking
+ // the button/link may navigate away before the injected javascript can
+ // reply, hanging the test.
+ rvh->ExecuteJavascriptInWebFrame(
+ string16(),
+ ASCIIToUTF16("document.getElementById('" + node_id + "').click();\n"));
+ return true;
+ }
+
+ bool ClickAndWaitForDetach(const std::string& node_id) {
+ // We wait for interstitial_detached rather than nav_entry_committed, as
+ // going back from a main-frame malware interstitial page will not cause a
+ // nav entry committed event.
+ content::WindowedNotificationObserver observer(
+ content::NOTIFICATION_INTERSTITIAL_DETACHED,
+ content::Source<WebContents>(chrome::GetActiveWebContents(browser())));
+ if (!Click(node_id))
return false;
- return value->GetAsBoolean(result);
+ observer.Wait();
+ return true;
}
protected:
@@ -415,10 +491,6 @@ class SafeBrowsingBlockingPageTest : public InProcessBrowserTest {
DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageTest);
};
-const char kEmptyPage[] = "files/empty.html";
-const char kMalwarePage[] = "files/safe_browsing/malware.html";
-const char kMalwareIframe[] = "files/safe_browsing/malware_iframe.html";
-
IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest,
MalwareRedirectInIFrameCanceled) {
// 1. Test the case that redirect is a subresource.
@@ -438,168 +510,98 @@ IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest,
}
IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareDontProceed) {
- GURL url = test_server()->GetURL(kEmptyPage);
- SetURLThreatType(url, SB_THREAT_TYPE_URL_MALWARE);
-
- ui_test_utils::NavigateToURL(browser(), url);
-
- bool hidden = false;
- EXPECT_TRUE(GetProceedLinkIsHidden(&hidden));
- EXPECT_FALSE(hidden);
-
- SendCommand("\"takeMeBack\""); // Simulate the user clicking "back"
+ SetupWarningAndNavigate(SB_THREAT_TYPE_URL_MALWARE);
+
+ EXPECT_EQ(VISIBLE, GetVisibility("malware-icon"));
+ EXPECT_EQ(HIDDEN, GetVisibility("subresource-icon"));
+ EXPECT_EQ(HIDDEN, GetVisibility("phishing-icon"));
+ EXPECT_EQ(VISIBLE, GetVisibility("check-report"));
+ EXPECT_EQ(HIDDEN, GetVisibility("show-diagnostic-link"));
+ EXPECT_EQ(HIDDEN, GetVisibility("report-error-link"));
+ EXPECT_EQ(HIDDEN, GetVisibility("proceed"));
+ EXPECT_TRUE(Click("see-more-link"));
+ EXPECT_EQ(VISIBLE, GetVisibility("show-diagnostic-link"));
+ EXPECT_EQ(HIDDEN, GetVisibility("report-error-link"));
+ EXPECT_EQ(VISIBLE, GetVisibility("proceed"));
+
+ EXPECT_TRUE(ClickAndWaitForDetach("back"));
AssertNoInterstitial(false); // Assert the interstitial is gone
EXPECT_EQ(
- GURL(chrome::kAboutBlankURL), // Back to "about:blank"
+ GURL(chrome::kAboutBlankURL), // Back to "about:blank"
chrome::GetActiveWebContents(browser())->GetURL());
}
IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareProceed) {
- GURL url = test_server()->GetURL(kEmptyPage);
- SetURLThreatType(url, SB_THREAT_TYPE_URL_MALWARE);
-
- // Note: NOTIFICATION_LOAD_STOP may come before or after the DidNavigate
- // event that clears the interstitial. We wait for DidNavigate instead.
- ui_test_utils::NavigateToURL(browser(), url);
- content::WindowedNotificationObserver observer(
- content::NOTIFICATION_NAV_ENTRY_COMMITTED,
- content::Source<NavigationController>(
- &chrome::GetActiveWebContents(browser())->GetController()));
- SendCommand("\"proceed\""); // Simulate the user clicking "proceed"
- observer.Wait();
- AssertNoInterstitial(true); // Assert the interstitial is gone.
- EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL());
-}
-
-IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, PhishingDontProceed) {
- GURL url = test_server()->GetURL(kEmptyPage);
- SetURLThreatType(url, SB_THREAT_TYPE_URL_PHISHING);
-
- ui_test_utils::NavigateToURL(browser(), url);
-
- SendCommand("\"takeMeBack\""); // Simulate the user clicking "proceed"
- AssertNoInterstitial(false); // Assert the interstitial is gone
- EXPECT_EQ(
- GURL(chrome::kAboutBlankURL), // We are back to "about:blank".
- chrome::GetActiveWebContents(browser())->GetURL());
-}
+ GURL url = SetupWarningAndNavigate(SB_THREAT_TYPE_URL_MALWARE);
-IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, PhishingProceed) {
- GURL url = test_server()->GetURL(kEmptyPage);
- SetURLThreatType(url, SB_THREAT_TYPE_URL_PHISHING);
-
- ui_test_utils::NavigateToURL(browser(), url);
-
- // Note: NOTIFICATION_LOAD_STOP may come before or after the DidNavigate
- // event that clears the interstitial. We wait for DidNavigate instead.
- content::WindowedNotificationObserver observer(
- content::NOTIFICATION_NAV_ENTRY_COMMITTED,
- content::Source<NavigationController>(
- &chrome::GetActiveWebContents(browser())->GetController()));
- SendCommand("\"proceed\""); // Simulate the user clicking "proceed".
- observer.Wait();
- AssertNoInterstitial(true); // Assert the interstitial is gone
+ EXPECT_TRUE(ClickAndWaitForDetach("proceed"));
+ AssertNoInterstitial(true); // Assert the interstitial is gone.
EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL());
}
-IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, PhishingReportError) {
- GURL url = test_server()->GetURL(kEmptyPage);
- SetURLThreatType(url, SB_THREAT_TYPE_URL_PHISHING);
-
- ui_test_utils::NavigateToURL(browser(), url);
-
- // Note: NOTIFICATION_LOAD_STOP may come before or after the DidNavigate
- // event that clears the interstitial. We wait for DidNavigate instead.
- content::WindowedNotificationObserver observer(
- content::NOTIFICATION_NAV_ENTRY_COMMITTED,
- content::Source<NavigationController>(
- &chrome::GetActiveWebContents(browser())->GetController()));
- SendCommand("\"reportError\""); // Simulate the user clicking "report error"
- observer.Wait();
- AssertNoInterstitial(false); // Assert the interstitial is gone
-
- // We are in the error reporting page.
- EXPECT_EQ(
- "/safebrowsing/report_error/",
- chrome::GetActiveWebContents(browser())->GetURL().path());
-}
-
IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest,
- PhishingLearnMore) {
- GURL url = test_server()->GetURL(kEmptyPage);
- SetURLThreatType(url, SB_THREAT_TYPE_URL_PHISHING);
+ MalwareLearnMore) {
+ SetupWarningAndNavigate(SB_THREAT_TYPE_URL_MALWARE);
- ui_test_utils::NavigateToURL(browser(), url);
-
- // Note: NOTIFICATION_LOAD_STOP may come before or after the DidNavigate
- // event that clears the interstitial. We wait for DidNavigate instead.
- content::WindowedNotificationObserver observer(
- content::NOTIFICATION_NAV_ENTRY_COMMITTED,
- content::Source<NavigationController>(
- &chrome::GetActiveWebContents(browser())->GetController()));
- SendCommand("\"learnMore\""); // Simulate the user clicking "learn more"
- observer.Wait();
- AssertNoInterstitial(false); // Assert the interstitial is gone
+ EXPECT_TRUE(ClickAndWaitForDetach("learn-more-link"));
+ AssertNoInterstitial(false); // Assert the interstitial is gone
// We are in the help page.
EXPECT_EQ(
- "/support/bin/answer.py",
+ "/goodtoknow/online-safety/malware/",
chrome::GetActiveWebContents(browser())->GetURL().path());
}
-IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareIframeDontProceed) {
- GURL url = test_server()->GetURL(kMalwarePage);
- GURL iframe_url = test_server()->GetURL(kMalwareIframe);
- SetURLThreatType(iframe_url, SB_THREAT_TYPE_URL_MALWARE);
-
- ui_test_utils::NavigateToURL(browser(), url);
-
- content::WindowedNotificationObserver observer(
- content::NOTIFICATION_NAV_ENTRY_COMMITTED,
- content::Source<NavigationController>(
- &chrome::GetActiveWebContents(browser())->GetController()));
- SendCommand("\"takeMeBack\""); // Simulate the user clicking "back"
- observer.Wait();
+IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest,
+ MalwareIframeDontProceed) {
+ SetupMalwareIframeWarningAndNavigate();
+
+ EXPECT_EQ(HIDDEN, GetVisibility("malware-icon"));
+ EXPECT_EQ(VISIBLE, GetVisibility("subresource-icon"));
+ EXPECT_EQ(HIDDEN, GetVisibility("phishing-icon"));
+ EXPECT_EQ(VISIBLE, GetVisibility("check-report"));
+ EXPECT_EQ(HIDDEN, GetVisibility("show-diagnostic-link"));
+ EXPECT_EQ(HIDDEN, GetVisibility("report-error-link"));
+ EXPECT_EQ(HIDDEN, GetVisibility("proceed"));
+ EXPECT_TRUE(Click("see-more-link"));
+ EXPECT_EQ(VISIBLE, GetVisibility("show-diagnostic-link"));
+ EXPECT_EQ(HIDDEN, GetVisibility("report-error-link"));
+ EXPECT_EQ(VISIBLE, GetVisibility("proceed"));
+
+ EXPECT_TRUE(ClickAndWaitForDetach("back"));
AssertNoInterstitial(false); // Assert the interstitial is gone
EXPECT_EQ(
- GURL(chrome::kAboutBlankURL), // Back to "about:blank"
+ GURL(chrome::kAboutBlankURL), // Back to "about:blank"
chrome::GetActiveWebContents(browser())->GetURL());
}
// Crashy, http://crbug.com/68834.
IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest,
DISABLED_MalwareIframeProceed) {
- GURL url = test_server()->GetURL(kMalwarePage);
- GURL iframe_url = test_server()->GetURL(kMalwareIframe);
- SetURLThreatType(iframe_url, SB_THREAT_TYPE_URL_MALWARE);
-
- ui_test_utils::NavigateToURL(browser(), url);
+ GURL url = SetupMalwareIframeWarningAndNavigate();
- SendCommand("\"proceed\""); // Simulate the user clicking "proceed"
- AssertNoInterstitial(true); // Assert the interstitial is gone
+ EXPECT_TRUE(ClickAndWaitForDetach("proceed"));
+ AssertNoInterstitial(true); // Assert the interstitial is gone
EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL());
}
IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest,
MalwareIframeReportDetails) {
- GURL url = test_server()->GetURL(kMalwarePage);
- GURL iframe_url = test_server()->GetURL(kMalwareIframe);
- SetURLThreatType(iframe_url, SB_THREAT_TYPE_URL_MALWARE);
-
- ui_test_utils::NavigateToURL(browser(), url);
+ GURL url = SetupMalwareIframeWarningAndNavigate();
// If the DOM details from renderer did not already return, wait for them.
details_factory_.get_details()->WaitForDOM();
- SendCommand("\"doReport\""); // Simulate the user checking the checkbox.
- EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean(
- prefs::kSafeBrowsingReportingEnabled));
+ EXPECT_TRUE(Click("check-report"));
- SendCommand("\"proceed\""); // Simulate the user clicking "back"
+ EXPECT_TRUE(ClickAndWaitForDetach("proceed"));
AssertNoInterstitial(true); // Assert the interstitial is gone
+ EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean(
+ prefs::kSafeBrowsingReportingEnabled));
+
EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL());
AssertReportSent();
}
@@ -612,19 +614,105 @@ IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, ProceedDisabled) {
browser()->profile()->GetPrefs()->SetBoolean(
prefs::kSafeBrowsingProceedAnywayDisabled, true);
- GURL url = test_server()->GetURL(kEmptyPage);
- SetURLThreatType(url, SB_THREAT_TYPE_URL_MALWARE);
- ui_test_utils::NavigateToURL(browser(), url);
+ SetupWarningAndNavigate(SB_THREAT_TYPE_URL_MALWARE);
- // The "proceed anyway" link should be hidden.
- bool hidden = false;
- EXPECT_TRUE(GetProceedLinkIsHidden(&hidden));
- EXPECT_TRUE(hidden);
+ EXPECT_EQ(VISIBLE, GetVisibility("check-report"));
+ EXPECT_EQ(HIDDEN, GetVisibility("show-diagnostic-link"));
+ EXPECT_EQ(HIDDEN, GetVisibility("proceed"));
+ EXPECT_EQ(HIDDEN, GetVisibility("proceed-span"));
+ EXPECT_TRUE(Click("see-more-link"));
+ EXPECT_EQ(VISIBLE, GetVisibility("show-diagnostic-link"));
+ EXPECT_EQ(HIDDEN, GetVisibility("proceed"));
+ EXPECT_EQ(HIDDEN, GetVisibility("proceed-span"));
// The "proceed" command should go back instead, if proceeding is disabled.
- SendCommand("\"proceed\"");
+ EXPECT_TRUE(ClickAndWaitForDetach("proceed"));
AssertNoInterstitial(true);
EXPECT_EQ(
- GURL(chrome::kAboutBlankURL), // Back to "about:blank"
+ GURL(chrome::kAboutBlankURL), // Back to "about:blank"
chrome::GetActiveWebContents(browser())->GetURL());
}
+
+// Verifies that the reporting checkbox is hidden on non-HTTP pages.
+// TODO(mattm): Should also verify that no report is sent, but there isn't a
+// good way to do that in the current design.
+IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, ReportingDisabled) {
+ browser()->profile()->GetPrefs()->SetBoolean(
+ prefs::kSafeBrowsingReportingEnabled, true);
+
+ net::TestServer https_server(net::TestServer::TYPE_HTTPS,
+ net::TestServer::kLocalhost,
+ FilePath(FILE_PATH_LITERAL("chrome/test/data")));
+ ASSERT_TRUE(https_server.Start());
+ GURL url = https_server.GetURL(kEmptyPage);
+ SetURLThreatType(url, SB_THREAT_TYPE_URL_MALWARE);
+ ui_test_utils::NavigateToURL(browser(), url);
+ ASSERT_TRUE(WaitForReady());
+
+ EXPECT_EQ(HIDDEN, GetVisibility("check-report"));
+ EXPECT_EQ(HIDDEN, GetVisibility("show-diagnostic-link"));
+ EXPECT_EQ(HIDDEN, GetVisibility("proceed"));
+ EXPECT_TRUE(Click("see-more-link"));
+ EXPECT_EQ(VISIBLE, GetVisibility("show-diagnostic-link"));
+ EXPECT_EQ(VISIBLE, GetVisibility("proceed"));
+
+ EXPECT_TRUE(ClickAndWaitForDetach("back"));
+ AssertNoInterstitial(false); // Assert the interstitial is gone
+ EXPECT_EQ(
+ GURL(chrome::kAboutBlankURL), // Back to "about:blank"
+ chrome::GetActiveWebContents(browser())->GetURL());
+}
+
+IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, PhishingDontProceed) {
+ SetupWarningAndNavigate(SB_THREAT_TYPE_URL_PHISHING);
+
+ EXPECT_EQ(HIDDEN, GetVisibility("malware-icon"));
+ EXPECT_EQ(HIDDEN, GetVisibility("subresource-icon"));
+ EXPECT_EQ(VISIBLE, GetVisibility("phishing-icon"));
+ EXPECT_EQ(HIDDEN, GetVisibility("check-report"));
+ EXPECT_EQ(HIDDEN, GetVisibility("show-diagnostic-link"));
+ EXPECT_EQ(HIDDEN, GetVisibility("report-error-link"));
+ EXPECT_EQ(HIDDEN, GetVisibility("proceed"));
+ EXPECT_TRUE(Click("see-more-link"));
+ EXPECT_EQ(HIDDEN, GetVisibility("show-diagnostic-link"));
+ EXPECT_EQ(VISIBLE, GetVisibility("report-error-link"));
+ EXPECT_EQ(VISIBLE, GetVisibility("proceed"));
+
+ EXPECT_TRUE(ClickAndWaitForDetach("back"));
+ AssertNoInterstitial(false); // Assert the interstitial is gone
+ EXPECT_EQ(
+ GURL(chrome::kAboutBlankURL), // We are back to "about:blank".
+ chrome::GetActiveWebContents(browser())->GetURL());
+}
+
+IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, PhishingProceed) {
+ GURL url = SetupWarningAndNavigate(SB_THREAT_TYPE_URL_PHISHING);
+
+ EXPECT_TRUE(ClickAndWaitForDetach("proceed"));
+ AssertNoInterstitial(true); // Assert the interstitial is gone
+ EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL());
+}
+
+IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, PhishingReportError) {
+ SetupWarningAndNavigate(SB_THREAT_TYPE_URL_PHISHING);
+
+ EXPECT_TRUE(ClickAndWaitForDetach("report-error-link"));
+ AssertNoInterstitial(false); // Assert the interstitial is gone
+
+ // We are in the error reporting page.
+ EXPECT_EQ(
+ "/safebrowsing/report_error/",
+ chrome::GetActiveWebContents(browser())->GetURL().path());
+}
+
+IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, PhishingLearnMore) {
+ SetupWarningAndNavigate(SB_THREAT_TYPE_URL_PHISHING);
+
+ EXPECT_TRUE(ClickAndWaitForDetach("learn-more-link"));
+ AssertNoInterstitial(false); // Assert the interstitial is gone
+
+ // We are in the help page.
+ EXPECT_EQ(
+ "/goodtoknow/online-safety/phishing/",
+ chrome::GetActiveWebContents(browser())->GetURL().path());
+}
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 23fbb4d..da7af73 100644
--- a/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc
@@ -32,11 +32,11 @@ static const char* kBadURL3 = "http://www.badguys3.com/";
namespace {
// A SafeBrowingBlockingPage class that does not create windows.
-class TestSafeBrowsingBlockingPage : public SafeBrowsingBlockingPageV1 {
+class TestSafeBrowsingBlockingPageV1 : public SafeBrowsingBlockingPageV1 {
public:
- TestSafeBrowsingBlockingPage(SafeBrowsingService* service,
- WebContents* web_contents,
- const UnsafeResourceList& unsafe_resources)
+ TestSafeBrowsingBlockingPageV1(SafeBrowsingService* service,
+ WebContents* web_contents,
+ const UnsafeResourceList& unsafe_resources)
: SafeBrowsingBlockingPageV1(service, web_contents, unsafe_resources) {
// Don't delay details at all for the unittest.
malware_details_proceed_delay_ms_ = 0;
@@ -46,6 +46,21 @@ class TestSafeBrowsingBlockingPage : public SafeBrowsingBlockingPageV1 {
}
};
+// A SafeBrowingBlockingPage class that does not create windows.
+class TestSafeBrowsingBlockingPageV2 : public SafeBrowsingBlockingPageV2 {
+ public:
+ TestSafeBrowsingBlockingPageV2(SafeBrowsingService* service,
+ WebContents* web_contents,
+ const UnsafeResourceList& unsafe_resources)
+ : SafeBrowsingBlockingPageV2(service, web_contents, unsafe_resources) {
+ // Don't delay details at all for the unittest.
+ malware_details_proceed_delay_ms_ = 0;
+
+ // Don't create a view.
+ interstitial_page()->DontCreateViewForTesting();
+ }
+};
+
class TestSafeBrowsingService: public SafeBrowsingService {
public:
virtual void SendSerializedMalwareDetails(const std::string& serialized) {
@@ -72,8 +87,16 @@ class TestSafeBrowsingBlockingPageFactory
SafeBrowsingService* service,
WebContents* web_contents,
const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) {
- return new TestSafeBrowsingBlockingPage(service, web_contents,
- unsafe_resources);
+ // TODO(mattm): remove this when SafeBrowsingBlockingPageV2 supports
+ // multi-threat warnings.
+ if (unsafe_resources.size() == 1 &&
+ (unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE ||
+ unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_PHISHING)) {
+ return new TestSafeBrowsingBlockingPageV2(service, web_contents,
+ unsafe_resources);
+ }
+ return new TestSafeBrowsingBlockingPageV1(service, web_contents,
+ unsafe_resources);
}
};
diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page_v2_test.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page_v2_test.cc
deleted file mode 100644
index a27d105..0000000
--- a/chrome/browser/safe_browsing/safe_browsing_blocking_page_v2_test.cc
+++ /dev/null
@@ -1,722 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-//
-// This test creates a fake safebrowsing service, where we can inject
-// malware and phishing urls. It then uses a real browser to go to
-// these urls, and sends "goback" or "proceed" commands and verifies
-// they work.
-//
-// TODO(mattm): remove / merge this file with
-// safe_browsing_blocking_page_test.cc once the SBInterstitial field trial
-// finishes.
-
-#include "base/bind.h"
-#include "base/utf_string_conversions.h"
-#include "base/values.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/safe_browsing/malware_details.h"
-#include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
-#include "chrome/browser/safe_browsing/safe_browsing_service.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_tabstrip.h"
-#include "chrome/browser/ui/tab_contents/tab_contents.h"
-#include "chrome/common/pref_names.h"
-#include "chrome/common/url_constants.h"
-#include "chrome/test/base/in_process_browser_test.h"
-#include "chrome/test/base/ui_test_utils.h"
-#include "content/public/browser/interstitial_page.h"
-#include "content/public/browser/navigation_controller.h"
-#include "content/public/browser/notification_types.h"
-#include "content/public/browser/render_view_host.h"
-#include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_view.h"
-#include "content/public/test/test_browser_thread.h"
-
-using content::BrowserThread;
-using content::InterstitialPage;
-using content::NavigationController;
-using content::WebContents;
-
-namespace {
-
-const char kEmptyPage[] = "files/empty.html";
-const char kMalwarePage[] = "files/safe_browsing/malware.html";
-const char kMalwareIframe[] = "files/safe_browsing/malware_iframe.html";
-
-// A SafeBrowingService class that allows us to inject the malicious URLs.
-class FakeSafeBrowsingService : public SafeBrowsingService {
- public:
- FakeSafeBrowsingService() {}
-
- // Called on the IO thread to check if the given url is safe or not. If we
- // can synchronously determine that the url is safe, CheckUrl returns true.
- // Otherwise it returns false, and "client" is called asynchronously with the
- // result when it is ready.
- // Overrides SafeBrowsingService::CheckBrowseUrl.
- virtual bool CheckBrowseUrl(const GURL& gurl, Client* client) {
- if (badurls[gurl.spec()] == SB_THREAT_TYPE_SAFE)
- return true;
-
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&FakeSafeBrowsingService::OnCheckBrowseURLDone,
- this, gurl, client));
- return false;
- }
-
- void OnCheckBrowseURLDone(const GURL& gurl, Client* client) {
- SafeBrowsingService::SafeBrowsingCheck check;
- check.urls.push_back(gurl);
- check.client = client;
- check.threat_type = badurls[gurl.spec()];
- client->OnSafeBrowsingResult(check);
- }
-
- void SetURLThreatType(const GURL& url, SBThreatType threat_type) {
- badurls[url.spec()] = threat_type;
- }
-
- // Overrides SafeBrowsingService.
- virtual void SendSerializedMalwareDetails(const std::string& serialized) {
- reports_.push_back(serialized);
- // Notify the UI thread that we got a report.
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&FakeSafeBrowsingService::OnMalwareDetailsDone, this));
- }
-
- void OnMalwareDetailsDone() {
- EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI));
- MessageLoopForUI::current()->Quit();
- }
-
- std::string GetReport() {
- EXPECT_TRUE(reports_.size() == 1);
- return reports_[0];
- }
-
- std::vector<std::string> reports_;
-
- private:
- virtual ~FakeSafeBrowsingService() {}
-
- base::hash_map<std::string, SBThreatType> badurls;
-};
-
-// Factory that creates FakeSafeBrowsingService instances.
-class TestSafeBrowsingServiceFactory : public SafeBrowsingServiceFactory {
- public:
- TestSafeBrowsingServiceFactory() { }
- virtual ~TestSafeBrowsingServiceFactory() { }
-
- virtual SafeBrowsingService* CreateSafeBrowsingService() {
- return new FakeSafeBrowsingService();
- }
-};
-
-// A MalwareDetails class lets us intercept calls from the renderer.
-class FakeMalwareDetails : public MalwareDetails {
- public:
- FakeMalwareDetails(SafeBrowsingService* sb_service,
- WebContents* web_contents,
- const SafeBrowsingService::UnsafeResource& unsafe_resource)
- : MalwareDetails(sb_service, web_contents, unsafe_resource),
- got_dom_(false),
- waiting_(false) { }
-
- virtual void AddDOMDetails(
- const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params)
- OVERRIDE {
- EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
- MalwareDetails::AddDOMDetails(params);
-
- // Notify the UI thread that we got the dom details.
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(&FakeMalwareDetails::OnDOMDetailsDone,
- this));
- }
-
- void WaitForDOM() {
- if (got_dom_) {
- LOG(INFO) << "Already got the dom details.";
- return;
- }
- // This condition might not trigger normally, but if you add a
- // sleep(1) in malware_dom_details it triggers :).
- waiting_ = true;
- LOG(INFO) << "Waiting for dom details.";
- content::RunMessageLoop();
- EXPECT_TRUE(got_dom_);
- }
-
- private:
- virtual ~FakeMalwareDetails() {}
-
- void OnDOMDetailsDone() {
- got_dom_ = true;
- if (waiting_) {
- MessageLoopForUI::current()->Quit();
- }
- }
-
- // Some logic to figure out if we should wait for the dom details or not.
- // These variables should only be accessed in the UI thread.
- bool got_dom_;
- bool waiting_;
-};
-
-class TestMalwareDetailsFactory : public MalwareDetailsFactory {
- public:
- TestMalwareDetailsFactory() { }
- virtual ~TestMalwareDetailsFactory() { }
-
- virtual MalwareDetails* CreateMalwareDetails(
- SafeBrowsingService* sb_service,
- WebContents* web_contents,
- const SafeBrowsingService::UnsafeResource& unsafe_resource) OVERRIDE {
- details_ = new FakeMalwareDetails(sb_service, web_contents,
- unsafe_resource);
- return details_;
- }
-
- FakeMalwareDetails* get_details() {
- return details_;
- }
-
- private:
- FakeMalwareDetails* details_;
-};
-
-// A SafeBrowingBlockingPage class that lets us wait until it's hidden.
-class TestSafeBrowsingBlockingPage : public SafeBrowsingBlockingPageV2 {
- public:
- TestSafeBrowsingBlockingPage(SafeBrowsingService* service,
- WebContents* web_contents,
- const UnsafeResourceList& unsafe_resources)
- : SafeBrowsingBlockingPageV2(service, web_contents, unsafe_resources),
- wait_for_delete_(false) {
- // Don't wait the whole 3 seconds for the browser test.
- malware_details_proceed_delay_ms_ = 100;
- }
-
- ~TestSafeBrowsingBlockingPage() {
- if (!wait_for_delete_)
- return;
-
- // Notify that we are gone
- MessageLoopForUI::current()->Quit();
- wait_for_delete_ = false;
- }
-
- void WaitForDelete() {
- wait_for_delete_ = true;
- content::RunMessageLoop();
- }
-
- private:
- bool wait_for_delete_;
-};
-
-class TestSafeBrowsingBlockingPageFactory
- : public SafeBrowsingBlockingPageFactory {
- public:
- TestSafeBrowsingBlockingPageFactory() { }
- ~TestSafeBrowsingBlockingPageFactory() { }
-
- virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage(
- SafeBrowsingService* service,
- WebContents* web_contents,
- const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources)
- OVERRIDE {
- return new TestSafeBrowsingBlockingPage(service, web_contents,
- unsafe_resources);
- }
-};
-
-} // namespace
-
-// Tests the safe browsing blocking page in a browser.
-class SafeBrowsingBlockingPageV2Test : public InProcessBrowserTest {
- public:
- enum Visibility {
- VISIBILITY_ERROR = -1,
- HIDDEN = 0,
- VISIBLE = 1,
- };
-
- SafeBrowsingBlockingPageV2Test() {
- }
-
- virtual void SetUp() OVERRIDE {
- SafeBrowsingService::RegisterFactory(&factory_);
- SafeBrowsingBlockingPage::RegisterFactory(&blocking_page_factory_);
- MalwareDetails::RegisterFactory(&details_factory_);
- InProcessBrowserTest::SetUp();
- }
-
- virtual void TearDown() OVERRIDE {
- InProcessBrowserTest::TearDown();
- SafeBrowsingBlockingPage::RegisterFactory(NULL);
- SafeBrowsingService::RegisterFactory(NULL);
- MalwareDetails::RegisterFactory(NULL);
- }
-
- virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
- ASSERT_TRUE(test_server()->Start());
- }
-
- void SetURLThreatType(const GURL& url, SBThreatType threat_type) {
- FakeSafeBrowsingService* service =
- static_cast<FakeSafeBrowsingService*>(
- g_browser_process->safe_browsing_service());
-
- ASSERT_TRUE(service);
- service->SetURLThreatType(url, threat_type);
- }
-
- // Adds a safebrowsing result of type |threat_type| to the fake safebrowsing
- // service, navigates to that page, and returns the url.
- GURL SetupWarningAndNavigate(SBThreatType threat_type) {
- GURL url = test_server()->GetURL(kEmptyPage);
- SetURLThreatType(url, threat_type);
-
- ui_test_utils::NavigateToURL(browser(), url);
- EXPECT_TRUE(WaitForReady());
- return url;
- }
-
- // Adds a safebrowsing malware result to the fake safebrowsing service,
- // navigates to a page with an iframe containing the malware site, and
- // returns the url of the parent page.
- GURL SetupMalwareIframeWarningAndNavigate() {
- GURL url = test_server()->GetURL(kMalwarePage);
- GURL iframe_url = test_server()->GetURL(kMalwareIframe);
- SetURLThreatType(iframe_url, SB_THREAT_TYPE_URL_MALWARE);
-
- ui_test_utils::NavigateToURL(browser(), url);
- EXPECT_TRUE(WaitForReady());
- return url;
- }
-
- void SendCommand(const std::string& command) {
- WebContents* contents = chrome::GetActiveWebContents(browser());
- // We use InterstitialPage::GetInterstitialPage(tab) instead of
- // tab->GetInterstitialPage() because the tab doesn't have a pointer
- // to its interstital page until it gets a command from the renderer
- // that it has indeed displayed it -- and this sometimes happens after
- // NavigateToURL returns.
- SafeBrowsingBlockingPage* interstitial_page =
- static_cast<SafeBrowsingBlockingPage*>(
- InterstitialPage::GetInterstitialPage(contents)->
- GetDelegateForTesting());
- ASSERT_TRUE(interstitial_page);
- interstitial_page->CommandReceived(command);
- }
-
- void DontProceedThroughInterstitial() {
- WebContents* contents = chrome::GetActiveWebContents(browser());
- InterstitialPage* interstitial_page = InterstitialPage::GetInterstitialPage(
- contents);
- ASSERT_TRUE(interstitial_page);
- interstitial_page->DontProceed();
- }
-
- void ProceedThroughInterstitial() {
- WebContents* contents = chrome::GetActiveWebContents(browser());
- InterstitialPage* interstitial_page = InterstitialPage::GetInterstitialPage(
- contents);
- ASSERT_TRUE(interstitial_page);
- interstitial_page->Proceed();
- }
-
- void AssertNoInterstitial(bool wait_for_delete) {
- WebContents* contents = chrome::GetActiveWebContents(browser());
-
- if (contents->ShowingInterstitialPage() && wait_for_delete) {
- // We'll get notified when the interstitial is deleted.
- TestSafeBrowsingBlockingPage* page =
- static_cast<TestSafeBrowsingBlockingPage*>(
- contents->GetInterstitialPage()->GetDelegateForTesting());
- page->WaitForDelete();
- }
-
- // Can't use InterstitialPage::GetInterstitialPage() because that
- // gets updated after the TestSafeBrowsingBlockingPage destructor
- ASSERT_FALSE(contents->ShowingInterstitialPage());
- }
-
- bool YesInterstitial() {
- WebContents* contents = chrome::GetActiveWebContents(browser());
- InterstitialPage* interstitial_page = InterstitialPage::GetInterstitialPage(
- contents);
- return interstitial_page != NULL;
- }
-
- void WaitForInterstitial() {
- WebContents* contents = chrome::GetActiveWebContents(browser());
- content::WindowedNotificationObserver interstitial_observer(
- content::NOTIFICATION_INTERSTITIAL_ATTACHED,
- content::Source<WebContents>(contents));
- if (!InterstitialPage::GetInterstitialPage(contents))
- interstitial_observer.Wait();
- }
-
- void AssertReportSent() {
- // When a report is scheduled in the IO thread we should get notified.
- content::RunMessageLoop();
-
- FakeSafeBrowsingService* service =
- static_cast<FakeSafeBrowsingService*>(
- g_browser_process->safe_browsing_service());
-
- std::string serialized = service->GetReport();
-
- safe_browsing::ClientMalwareReportRequest report;
- ASSERT_TRUE(report.ParseFromString(serialized));
-
- // Verify the report is complete.
- EXPECT_TRUE(report.complete());
- }
-
- void MalwareRedirectCancelAndProceed(const std::string open_function) {
- GURL load_url = test_server()->GetURL(
- "files/safe_browsing/interstitial_cancel.html");
- GURL malware_url("http://localhost/files/safe_browsing/malware.html");
- SetURLThreatType(malware_url, SB_THREAT_TYPE_URL_MALWARE);
-
- // Load the test page.
- ui_test_utils::NavigateToURL(browser(), load_url);
- // Trigger the safe browsing interstitial page via a redirect in
- // "openWin()".
- ui_test_utils::NavigateToURLWithDisposition(
- browser(),
- GURL("javascript:" + open_function + "()"),
- CURRENT_TAB,
- ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
- WaitForInterstitial();
- // Cancel the redirect request while interstitial page is open.
- chrome::ActivateTabAt(browser(), 0, true);
- ui_test_utils::NavigateToURLWithDisposition(
- browser(),
- GURL("javascript:stopWin()"),
- CURRENT_TAB,
- ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
- chrome::ActivateTabAt(browser(), 1, true);
- // Simulate the user clicking "proceed", there should be no crash. Since
- // clicking proceed may do nothing (see comment in MalwareRedirectCanceled
- // below, and crbug.com/76460), we use SendCommand to trigger the callback
- // directly rather than using ClickAndWaitForDetach since there might not
- // be a notification to wait for.
- SendCommand("\"proceed\"");
- }
-
- content::RenderViewHost* GetRenderViewHost() {
- InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage(
- chrome::GetActiveWebContents(browser()));
- if (!interstitial)
- return NULL;
- return interstitial->GetRenderViewHostForTesting();
- }
-
- bool WaitForReady() {
- content::RenderViewHost* rvh = GetRenderViewHost();
- if (!rvh)
- return false;
- // Wait until all <script> tags have executed, including jstemplate.
- // TODO(joaodasilva): it would be nice to avoid the busy loop, though in
- // practice it spins at most once or twice.
- std::string ready_state;
- do {
- scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(
- string16(),
- ASCIIToUTF16("document.readyState")));
- if (!value.get() || !value->GetAsString(&ready_state))
- return false;
- } while (ready_state != "complete");
- return true;
- }
-
- Visibility GetVisibility(const std::string& node_id) {
- content::RenderViewHost* rvh = GetRenderViewHost();
- if (!rvh)
- return VISIBILITY_ERROR;
- scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(
- string16(),
- ASCIIToUTF16(
- "var node = document.getElementById('" + node_id + "');\n"
- "if (node)\n"
- " node.offsetWidth > 0 && node.offsetHeight > 0;"
- "else\n"
- " 'node not found';\n")));
- if (!value.get())
- return VISIBILITY_ERROR;
- bool result = false;
- if (!value->GetAsBoolean(&result))
- return VISIBILITY_ERROR;
- return result ? VISIBLE : HIDDEN;
- }
-
- bool Click(const std::string& node_id) {
- content::RenderViewHost* rvh = GetRenderViewHost();
- if (!rvh)
- return false;
- // We don't use ExecuteJavascriptAndGetValue for this one, since clicking
- // the button/link may navigate away before the injected javascript can
- // reply, hanging the test.
- rvh->ExecuteJavascriptInWebFrame(
- string16(),
- ASCIIToUTF16("document.getElementById('" + node_id + "').click();\n"));
- return true;
- }
-
- bool ClickAndWaitForDetach(const std::string& node_id) {
- // We wait for interstitial_detached rather than nav_entry_committed, as
- // going back from a main-frame malware interstitial page will not cause a
- // nav entry committed event.
- content::WindowedNotificationObserver observer(
- content::NOTIFICATION_INTERSTITIAL_DETACHED,
- content::Source<WebContents>(chrome::GetActiveWebContents(browser())));
- if (!Click(node_id))
- return false;
- observer.Wait();
- return true;
- }
-
- protected:
- TestMalwareDetailsFactory details_factory_;
-
- private:
- TestSafeBrowsingServiceFactory factory_;
- TestSafeBrowsingBlockingPageFactory blocking_page_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageV2Test);
-};
-
-IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageV2Test,
- MalwareRedirectInIFrameCanceled) {
- // 1. Test the case that redirect is a subresource.
- MalwareRedirectCancelAndProceed("openWinIFrame");
- // If the redirect was from subresource but canceled, "proceed" will continue
- // with the rest of resources.
- AssertNoInterstitial(true);
-}
-
-IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageV2Test,
- MalwareRedirectCanceled) {
- // 2. Test the case that redirect is the only resource.
- MalwareRedirectCancelAndProceed("openWin");
- // Clicking proceed won't do anything if the main request is cancelled
- // already. See crbug.com/76460.
- EXPECT_TRUE(YesInterstitial());
-}
-
-IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageV2Test, MalwareDontProceed) {
- SetupWarningAndNavigate(SB_THREAT_TYPE_URL_MALWARE);
-
- EXPECT_EQ(VISIBLE, GetVisibility("malware-icon"));
- EXPECT_EQ(HIDDEN, GetVisibility("subresource-icon"));
- EXPECT_EQ(HIDDEN, GetVisibility("phishing-icon"));
- EXPECT_EQ(VISIBLE, GetVisibility("check-report"));
- EXPECT_EQ(HIDDEN, GetVisibility("show-diagnostic-link"));
- EXPECT_EQ(HIDDEN, GetVisibility("report-error-link"));
- EXPECT_EQ(HIDDEN, GetVisibility("proceed"));
- EXPECT_TRUE(Click("see-more-link"));
- EXPECT_EQ(VISIBLE, GetVisibility("show-diagnostic-link"));
- EXPECT_EQ(HIDDEN, GetVisibility("report-error-link"));
- EXPECT_EQ(VISIBLE, GetVisibility("proceed"));
-
- EXPECT_TRUE(ClickAndWaitForDetach("back"));
- AssertNoInterstitial(false); // Assert the interstitial is gone
- EXPECT_EQ(
- GURL(chrome::kAboutBlankURL), // Back to "about:blank"
- chrome::GetActiveWebContents(browser())->GetURL());
-}
-
-IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageV2Test, MalwareProceed) {
- GURL url = SetupWarningAndNavigate(SB_THREAT_TYPE_URL_MALWARE);
-
- EXPECT_TRUE(ClickAndWaitForDetach("proceed"));
- AssertNoInterstitial(true); // Assert the interstitial is gone.
- EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL());
-}
-
-IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageV2Test,
- MalwareLearnMore) {
- SetupWarningAndNavigate(SB_THREAT_TYPE_URL_MALWARE);
-
- EXPECT_TRUE(ClickAndWaitForDetach("learn-more-link"));
- AssertNoInterstitial(false); // Assert the interstitial is gone
-
- // We are in the help page.
- EXPECT_EQ(
- "/goodtoknow/online-safety/malware/",
- chrome::GetActiveWebContents(browser())->GetURL().path());
-}
-
-IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageV2Test,
- MalwareIframeDontProceed) {
- SetupMalwareIframeWarningAndNavigate();
-
- EXPECT_EQ(HIDDEN, GetVisibility("malware-icon"));
- EXPECT_EQ(VISIBLE, GetVisibility("subresource-icon"));
- EXPECT_EQ(HIDDEN, GetVisibility("phishing-icon"));
- EXPECT_EQ(VISIBLE, GetVisibility("check-report"));
- EXPECT_EQ(HIDDEN, GetVisibility("show-diagnostic-link"));
- EXPECT_EQ(HIDDEN, GetVisibility("report-error-link"));
- EXPECT_EQ(HIDDEN, GetVisibility("proceed"));
- EXPECT_TRUE(Click("see-more-link"));
- EXPECT_EQ(VISIBLE, GetVisibility("show-diagnostic-link"));
- EXPECT_EQ(HIDDEN, GetVisibility("report-error-link"));
- EXPECT_EQ(VISIBLE, GetVisibility("proceed"));
-
- EXPECT_TRUE(ClickAndWaitForDetach("back"));
- AssertNoInterstitial(false); // Assert the interstitial is gone
-
- EXPECT_EQ(
- GURL(chrome::kAboutBlankURL), // Back to "about:blank"
- chrome::GetActiveWebContents(browser())->GetURL());
-}
-
-// Crashy, http://crbug.com/68834.
-IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageV2Test,
- DISABLED_MalwareIframeProceed) {
- GURL url = SetupMalwareIframeWarningAndNavigate();
-
- EXPECT_TRUE(ClickAndWaitForDetach("proceed"));
- AssertNoInterstitial(true); // Assert the interstitial is gone
-
- EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL());
-}
-
-IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageV2Test,
- MalwareIframeReportDetails) {
- GURL url = SetupMalwareIframeWarningAndNavigate();
-
- // If the DOM details from renderer did not already return, wait for them.
- details_factory_.get_details()->WaitForDOM();
-
- EXPECT_TRUE(Click("check-report"));
-
- EXPECT_TRUE(ClickAndWaitForDetach("proceed"));
- AssertNoInterstitial(true); // Assert the interstitial is gone
-
- EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean(
- prefs::kSafeBrowsingReportingEnabled));
-
- EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL());
- AssertReportSent();
-}
-
-// Verifies that the "proceed anyway" link isn't available when it is disabled
-// by the corresponding policy. Also verifies that sending the "proceed"
-// command anyway doesn't advance to the malware site.
-IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageV2Test, ProceedDisabled) {
- // Simulate a policy disabling the "proceed anyway" link.
- browser()->profile()->GetPrefs()->SetBoolean(
- prefs::kSafeBrowsingProceedAnywayDisabled, true);
-
- SetupWarningAndNavigate(SB_THREAT_TYPE_URL_MALWARE);
-
- EXPECT_EQ(VISIBLE, GetVisibility("check-report"));
- EXPECT_EQ(HIDDEN, GetVisibility("show-diagnostic-link"));
- EXPECT_EQ(HIDDEN, GetVisibility("proceed"));
- EXPECT_EQ(HIDDEN, GetVisibility("proceed-span"));
- EXPECT_TRUE(Click("see-more-link"));
- EXPECT_EQ(VISIBLE, GetVisibility("show-diagnostic-link"));
- EXPECT_EQ(HIDDEN, GetVisibility("proceed"));
- EXPECT_EQ(HIDDEN, GetVisibility("proceed-span"));
-
- // The "proceed" command should go back instead, if proceeding is disabled.
- EXPECT_TRUE(ClickAndWaitForDetach("proceed"));
- AssertNoInterstitial(true);
- EXPECT_EQ(
- GURL(chrome::kAboutBlankURL), // Back to "about:blank"
- chrome::GetActiveWebContents(browser())->GetURL());
-}
-
-// Verifies that the reporting checkbox is hidden on non-HTTP pages.
-// TODO(mattm): Should also verify that no report is sent, but there isn't a
-// good way to do that in the current design.
-IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageV2Test, ReportingDisabled) {
- browser()->profile()->GetPrefs()->SetBoolean(
- prefs::kSafeBrowsingReportingEnabled, true);
-
- net::TestServer https_server(net::TestServer::TYPE_HTTPS,
- net::TestServer::kLocalhost,
- FilePath(FILE_PATH_LITERAL("chrome/test/data")));
- ASSERT_TRUE(https_server.Start());
- GURL url = https_server.GetURL(kEmptyPage);
- SetURLThreatType(url, SB_THREAT_TYPE_URL_MALWARE);
- ui_test_utils::NavigateToURL(browser(), url);
- ASSERT_TRUE(WaitForReady());
-
- EXPECT_EQ(HIDDEN, GetVisibility("check-report"));
- EXPECT_EQ(HIDDEN, GetVisibility("show-diagnostic-link"));
- EXPECT_EQ(HIDDEN, GetVisibility("proceed"));
- EXPECT_TRUE(Click("see-more-link"));
- EXPECT_EQ(VISIBLE, GetVisibility("show-diagnostic-link"));
- EXPECT_EQ(VISIBLE, GetVisibility("proceed"));
-
- EXPECT_TRUE(ClickAndWaitForDetach("back"));
- AssertNoInterstitial(false); // Assert the interstitial is gone
- EXPECT_EQ(
- GURL(chrome::kAboutBlankURL), // Back to "about:blank"
- chrome::GetActiveWebContents(browser())->GetURL());
-}
-
-IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageV2Test, PhishingDontProceed) {
- SetupWarningAndNavigate(SB_THREAT_TYPE_URL_PHISHING);
-
- EXPECT_EQ(HIDDEN, GetVisibility("malware-icon"));
- EXPECT_EQ(HIDDEN, GetVisibility("subresource-icon"));
- EXPECT_EQ(VISIBLE, GetVisibility("phishing-icon"));
- EXPECT_EQ(HIDDEN, GetVisibility("check-report"));
- EXPECT_EQ(HIDDEN, GetVisibility("show-diagnostic-link"));
- EXPECT_EQ(HIDDEN, GetVisibility("report-error-link"));
- EXPECT_EQ(HIDDEN, GetVisibility("proceed"));
- EXPECT_TRUE(Click("see-more-link"));
- EXPECT_EQ(HIDDEN, GetVisibility("show-diagnostic-link"));
- EXPECT_EQ(VISIBLE, GetVisibility("report-error-link"));
- EXPECT_EQ(VISIBLE, GetVisibility("proceed"));
-
- EXPECT_TRUE(ClickAndWaitForDetach("back"));
- AssertNoInterstitial(false); // Assert the interstitial is gone
- EXPECT_EQ(
- GURL(chrome::kAboutBlankURL), // We are back to "about:blank".
- chrome::GetActiveWebContents(browser())->GetURL());
-}
-
-IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageV2Test, PhishingProceed) {
- GURL url = SetupWarningAndNavigate(SB_THREAT_TYPE_URL_PHISHING);
-
- EXPECT_TRUE(ClickAndWaitForDetach("proceed"));
- AssertNoInterstitial(true); // Assert the interstitial is gone
- EXPECT_EQ(url, chrome::GetActiveWebContents(browser())->GetURL());
-}
-
-IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageV2Test, PhishingReportError) {
- SetupWarningAndNavigate(SB_THREAT_TYPE_URL_PHISHING);
-
- EXPECT_TRUE(ClickAndWaitForDetach("report-error-link"));
- AssertNoInterstitial(false); // Assert the interstitial is gone
-
- // We are in the error reporting page.
- EXPECT_EQ(
- "/safebrowsing/report_error/",
- chrome::GetActiveWebContents(browser())->GetURL().path());
-}
-
-IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageV2Test, PhishingLearnMore) {
- SetupWarningAndNavigate(SB_THREAT_TYPE_URL_PHISHING);
-
- EXPECT_TRUE(ClickAndWaitForDetach("learn-more-link"));
- AssertNoInterstitial(false); // Assert the interstitial is gone
-
- // We are in the help page.
- EXPECT_EQ(
- "/goodtoknow/online-safety/phishing/",
- chrome::GetActiveWebContents(browser())->GetURL().path());
-}
diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page_v2_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page_v2_unittest.cc
deleted file mode 100644
index fd3afce..0000000
--- a/chrome/browser/safe_browsing/safe_browsing_blocking_page_v2_unittest.cc
+++ /dev/null
@@ -1,537 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-//
-// TODO(mattm): remove / merge this file with
-// safe_browsing_blocking_page_unittest.cc once the SBInterstitial field trial
-// finishes.
-
-#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/safe_browsing/malware_details.h"
-#include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
-#include "chrome/common/pref_names.h"
-#include "chrome/test/base/chrome_render_view_host_test_harness.h"
-#include "content/public/browser/interstitial_page.h"
-#include "content/public/browser/navigation_entry.h"
-#include "content/public/browser/render_process_host.h"
-#include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_view.h"
-#include "content/public/test/test_browser_thread.h"
-#include "content/public/test/web_contents_tester.h"
-
-using content::BrowserThread;
-using content::InterstitialPage;
-using content::NavigationEntry;
-using content::WebContents;
-using content::WebContentsTester;
-using content::WebContentsView;
-
-static const char* kGoogleURL = "http://www.google.com/";
-static const char* kGoodURL = "http://www.goodguys.com/";
-static const char* kBadURL = "http://www.badguys.com/";
-static const char* kBadURL2 = "http://www.badguys2.com/";
-static const char* kBadURL3 = "http://www.badguys3.com/";
-
-namespace {
-
-// A SafeBrowingBlockingPage class that does not create windows.
-class TestSafeBrowsingBlockingPage : public SafeBrowsingBlockingPageV2 {
- public:
- TestSafeBrowsingBlockingPage(SafeBrowsingService* service,
- WebContents* web_contents,
- const UnsafeResourceList& unsafe_resources)
- : SafeBrowsingBlockingPageV2(service, web_contents, unsafe_resources) {
- // Don't delay details at all for the unittest.
- malware_details_proceed_delay_ms_ = 0;
-
- // Don't create a view.
- interstitial_page()->DontCreateViewForTesting();
- }
-};
-
-class TestSafeBrowsingService: public SafeBrowsingService {
- public:
- virtual void SendSerializedMalwareDetails(const std::string& serialized) {
- details_.push_back(serialized);
- }
-
- std::list<std::string>* GetDetails() {
- return &details_;
- }
-
- private:
- virtual ~TestSafeBrowsingService() {}
-
- std::list<std::string> details_;
-};
-
-class TestSafeBrowsingBlockingPageFactory
- : public SafeBrowsingBlockingPageFactory {
- public:
- TestSafeBrowsingBlockingPageFactory() { }
- ~TestSafeBrowsingBlockingPageFactory() { }
-
- virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage(
- SafeBrowsingService* service,
- WebContents* web_contents,
- const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) {
- return new TestSafeBrowsingBlockingPage(service, web_contents,
- unsafe_resources);
- }
-};
-
-} // namespace
-
-class SafeBrowsingBlockingPageV2Test : public ChromeRenderViewHostTestHarness {
- public:
- // The decision the user made.
- enum UserResponse {
- PENDING,
- OK,
- CANCEL
- };
-
- SafeBrowsingBlockingPageV2Test()
- : ui_thread_(BrowserThread::UI, MessageLoop::current()),
- file_user_blocking_thread_(
- BrowserThread::FILE_USER_BLOCKING, MessageLoop::current()),
- io_thread_(BrowserThread::IO, MessageLoop::current()) {
- ResetUserResponse();
- service_ = new TestSafeBrowsingService();
- }
-
- virtual void SetUp() {
- ChromeRenderViewHostTestHarness::SetUp();
- SafeBrowsingBlockingPage::RegisterFactory(&factory_);
- MalwareDetails::RegisterFactory(NULL); // Create it fresh each time.
- ResetUserResponse();
- }
-
- virtual void TearDown() {
- // Release the SafeBrowsingService before the BrowserThreads are destroyed.
- service_ = NULL;
- ChromeRenderViewHostTestHarness::TearDown();
- }
-
- void OnBlockingPageComplete(bool proceed) {
- if (proceed)
- user_response_ = OK;
- else
- user_response_ = CANCEL;
- }
-
- void Navigate(const char* url, int page_id) {
- WebContentsTester::For(web_contents())->TestDidNavigate(
- web_contents()->GetRenderViewHost(), page_id, GURL(url),
- content::PAGE_TRANSITION_TYPED);
- }
-
- void GoBack(bool is_cross_site) {
- NavigationEntry* entry =
- web_contents()->GetController().GetEntryAtOffset(-1);
- ASSERT_TRUE(entry);
- web_contents()->GetController().GoBack();
-
- // The pending RVH should commit for cross-site navigations.
- content::RenderViewHost* rvh = is_cross_site ?
- WebContentsTester::For(web_contents())->GetPendingRenderViewHost() :
- web_contents()->GetRenderViewHost();
- WebContentsTester::For(web_contents())->TestDidNavigate(
- rvh,
- entry->GetPageID(),
- GURL(entry->GetURL()),
- content::PAGE_TRANSITION_TYPED);
- }
-
- void ShowInterstitial(bool is_subresource, const char* url) {
- SafeBrowsingService::UnsafeResource resource;
- InitResource(&resource, is_subresource, GURL(url));
- SafeBrowsingBlockingPage::ShowBlockingPage(service_, resource);
- }
-
- // Returns the SafeBrowsingBlockingPage currently showing or NULL if none is
- // showing.
- SafeBrowsingBlockingPage* GetSafeBrowsingBlockingPage() {
- InterstitialPage* interstitial =
- InterstitialPage::GetInterstitialPage(web_contents());
- if (!interstitial)
- return NULL;
- return static_cast<SafeBrowsingBlockingPage*>(
- interstitial->GetDelegateForTesting());
- }
-
- UserResponse user_response() const { return user_response_; }
- void ResetUserResponse() { user_response_ = PENDING; }
-
- static void ProceedThroughInterstitial(
- SafeBrowsingBlockingPage* sb_interstitial) {
- sb_interstitial->interstitial_page_->Proceed();
- // Proceed() posts a task to update the SafeBrowsingService::Client.
- MessageLoop::current()->RunAllPending();
- }
-
- static void DontProceedThroughInterstitial(
- SafeBrowsingBlockingPage* sb_interstitial) {
- sb_interstitial->interstitial_page_->DontProceed();
- // DontProceed() posts a task to update the SafeBrowsingService::Client.
- MessageLoop::current()->RunAllPending();
- }
-
- void DontProceedThroughSubresourceInterstitial(
- SafeBrowsingBlockingPage* sb_interstitial) {
- // CommandReceived(kTakeMeBackCommand) does a back navigation for
- // subresource interstitials.
- GoBack(false);
- // DontProceed() posts a task to update the SafeBrowsingService::Client.
- MessageLoop::current()->RunAllPending();
- }
-
- scoped_refptr<TestSafeBrowsingService> service_;
-
- private:
- void InitResource(SafeBrowsingService::UnsafeResource* resource,
- bool is_subresource,
- const GURL& url) {
- resource->callback =
- base::Bind(&SafeBrowsingBlockingPageV2Test::OnBlockingPageComplete,
- base::Unretained(this));
- resource->url = url;
- resource->is_subresource = is_subresource;
- resource->threat_type = SB_THREAT_TYPE_URL_MALWARE;
- resource->render_process_host_id =
- web_contents()->GetRenderProcessHost()->GetID();
- resource->render_view_id =
- web_contents()->GetRenderViewHost()->GetRoutingID();
- }
-
- UserResponse user_response_;
- TestSafeBrowsingBlockingPageFactory factory_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread file_user_blocking_thread_;
- content::TestBrowserThread io_thread_;
-};
-
-// Tests showing a blocking page for a malware page and not proceeding.
-TEST_F(SafeBrowsingBlockingPageV2Test, MalwarePageDontProceed) {
- // Enable malware details.
- Profile* profile = Profile::FromBrowserContext(
- web_contents()->GetBrowserContext());
- profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true);
-
- // Start a load.
- controller().LoadURL(GURL(kBadURL), content::Referrer(),
- content::PAGE_TRANSITION_TYPED, std::string());
-
-
- // Simulate the load causing a safe browsing interstitial to be shown.
- ShowInterstitial(false, kBadURL);
- SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
- ASSERT_TRUE(sb_interstitial);
-
- MessageLoop::current()->RunAllPending();
-
- // Simulate the user clicking "don't proceed".
- DontProceedThroughInterstitial(sb_interstitial);
-
- // The interstitial should be gone.
- EXPECT_EQ(CANCEL, user_response());
- EXPECT_FALSE(GetSafeBrowsingBlockingPage());
-
- // We did not proceed, the pending entry should be gone.
- EXPECT_FALSE(controller().GetPendingEntry());
-
- // A report should have been sent.
- EXPECT_EQ(1u, service_->GetDetails()->size());
- service_->GetDetails()->clear();
-}
-
-// Tests showing a blocking page for a malware page and then proceeding.
-TEST_F(SafeBrowsingBlockingPageV2Test, MalwarePageProceed) {
- // Enable malware reports.
- Profile* profile = Profile::FromBrowserContext(
- web_contents()->GetBrowserContext());
- profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true);
-
- // Start a load.
- controller().LoadURL(GURL(kBadURL), content::Referrer(),
- content::PAGE_TRANSITION_TYPED, std::string());
-
- // Simulate the load causing a safe browsing interstitial to be shown.
- ShowInterstitial(false, kBadURL);
- SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
- ASSERT_TRUE(sb_interstitial);
-
- // Simulate the user clicking "proceed".
- ProceedThroughInterstitial(sb_interstitial);
-
- // The interstitial is shown until the navigation commits.
- ASSERT_TRUE(InterstitialPage::GetInterstitialPage(web_contents()));
- // Commit the navigation.
- Navigate(kBadURL, 1);
- // The interstitial should be gone now.
- ASSERT_FALSE(InterstitialPage::GetInterstitialPage(web_contents()));
-
- // A report should have been sent.
- EXPECT_EQ(1u, service_->GetDetails()->size());
- service_->GetDetails()->clear();
-}
-
-// Tests showing a blocking page for a page that contains malware subresources
-// and not proceeding.
-TEST_F(SafeBrowsingBlockingPageV2Test, PageWithMalwareResourceDontProceed) {
- // Enable malware reports.
- Profile* profile = Profile::FromBrowserContext(
- web_contents()->GetBrowserContext());
- profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true);
-
- // Navigate somewhere.
- Navigate(kGoogleURL, 1);
-
- // Navigate somewhere else.
- Navigate(kGoodURL, 2);
-
- // Simulate that page loading a bad-resource triggering an interstitial.
- ShowInterstitial(true, kBadURL);
-
- SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
- ASSERT_TRUE(sb_interstitial);
-
- // Simulate the user clicking "don't proceed".
- DontProceedThroughSubresourceInterstitial(sb_interstitial);
- EXPECT_EQ(CANCEL, user_response());
- EXPECT_FALSE(GetSafeBrowsingBlockingPage());
-
- // We did not proceed, we should be back to the first page, the 2nd one should
- // have been removed from the navigation controller.
- ASSERT_EQ(1, controller().GetEntryCount());
- EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec());
-
- // A report should have been sent.
- EXPECT_EQ(1u, service_->GetDetails()->size());
- service_->GetDetails()->clear();
-}
-
-// Tests showing a blocking page for a page that contains malware subresources
-// and proceeding.
-TEST_F(SafeBrowsingBlockingPageV2Test, PageWithMalwareResourceProceed) {
- // Enable malware reports.
- Profile* profile = Profile::FromBrowserContext(
- web_contents()->GetBrowserContext());
- profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true);
-
- // Navigate somewhere.
- Navigate(kGoodURL, 1);
-
- // Simulate that page loading a bad-resource triggering an interstitial.
- ShowInterstitial(true, kBadURL);
-
- SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
- ASSERT_TRUE(sb_interstitial);
-
- // Simulate the user clicking "proceed".
- ProceedThroughInterstitial(sb_interstitial);
- EXPECT_EQ(OK, user_response());
- EXPECT_FALSE(GetSafeBrowsingBlockingPage());
-
- // We did proceed, we should be back to showing the page.
- ASSERT_EQ(1, controller().GetEntryCount());
- EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->GetURL().spec());
-
- // A report should have been sent.
- EXPECT_EQ(1u, service_->GetDetails()->size());
- service_->GetDetails()->clear();
-}
-
-// Tests showing a blocking page for a page that contains multiple malware
-// subresources and not proceeding. This just tests that the extra malware
-// subresources (which trigger queued interstitial pages) do not break anything.
-TEST_F(SafeBrowsingBlockingPageV2Test,
- PageWithMultipleMalwareResourceDontProceed) {
- // Enable malware reports.
- Profile* profile = Profile::FromBrowserContext(
- web_contents()->GetBrowserContext());
- profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true);
-
- // Navigate somewhere.
- Navigate(kGoogleURL, 1);
-
- // Navigate somewhere else.
- Navigate(kGoodURL, 2);
-
- // Simulate that page loading a bad-resource triggering an interstitial.
- ShowInterstitial(true, kBadURL);
-
- // More bad resources loading causing more interstitials. The new
- // interstitials should be queued.
- ShowInterstitial(true, kBadURL2);
- ShowInterstitial(true, kBadURL3);
-
- SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
- ASSERT_TRUE(sb_interstitial);
-
- // Simulate the user clicking "don't proceed".
- DontProceedThroughSubresourceInterstitial(sb_interstitial);
- EXPECT_EQ(CANCEL, user_response());
- EXPECT_FALSE(GetSafeBrowsingBlockingPage());
-
- // We did not proceed, we should be back to the first page, the 2nd one should
- // have been removed from the navigation controller.
- ASSERT_EQ(1, controller().GetEntryCount());
- EXPECT_EQ(kGoogleURL, controller().GetActiveEntry()->GetURL().spec());
-
- // A report should have been sent.
- EXPECT_EQ(1u, service_->GetDetails()->size());
- service_->GetDetails()->clear();
-}
-
-// Tests showing a blocking page then navigating back and forth to make sure the
-// controller entries are OK. http://crbug.com/17627
-TEST_F(SafeBrowsingBlockingPageV2Test, NavigatingBackAndForth) {
- // Enable malware reports.
- Profile* profile = Profile::FromBrowserContext(
- web_contents()->GetBrowserContext());
- profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true);
-
- // Navigate somewhere.
- Navigate(kGoodURL, 1);
-
- // Now navigate to a bad page triggerring an interstitial.
- controller().LoadURL(GURL(kBadURL), content::Referrer(),
- content::PAGE_TRANSITION_TYPED, std::string());
- ShowInterstitial(false, kBadURL);
- SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
- ASSERT_TRUE(sb_interstitial);
-
- // Proceed, then navigate back.
- ProceedThroughInterstitial(sb_interstitial);
- Navigate(kBadURL, 2); // Commit the navigation.
- GoBack(true);
-
- // We are back on the good page.
- sb_interstitial = GetSafeBrowsingBlockingPage();
- ASSERT_FALSE(sb_interstitial);
- ASSERT_EQ(2, controller().GetEntryCount());
- EXPECT_EQ(kGoodURL, controller().GetActiveEntry()->GetURL().spec());
-
- // Navigate forward to the malware URL.
- web_contents()->GetController().GoForward();
- 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.
- sb_interstitial = GetSafeBrowsingBlockingPage();
- ASSERT_FALSE(sb_interstitial);
- ASSERT_EQ(2, controller().GetEntryCount());
- EXPECT_EQ(kBadURL, controller().GetActiveEntry()->GetURL().spec());
-
- // Two reports should have been sent.
- EXPECT_EQ(2u, service_->GetDetails()->size());
- service_->GetDetails()->clear();
-}
-
-// Tests that calling "don't proceed" after "proceed" has been called doesn't
-// cause problems. http://crbug.com/30079
-TEST_F(SafeBrowsingBlockingPageV2Test, ProceedThenDontProceed) {
- // Enable malware reports.
- Profile* profile = Profile::FromBrowserContext(
- web_contents()->GetBrowserContext());
- profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, true);
-
- // Start a load.
- controller().LoadURL(GURL(kBadURL), content::Referrer(),
- content::PAGE_TRANSITION_TYPED, std::string());
-
- // Simulate the load causing a safe browsing interstitial to be shown.
- ShowInterstitial(false, kBadURL);
- SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
- ASSERT_TRUE(sb_interstitial);
-
- MessageLoop::current()->RunAllPending();
-
- // Simulate the user clicking "proceed" then "don't proceed" (before the
- // interstitial is shown).
- sb_interstitial->interstitial_page_->Proceed();
- sb_interstitial->interstitial_page_->DontProceed();
- // Proceed() and DontProceed() post a task to update the
- // SafeBrowsingService::Client.
- MessageLoop::current()->RunAllPending();
-
- // The interstitial should be gone.
- EXPECT_EQ(OK, user_response());
- EXPECT_FALSE(GetSafeBrowsingBlockingPage());
-
- // Only one report should have been sent.
- EXPECT_EQ(1u, service_->GetDetails()->size());
- service_->GetDetails()->clear();
-}
-
-// Tests showing a blocking page for a malware page with reports disabled.
-TEST_F(SafeBrowsingBlockingPageV2Test, MalwareReportsDisabled) {
- // Disable malware reports.
- Profile* profile = Profile::FromBrowserContext(
- web_contents()->GetBrowserContext());
- profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false);
-
- // Start a load.
- controller().LoadURL(GURL(kBadURL), content::Referrer(),
- content::PAGE_TRANSITION_TYPED, std::string());
-
- // Simulate the load causing a safe browsing interstitial to be shown.
- ShowInterstitial(false, kBadURL);
- SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
- ASSERT_TRUE(sb_interstitial);
-
- MessageLoop::current()->RunAllPending();
-
- // Simulate the user clicking "don't proceed".
- DontProceedThroughInterstitial(sb_interstitial);
-
- // The interstitial should be gone.
- EXPECT_EQ(CANCEL, user_response());
- EXPECT_FALSE(GetSafeBrowsingBlockingPage());
-
- // We did not proceed, the pending entry should be gone.
- EXPECT_FALSE(controller().GetPendingEntry());
-
- // No report should have been sent.
- EXPECT_EQ(0u, service_->GetDetails()->size());
- service_->GetDetails()->clear();
-}
-
-// Test setting the malware report preferance
-TEST_F(SafeBrowsingBlockingPageV2Test, MalwareReports) {
- // Disable malware reports.
- Profile* profile = Profile::FromBrowserContext(
- web_contents()->GetBrowserContext());
- profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingReportingEnabled, false);
-
- // Start a load.
- controller().LoadURL(GURL(kBadURL), content::Referrer(),
- content::PAGE_TRANSITION_TYPED, std::string());
-
- // Simulate the load causing a safe browsing interstitial to be shown.
- ShowInterstitial(false, kBadURL);
- SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
- ASSERT_TRUE(sb_interstitial);
-
- MessageLoop::current()->RunAllPending();
-
- EXPECT_FALSE(profile->GetPrefs()->GetBoolean(
- prefs::kSafeBrowsingReportingEnabled));
-
- // Simulate the user check the report agreement checkbox.
- sb_interstitial->SetReportingPreference(true);
-
- EXPECT_TRUE(profile->GetPrefs()->GetBoolean(
- prefs::kSafeBrowsingReportingEnabled));
-
- // Simulate the user uncheck the report agreement checkbox.
- sb_interstitial->SetReportingPreference(false);
-
- EXPECT_FALSE(profile->GetPrefs()->GetBoolean(
- prefs::kSafeBrowsingReportingEnabled));
-}
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index b633f33..c350557 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1674,7 +1674,6 @@
'browser/safe_browsing/protocol_manager_unittest.cc',
'browser/safe_browsing/protocol_parser_unittest.cc',
'browser/safe_browsing/safe_browsing_blocking_page_unittest.cc',
- 'browser/safe_browsing/safe_browsing_blocking_page_v2_unittest.cc',
'browser/safe_browsing/safe_browsing_database_unittest.cc',
'browser/safe_browsing/safe_browsing_store_file_unittest.cc',
'browser/safe_browsing/safe_browsing_store_unittest.cc',
@@ -3173,7 +3172,6 @@
'browser/renderer_host/web_cache_manager_browsertest.cc',
'browser/rlz/rlz_extension_apitest.cc',
'browser/safe_browsing/safe_browsing_blocking_page_test.cc',
- 'browser/safe_browsing/safe_browsing_blocking_page_v2_test.cc',
'browser/safe_browsing/safe_browsing_service_browsertest.cc',
'browser/service/service_process_control_browsertest.cc',
'browser/sessions/better_session_restore_browsertest.cc',
diff --git a/chrome/tools/extract_actions.py b/chrome/tools/extract_actions.py
index 96544a3..fc2e40d 100755
--- a/chrome/tools/extract_actions.py
+++ b/chrome/tools/extract_actions.py
@@ -133,8 +133,7 @@ def AddComputedActions(actions):
# Actions for safe_browsing_blocking_page.cc.
for interstitial in ('Phishing', 'Malware', 'Multiple'):
for action in ('Show', 'Proceed', 'DontProceed', 'ForcedDontProceed'):
- for group in ('', '_V1', '_V2'):
- actions.add('SBInterstitial%s%s%s' % (interstitial, action, group))
+ actions.add('SBInterstitial%s%s' % (interstitial, action))
# Actions for language_options_handler.cc (Chrome OS specific).
for input_method_id in INPUT_METHOD_IDS:
diff --git a/tools/valgrind/gtest_exclude/browser_tests.gtest-drmemory_win32.txt b/tools/valgrind/gtest_exclude/browser_tests.gtest-drmemory_win32.txt
index e5dd35f..529b6d7 100644
--- a/tools/valgrind/gtest_exclude/browser_tests.gtest-drmemory_win32.txt
+++ b/tools/valgrind/gtest_exclude/browser_tests.gtest-drmemory_win32.txt
@@ -30,7 +30,6 @@ IsolatedAppTest.*
ProxyBrowserTest.*
RedirectTest.*
SafeBrowsingBlockingPageTest.*
-SafeBrowsingBlockingPageV2Test.*
SSLUITest.*
SSLUITestIgnoreCertErrors.*
# DrM-i#1052-c#3