Commit 67e7103a authored by Matt Menke's avatar Matt Menke Committed by Commit Bot

Make BrowserEncodingBrowsertests pass when using the network service.

In particular, switch them to using the EmbeddedTestServer from
URLRequestFilter, which required them to be in the same process
as the network stack.

Bug: 776589
Change-Id: I5d4d363d47149a11ccb38b5c18d8c57c377b58b4
Reviewed-on: https://chromium-review.googlesource.com/730888Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarYuzhu Shen <yzshen@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Commit-Queue: Matt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513128}
parent 687a6171
......@@ -4,21 +4,21 @@
#include <stddef.h>
#include "base/bind.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/macros.h"
#include "base/path_service.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "chrome/browser/net/url_request_mock_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/notification_service.h"
......@@ -27,7 +27,7 @@
#include "content/public/browser/web_contents.h"
#include "content/public/test/download_test_observer.h"
#include "content/public/test/test_navigation_observer.h"
#include "net/test/url_request/url_request_mock_http_job.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
namespace {
......@@ -71,8 +71,6 @@ const EncodingTestData kEncodingTestDatas[] = {
} // namespace
using content::BrowserThread;
static const base::FilePath::CharType* kTestDir =
FILE_PATH_LITERAL("encoding_tests");
......@@ -85,7 +83,8 @@ class BrowserEncodingTest
// Saves the current page and verifies that the output matches the expected
// result.
void SaveAndCompare(const char* filename_to_write,
const base::FilePath& expected) {
const base::FilePath& expected,
const GURL& url) {
// Dump the page, the content of dump page should be identical to the
// expected result file.
base::FilePath full_file_name = save_dir_.AppendASCII(filename_to_write);
......@@ -105,19 +104,32 @@ class BrowserEncodingTest
base::FilePath expected_file_name = ui_test_utils::GetTestFilePath(
base::FilePath(kTestDir), expected);
EXPECT_TRUE(base::ContentsEqual(full_file_name, expected_file_name)) <<
"generated_file = " << full_file_name.AsUTF8Unsafe() <<
", expected_file = " << expected_file_name.AsUTF8Unsafe();
std::string actual_contents;
std::string expected_contents;
{
base::ScopedAllowBlockingForTesting allow_blocking;
ASSERT_TRUE(base::ReadFileToString(full_file_name, &actual_contents));
ASSERT_TRUE(
base::ReadFileToString(expected_file_name, &expected_contents));
}
// Add "Mark of the Web" path with source URL.
expected_contents = base::StringPrintf(
expected_contents.c_str(), url.spec().length(), url.spec().c_str());
EXPECT_EQ(expected_contents, actual_contents);
}
void SetUpOnMainThread() override {
base::FilePath test_data_dir;
ASSERT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));
embedded_test_server()->ServeFilesFromDirectory(test_data_dir);
ASSERT_TRUE(embedded_test_server()->Start());
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
save_dir_ = temp_dir_.GetPath();
temp_sub_resource_dir_ = save_dir_.AppendASCII("sub_resource_files");
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
}
base::ScopedTempDir temp_dir_;
......@@ -140,7 +152,7 @@ IN_PROC_BROWSER_TEST_P(BrowserEncodingTest, TestEncodingAliasMapping) {
GetParam().file_name);
GURL url =
net::URLRequestMockHTTPJob::GetMockUrl(test_file_path.MaybeAsASCII());
embedded_test_server()->GetURL("/" + test_file_path.MaybeAsASCII());
ui_test_utils::NavigateToURL(browser(), url);
EXPECT_EQ(GetParam().encoding_name,
browser()->tab_strip_model()->GetActiveWebContents()->
......@@ -232,7 +244,7 @@ IN_PROC_BROWSER_TEST_F(BrowserEncodingTest, TestEncodingAutoDetect) {
base::FilePath test_file_path(test_dir_path);
test_file_path = test_file_path.AppendASCII(kTestDatas[i].test_file_name);
GURL url =
net::URLRequestMockHTTPJob::GetMockUrl(test_file_path.MaybeAsASCII());
embedded_test_server()->GetURL("/" + test_file_path.MaybeAsASCII());
ui_test_utils::NavigateToURL(browser(), url);
// Get the encoding of page. It should return the real encoding now.
......@@ -244,6 +256,7 @@ IN_PROC_BROWSER_TEST_F(BrowserEncodingTest, TestEncodingAutoDetect) {
base::FilePath().AppendASCII(kAutoDetectDir).
AppendASCII(kExpectedResultDir).
AppendASCII(kTestDatas[i].expected_result);
SaveAndCompare(kTestDatas[i].test_file_name, expected_result_file_name);
SaveAndCompare(kTestDatas[i].test_file_name, expected_result_file_name,
url);
}
}
<!-- saved from url=(0080)http://mock.http/encoding_tests/auto_detect/Big5_with_no_encoding_specified.html -->
<!-- saved from url=(%04d)%s -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=Big5">
<title> Big5 </title>
</head>
......
<!-- saved from url=(0082)http://mock.http/encoding_tests/auto_detect/EUC-KR_with_no_encoding_specified.html -->
<!-- saved from url=(%04d)%s -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title> EUC-KR </title>
</head>
......
<!DOCTYPE html PUBLIC "-//W3C//DTD Xhtml 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0079)http://mock.http/encoding_tests/auto_detect/GBK_with_no_encoding_specified.html -->
<!-- saved from url=(%04d)%s -->
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>中国制造的领军者3名</title>
</head>
......
<!-- saved from url=(0086)http://mock.http/encoding_tests/auto_detect/ISO-8859-5_with_no_encoding_specified.html -->
<!-- saved from url=(%04d)%s -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-5">
<title> ISO-8859-5 </title>
</head>
......
<!-- saved from url=(0086)http://mock.http/encoding_tests/auto_detect/ISO-8859-6_with_no_encoding_specified.html -->
<!-- saved from url=(%04d)%s -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-6">
<title> ISO-8859-6 </title>
</head>
......
<!-- saved from url=(0086)http://mock.http/encoding_tests/auto_detect/ISO-8859-7_with_no_encoding_specified.html -->
<!-- saved from url=(%04d)%s -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-7">
<title> ISO-8859-7 </title>
</head>
......
<!-- saved from url=(0088)http://mock.http/encoding_tests/auto_detect/ISO-8859-8-I_with_no_encoding_specified.html -->
<!-- saved from url=(%04d)%s -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
<title> ISO-8859-8-I </title>
</head>
......
<!-- saved from url=(0082)http://mock.http/encoding_tests/auto_detect/KOI8-R_with_no_encoding_specified.html -->
<!-- saved from url=(%04d)%s -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=KOI8-R">
<title> KOI8-R </title>
</head>
......
<!-- saved from url=(0085)http://mock.http/encoding_tests/auto_detect/Shift-JIS_with_no_encoding_specified.html -->
<!-- saved from url=(%04d)%s -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<title> Shift_JIS </title>
</head>
......
<!DOCTYPE html PUBLIC "-//W3C//DTD html 4.01 Transitional//EN" "http://www.w3c.o rg/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0086)http://mock.http/encoding_tests/auto_detect/iso-8859-1_with_no_encoding_specified.html -->
<!-- saved from url=(%04d)%s -->
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml"><head profile="http://www.w3.org/2000/08/w3c-synd/#"><meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>iso-8859-1</title>
</head>
<body>
<h1 id="logo"><img height="48" alt="The World Wide Web Consortium (W3C)" src="http://mock.http/Icons/w3c_main" width="315"></h1>
<h1 id="logo"><img height="48" alt="The World Wide Web Consortium (W3C)" src="./sub_resource_files/w3c_main" width="315"></h1>
<h2 id="slogan">Leading the Web to Its Full Potential...</h2>
</body></html>
\ No newline at end of file
<!-- saved from url=(0088)http://mock.http/encoding_tests/auto_detect/windows-1251_with_no_encoding_specified.html -->
<!-- saved from url=(%04d)%s -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title> windows-1251 </title>
</head>
......
<!-- saved from url=(0088)http://mock.http/encoding_tests/auto_detect/windows-1254_with_no_encoding_specified.html -->
<!-- saved from url=(%04d)%s -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1254">
<title> windows-1254 </title>
</head>
......
<!-- saved from url=(0088)http://mock.http/encoding_tests/auto_detect/windows-1255_with_no_encoding_specified.html -->
<!-- saved from url=(%04d)%s -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
<title> windows-1255 </title>
</head>
......
<!-- saved from url=(0088)http://mock.http/encoding_tests/auto_detect/windows-1256_with_no_encoding_specified.html -->
<!-- saved from url=(%04d)%s -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
<title> windows-1256 </title>
</head>
......
......@@ -2384,7 +2384,6 @@
-BrowserCloseManagerWithDownloadsBrowserTest/BrowserCloseManagerWithDownloadsBrowserTest.TestWithOffTheRecordDownloads/1
-BrowserCloseManagerWithDownloadsBrowserTest/BrowserCloseManagerWithDownloadsBrowserTest.TestWithOffTheRecordWindowAndRegularDownload/0
-BrowserCloseManagerWithDownloadsBrowserTest/BrowserCloseManagerWithDownloadsBrowserTest.TestWithOffTheRecordWindowAndRegularDownload/1
-BrowserEncodingTest.TestEncodingAutoDetect
-CaptivePortalBrowserTest.AbortLoad
-CaptivePortalBrowserTest.CloseLoginTab
-CaptivePortalBrowserTest.Disabled
......@@ -2539,35 +2538,6 @@
-DownloadTest.UnknownSize
-DownloadTestWithFakeSafeBrowsing.NoUncommonDownloadReportWithoutUserProceed
-DownloadTestWithFakeSafeBrowsing.SendUncommonDownloadReportIfUserProceed
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/0
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/1
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/10
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/11
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/12
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/13
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/14
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/15
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/16
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/18
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/19
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/2
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/20
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/21
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/22
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/23
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/24
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/25
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/26
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/27
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/28
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/29
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/3
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/4
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/5
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/6
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/7
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/8
-EncodingAliases/BrowserEncodingTest.TestEncodingAliasMapping/9
-ErrorPageAutoReloadTest.AutoReload
-ErrorPageAutoReloadTest.IgnoresSameDocumentNavigation
-ErrorPageAutoReloadTest.ManualReloadNotSuppressed
......
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