Commit f0747fdc authored by Matt Menke's avatar Matt Menke Committed by Commit Bot

Convert IOThread unit tests to browser tests.

Creating an IOThread outside of a full Chrome environment requires a
fair bit of weirdness, and I'm running into DCHECKs in another CL in
the IOThread unit test test fixture.  Rather than try and debug it,
it's simpler just to convert them to browser tests and not support
unit testing of IOThread (Which is going away at some point, anyways).

IOThreadTestWithIOThreadObject.UpdateAuthAndroidNegotiateAccountType
is Android only, so can't be tested in a browser test. This CL just
removes it, which is a bit unfortunate, though the test only checks
that prefs::kAuthAndroidNegotiateAccountType make it to
http_auth_preferences.

Bug: 754007
Change-Id: Ifddd5fb3dcd6d20a36352ed749b3fd5614c68289
Reviewed-on: https://chromium-review.googlesource.com/764687
Commit-Queue: Matt Menke <mmenke@chromium.org>
Reviewed-by: 's avatarTarun Bansal <tbansal@chromium.org>
Reviewed-by: 's avatarAsanka Herath <asanka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#516143}
parent a5f21099
......@@ -98,10 +98,6 @@ namespace policy {
class PolicyService;
} // namespace policy
namespace test {
class IOThreadPeer;
} // namespace test
// Contains state associated with, initialized and cleaned up on, and
// primarily used on, the IO thread.
//
......@@ -233,8 +229,6 @@ class IOThread : public content::BrowserThreadDelegate {
content::mojom::NetworkService* GetNetworkServiceOnUIThread();
private:
friend class test::IOThreadPeer;
// BrowserThreadDelegate implementation, runs on the IO thread.
// This handles initialization and destruction of state that must
// live on the IO thread.
......
......@@ -4,20 +4,30 @@
#include "chrome/browser/io_thread.h"
#include <map>
#include <memory>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/field_trial.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/prefs/pref_service.h"
#include "components/variations/variations_associated_data.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/filename_util.h"
#include "net/base/host_port_pair.h"
#include "net/http/http_auth_preferences.h"
#include "net/nqe/network_quality_estimator.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/simple_connection_listener.h"
#include "net/url_request/url_fetcher.h"
......@@ -59,6 +69,46 @@ class TestURLFetcherDelegate : public net::URLFetcherDelegate {
DISALLOW_COPY_AND_ASSIGN(TestURLFetcherDelegate);
};
// Runs a task on the IOThread and waits for it to complete.
void RunOnIOThreadBlocking(const base::Closure& task) {
base::RunLoop run_loop;
content::BrowserThread::PostTaskAndReply(
content::BrowserThread::IO, FROM_HERE, task, run_loop.QuitClosure());
run_loop.Run();
}
void CheckCnameLookup(IOThread* io_thread, bool expected) {
EXPECT_EQ(expected,
io_thread->globals()
->http_auth_preferences->NegotiateDisableCnameLookup());
}
void CheckNegotiateEnablePort(IOThread* io_thread, bool expected) {
EXPECT_EQ(expected,
io_thread->globals()->http_auth_preferences->NegotiateEnablePort());
}
void CheckCanUseDefaultCredentials(IOThread* io_thread,
bool expected,
const GURL& url) {
EXPECT_EQ(
expected,
io_thread->globals()->http_auth_preferences->CanUseDefaultCredentials(
url));
}
void CheckCanDelegate(IOThread* io_thread, bool expected, const GURL& url) {
EXPECT_EQ(expected,
io_thread->globals()->http_auth_preferences->CanDelegate(url));
}
void CheckEffectiveConnectionType(IOThread* io_thread,
net::EffectiveConnectionType expected) {
EXPECT_EQ(expected,
io_thread->globals()
->network_quality_estimator->GetEffectiveConnectionType());
}
class IOThreadBrowserTest : public InProcessBrowserTest {
public:
IOThreadBrowserTest() {}
......@@ -82,6 +132,131 @@ class IOThreadBrowserTest : public InProcessBrowserTest {
}
};
// This test uses the kDisableAuthNegotiateCnameLookup to check that
// the HttpAuthPreferences are correctly initialized and running on the
// IO thread. The other preferences are tested by the HttpAuthPreferences
// unit tests.
IN_PROC_BROWSER_TEST_F(IOThreadBrowserTest, UpdateNegotiateDisableCnameLookup) {
g_browser_process->local_state()->SetBoolean(
prefs::kDisableAuthNegotiateCnameLookup, false);
RunOnIOThreadBlocking(
base::Bind(&CheckCnameLookup,
base::Unretained(g_browser_process->io_thread()), false));
g_browser_process->local_state()->SetBoolean(
prefs::kDisableAuthNegotiateCnameLookup, true);
RunOnIOThreadBlocking(
base::Bind(&CheckCnameLookup,
base::Unretained(g_browser_process->io_thread()), true));
}
IN_PROC_BROWSER_TEST_F(IOThreadBrowserTest, UpdateEnableAuthNegotiatePort) {
g_browser_process->local_state()->SetBoolean(prefs::kEnableAuthNegotiatePort,
false);
RunOnIOThreadBlocking(
base::Bind(&CheckNegotiateEnablePort,
base::Unretained(g_browser_process->io_thread()), false));
g_browser_process->local_state()->SetBoolean(prefs::kEnableAuthNegotiatePort,
true);
RunOnIOThreadBlocking(
base::Bind(&CheckNegotiateEnablePort,
base::Unretained(g_browser_process->io_thread()), true));
}
IN_PROC_BROWSER_TEST_F(IOThreadBrowserTest, UpdateServerWhitelist) {
GURL url("http://test.example.com");
g_browser_process->local_state()->SetString(prefs::kAuthServerWhitelist,
"xxx");
RunOnIOThreadBlocking(
base::Bind(&CheckCanUseDefaultCredentials,
base::Unretained(g_browser_process->io_thread()), false, url));
g_browser_process->local_state()->SetString(prefs::kAuthServerWhitelist, "*");
RunOnIOThreadBlocking(
base::Bind(&CheckCanUseDefaultCredentials,
base::Unretained(g_browser_process->io_thread()), true, url));
}
IN_PROC_BROWSER_TEST_F(IOThreadBrowserTest, UpdateDelegateWhitelist) {
GURL url("http://test.example.com");
g_browser_process->local_state()->SetString(
prefs::kAuthNegotiateDelegateWhitelist, "");
RunOnIOThreadBlocking(
base::Bind(&CheckCanDelegate,
base::Unretained(g_browser_process->io_thread()), false, url));
g_browser_process->local_state()->SetString(
prefs::kAuthNegotiateDelegateWhitelist, "*");
RunOnIOThreadBlocking(
base::Bind(&CheckCanDelegate,
base::Unretained(g_browser_process->io_thread()), true, url));
}
class IOThreadEctCommandLineBrowserTest : public IOThreadBrowserTest {
public:
IOThreadEctCommandLineBrowserTest() {}
~IOThreadEctCommandLineBrowserTest() override {}
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitchASCII("--force-effective-connection-type",
"Slow-2G");
}
};
IN_PROC_BROWSER_TEST_F(IOThreadEctCommandLineBrowserTest,
ForceECTFromCommandLine) {
RunOnIOThreadBlocking(
base::Bind(&CheckEffectiveConnectionType,
base::Unretained(g_browser_process->io_thread()),
net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G));
}
class IOThreadEctFieldTrialBrowserTest : public IOThreadBrowserTest {
public:
IOThreadEctFieldTrialBrowserTest() {}
~IOThreadEctFieldTrialBrowserTest() override {}
void SetUpCommandLine(base::CommandLine* command_line) override {
variations::testing::ClearAllVariationParams();
std::map<std::string, std::string> variation_params;
variation_params["force_effective_connection_type"] = "2G";
ASSERT_TRUE(variations::AssociateVariationParams(
"NetworkQualityEstimator", "Enabled", variation_params));
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"NetworkQualityEstimator", "Enabled"));
}
};
IN_PROC_BROWSER_TEST_F(IOThreadEctFieldTrialBrowserTest,
ForceECTUsingFieldTrial) {
RunOnIOThreadBlocking(
base::Bind(&CheckEffectiveConnectionType,
base::Unretained(g_browser_process->io_thread()),
net::EFFECTIVE_CONNECTION_TYPE_2G));
}
class IOThreadEctFieldTrialAndCommandLineBrowserTest
: public IOThreadEctFieldTrialBrowserTest {
public:
IOThreadEctFieldTrialAndCommandLineBrowserTest() {}
~IOThreadEctFieldTrialAndCommandLineBrowserTest() override {}
void SetUpCommandLine(base::CommandLine* command_line) override {
IOThreadEctFieldTrialBrowserTest::SetUpCommandLine(command_line);
command_line->AppendSwitchASCII("--force-effective-connection-type",
"Slow-2G");
}
};
IN_PROC_BROWSER_TEST_F(IOThreadEctFieldTrialAndCommandLineBrowserTest,
ECTFromCommandLineOverridesFieldTrial) {
RunOnIOThreadBlocking(
base::Bind(&CheckEffectiveConnectionType,
base::Unretained(g_browser_process->io_thread()),
net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G));
}
class IOThreadBrowserTestWithHangingPacRequest : public IOThreadBrowserTest {
public:
IOThreadBrowserTestWithHangingPacRequest() {}
......
This diff is collapsed.
......@@ -3202,7 +3202,6 @@ test("unit_tests") {
"../browser/installable/installable_manager_unittest.cc",
"../browser/installable/installable_task_queue_unittest.cc",
"../browser/internal_auth_unittest.cc",
"../browser/io_thread_unittest.cc",
"../browser/language/language_model_factory_unittest.cc",
"../browser/language/url_language_histogram_factory_unittest.cc",
"../browser/loader/chrome_navigation_data_unittest.cc",
......
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