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

Unified Diff: chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc

Issue 10694037: Add a policy to disable proceeding through the Safe Browsing interstitials. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed <button>/jstemplate Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc
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 394f2c659b1ea8b87310be761a9a757ccc14f9c2..23d8c5bb59b333dd8fb77c48c267203163e9e567 100644
--- a/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc
@@ -8,6 +8,8 @@
// they work.
#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"
@@ -24,6 +26,7 @@
#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"
@@ -369,6 +372,27 @@ class SafeBrowsingBlockingPageTest : public InProcessBrowserTest {
SendCommand("\"proceed\"");
}
+ bool GetProceedLinkIsHidden(bool* result) {
+ InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage(
+ chrome::GetActiveWebContents(browser()));
+ if (!interstitial)
+ return false;
+ content::RenderViewHost* rvh = interstitial->GetRenderViewHostForTesting();
+ if (!rvh)
+ return false;
+ scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(
+ string16(),
+ ASCIIToUTF16("var isHidden = false;\n"
+ "var list = document.querySelectorAll("
+ "'div[jsdisplay=\"!proceedDisabled\"]');"
+ "if (list.length == 1)\n"
+ " isHidden = list[0].style.display === 'none';\n"
+ "isHidden;\n")));
+ if (!value.get())
+ return false;
+ return value->GetAsBoolean(result);
+ }
+
protected:
TestMalwareDetailsFactory details_factory_;
@@ -406,6 +430,10 @@ IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareDontProceed) {
ui_test_utils::NavigateToURL(browser(), url);
+ bool hidden = false;
+ EXPECT_TRUE(GetProceedLinkIsHidden(&hidden));
+ EXPECT_FALSE(hidden);
+
SendCommand("\"takeMeBack\""); // Simulate the user clicking "back"
AssertNoInterstitial(false); // Assert the interstitial is gone
EXPECT_EQ(
@@ -562,3 +590,28 @@ IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest,
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(SafeBrowsingBlockingPageTest, ProceedDisabled) {
+ // Simulate a policy disabling the "proceed anyway" link.
+ browser()->profile()->GetPrefs()->SetBoolean(
+ prefs::kSafeBrowsingProceedAnywayDisabled, true);
+
+ GURL url = test_server()->GetURL(kEmptyPage);
+ AddURLResult(url, SafeBrowsingService::URL_MALWARE);
+ ui_test_utils::NavigateToURL(browser(), url);
+
+ // The "proceed anyway" link should be hidden.
+ bool hidden = false;
+ EXPECT_TRUE(GetProceedLinkIsHidden(&hidden));
+ EXPECT_TRUE(hidden);
+
+ // The "proceed" command should go back instead, if proceeding is disabled.
+ SendCommand("\"proceed\"");
+ AssertNoInterstitial(true);
+ EXPECT_EQ(
+ GURL(chrome::kAboutBlankURL), // Back to "about:blank"
+ chrome::GetActiveWebContents(browser())->GetURL());
+}

Powered by Google App Engine
This is Rietveld 408576698