Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(727)

Unified Diff: content/public/test/browser_test_base.cc

Issue 506113002: Add support for tracing in browser tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/public/test/browser_test_base.cc
diff --git a/content/public/test/browser_test_base.cc b/content/public/test/browser_test_base.cc
index e31d9372968ef42fdb3df519a05d824ca265d903..c942236b267e7e9bad8abe2a8b5b95cd4b7695f3 100644
--- a/content/public/test/browser_test_base.cc
+++ b/content/public/test/browser_test_base.cc
@@ -15,6 +15,7 @@
#include "content/public/app/content_main.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/tracing_controller.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/main_function_params.h"
#include "content/public/test/test_launcher.h"
@@ -121,6 +122,12 @@ class LocalHostResolverProc : public net::HostResolverProc {
virtual ~LocalHostResolverProc() {}
};
+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&);
@@ -269,7 +276,35 @@ void BrowserTestBase::ProxyRunTestOnMainThreadLoop() {
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(
+ trace_file,
+ base::Bind(&TraceDisableRecordingComplete, run_loop.QuitClosure()));
+ run_loop.Run();
+ }
}
void BrowserTestBase::CreateTestServer(const base::FilePath& test_server_base) {
« content/public/common/content_switches.cc ('K') | « content/public/common/content_switches.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698