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

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: 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 4956e73d8c97957035ab77fb73cd528630b57b2a..8c965893aec944db76d8476dca7bd74f40675de7 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"
@@ -23,6 +25,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"
@@ -368,6 +371,27 @@ class SafeBrowsingBlockingPageTest : public InProcessBrowserTest {
SendCommand("\"proceed\"");
}
+ bool GetProceedLinkIsHidden(bool* result) {
+ InterstitialPage* interstitial = InterstitialPage::GetInterstitialPage(
+ browser()->GetActiveWebContents());
+ if (!interstitial)
+ return false;
+ content::RenderViewHost* rvh = interstitial->GetRenderViewHostForTesting();
+ if (!rvh)
+ return false;
+ scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(
+ ASCIIToUTF16(""),
James Hawkins 2012/06/29 17:31:51 string16().
Joao da Silva 2012/07/02 10:08:40 Done.
+ ASCIIToUTF16("var isHidden = false;\n"
+ "var list = document.querySelectorAll("
+ "'div[jsdisplay=\"!proceed_disabled\"]');"
+ "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_;
@@ -405,6 +429,10 @@ IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, MalwareDontProceed) {
ui_test_utils::NavigateToURL(browser(), url);
+ bool hidden = false;
+ ASSERT_TRUE(GetProceedLinkIsHidden(&hidden));
James Hawkins 2012/06/29 17:31:51 s/ASSERT/EXPECT/
Joao da Silva 2012/07/02 10:08:40 Done.
+ EXPECT_FALSE(hidden);
+
SendCommand("\"takeMeBack\""); // Simulate the user clicking "back"
AssertNoInterstitial(false); // Assert the interstitial is gone
EXPECT_EQ(
@@ -561,3 +589,25 @@ IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest,
EXPECT_EQ(url, browser()->GetActiveWebContents()->GetURL());
AssertReportSent();
}
+
+IN_PROC_BROWSER_TEST_F(SafeBrowsingBlockingPageTest, ProceedDisabled) {
James Hawkins 2012/06/29 17:31:51 nit: Document what this test is testing.
Joao da Silva 2012/07/02 10:08:40 Done.
+ // 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;
+ ASSERT_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"
+ browser()->GetActiveWebContents()->GetURL());
+}

Powered by Google App Engine
This is Rietveld 408576698