Commit f9b85d83 authored by joi@chromium.org's avatar joi@chromium.org

This goes most of the way to re-enabling chrome_frame_net_tests by making it a...

This goes most of the way to re-enabling chrome_frame_net_tests by making it a content::BrowserMainParts.  The tests are still disabled until we are able to test them on IE8 and older; on IE9 all tests currently pass except for a few that hang.

Additionally, this makes chrome_frame_net_tests determine protocol version using the exact same version information as npchrome_frame.dll does, so that version mismatch due to the RC dependency problems we have sometimes seen should not happen any more with this test suite.

While in there, I also updated the poor_mans_trybot.bat script.

BUG=105435

Review URL: http://codereview.chromium.org/8894008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114080 0039d316-1c4b-4281-b951-d872f2087c98
parent 810aa6d0
......@@ -30,7 +30,6 @@ class BrowserOnlineStateObserver;
class ChromeNetLog;
class ChromeResourceDispatcherHostDelegate;
class CommandLine;
class ChromeFrameFriendOfBrowserProcessImpl; // TODO(joi): Remove
class RemoteDebuggingServer;
class TabCloseableStateWatcher;
......@@ -128,9 +127,6 @@ class BrowserProcessImpl : public BrowserProcess,
virtual CRLSetFetcher* crl_set_fetcher() OVERRIDE;
private:
// TODO(joi): Remove. Temporary hack to get at CreateIOThreadState.
friend class ChromeFrameFriendOfBrowserProcessImpl;
// Must be called right before the IO thread is started.
void CreateIOThreadState();
......
......@@ -379,6 +379,7 @@
'../chrome/chrome.gyp:renderer',
'../chrome/chrome.gyp:syncapi_core',
'../chrome/chrome_resources.gyp:chrome_resources',
'../content/content.gyp:content_app',
'../content/content.gyp:content_gpu',
'../content/content.gyp:test_support_content',
'../net/net.gyp:net',
......
......@@ -27,8 +27,8 @@
#include "base/win/scoped_com_initializer.h"
#include "base/win/scoped_comptr.h"
#include "base/win/scoped_handle.h"
#include "chrome/app/chrome_main_delegate.h"
#include "chrome/browser/automation/automation_provider_list.h"
#include "chrome/browser/browser_process_impl.h" // TODO(joi): Remove
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/prefs/pref_service.h"
......@@ -49,12 +49,15 @@
#include "chrome_frame/test/simulate_input.h"
#include "chrome_frame/test/win_event_receiver.h"
#include "chrome_frame/utils.h"
#include "content/app/content_main.h"
#include "content/browser/plugin_service.h"
#include "content/browser/notification_service_impl.h"
#include "content/public/app/startup_helper_win.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_paths.h"
#include "content/test/test_browser_thread.h" // TODO(joi): Remove
#include "sandbox/src/sandbox_types.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
......@@ -63,6 +66,13 @@ using content::BrowserThread;
namespace {
// We must store this globally so that our main delegate can set it.
static CFUrlRequestUnittestRunner* g_test_suite = NULL;
// Copied here for access by CreateBrowserMainParts and InitGoogleTest.
static int g_argc = 0;
static char** g_argv = NULL;
// A special command line switch to allow developers to manually launch the
// browser and debug CF inside the browser.
const char kManualBrowserLaunch[] = "manual-browser";
......@@ -113,6 +123,176 @@ bool SetFocusToAccessibleWindow(HWND hwnd) {
return ret;
}
class FakeContentBrowserClient : public chrome::ChromeContentBrowserClient {
public:
virtual ~FakeContentBrowserClient() {}
virtual content::BrowserMainParts* CreateBrowserMainParts(
const content::MainFunctionParams& parameters) OVERRIDE;
};
base::LazyInstance<chrome::ChromeContentClient>
g_chrome_content_client = LAZY_INSTANCE_INITIALIZER;
// Override the default ContentBrowserClient to let Chrome participate in
// content logic. Must be done before any tabs are created.
base::LazyInstance<FakeContentBrowserClient>
g_browser_client = LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<chrome::ChromeContentRendererClient>
g_renderer_client = LAZY_INSTANCE_INITIALIZER;
class FakeMainDelegate : public content::ContentMainDelegate {
public:
virtual ~FakeMainDelegate() {}
virtual bool BasicStartupComplete(int* exit_code) OVERRIDE {
return false;
}
virtual void PreSandboxStartup() OVERRIDE {
// Initialize the content client.
content::SetContentClient(&g_chrome_content_client.Get());
// Override the default ContentBrowserClient to let Chrome participate in
// content logic. We use a subclass of Chrome's implementation,
// FakeContentBrowserClient, to override CreateBrowserMainParts. Must
// be done before any tabs are created.
content::GetContentClient()->set_browser(&g_browser_client.Get());
content::GetContentClient()->set_renderer(&g_renderer_client.Get());
}
virtual void SandboxInitialized(const std::string& process_type) OVERRIDE {}
virtual int RunProcess(
const std::string& process_type,
const content::MainFunctionParams& main_function_params) OVERRIDE {
return -1;
}
virtual void ProcessExiting(const std::string& process_type) OVERRIDE {}
};
void FilterDisabledTests() {
if (::testing::FLAGS_gtest_filter.length() &&
::testing::FLAGS_gtest_filter.Compare("*") != 0) {
// Don't override user specified filters.
return;
}
const char* disabled_tests[] = {
// Tests disabled since they're testing the same functionality used
// by the TestAutomationProvider.
"URLRequestTest.Intercept",
"URLRequestTest.InterceptNetworkError",
"URLRequestTest.InterceptRestartRequired",
"URLRequestTest.InterceptRespectsCancelMain",
"URLRequestTest.InterceptRespectsCancelRedirect",
"URLRequestTest.InterceptRespectsCancelFinal",
"URLRequestTest.InterceptRespectsCancelInRestart",
"URLRequestTest.InterceptRedirect",
"URLRequestTest.InterceptServerError",
"URLRequestTestFTP.*",
// Tests that are currently not working:
// Temporarily disabled because they needs user input (login dialog).
"URLRequestTestHTTP.BasicAuth",
"URLRequestTestHTTP.BasicAuthWithCookies",
// HTTPS tests temporarily disabled due to the certificate error dialog.
// TODO(tommi): The tests currently fail though, so need to fix.
"HTTPSRequestTest.HTTPSMismatchedTest",
"HTTPSRequestTest.HTTPSExpiredTest",
"HTTPSRequestTest.ClientAuthTest",
// Tests chrome's network stack's cache (might not apply to CF).
"URLRequestTestHTTP.VaryHeader",
"URLRequestTestHTTP.GetZippedTest",
// I suspect we can only get this one to work (if at all) on IE8 and
// later by using the new INTERNET_OPTION_SUPPRESS_BEHAVIOR flags
// See http://msdn.microsoft.com/en-us/library/aa385328(VS.85).aspx
"URLRequestTest.DoNotSaveCookies",
"URLRequestTest.DelayedCookieCallback",
// TODO(ananta): This test has been consistently failing. Disabling it for
// now.
"URLRequestTestHTTP.GetTest_NoCache",
// These tests have been disabled as the Chrome cookie policies don't make
// sense or have not been implemented for the host network stack.
"URLRequestTest.DoNotSaveCookies_ViaPolicy",
"URLRequestTest.DoNotSendCookies_ViaPolicy",
"URLRequestTest.DoNotSaveCookies_ViaPolicy_Async",
"URLRequestTest.CookiePolicy_ForceSession",
"URLRequestTest.DoNotSendCookies",
"URLRequestTest.DoNotSendCookies_ViaPolicy_Async",
"URLRequestTest.CancelTest_During_OnGetCookies",
"URLRequestTest.CancelTest_During_OnSetCookie",
// These tests are disabled as the rely on functionality provided by
// Chrome's HTTP stack like the ability to set the proxy for a URL, etc.
"URLRequestTestHTTP.ProxyTunnelRedirectTest",
"URLRequestTestHTTP.UnexpectedServerAuthTest",
// This test is disabled as it expects an empty UA to be echoed back from
// the server which is not the case in ChromeFrame.
"URLRequestTestHTTP.DefaultUserAgent",
// This test modifies the UploadData object after it has been marshaled to
// ChromeFrame. We don't support this.
"URLRequestTestHTTP.TestPostChunkedDataAfterStart",
// Do not work in CF, it may well be that IE is unconditionally
// adding Accept-Encoding header by default to outgoing requests.
"URLRequestTestHTTP.DefaultAcceptEncoding",
"URLRequestTestHTTP.OverrideAcceptEncoding",
// Not supported in ChromeFrame as we use IE's network stack.
"URLRequestTest.NetworkDelegateProxyError",
// URLRequestAutomationJob needs to support NeedsAuth.
// http://crbug.com/98446
"URLRequestTestHTTP.NetworkDelegateOnAuthRequiredSyncNoAction",
"URLRequestTestHTTP.NetworkDelegateOnAuthRequiredSyncSetAuth",
"URLRequestTestHTTP.NetworkDelegateOnAuthRequiredSyncCancel",
"URLRequestTestHTTP.NetworkDelegateOnAuthRequiredAsyncNoAction",
"URLRequestTestHTTP.NetworkDelegateOnAuthRequiredAsyncSetAuth",
"URLRequestTestHTTP.NetworkDelegateOnAuthRequiredAsyncCancel",
// Flaky on the tryservers, http://crbug.com/103097
"URLRequestTestHTTP.MultipleRedirectTest",
"URLRequestTestHTTP.NetworkDelegateRedirectRequest",
};
const char* ie9_disabled_tests[] = {
// These always hang on Joi's box with IE9, http://crbug.com/105435.
// Several other tests, e.g. URLRequestTestHTTP.CancelTest2, 3 and
// 5, often hang but not always.
"URLRequestTestHTTP.NetworkDelegateRedirectRequestPost",
"URLRequestTestHTTP.GetTest",
"HTTPSRequestTest.HTTPSPreloadedHSTSTest",
};
std::string filter("-"); // All following filters will be negative.
for (int i = 0; i < arraysize(disabled_tests); ++i) {
if (i > 0)
filter += ":";
filter += disabled_tests[i];
}
if (chrome_frame_test::GetInstalledIEVersion() >= IE_9) {
for (int i = 0; i < arraysize(ie9_disabled_tests); ++i) {
filter += ":";
filter += ie9_disabled_tests[i];
}
}
::testing::FLAGS_gtest_filter = filter;
}
} // namespace
// Same as BrowserProcessImpl, but uses custom profile manager.
class FakeBrowserProcessImpl : public BrowserProcessImpl {
public:
......@@ -121,7 +301,9 @@ class FakeBrowserProcessImpl : public BrowserProcessImpl {
profiles_dir_.CreateUniqueTempDir();
}
virtual ProfileManager* profile_manager() {
virtual ~FakeBrowserProcessImpl() {}
virtual ProfileManager* profile_manager() OVERRIDE {
if (!profile_manager_.get()) {
profile_manager_.reset(
new ProfileManagerWithoutInit(profiles_dir_.path()));
......@@ -129,29 +311,19 @@ class FakeBrowserProcessImpl : public BrowserProcessImpl {
return profile_manager_.get();
}
virtual MetricsService* metrics_service() {
virtual MetricsService* metrics_service() OVERRIDE {
return NULL;
}
void DestroyProfileManager() {
profile_manager_.reset();
}
private:
ScopedTempDir profiles_dir_;
scoped_ptr<ProfileManager> profile_manager_;
};
base::LazyInstance<chrome::ChromeContentClient>
g_chrome_content_client = LAZY_INSTANCE_INITIALIZER;
// Override the default ContentBrowserClient to let Chrome participate in
// content logic. Must be done before any tabs are created.
base::LazyInstance<chrome::ChromeContentBrowserClient>
g_browser_client = LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<chrome::ChromeContentRendererClient>
g_renderer_client = LAZY_INSTANCE_INITIALIZER;
} // namespace
class SupplyProxyCredentials : public WindowObserver {
public:
SupplyProxyCredentials(const char* username, const char* password);
......@@ -238,19 +410,8 @@ FakeExternalTab::~FakeExternalTab() {
void FakeExternalTab::Initialize() {
DCHECK(g_browser_process == NULL);
notificaton_service_.reset(new NotificationServiceImpl);
base::SystemMonitor system_monitor;
icu_util::Initialize();
TestTimeouts::Initialize();
// Do not call chrome::RegisterPathProvider() since it is also called by our
// test runner, CFUrlRequestUnittestRunner, and calling it twice unfortunately
// causes a DCHECK().
content::RegisterPathProvider();
ui::RegisterPathProvider();
// Load Chrome.dll as our resource dll.
FilePath dll;
PathService::Get(base::DIR_MODULE, &dll);
......@@ -275,15 +436,6 @@ void FakeExternalTab::Initialize() {
browser_process_->local_state()->RegisterBooleanPref(
prefs::kMetricsReportingEnabled, false);
// Initialize the content client which that code uses to talk to Chrome.
content::SetContentClient(&g_chrome_content_client.Get());
// Override the default ContentBrowserClient to let Chrome participate in
// content logic. Must be done before any tabs are created.
content::GetContentClient()->set_browser(&g_browser_client.Get());
content::GetContentClient()->set_renderer(&g_renderer_client.Get());
}
void FakeExternalTab::InitializePostThreadsCreated() {
......@@ -300,46 +452,18 @@ void FakeExternalTab::Shutdown() {
ResourceBundle::CleanupSharedInstance();
}
// TODO(joi): Remove!
class ChromeFrameFriendOfBrowserProcessImpl {
public:
static void CreateIOThreadState() {
reinterpret_cast<BrowserProcessImpl*>(
g_browser_process)->CreateIOThreadState();
}
};
FakeBrowserProcessImpl* FakeExternalTab::browser_process() const {
return browser_process_.get();
}
CFUrlRequestUnittestRunner::CFUrlRequestUnittestRunner(int argc, char** argv)
: NetTestSuite(argc, argv),
chrome_frame_html_("/chrome_frame", kChromeFrameHtml),
registrar_(chrome_frame_test::GetTestBedType()),
test_result_(0) {
// Register the main thread by instantiating it, but don't call any methods.
main_thread_.reset(new content::TestBrowserThread(
BrowserThread::UI, MessageLoop::current()));
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
fake_chrome_.Initialize();
db_thread_.reset(new content::TestBrowserThread(BrowserThread::DB));
db_thread_->Start();
file_thread_.reset(new content::TestBrowserThread(BrowserThread::FILE));
file_thread_->Start();
ChromeFrameFriendOfBrowserProcessImpl::CreateIOThreadState();
io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO));
io_thread_->StartIOThread();
fake_chrome_.InitializePostThreadsCreated();
pss_subclass_.reset(new ProcessSingletonSubclass(this));
EXPECT_TRUE(pss_subclass_->Subclass(fake_chrome_.user_data()));
StartChromeFrameInHostBrowser();
}
CFUrlRequestUnittestRunner::~CFUrlRequestUnittestRunner() {
fake_chrome_.Shutdown();
}
void CFUrlRequestUnittestRunner::StartChromeFrameInHostBrowser() {
......@@ -382,14 +506,13 @@ void CFUrlRequestUnittestRunner::Initialize() {
// directly because it will attempt to initialize some things such as
// ICU that have already been initialized for this process.
CFUrlRequestUnittestRunner::InitializeLogging();
base::Time::EnableHighResolutionTimer(true);
SuppressErrorDialogs();
base::debug::SetSuppressDebugUI(true);
logging::SetLogAssertHandler(UnitTestAssertHandler);
// Next, do some initialization for NetTestSuite.
NetTestSuite::InitializeTestThread();
NetTestSuite::InitializeTestThreadNoNetworkChangeNotifier();
}
void CFUrlRequestUnittestRunner::Shutdown() {
......@@ -401,7 +524,7 @@ void CFUrlRequestUnittestRunner::Shutdown() {
void CFUrlRequestUnittestRunner::OnConnectAutomationProviderToChannel(
const std::string& channel_id) {
Profile* profile = g_browser_process->profile_manager()->
GetDefaultProfile(fake_chrome_.user_data());
GetDefaultProfile(fake_chrome_->user_data());
AutomationProviderList* list = g_browser_process->GetAutomationProviderList();
DCHECK(list);
......@@ -414,12 +537,6 @@ void CFUrlRequestUnittestRunner::OnInitialTabLoaded() {
StartTests();
}
void CFUrlRequestUnittestRunner::RunMainUIThread() {
DCHECK(MessageLoop::current());
DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
MessageLoop::current()->Run();
}
void CFUrlRequestUnittestRunner::StartTests() {
if (PromptAfterSetup())
MessageBoxA(NULL, "click ok to run", "", MB_OK);
......@@ -433,12 +550,11 @@ void CFUrlRequestUnittestRunner::StartTests() {
// static
DWORD CFUrlRequestUnittestRunner::RunAllUnittests(void* param) {
base::PlatformThread::SetName("CFUrlRequestUnittestRunner");
// Needed for some url request tests like the intercept job tests, etc.
NotificationServiceImpl service;
CFUrlRequestUnittestRunner* me =
reinterpret_cast<CFUrlRequestUnittestRunner*>(param);
me->test_result_ = me->Run();
me->fake_chrome_.ui_loop()->PostTask(FROM_HERE,
BrowserThread::PostTask(BrowserThread::UI,
FROM_HERE,
base::Bind(TakeDownBrowser, me));
return 0;
}
......@@ -450,7 +566,8 @@ void CFUrlRequestUnittestRunner::TakeDownBrowser(
MessageBoxA(NULL, "click ok to exit", "", MB_OK);
me->ShutDownHostBrowser();
me->fake_chrome_.ui_loop()->PostDelayedTask(FROM_HERE,
BrowserThread::PostDelayedTask(BrowserThread::UI,
FROM_HERE,
MessageLoop::QuitClosure(),
TestTimeouts::tiny_timeout_ms());
}
......@@ -470,106 +587,76 @@ void CFUrlRequestUnittestRunner::InitializeLogging() {
logging::SetLogItems(true, true, true, true);
}
void FilterDisabledTests() {
if (::testing::FLAGS_gtest_filter.length() &&
::testing::FLAGS_gtest_filter.Compare("*") != 0) {
// Don't override user specified filters.
return;
}
void CFUrlRequestUnittestRunner::PreEarlyInitialization() {
testing::InitGoogleTest(&g_argc, g_argv);
FilterDisabledTests();
}
const char* disabled_tests[] = {
// Tests disabled since they're testing the same functionality used
// by the TestAutomationProvider.
"URLRequestTest.Intercept",
"URLRequestTest.InterceptNetworkError",
"URLRequestTest.InterceptRestartRequired",
"URLRequestTest.InterceptRespectsCancelMain",
"URLRequestTest.InterceptRespectsCancelRedirect",
"URLRequestTest.InterceptRespectsCancelFinal",
"URLRequestTest.InterceptRespectsCancelInRestart",
"URLRequestTest.InterceptRedirect",
"URLRequestTest.InterceptServerError",
"URLRequestTestFTP.*",
void CFUrlRequestUnittestRunner::PreCreateThreads() {
fake_chrome_.reset(new FakeExternalTab());
fake_chrome_->Initialize();
// Tests that are currently not working:
pss_subclass_.reset(new ProcessSingletonSubclass(this));
EXPECT_TRUE(pss_subclass_->Subclass(fake_chrome_->user_data()));
StartChromeFrameInHostBrowser();
}
// Temporarily disabled because they needs user input (login dialog).
"URLRequestTestHTTP.BasicAuth",
"URLRequestTestHTTP.BasicAuthWithCookies",
void CFUrlRequestUnittestRunner::PreStartThread(BrowserThread::ID identifier) {
fake_chrome_->browser_process()->PreStartThread(identifier);
}
// HTTPS tests temporarily disabled due to the certificate error dialog.
// TODO(tommi): The tests currently fail though, so need to fix.
"HTTPSRequestTest.HTTPSMismatchedTest",
"HTTPSRequestTest.HTTPSExpiredTest",
"HTTPSRequestTest.ClientAuthTest",
void CFUrlRequestUnittestRunner::PostStartThread(BrowserThread::ID identifier) {
fake_chrome_->browser_process()->PostStartThread(identifier);
}
// Tests chrome's network stack's cache (might not apply to CF).
"URLRequestTestHTTP.VaryHeader",
"URLRequestTestHTTP.GetZippedTest",
void CFUrlRequestUnittestRunner::PreMainMessageLoopRun() {
fake_chrome_->InitializePostThreadsCreated();
}
// I suspect we can only get this one to work (if at all) on IE8 and
// later by using the new INTERNET_OPTION_SUPPRESS_BEHAVIOR flags
// See http://msdn.microsoft.com/en-us/library/aa385328(VS.85).aspx
"URLRequestTest.DoNotSaveCookies",
"URLRequestTest.DelayedCookieCallback",
bool CFUrlRequestUnittestRunner::MainMessageLoopRun(int* result_code) {
DCHECK(MessageLoop::current());
DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
// TODO(ananta): This test has been consistently failing. Disabling it for
// now.
"URLRequestTestHTTP.GetTest_NoCache",
// We need to allow IO on the main thread for these tests.
base::ThreadRestrictions::SetIOAllowed(true);
// These tests have been disabled as the Chrome cookie policies don't make
// sense or have not been implemented for the host network stack.
"URLRequestTest.DoNotSaveCookies_ViaPolicy",
"URLRequestTest.DoNotSendCookies_ViaPolicy",
"URLRequestTest.DoNotSaveCookies_ViaPolicy_Async",
"URLRequestTest.CookiePolicy_ForceSession",
"URLRequestTest.DoNotSendCookies",
"URLRequestTest.DoNotSendCookies_ViaPolicy_Async",
"URLRequestTest.CancelTest_During_OnGetCookies",
"URLRequestTest.CancelTest_During_OnSetCookie",
return false;
}
// These tests are disabled as the rely on functionality provided by
// Chrome's HTTP stack like the ability to set the proxy for a URL, etc.
"URLRequestTestHTTP.ProxyTunnelRedirectTest",
"URLRequestTestHTTP.UnexpectedServerAuthTest",
void CFUrlRequestUnittestRunner::PostMainMessageLoopRun() {
fake_chrome_->browser_process()->StartTearDown();
// This test is disabled as it expects an empty UA to be echoed back from
// the server which is not the case in ChromeFrame.
"URLRequestTestHTTP.DefaultUserAgent",
// This test modifies the UploadData object after it has been marshaled to
// ChromeFrame. We don't support this.
"URLRequestTestHTTP.TestPostChunkedDataAfterStart",
// Must do this separately as the mock profile_manager_ is not the
// same member as BrowserProcessImpl::StartTearDown resets.
fake_chrome_->browser_process()->DestroyProfileManager();
// Do not work in CF, it may well be that IE is unconditionally
// adding Accept-Encoding header by default to outgoing requests.
"URLRequestTestHTTP.DefaultAcceptEncoding",
"URLRequestTestHTTP.OverrideAcceptEncoding",
if (crash_service_)
base::KillProcess(crash_service_, 0, false);
// Not supported in ChromeFrame as we use IE's network stack.
"URLRequestTest.NetworkDelegateProxyError",
base::KillProcesses(chrome_frame_test::kIEImageName, 0, NULL);
base::KillProcesses(chrome_frame_test::kIEBrokerImageName, 0, NULL);
}
// URLRequestAutomationJob needs to support NeedsAuth.
// http://crbug.com/98446
"URLRequestTestHTTP.NetworkDelegateOnAuthRequiredSyncNoAction",
"URLRequestTestHTTP.NetworkDelegateOnAuthRequiredSyncSetAuth",
"URLRequestTestHTTP.NetworkDelegateOnAuthRequiredSyncCancel",
"URLRequestTestHTTP.NetworkDelegateOnAuthRequiredAsyncNoAction",
"URLRequestTestHTTP.NetworkDelegateOnAuthRequiredAsyncSetAuth",
"URLRequestTestHTTP.NetworkDelegateOnAuthRequiredAsyncCancel",
void CFUrlRequestUnittestRunner::PreStopThread(
content::BrowserThread::ID identifier) {
fake_chrome_->browser_process()->PreStopThread(identifier);
}
// Flaky on the tryservers, http://crbug.com/103097
"URLRequestTestHTTP.MultipleRedirectTest",
"URLRequestTestHTTP.NetworkDelegateRedirectRequest",
};
void CFUrlRequestUnittestRunner::PostStopThread(
content::BrowserThread::ID identifier) {
fake_chrome_->browser_process()->PostStopThread(identifier);
}
std::string filter("-"); // All following filters will be negative.
for (int i = 0; i < arraysize(disabled_tests); ++i) {
if (i > 0)
filter += ":";
filter += disabled_tests[i];
}
void CFUrlRequestUnittestRunner::PostDestroyThreads() {
fake_chrome_->Shutdown();
fake_chrome_.reset();
::testing::FLAGS_gtest_filter = filter;
#ifndef NDEBUG
// Avoid CRT cleanup in debug test runs to ensure that webkit ASSERTs which
// check if globals are created and destroyed on the same thread don't fire.
// Webkit global objects are created on the inproc renderer thread.
ExitProcess(test_result());
#endif
}
// We need a module since some of the accessibility code that gets pulled
......@@ -608,54 +695,75 @@ const char* IEVersionToString(IEVersion version) {
}
}
content::BrowserMainParts* FakeContentBrowserClient::CreateBrowserMainParts(
const content::MainFunctionParams& parameters) {
// We never delete this, as the content module takes ownership.
//
// We must not construct this earlier, or we will have out-of-order
// AtExitManager creation/destruction.
g_test_suite = new CFUrlRequestUnittestRunner(g_argc, g_argv);
g_test_suite->set_crash_service(chrome_frame_test::StartCrashService());
return g_test_suite;
}
// We must provide a few functions content/ expects to link with. They
// are never called for this executable.
int PluginMain(const content::MainFunctionParams& parameters) {
NOTREACHED();
return 0;
}
int PpapiBrokerMain(const content::MainFunctionParams& parameters) {
return PluginMain(parameters);
}
int PpapiPluginMain(const content::MainFunctionParams& parameters) {
return PluginMain(parameters);
}
int WorkerMain(const content::MainFunctionParams& parameters) {
return PluginMain(parameters);
}
int main(int argc, char** argv) {
// TODO(joi): Remove the "true" part here and fix the log statement below.
g_argc = argc;
g_argv = argv;
// Temporarily disabled, http://crbug.com/105435.
if (true || chrome_frame_test::GetInstalledIEVersion() >= IE_9) {
// Adding this here as the command line and the logging stuff gets
// initialized in the NetTestSuite constructor. Did not want to break that.
base::AtExitManager at_exit_manager;
CommandLine::Init(argc, argv);
CFUrlRequestUnittestRunner::InitializeLogging();
LOG(INFO) << "Temporarily not running any ChromeFrame "
<< "net tests (http://crbug.com/105435)";
LOG(INFO) << "Temporarily not running ChromeFrame net tests.";
//LOG(INFO) << "Not running ChromeFrame net tests on IE9+";
return 0;
}
google_breakpad::scoped_ptr<google_breakpad::ExceptionHandler> breakpad(
InitializeCrashReporting(HEADLESS));
// TODO(tommi): Stuff be broke. Needs a fixin'.
// This is awkward: the TestSuite derived CFUrlRequestUnittestRunner contains
// the instance of the AtExitManager that RegisterPathProvider() and others
// below require. So we have to instantiate this first.
CFUrlRequestUnittestRunner test_suite(argc, argv);
// Display the IE version we run with. This must be done after
// CFUrlRequestUnittestRunner is constructed since that initializes logging.
IEVersion ie_version = chrome_frame_test::GetInstalledIEVersion();
LOG(INFO) << "Running CF net tests with IE version: "
<< IEVersionToString(ie_version);
base::ProcessHandle crash_service = chrome_frame_test::StartCrashService();
WindowWatchdog watchdog;
// See url_request_unittest.cc for these credentials.
SupplyProxyCredentials credentials("user", "secret");
WindowWatchdog watchdog;
watchdog.AddObserver(&credentials, "Windows Security", "");
testing::InitGoogleTest(&argc, argv);
FilterDisabledTests();
test_suite.RunMainUIThread();
if (crash_service)
base::KillProcess(crash_service, 0, false);
base::KillProcesses(chrome_frame_test::kIEImageName, 0, NULL);
base::KillProcesses(chrome_frame_test::kIEBrokerImageName, 0, NULL);
// Avoid CRT cleanup in debug test runs to ensure that webkit ASSERTs which
// check if globals are created and destroyed on the same thread don't fire.
// Webkit global objects are created on the inproc renderer thread.
#if !defined(NDEBUG)
ExitProcess(test_suite.test_result());
#endif // NDEBUG
return test_suite.test_result();
sandbox::SandboxInterfaceInfo sandbox_info = {0};
// This would normally be done, but is probably not needed for these tests.
// content::InitializeSandboxInfo(&sandbox_info);
FakeMainDelegate delegate;
content::ContentMain(
reinterpret_cast<HINSTANCE>(GetModuleHandle(NULL)),
&sandbox_info,
&delegate);
// Note: In debug builds, we ExitProcess during PostDestroyThreads.
return g_test_suite->test_result();
}
......@@ -10,6 +10,7 @@
#include "base/file_path.h"
#include "base/message_loop.h"
#include "base/process.h"
#include "base/win/scoped_handle.h"
#include "chrome/app/scoped_ole_initializer.h"
#include "chrome/browser/browser_process_impl.h"
......@@ -17,9 +18,11 @@
#include "chrome_frame/test/net/test_automation_provider.h"
#include "chrome_frame/test/test_server.h"
#include "chrome_frame/test_utils.h"
#include "content/test/test_browser_thread.h"
#include "content/public/browser/browser_main_parts.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/net_test_suite.h"
class FakeBrowserProcessImpl;
class ProcessSingleton;
namespace content {
......@@ -39,27 +42,33 @@ class FakeExternalTab {
return user_data_dir_;
}
MessageLoopForUI* ui_loop() {
return &loop_;
}
FakeBrowserProcessImpl* browser_process() const;
protected:
MessageLoopForUI loop_;
scoped_ptr<BrowserProcess> browser_process_;
scoped_ptr<FakeBrowserProcessImpl> browser_process_;
FilePath overridden_user_dir_;
FilePath user_data_dir_;
scoped_ptr<ProcessSingleton> process_singleton_;
scoped_ptr<content::NotificationService> notificaton_service_;
DISALLOW_COPY_AND_ASSIGN(FakeExternalTab);
};
// The "master class" that spins the UI and test threads.
//
// In this weird test executable that pretends to almost be Chrome, it
// plays a similar role to ChromeBrowserMainParts, and must fulfill
// the existing contract between ChromeBrowserMainParts and
// BrowserProcessImpl, i.e. poking BrowserProcessImpl at certain
// lifetime events.
class CFUrlRequestUnittestRunner
: public NetTestSuite,
public ProcessSingletonSubclassDelegate,
public TestAutomationProviderDelegate {
public TestAutomationProviderDelegate,
public content::BrowserMainParts {
public:
CFUrlRequestUnittestRunner(int argc, char** argv);
~CFUrlRequestUnittestRunner();
virtual ~CFUrlRequestUnittestRunner();
virtual void StartChromeFrameInHostBrowser();
......@@ -76,8 +85,6 @@ class CFUrlRequestUnittestRunner
// TestAutomationProviderDelegate.
virtual void OnInitialTabLoaded();
void RunMainUIThread();
void StartTests();
// Borrowed from TestSuite::Initialize().
......@@ -87,6 +94,27 @@ class CFUrlRequestUnittestRunner
return test_result_;
}
void set_crash_service(base::ProcessHandle handle) {
crash_service_ = handle;
}
// content::BrowserMainParts implementation.
virtual void PreEarlyInitialization() OVERRIDE;
virtual void PostEarlyInitialization() OVERRIDE {}
virtual void PreMainMessageLoopStart() OVERRIDE {}
virtual void PostMainMessageLoopStart() OVERRIDE {}
virtual void ToolkitInitialized() OVERRIDE {}
virtual void PreCreateThreads() OVERRIDE;
virtual void PreStartThread(content::BrowserThread::ID identifier) OVERRIDE;
virtual void PostStartThread(
content::BrowserThread::ID identifier) OVERRIDE;
virtual void PreMainMessageLoopRun() OVERRIDE;
virtual bool MainMessageLoopRun(int* result_code) OVERRIDE;
virtual void PostMainMessageLoopRun() OVERRIDE;
virtual void PreStopThread(content::BrowserThread::ID identifier) OVERRIDE;
virtual void PostStopThread(content::BrowserThread::ID identifier) OVERRIDE;
virtual void PostDestroyThreads() OVERRIDE;
protected:
// This is the thread that runs all the UrlRequest tests.
// Within its context, the Initialize() and Shutdown() routines above
......@@ -97,24 +125,19 @@ class CFUrlRequestUnittestRunner
protected:
base::win::ScopedHandle test_thread_;
base::ProcessHandle crash_service_;
DWORD test_thread_id_;
scoped_ptr<test_server::SimpleWebServer> test_http_server_;
test_server::SimpleResponse chrome_frame_html_;
// The fake chrome instance. This instance owns the UI message loop
// on the main thread.
FakeExternalTab fake_chrome_;
// The fake chrome instance.
scoped_ptr<FakeExternalTab> fake_chrome_;
scoped_ptr<ProcessSingletonSubclass> pss_subclass_;
scoped_ptr<content::TestBrowserThread> main_thread_;
ScopedChromeFrameRegistrar registrar_;
int test_result_;
// TODO(joi): This should be fixed so that this test executable uses
// content::BrowserMainParts. As it stands it is a horrible hack.
scoped_ptr<content::TestBrowserThread> db_thread_;
scoped_ptr<content::TestBrowserThread> file_thread_;
scoped_ptr<content::TestBrowserThread> io_thread_;
DISALLOW_COPY_AND_ASSIGN(CFUrlRequestUnittestRunner);
};
#endif // CHROME_FRAME_TEST_NET_FAKE_EXTERNAL_TAB_H_
......@@ -99,10 +99,17 @@ net::URLRequestJob* TestAutomationProvider::Factory(net::URLRequest* request,
}
std::string TestAutomationProvider::GetProtocolVersion() {
// Return the version of chrome.dll
// Return the version of npchrome_frame.dll. We used to use
// chrome.dll, but the other end of the pipe in this case is
// actually npchrome_frame.dll (which fetches its version info from
// itself), and occasionally we run into RC dependency problems in
// incremental builds so that the version information does not get
// updated in one module but does in another, so better to use the
// exact same version to avoid hard-to-debug problems in development
// builds.
FilePath path;
PathService::Get(base::DIR_MODULE, &path);
path = path.AppendASCII("chrome.dll");
path = path.AppendASCII("npchrome_frame.dll");
std::string version;
scoped_ptr<FileVersionInfo> version_info(
......
@ECHO OFF
REM Copyright (c) 2009 The Chromium Authors. All rights reserved.
REM Copyright (c) 2011 The Chromium Authors. All rights reserved.
REM Use of this source code is governed by a BSD-style license that can be
REM found in the LICENSE file.
REM
......@@ -59,22 +59,31 @@ mkdir base
mkdir build\%CONFIG%
mkdir chrome_frame\test\data
mkdir chrome_frame\test\html_util_test_data
mkdir net\data
mkdir net\tools\testserver
mkdir third_party\pyftpdlib
mkdir third_party\pylib
mkdir third_party\python_26
mkdir third_party\tlslite
copy %CLIENT_ROOT%\base\base_paths_win.cc base\base_paths_win.cc
xcopy %CLIENT_ROOT%\build\%CONFIG% build\%CONFIG% /E /EXCLUDE:%CLIENT_ROOT%\chrome_frame\test\poor_mans_trybot_xcopy_filter.txt
xcopy %CLIENT_ROOT%\chrome_frame\test\data chrome_frame\test\data /E
xcopy %CLIENT_ROOT%\net\data net\data /E
xcopy %CLIENT_ROOT%\net\tools\testserver net\tools\testserver /E
xcopy %CLIENT_ROOT%\third_party\pyftpdlib third_party\pyftpdlib /E
xcopy %CLIENT_ROOT%\third_party\pylib third_party\pylib /E
xcopy %CLIENT_ROOT%\third_party\python_26 third_party\python_26 /E
xcopy %CLIENT_ROOT%\third_party\tlslite third_party\tlslite /E
xcopy %CLIENT_ROOT%\chrome_frame\test\html_util_test_data chrome_frame\test\html_util_test_data /E
copy %CLIENT_ROOT%\chrome_frame\CFInstance.js chrome_frame\CFInstance.js
copy %CLIENT_ROOT%\chrome_frame\CFInstall.js chrome_frame\CFInstall.js
@ECHO OFF
echo ************************************
echo DO THE FOLLOWING IN AN ADMIN PROMPT:
echo ************************************
echo regsvr32 \trybot\build\%CONFIG%\servers\npchrome_frame.dll
echo *********************************
echo THEN DO THIS IN A REGULAR PROMPT:
echo *********************************
echo \trybot\build\%CONFIG%\chrome_frame_unittests.exe
echo \trybot\build\%CONFIG%\chrome_frame_tests.exe
echo %DRIVE%%INSTALL_ROOT%\build\%CONFIG%\chrome_frame_unittests.exe
echo %DRIVE%%INSTALL_ROOT%\build\%CONFIG%\chrome_frame_tests.exe
echo %DRIVE%%INSTALL_ROOT%\build\%CONFIG%\chrome_frame_net_tests.exe
goto end
:usage
......
......@@ -45,6 +45,10 @@ void NetTestSuite::Shutdown() {
void NetTestSuite::InitializeTestThread() {
network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock());
InitializeTestThreadNoNetworkChangeNotifier();
}
void NetTestSuite::InitializeTestThreadNoNetworkChangeNotifier() {
host_resolver_proc_ = new net::RuleBasedHostResolverProc(NULL);
scoped_host_resolver_proc_.Init(host_resolver_proc_.get());
// In case any attempts are made to resolve host names, force them all to
......
......@@ -34,6 +34,12 @@ class NetTestSuite : public base::TestSuite {
// initialization that can only be done once.
void InitializeTestThread();
// Same as above, except it does not create a mock
// NetworkChangeNotifier. Use this if your test needs to create and
// manage its own mock NetworkChangeNotifier, or if your test uses
// the production NetworkChangeNotifier.
void InitializeTestThreadNoNetworkChangeNotifier();
private:
scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
scoped_ptr<MessageLoop> message_loop_;
......
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