Commit dbdcceb6 authored by mattm's avatar mattm Committed by Commit bot

safe_browsing_blocking_page_test.cc: Use mock URLRequest jobs instead of SpawnedTestServer.

BUG=493800

Review URL: https://codereview.chromium.org/1147353007

Cr-Commit-Position: refs/heads/master@{#333123}
parent 273d29cd
......@@ -14,6 +14,7 @@
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/interstitials/security_interstitial_page_test_utils.h"
#include "chrome/browser/net/url_request_mock_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/database_manager.h"
#include "chrome/browser/safe_browsing/local_database_manager.h"
......@@ -42,6 +43,7 @@
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_browser_thread.h"
#include "content/public/test/test_utils.h"
#include "net/test/url_request/url_request_mock_http_job.h"
using chrome_browser_interstitials::SecurityInterstitialIDNTest;
using content::BrowserThread;
......@@ -51,9 +53,9 @@ 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";
const char kEmptyPage[] = "empty.html";
const char kMalwarePage[] = "safe_browsing/malware.html";
const char kMalwareIframe[] = "safe_browsing/malware_iframe.html";
// A SafeBrowsingDatabaseManager class that allows us to inject the malicious
// URLs.
......@@ -381,8 +383,10 @@ class SafeBrowsingBlockingPageBrowserTest
MalwareDetails::RegisterFactory(NULL);
}
void SetUpInProcessBrowserTestFixture() override {
ASSERT_TRUE(test_server()->Start());
void SetUpOnMainThread() override {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
}
void SetURLThreatType(const GURL& url, SBThreatType threat_type) {
......@@ -397,7 +401,7 @@ class SafeBrowsingBlockingPageBrowserTest
// Adds a safebrowsing result of the current test threat to the fake
// safebrowsing service, navigates to that page, and returns the url.
GURL SetupWarningAndNavigate() {
GURL url = test_server()->GetURL(kEmptyPage);
GURL url = net::URLRequestMockHTTPJob::GetMockUrl(kEmptyPage);
SetURLThreatType(url, GetParam());
ui_test_utils::NavigateToURL(browser(), url);
......@@ -409,8 +413,8 @@ class SafeBrowsingBlockingPageBrowserTest
// navigates to a page with an iframe containing the threat site, and returns
// the url of the parent page.
GURL SetupThreatIframeWarningAndNavigate() {
GURL url = test_server()->GetURL(kMalwarePage);
GURL iframe_url = test_server()->GetURL(kMalwareIframe);
GURL url = net::URLRequestMockHTTPJob::GetMockUrl(kMalwarePage);
GURL iframe_url = net::URLRequestMockHTTPJob::GetMockUrl(kMalwareIframe);
SetURLThreatType(iframe_url, GetParam());
ui_test_utils::NavigateToURL(browser(), url);
......@@ -493,9 +497,9 @@ class SafeBrowsingBlockingPageBrowserTest
}
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");
GURL load_url = net::URLRequestMockHTTPJob::GetMockUrl(
"safe_browsing/interstitial_cancel.html");
GURL malware_url = net::URLRequestMockHTTPJob::GetMockUrl(kMalwarePage);
SetURLThreatType(malware_url, GetParam());
// Load the test page.
......@@ -791,13 +795,8 @@ IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, ReportingDisabled) {
browser()->profile()->GetPrefs()->SetBoolean(
prefs::kSafeBrowsingExtendedReportingEnabled, true);
net::SpawnedTestServer https_server(
net::SpawnedTestServer::TYPE_HTTPS, net::SpawnedTestServer::kLocalhost,
base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
ASSERT_TRUE(https_server.Start());
GURL url = https_server.GetURL(kEmptyPage);
TestReportingDisabledAndDontProceed(url);
TestReportingDisabledAndDontProceed(
net::URLRequestMockHTTPJob::GetMockHttpsUrl(kEmptyPage));
}
// Verifies that the reporting checkbox is hidden when opt-in is
......@@ -816,7 +815,8 @@ IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest,
browser()->profile()->GetPrefs()->SetBoolean(
prefs::kSafeBrowsingExtendedReportingOptInAllowed, false);
TestReportingDisabledAndDontProceed(test_server()->GetURL(kEmptyPage));
TestReportingDisabledAndDontProceed(
net::URLRequestMockHTTPJob::GetMockUrl(kEmptyPage));
}
IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, LearnMore) {
......
<html>
<body>
<iframe src ="/server-redirect?http://localhost/files/safe_browsing/malware.html" width="100%" height="300">
<iframe src="redirect_to_malware.html" width="100%" height="300">
<p>Your browser does not support iframes.</p>
</iframe>
<iframe src ="/empty.hml" width="100%" height="300">
<iframe src="/empty.hml" width="100%" height="300">
<p>Your browser does not support iframes.</p>
</iframe>
</body>
......
......@@ -7,21 +7,16 @@ function openWinIFrame()
tab = window.open("iframe_redirect_malware.html");
}
function openMalware()
{
window.open("http://localhost");
}
function openWin()
{
tab = window.open("/server-redirect?http://localhost/files/safe_browsing/malware.html");
tab = window.open("redirect_to_malware.html");
}
function stopWin()
{
tab.stop();
// This will trigger a navigation event.
window.location = "http://localhost";
window.location = "/";
}
</script>
......@@ -35,10 +30,6 @@ function stopWin()
<form>
<input type=button value="Stop Window" onclick="stopWin()">
</form>
<form>
<input type=button value="Open malware in tab" onclick="openMalware()">
</form>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment