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

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

Issue 10690102: Relanding https://chromiumcodereview.appspot.com/10694037 after a revert. The original CL failed on… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed the test Created 8 years, 5 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
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_blocking_page.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..2366ce2079df90eb7425a3c2ecf29d4eba4c8b57 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,38 @@ 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;
+ // Wait until jstemplate is finished.
+ std::string ready_state;
+ do {
+ ready_state.clear();
+ scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(
+ string16(),
+ ASCIIToUTF16("document.readyState;")));
+ if (!value.get() || !value->GetAsString(&ready_state))
+ return false;
+ } while (ready_state == "loading");
Mattias Nissler (ping if slow) 2012/07/09 08:32:26 I guess this loop spins pretty fast and thus eats
Joao da Silva 2012/07/10 09:52:20 I've had a deeper look into this. document.readySt
+ // Now get the display style for the "proceed anyway" div.
+ scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(
+ string16(),
+ ASCIIToUTF16("var list = document.querySelectorAll("
+ "'div[jsdisplay=\"!proceedDisabled\"]');"
+ "if (list.length == 1)\n"
+ " list[0].style.display === 'none';\n"
+ "else\n"
+ " 'Fail with non-boolean result value';\n")));
+ if (!value.get())
+ return false;
+ return value->GetAsBoolean(result);
+ }
+
protected:
TestMalwareDetailsFactory details_factory_;
@@ -406,6 +441,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 +601,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());
+}
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_blocking_page.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698