#include "base/bind.h"
#include "base/command_line.h"
#include "base/debug/stack_trace.h"
+#include "base/i18n/icu_util.h"
#include "base/message_loop/message_loop.h"
+#include "base/strings/string_number_conversions.h"
#include "base/sys_info.h"
+#include "base/test/test_timeouts.h"
+#include "content/public/app/content_main.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
+#include "content/browser/tracing/tracing_controller_impl.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/main_function_params.h"
+#include "content/public/test/test_launcher.h"
#include "content/public/test/test_utils.h"
#include "net/base/net_errors.h"
#include "net/dns/mock_host_resolver.h"
#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
-#include "base/power_monitor/power_monitor_device_source.h"
#endif
#if defined(OS_ANDROID)
#endif
#if defined(USE_AURA)
-#include "content/browser/aura/image_transport_factory.h"
-#include "ui/compositor/test/test_context_factory.h"
+#include "content/browser/compositor/image_transport_factory.h"
+#include "ui/aura/test/event_generator_delegate_aura.h"
+#if defined(USE_X11)
+#include "ui/aura/window_tree_host_x11.h"
+#endif
#endif
namespace content {
public:
LocalHostResolverProc() : HostResolverProc(NULL) {}
- virtual int Resolve(const std::string& host,
- net::AddressFamily address_family,
- net::HostResolverFlags host_resolver_flags,
- net::AddressList* addrlist,
- int* os_error) OVERRIDE {
+ int Resolve(const std::string& host,
+ net::AddressFamily address_family,
+ net::HostResolverFlags host_resolver_flags,
+ net::AddressList* addrlist,
+ int* os_error) override {
const char* kLocalHostNames[] = {"localhost", "127.0.0.1", "::1"};
bool local = false;
}
private:
- virtual ~LocalHostResolverProc() {}
+ ~LocalHostResolverProc() override {}
};
+void TraceDisableRecordingComplete(const base::Closure& quit,
+ const base::FilePath& file_path) {
+ LOG(ERROR) << "Tracing written to: " << file_path.value();
+ quit.Run();
+}
+
} // namespace
extern int BrowserMain(const MainFunctionParams&);
BrowserTestBase::BrowserTestBase()
- : allow_test_contexts_(true),
- allow_osmesa_(true) {
+ : expected_exit_code_(0),
+ enable_pixel_output_(false),
+ use_software_compositing_(false) {
#if defined(OS_MACOSX)
base::mac::SetOverrideAmIBundled(true);
- base::PowerMonitorDeviceSource::AllocateSystemIOPorts();
+#endif
+
+#if defined(USE_AURA)
+#if defined(USE_X11)
+ aura::test::SetUseOverrideRedirectWindowByDefault(true);
+#endif
+ aura::test::InitializeAuraEventGeneratorDelegate();
#endif
#if defined(OS_POSIX)
handle_sigterm_ = true;
#endif
+ // This is called through base::TestSuite initially. It'll also be called
+ // inside BrowserMain, so tell the code to ignore the check that it's being
+ // called more than once
+ base::i18n::AllowMultipleInitializeCallsForTesting();
+
embedded_test_server_.reset(new net::test_server::EmbeddedTestServer);
}
void BrowserTestBase::SetUp() {
CommandLine* command_line = CommandLine::ForCurrentProcess();
+ // Override the child process connection timeout since tests can exceed that
+ // when sharded.
+ command_line->AppendSwitchASCII(
+ switches::kIPCConnectionTimeout,
+ base::IntToString(TestTimeouts::action_max_timeout().InSeconds()));
+
// The tests assume that file:// URIs can freely access other file:// URIs.
command_line->AppendSwitch(switches::kAllowFileAccessFromFiles);
// GPU blacklisting decisions were made.
command_line->AppendSwitch(switches::kLogGpuControlListDecisions);
-#if defined(OS_CHROMEOS)
- // If the test is running on the chromeos envrionment (such as
- // device or vm bots), always use real contexts.
- if (base::SysInfo::IsRunningOnChromeOS())
- allow_test_contexts_ = false;
+ if (use_software_compositing_) {
+ command_line->AppendSwitch(switches::kDisableGpu);
+#if defined(USE_AURA)
+ command_line->AppendSwitch(switches::kUIDisableThreadedCompositing);
#endif
+ }
#if defined(USE_AURA)
- if (command_line->HasSwitch(switches::kDisableTestCompositor))
- allow_test_contexts_ = false;
-
- // Use test contexts for browser tests unless they override and force us to
- // use a real context.
- if (allow_test_contexts_) {
- content::ImageTransportFactory::InitializeForUnitTests(
- scoped_ptr<ui::ContextFactory>(new ui::TestContextFactory));
+ // Most tests do not need pixel output, so we don't produce any. The command
+ // line can override this behaviour to allow for visual debugging.
+ if (command_line->HasSwitch(switches::kEnablePixelOutputInTests))
+ enable_pixel_output_ = true;
+
+ if (command_line->HasSwitch(switches::kDisableGLDrawingForTests)) {
+ NOTREACHED() << "kDisableGLDrawingForTests should not be used as it"
+ "is chosen by tests. Use kEnablePixelOutputInTests "
+ "to enable pixel output.";
}
+
+ // Don't enable pixel output for browser tests unless they override and force
+ // us to, or it's requested on the command line.
+ if (!enable_pixel_output_ && !use_software_compositing_)
+ command_line->AppendSwitch(switches::kDisableGLDrawingForTests);
#endif
- // When using real GL contexts, we usually use OSMesa as this works on all
- // bots. The command line can override this behaviour to use a real GPU.
+ bool use_osmesa = true;
+
+ // We usually use OSMesa as this works on all bots. The command line can
+ // override this behaviour to use hardware GL.
if (command_line->HasSwitch(switches::kUseGpuInTests))
- allow_osmesa_ = false;
+ use_osmesa = false;
- // Some bots pass this flag when they want to use a real GPU.
+ // Some bots pass this flag when they want to use hardware GL.
if (command_line->HasSwitch("enable-gpu"))
- allow_osmesa_ = false;
+ use_osmesa = false;
#if defined(OS_MACOSX)
- // On Mac we always use a real GPU.
- allow_osmesa_ = false;
+ // On Mac we always use hardware GL.
+ use_osmesa = false;
#endif
#if defined(OS_ANDROID)
- // On Android we always use a real GPU.
- allow_osmesa_ = false;
+ // On Android we always use hardware GL.
+ use_osmesa = false;
#endif
#if defined(OS_CHROMEOS)
// If the test is running on the chromeos envrionment (such as
- // device or vm bots), the compositor will use real GL contexts, and
- // we should use real GL bindings with it.
+ // device or vm bots), we use hardware GL.
if (base::SysInfo::IsRunningOnChromeOS())
- allow_osmesa_ = false;
+ use_osmesa = false;
#endif
- if (command_line->HasSwitch(switches::kUseGL)) {
- NOTREACHED() <<
- "kUseGL should not be used with tests. Try kUseGpuInTests instead.";
- }
-
- if (allow_osmesa_) {
- command_line->AppendSwitchASCII(
- switches::kUseGL, gfx::kGLImplementationOSMesaName);
- }
+ if (use_osmesa && !use_software_compositing_)
+ command_line->AppendSwitch(switches::kOverrideUseGLWithOSMesaForTests);
scoped_refptr<net::HostResolverProc> local_resolver =
new LocalHostResolverProc();
rule_based_resolver_->AddSimulatedFailure("wpad");
net::ScopedDefaultHostResolverProc scoped_local_host_resolver_proc(
rule_based_resolver_.get());
-
SetUpInProcessBrowserTestFixture();
- MainFunctionParams params(*command_line);
- params.ui_task =
+ base::Closure* ui_task =
new base::Closure(
base::Bind(&BrowserTestBase::ProxyRunTestOnMainThreadLoop, this));
#if defined(OS_ANDROID)
- BrowserMainRunner::Create()->Initialize(params);
- // We are done running the test by now. During teardown we
- // need to be able to perform IO.
- base::ThreadRestrictions::SetIOAllowed(true);
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed),
- true));
-#else
+ MainFunctionParams params(*command_line);
+ params.ui_task = ui_task;
+ // TODO(phajdan.jr): Check return code, http://crbug.com/374738 .
BrowserMain(params);
+#else
+ GetContentMainParams()->ui_task = ui_task;
+ EXPECT_EQ(expected_exit_code_, ContentMain(*GetContentMainParams()));
#endif
TearDownInProcessBrowserTestFixture();
}
signal(SIGTERM, DumpStackTraceSignalHandler);
}
#endif // defined(OS_POSIX)
+
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableTracing)) {
+ base::debug::CategoryFilter category_filter(
+ CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ switches::kEnableTracing));
+ TracingController::GetInstance()->EnableRecording(
+ category_filter,
+ base::debug::TraceOptions(base::debug::RECORD_CONTINUOUSLY),
+ TracingController::EnableRecordingDoneCallback());
+ }
+
RunTestOnMainThreadLoop();
+
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableTracing)) {
+ base::FilePath trace_file =
+ CommandLine::ForCurrentProcess()->GetSwitchValuePath(
+ switches::kEnableTracingOutput);
+ // If there was no file specified, put a hardcoded one in the current
+ // working directory.
+ if (trace_file.empty())
+ trace_file = base::FilePath().AppendASCII("trace.json");
+
+ // Wait for tracing to collect results from the renderers.
+ base::RunLoop run_loop;
+ TracingController::GetInstance()->DisableRecording(
+ TracingControllerImpl::CreateFileSink(
+ trace_file,
+ base::Bind(&TraceDisableRecordingComplete,
+ run_loop.QuitClosure(),
+ trace_file)));
+ run_loop.Run();
+ }
}
void BrowserTestBase::CreateTestServer(const base::FilePath& test_server_base) {
runner->Run();
}
+void BrowserTestBase::EnablePixelOutput() { enable_pixel_output_ = true; }
+
+void BrowserTestBase::UseSoftwareCompositing() {
+ use_software_compositing_ = true;
+}
+
+bool BrowserTestBase::UsingOSMesa() const {
+ CommandLine* cmd = CommandLine::ForCurrentProcess();
+ return cmd->GetSwitchValueASCII(switches::kUseGL) ==
+ gfx::kGLImplementationOSMesaName;
+}
+
} // namespace content