| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/public/browser/tracing_controller.h" | 5 #include "content/public/browser/tracing_controller.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/memory/ref_counted_memory.h" | 11 #include "base/memory/ref_counted_memory.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/strings/pattern.h" | 13 #include "base/strings/pattern.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "content/browser/tracing/tracing_controller_impl.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
| 17 #include "content/public/test/content_browser_test.h" | 18 #include "content/public/test/content_browser_test.h" |
| 18 #include "content/public/test/content_browser_test_utils.h" | 19 #include "content/public/test/content_browser_test_utils.h" |
| 19 #include "content/shell/browser/shell.h" | 20 #include "content/shell/browser/shell.h" |
| 20 | 21 |
| 21 using base::trace_event::RECORD_CONTINUOUSLY; | 22 using base::trace_event::RECORD_CONTINUOUSLY; |
| 22 using base::trace_event::RECORD_UNTIL_FULL; | 23 using base::trace_event::RECORD_UNTIL_FULL; |
| 23 using base::trace_event::TraceConfig; | 24 using base::trace_event::TraceConfig; |
| 24 | 25 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 48 base::trace_event::ArgumentNameFilterPredicate* arg_filter) { | 49 base::trace_event::ArgumentNameFilterPredicate* arg_filter) { |
| 49 if (base::MatchPattern(category_group_name, "benchmark") && | 50 if (base::MatchPattern(category_group_name, "benchmark") && |
| 50 base::MatchPattern(event_name, "whitelisted")) { | 51 base::MatchPattern(event_name, "whitelisted")) { |
| 51 return true; | 52 return true; |
| 52 } | 53 } |
| 53 return false; | 54 return false; |
| 54 } | 55 } |
| 55 | 56 |
| 56 } // namespace | 57 } // namespace |
| 57 | 58 |
| 58 class TracingControllerTestEndpoint | 59 class TracingControllerTestEndpoint : public TraceDataEndpoint { |
| 59 : public TracingController::TraceDataEndpoint { | |
| 60 public: | 60 public: |
| 61 TracingControllerTestEndpoint( | 61 TracingControllerTestEndpoint( |
| 62 base::Callback<void(std::unique_ptr<const base::DictionaryValue>, | 62 base::Callback<void(std::unique_ptr<const base::DictionaryValue>, |
| 63 base::RefCountedString*)> done_callback) | 63 base::RefCountedString*)> done_callback) |
| 64 : done_callback_(done_callback) {} | 64 : done_callback_(done_callback) {} |
| 65 | 65 |
| 66 void ReceiveTraceChunk(const std::string& chunk) override { | 66 void ReceiveTraceChunk(const std::string& chunk) override { |
| 67 EXPECT_FALSE(chunk.empty()); | 67 EXPECT_FALSE(chunk.empty()); |
| 68 trace_ += chunk; | 68 trace_ += chunk; |
| 69 } | 69 } |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 } | 264 } |
| 265 | 265 |
| 266 { | 266 { |
| 267 base::RunLoop run_loop; | 267 base::RunLoop run_loop; |
| 268 base::Callback<void(std::unique_ptr<const base::DictionaryValue>, | 268 base::Callback<void(std::unique_ptr<const base::DictionaryValue>, |
| 269 base::RefCountedString*)> | 269 base::RefCountedString*)> |
| 270 callback = base::Bind( | 270 callback = base::Bind( |
| 271 &TracingControllerTest::StopTracingStringDoneCallbackTest, | 271 &TracingControllerTest::StopTracingStringDoneCallbackTest, |
| 272 base::Unretained(this), run_loop.QuitClosure()); | 272 base::Unretained(this), run_loop.QuitClosure()); |
| 273 bool result = controller->StopTracing( | 273 bool result = controller->StopTracing( |
| 274 TracingController::CreateCompressedStringSink( | 274 TracingControllerImpl::CreateCompressedStringSink( |
| 275 new TracingControllerTestEndpoint(callback))); | 275 new TracingControllerTestEndpoint(callback))); |
| 276 ASSERT_TRUE(result); | 276 ASSERT_TRUE(result); |
| 277 run_loop.Run(); | 277 run_loop.Run(); |
| 278 EXPECT_EQ(disable_recording_done_callback_count(), 1); | 278 EXPECT_EQ(disable_recording_done_callback_count(), 1); |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 | 281 |
| 282 void TestStartAndStopTracingCompressedFile( | 282 void TestStartAndStopTracingCompressedFile( |
| 283 const base::FilePath& result_file_path) { | 283 const base::FilePath& result_file_path) { |
| 284 Navigate(shell()); | 284 Navigate(shell()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 295 run_loop.Run(); | 295 run_loop.Run(); |
| 296 EXPECT_EQ(enable_recording_done_callback_count(), 1); | 296 EXPECT_EQ(enable_recording_done_callback_count(), 1); |
| 297 } | 297 } |
| 298 | 298 |
| 299 { | 299 { |
| 300 base::RunLoop run_loop; | 300 base::RunLoop run_loop; |
| 301 base::Closure callback = base::Bind( | 301 base::Closure callback = base::Bind( |
| 302 &TracingControllerTest::StopTracingFileDoneCallbackTest, | 302 &TracingControllerTest::StopTracingFileDoneCallbackTest, |
| 303 base::Unretained(this), run_loop.QuitClosure(), result_file_path); | 303 base::Unretained(this), run_loop.QuitClosure(), result_file_path); |
| 304 bool result = controller->StopTracing( | 304 bool result = controller->StopTracing( |
| 305 TracingController::CreateCompressedStringSink( | 305 TracingControllerImpl::CreateCompressedStringSink( |
| 306 TracingController::CreateFileEndpoint(result_file_path, | 306 TracingControllerImpl::CreateFileEndpoint(result_file_path, |
| 307 callback))); | 307 callback))); |
| 308 ASSERT_TRUE(result); | 308 ASSERT_TRUE(result); |
| 309 run_loop.Run(); | 309 run_loop.Run(); |
| 310 EXPECT_EQ(disable_recording_done_callback_count(), 1); | 310 EXPECT_EQ(disable_recording_done_callback_count(), 1); |
| 311 } | 311 } |
| 312 } | 312 } |
| 313 | 313 |
| 314 void TestStartAndStopTracingFile( | 314 void TestStartAndStopTracingFile( |
| 315 const base::FilePath& result_file_path) { | 315 const base::FilePath& result_file_path) { |
| 316 Navigate(shell()); | 316 Navigate(shell()); |
| 317 | 317 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 | 456 |
| 457 TracingController* controller = TracingController::GetInstance(); | 457 TracingController* controller = TracingController::GetInstance(); |
| 458 EXPECT_TRUE(controller->StartTracing( | 458 EXPECT_TRUE(controller->StartTracing( |
| 459 TraceConfig(), | 459 TraceConfig(), |
| 460 TracingController::StartTracingDoneCallback())); | 460 TracingController::StartTracingDoneCallback())); |
| 461 EXPECT_TRUE(controller->StopTracing(NULL)); | 461 EXPECT_TRUE(controller->StopTracing(NULL)); |
| 462 base::RunLoop().RunUntilIdle(); | 462 base::RunLoop().RunUntilIdle(); |
| 463 } | 463 } |
| 464 | 464 |
| 465 } // namespace content | 465 } // namespace content |
| OLD | NEW |