Skip to content

Commit

Permalink
Revert 236071 "Allow TracingController output trace data to spec..."
Browse files Browse the repository at this point in the history
> Allow TracingController output trace data to specified file
> 
> Sometimes we need to let TracingController output traces to specified
> file, e.g. trace-startup (which will be migrated from TraceController
> to TracingController).
> 
> Also fixed the problem of IO operations in UI thread.
> 
> BUG=none
> TEST=TracingControllerTest.EnableAndDisableRecordingWithFilePath
> TEST=TracingControllerTest.EnableCaptureAndDisableMonitoringWithFilePath
> R=joi@chromium.org, nduca@chromium.org
> 
> Review URL: https://codereview.chromium.org/66893003

TBR=wangxianzhu@chromium.org

Review URL: https://codereview.chromium.org/77063003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236088 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
yzshen@chromium.org committed Nov 20, 2013
1 parent 4d4fc8d commit 5f0d8c0
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 307 deletions.
3 changes: 1 addition & 2 deletions content/browser/tracing/trace_message_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ void TraceMessageFilter::OnMonitoringTraceDataCollected(
const std::string& data) {
scoped_refptr<base::RefCountedString> data_ptr(new base::RefCountedString());
data_ptr->data() = data;
TracingControllerImpl::GetInstance()->OnMonitoringTraceDataCollected(
data_ptr);
TracingControllerImpl::GetInstance()->OnTraceDataCollected(data_ptr);
}

void TraceMessageFilter::OnTraceNotification(int notification) {
Expand Down
205 changes: 68 additions & 137 deletions content/browser/tracing/tracing_controller_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ class TracingControllerTest : public ContentBrowserTest {
}

void DisableRecordingDoneCallbackTest(base::Closure quit_callback,
const base::FilePath& file_path) {
scoped_ptr<base::FilePath> file_path) {
disable_recording_done_callback_count_++;
EXPECT_TRUE(PathExists(file_path));
EXPECT_TRUE(PathExists(*file_path));
int64 file_size;
file_util::GetFileSize(file_path, &file_size);
file_util::GetFileSize(*file_path, &file_size);
EXPECT_TRUE(file_size > 0);
quit_callback.Run();
last_actual_recording_file_path_ = file_path;
}

void EnableMonitoringDoneCallbackTest(base::Closure quit_callback) {
Expand All @@ -68,14 +67,13 @@ class TracingControllerTest : public ContentBrowserTest {
}

void CaptureMonitoringSnapshotDoneCallbackTest(
base::Closure quit_callback, const base::FilePath& file_path) {
base::Closure quit_callback, scoped_ptr<base::FilePath> file_path) {
capture_monitoring_snapshot_done_callback_count_++;
EXPECT_TRUE(PathExists(file_path));
EXPECT_TRUE(PathExists(*file_path));
int64 file_size;
file_util::GetFileSize(file_path, &file_size);
file_util::GetFileSize(*file_path, &file_size);
EXPECT_TRUE(file_size > 0);
quit_callback.Run();
last_actual_monitoring_file_path_ = file_path;
}

int get_categories_done_callback_count() const {
Expand All @@ -102,100 +100,13 @@ class TracingControllerTest : public ContentBrowserTest {
return capture_monitoring_snapshot_done_callback_count_;
}

base::FilePath last_actual_recording_file_path() const {
return last_actual_recording_file_path_;
}

base::FilePath last_actual_monitoring_file_path() const {
return last_actual_monitoring_file_path_;
}

void TestEnableAndDisableRecording(const base::FilePath& result_file_path) {
Navigate(shell());

TracingController* controller = TracingController::GetInstance();

{
base::RunLoop run_loop;
TracingController::EnableRecordingDoneCallback callback =
base::Bind(&TracingControllerTest::EnableRecordingDoneCallbackTest,
base::Unretained(this),
run_loop.QuitClosure());
bool result = controller->EnableRecording(
base::debug::CategoryFilter(""), TracingController::Options(),
callback);
EXPECT_TRUE(result);
run_loop.Run();
EXPECT_EQ(enable_recording_done_callback_count(), 1);
}

{
base::RunLoop run_loop;
TracingController::TracingFileResultCallback callback =
base::Bind(&TracingControllerTest::DisableRecordingDoneCallbackTest,
base::Unretained(this),
run_loop.QuitClosure());
bool result = controller->DisableRecording(result_file_path, callback);
EXPECT_TRUE(result);
run_loop.Run();
EXPECT_EQ(disable_recording_done_callback_count(), 1);
}
}

void TestEnableCaptureAndDisableMonitoring(
const base::FilePath& result_file_path) {
Navigate(shell());

TracingController* controller = TracingController::GetInstance();

{
base::RunLoop run_loop;
TracingController::EnableMonitoringDoneCallback callback =
base::Bind(&TracingControllerTest::EnableMonitoringDoneCallbackTest,
base::Unretained(this),
run_loop.QuitClosure());
bool result = controller->EnableMonitoring(
base::debug::CategoryFilter(""), TracingController::ENABLE_SAMPLING,
callback);
EXPECT_TRUE(result);
run_loop.Run();
EXPECT_EQ(enable_monitoring_done_callback_count(), 1);
}

{
base::RunLoop run_loop;
TracingController::TracingFileResultCallback callback =
base::Bind(&TracingControllerTest::
CaptureMonitoringSnapshotDoneCallbackTest,
base::Unretained(this),
run_loop.QuitClosure());
controller->CaptureMonitoringSnapshot(result_file_path, callback);
run_loop.Run();
EXPECT_EQ(capture_monitoring_snapshot_done_callback_count(), 1);
}

{
base::RunLoop run_loop;
TracingController::DisableMonitoringDoneCallback callback =
base::Bind(&TracingControllerTest::DisableMonitoringDoneCallbackTest,
base::Unretained(this),
run_loop.QuitClosure());
bool result = controller->DisableMonitoring(callback);
EXPECT_TRUE(result);
run_loop.Run();
EXPECT_EQ(disable_monitoring_done_callback_count(), 1);
}
}

private:
int get_categories_done_callback_count_;
int enable_recording_done_callback_count_;
int disable_recording_done_callback_count_;
int enable_monitoring_done_callback_count_;
int disable_monitoring_done_callback_count_;
int capture_monitoring_snapshot_done_callback_count_;
base::FilePath last_actual_recording_file_path_;
base::FilePath last_actual_monitoring_file_path_;
};

IN_PROC_BROWSER_TEST_F(TracingControllerTest, GetCategories) {
Expand All @@ -214,58 +125,78 @@ IN_PROC_BROWSER_TEST_F(TracingControllerTest, GetCategories) {
}

IN_PROC_BROWSER_TEST_F(TracingControllerTest, EnableAndDisableRecording) {
TestEnableAndDisableRecording(base::FilePath());
}

IN_PROC_BROWSER_TEST_F(TracingControllerTest,
EnableAndDisableRecordingWithFilePath) {
base::FilePath file_path;
file_util::CreateTemporaryFile(&file_path);
TestEnableAndDisableRecording(file_path);
EXPECT_EQ(file_path.value(), last_actual_recording_file_path().value());
}

IN_PROC_BROWSER_TEST_F(TracingControllerTest,
EnableAndDisableRecordingWithEmptyFileAndNullCallback) {
Navigate(shell());

TracingController* controller = TracingController::GetInstance();
EXPECT_TRUE(controller->EnableRecording(
base::debug::CategoryFilter(""), TracingController::Options(),
TracingController::EnableRecordingDoneCallback()));
EXPECT_TRUE(controller->DisableRecording(
base::FilePath(), TracingController::TracingFileResultCallback()));
base::RunLoop().RunUntilIdle();
}

IN_PROC_BROWSER_TEST_F(TracingControllerTest,
EnableCaptureAndDisableMonitoring) {
TestEnableCaptureAndDisableMonitoring(base::FilePath());
{
base::RunLoop run_loop;
TracingController::EnableRecordingDoneCallback callback =
base::Bind(&TracingControllerTest::EnableRecordingDoneCallbackTest,
base::Unretained(this),
run_loop.QuitClosure());
bool result = controller->EnableRecording(base::debug::CategoryFilter("*"),
TracingController::Options(), callback);
EXPECT_TRUE(result);
run_loop.Run();
EXPECT_EQ(enable_recording_done_callback_count(), 1);
}

{
base::RunLoop run_loop;
TracingController::TracingFileResultCallback callback =
base::Bind(&TracingControllerTest::DisableRecordingDoneCallbackTest,
base::Unretained(this),
run_loop.QuitClosure());
bool result = controller->DisableRecording(callback);
EXPECT_TRUE(result);
run_loop.Run();
EXPECT_EQ(disable_recording_done_callback_count(), 1);
}
}

IN_PROC_BROWSER_TEST_F(TracingControllerTest,
EnableCaptureAndDisableMonitoringWithFilePath) {
base::FilePath file_path;
file_util::CreateTemporaryFile(&file_path);
TestEnableCaptureAndDisableMonitoring(file_path);
EXPECT_EQ(file_path.value(), last_actual_monitoring_file_path().value());
}

IN_PROC_BROWSER_TEST_F(
TracingControllerTest,
EnableCaptureAndDisableMonitoringWithEmptyFileAndNullCallback) {
EnableCaptureAndDisableMonitoring) {
Navigate(shell());

TracingController* controller = TracingController::GetInstance();
EXPECT_TRUE(controller->EnableMonitoring(
base::debug::CategoryFilter(""), TracingController::ENABLE_SAMPLING,
TracingController::EnableMonitoringDoneCallback()));
controller->CaptureMonitoringSnapshot(
base::FilePath(), TracingController::TracingFileResultCallback());
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(controller->DisableMonitoring(
TracingController::DisableMonitoringDoneCallback()));
base::RunLoop().RunUntilIdle();

{
base::RunLoop run_loop;
TracingController::EnableMonitoringDoneCallback callback =
base::Bind(&TracingControllerTest::EnableMonitoringDoneCallbackTest,
base::Unretained(this),
run_loop.QuitClosure());
bool result = controller->EnableMonitoring(base::debug::CategoryFilter("*"),
TracingController::ENABLE_SAMPLING, callback);
EXPECT_TRUE(result);
run_loop.Run();
EXPECT_EQ(enable_monitoring_done_callback_count(), 1);
}

{
base::RunLoop run_loop;
TracingController::TracingFileResultCallback callback =
base::Bind(&TracingControllerTest::
CaptureMonitoringSnapshotDoneCallbackTest,
base::Unretained(this),
run_loop.QuitClosure());
controller->CaptureMonitoringSnapshot(callback);
run_loop.Run();
EXPECT_EQ(capture_monitoring_snapshot_done_callback_count(), 1);
}

{
base::RunLoop run_loop;
TracingController::DisableMonitoringDoneCallback callback =
base::Bind(&TracingControllerTest::DisableMonitoringDoneCallbackTest,
base::Unretained(this),
run_loop.QuitClosure());
bool result = controller->DisableMonitoring(callback);
EXPECT_TRUE(result);
run_loop.Run();
EXPECT_EQ(disable_monitoring_done_callback_count(), 1);
}
}

} // namespace content
Loading

0 comments on commit 5f0d8c0

Please sign in to comment.