| 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" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 class TracingControllerTest : public ContentBrowserTest { | 94 class TracingControllerTest : public ContentBrowserTest { |
| 95 public: | 95 public: |
| 96 TracingControllerTest() {} | 96 TracingControllerTest() {} |
| 97 | 97 |
| 98 void SetUp() override { | 98 void SetUp() override { |
| 99 get_categories_done_callback_count_ = 0; | 99 get_categories_done_callback_count_ = 0; |
| 100 enable_recording_done_callback_count_ = 0; | 100 enable_recording_done_callback_count_ = 0; |
| 101 disable_recording_done_callback_count_ = 0; | 101 disable_recording_done_callback_count_ = 0; |
| 102 enable_monitoring_done_callback_count_ = 0; | |
| 103 disable_monitoring_done_callback_count_ = 0; | |
| 104 capture_monitoring_snapshot_done_callback_count_ = 0; | |
| 105 ContentBrowserTest::SetUp(); | 102 ContentBrowserTest::SetUp(); |
| 106 } | 103 } |
| 107 | 104 |
| 108 void TearDown() override { ContentBrowserTest::TearDown(); } | 105 void TearDown() override { ContentBrowserTest::TearDown(); } |
| 109 | 106 |
| 110 void Navigate(Shell* shell) { | 107 void Navigate(Shell* shell) { |
| 111 NavigateToURL(shell, GetTestUrl("", "title.html")); | 108 NavigateToURL(shell, GetTestUrl("", "title.html")); |
| 112 } | 109 } |
| 113 | 110 |
| 114 void GetCategoriesDoneCallbackTest(base::Closure quit_callback, | 111 void GetCategoriesDoneCallbackTest(base::Closure quit_callback, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 138 const base::FilePath& file_path) { | 135 const base::FilePath& file_path) { |
| 139 disable_recording_done_callback_count_++; | 136 disable_recording_done_callback_count_++; |
| 140 EXPECT_TRUE(PathExists(file_path)); | 137 EXPECT_TRUE(PathExists(file_path)); |
| 141 int64_t file_size; | 138 int64_t file_size; |
| 142 base::GetFileSize(file_path, &file_size); | 139 base::GetFileSize(file_path, &file_size); |
| 143 EXPECT_TRUE(file_size > 0); | 140 EXPECT_TRUE(file_size > 0); |
| 144 quit_callback.Run(); | 141 quit_callback.Run(); |
| 145 last_actual_recording_file_path_ = file_path; | 142 last_actual_recording_file_path_ = file_path; |
| 146 } | 143 } |
| 147 | 144 |
| 148 void StartMonitoringDoneCallbackTest(base::Closure quit_callback) { | 145 int get_categories_done_callback_count() const { |
| 149 enable_monitoring_done_callback_count_++; | |
| 150 quit_callback.Run(); | |
| 151 } | |
| 152 | |
| 153 void StopMonitoringDoneCallbackTest(base::Closure quit_callback) { | |
| 154 disable_monitoring_done_callback_count_++; | |
| 155 quit_callback.Run(); | |
| 156 } | |
| 157 | |
| 158 void CaptureMonitoringSnapshotDoneCallbackTest( | |
| 159 base::Closure quit_callback, const base::FilePath& file_path) { | |
| 160 capture_monitoring_snapshot_done_callback_count_++; | |
| 161 EXPECT_TRUE(PathExists(file_path)); | |
| 162 int64_t file_size; | |
| 163 base::GetFileSize(file_path, &file_size); | |
| 164 EXPECT_TRUE(file_size > 0); | |
| 165 quit_callback.Run(); | |
| 166 last_actual_monitoring_file_path_ = file_path; | |
| 167 } | |
| 168 | |
| 169 int get_categories_done_callback_count() const { | |
| 170 return get_categories_done_callback_count_; | 146 return get_categories_done_callback_count_; |
| 171 } | 147 } |
| 172 | 148 |
| 173 int enable_recording_done_callback_count() const { | 149 int enable_recording_done_callback_count() const { |
| 174 return enable_recording_done_callback_count_; | 150 return enable_recording_done_callback_count_; |
| 175 } | 151 } |
| 176 | 152 |
| 177 int disable_recording_done_callback_count() const { | 153 int disable_recording_done_callback_count() const { |
| 178 return disable_recording_done_callback_count_; | 154 return disable_recording_done_callback_count_; |
| 179 } | 155 } |
| 180 | 156 |
| 181 int enable_monitoring_done_callback_count() const { | |
| 182 return enable_monitoring_done_callback_count_; | |
| 183 } | |
| 184 | |
| 185 int disable_monitoring_done_callback_count() const { | |
| 186 return disable_monitoring_done_callback_count_; | |
| 187 } | |
| 188 | |
| 189 int capture_monitoring_snapshot_done_callback_count() const { | |
| 190 return capture_monitoring_snapshot_done_callback_count_; | |
| 191 } | |
| 192 | |
| 193 base::FilePath last_actual_recording_file_path() const { | 157 base::FilePath last_actual_recording_file_path() const { |
| 194 return last_actual_recording_file_path_; | 158 return last_actual_recording_file_path_; |
| 195 } | 159 } |
| 196 | 160 |
| 197 base::FilePath last_actual_monitoring_file_path() const { | |
| 198 return last_actual_monitoring_file_path_; | |
| 199 } | |
| 200 | |
| 201 const base::DictionaryValue* last_metadata() const { | 161 const base::DictionaryValue* last_metadata() const { |
| 202 return last_metadata_.get(); | 162 return last_metadata_.get(); |
| 203 } | 163 } |
| 204 | 164 |
| 205 const std::string& last_data() const { | 165 const std::string& last_data() const { |
| 206 return last_data_; | 166 return last_data_; |
| 207 } | 167 } |
| 208 | 168 |
| 209 void TestStartAndStopTracingString() { | 169 void TestStartAndStopTracingString() { |
| 210 Navigate(shell()); | 170 Navigate(shell()); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 run_loop.QuitClosure(), | 335 run_loop.QuitClosure(), |
| 376 result_file_path); | 336 result_file_path); |
| 377 bool result = controller->StopTracing( | 337 bool result = controller->StopTracing( |
| 378 TracingController::CreateFileSink(result_file_path, callback)); | 338 TracingController::CreateFileSink(result_file_path, callback)); |
| 379 ASSERT_TRUE(result); | 339 ASSERT_TRUE(result); |
| 380 run_loop.Run(); | 340 run_loop.Run(); |
| 381 EXPECT_EQ(disable_recording_done_callback_count(), 1); | 341 EXPECT_EQ(disable_recording_done_callback_count(), 1); |
| 382 } | 342 } |
| 383 } | 343 } |
| 384 | 344 |
| 385 void TestEnableCaptureAndStopMonitoring( | |
| 386 const base::FilePath& result_file_path) { | |
| 387 Navigate(shell()); | |
| 388 | |
| 389 TracingController* controller = TracingController::GetInstance(); | |
| 390 | |
| 391 { | |
| 392 bool is_monitoring; | |
| 393 TraceConfig trace_config("", ""); | |
| 394 controller->GetMonitoringStatus( | |
| 395 &is_monitoring, &trace_config); | |
| 396 EXPECT_FALSE(is_monitoring); | |
| 397 EXPECT_EQ("-*Debug,-*Test", trace_config.ToCategoryFilterString()); | |
| 398 EXPECT_FALSE(trace_config.GetTraceRecordMode() == RECORD_CONTINUOUSLY); | |
| 399 EXPECT_FALSE(trace_config.IsSamplingEnabled()); | |
| 400 EXPECT_FALSE(trace_config.IsSystraceEnabled()); | |
| 401 } | |
| 402 | |
| 403 { | |
| 404 base::RunLoop run_loop; | |
| 405 TracingController::StartMonitoringDoneCallback callback = | |
| 406 base::Bind(&TracingControllerTest::StartMonitoringDoneCallbackTest, | |
| 407 base::Unretained(this), | |
| 408 run_loop.QuitClosure()); | |
| 409 | |
| 410 TraceConfig trace_config("*", ""); | |
| 411 trace_config.EnableSampling(); | |
| 412 bool result = controller->StartMonitoring(trace_config, callback); | |
| 413 ASSERT_TRUE(result); | |
| 414 run_loop.Run(); | |
| 415 EXPECT_EQ(enable_monitoring_done_callback_count(), 1); | |
| 416 } | |
| 417 | |
| 418 { | |
| 419 bool is_monitoring; | |
| 420 TraceConfig trace_config("", ""); | |
| 421 controller->GetMonitoringStatus(&is_monitoring, &trace_config); | |
| 422 EXPECT_TRUE(is_monitoring); | |
| 423 EXPECT_EQ("*", trace_config.ToCategoryFilterString()); | |
| 424 EXPECT_FALSE(trace_config.GetTraceRecordMode() == RECORD_CONTINUOUSLY); | |
| 425 EXPECT_TRUE(trace_config.IsSamplingEnabled()); | |
| 426 EXPECT_FALSE(trace_config.IsSystraceEnabled()); | |
| 427 } | |
| 428 | |
| 429 { | |
| 430 base::RunLoop run_loop; | |
| 431 base::Closure callback = base::Bind( | |
| 432 &TracingControllerTest::CaptureMonitoringSnapshotDoneCallbackTest, | |
| 433 base::Unretained(this), | |
| 434 run_loop.QuitClosure(), | |
| 435 result_file_path); | |
| 436 ASSERT_TRUE(controller->CaptureMonitoringSnapshot( | |
| 437 TracingController::CreateFileSink(result_file_path, callback))); | |
| 438 run_loop.Run(); | |
| 439 EXPECT_EQ(capture_monitoring_snapshot_done_callback_count(), 1); | |
| 440 } | |
| 441 | |
| 442 { | |
| 443 base::RunLoop run_loop; | |
| 444 TracingController::StopMonitoringDoneCallback callback = | |
| 445 base::Bind(&TracingControllerTest::StopMonitoringDoneCallbackTest, | |
| 446 base::Unretained(this), | |
| 447 run_loop.QuitClosure()); | |
| 448 bool result = controller->StopMonitoring(callback); | |
| 449 ASSERT_TRUE(result); | |
| 450 run_loop.Run(); | |
| 451 EXPECT_EQ(disable_monitoring_done_callback_count(), 1); | |
| 452 } | |
| 453 | |
| 454 { | |
| 455 bool is_monitoring; | |
| 456 TraceConfig trace_config("", ""); | |
| 457 controller->GetMonitoringStatus(&is_monitoring, &trace_config); | |
| 458 EXPECT_FALSE(is_monitoring); | |
| 459 EXPECT_EQ("", trace_config.ToCategoryFilterString()); | |
| 460 EXPECT_FALSE(trace_config.GetTraceRecordMode() == RECORD_CONTINUOUSLY); | |
| 461 EXPECT_FALSE(trace_config.IsSamplingEnabled()); | |
| 462 EXPECT_FALSE(trace_config.IsSystraceEnabled()); | |
| 463 } | |
| 464 } | |
| 465 | |
| 466 private: | 345 private: |
| 467 int get_categories_done_callback_count_; | 346 int get_categories_done_callback_count_; |
| 468 int enable_recording_done_callback_count_; | 347 int enable_recording_done_callback_count_; |
| 469 int disable_recording_done_callback_count_; | 348 int disable_recording_done_callback_count_; |
| 470 int enable_monitoring_done_callback_count_; | |
| 471 int disable_monitoring_done_callback_count_; | |
| 472 int capture_monitoring_snapshot_done_callback_count_; | |
| 473 base::FilePath last_actual_recording_file_path_; | 349 base::FilePath last_actual_recording_file_path_; |
| 474 base::FilePath last_actual_monitoring_file_path_; | |
| 475 scoped_ptr<const base::DictionaryValue> last_metadata_; | 350 scoped_ptr<const base::DictionaryValue> last_metadata_; |
| 476 std::string last_data_; | 351 std::string last_data_; |
| 477 }; | 352 }; |
| 478 | 353 |
| 479 IN_PROC_BROWSER_TEST_F(TracingControllerTest, GetCategories) { | 354 IN_PROC_BROWSER_TEST_F(TracingControllerTest, GetCategories) { |
| 480 Navigate(shell()); | 355 Navigate(shell()); |
| 481 | 356 |
| 482 TracingController* controller = TracingController::GetInstance(); | 357 TracingController* controller = TracingController::GetInstance(); |
| 483 | 358 |
| 484 base::RunLoop run_loop; | 359 base::RunLoop run_loop; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 Navigate(shell()); | 453 Navigate(shell()); |
| 579 | 454 |
| 580 TracingController* controller = TracingController::GetInstance(); | 455 TracingController* controller = TracingController::GetInstance(); |
| 581 EXPECT_TRUE(controller->StartTracing( | 456 EXPECT_TRUE(controller->StartTracing( |
| 582 TraceConfig(), | 457 TraceConfig(), |
| 583 TracingController::StartTracingDoneCallback())); | 458 TracingController::StartTracingDoneCallback())); |
| 584 EXPECT_TRUE(controller->StopTracing(NULL)); | 459 EXPECT_TRUE(controller->StopTracing(NULL)); |
| 585 base::RunLoop().RunUntilIdle(); | 460 base::RunLoop().RunUntilIdle(); |
| 586 } | 461 } |
| 587 | 462 |
| 588 IN_PROC_BROWSER_TEST_F(TracingControllerTest, | |
| 589 EnableCaptureAndStopMonitoring) { | |
| 590 base::FilePath file_path; | |
| 591 base::CreateTemporaryFile(&file_path); | |
| 592 TestEnableCaptureAndStopMonitoring(file_path); | |
| 593 } | |
| 594 | |
| 595 IN_PROC_BROWSER_TEST_F(TracingControllerTest, | |
| 596 EnableCaptureAndStopMonitoringWithFilePath) { | |
| 597 base::FilePath file_path; | |
| 598 base::CreateTemporaryFile(&file_path); | |
| 599 TestEnableCaptureAndStopMonitoring(file_path); | |
| 600 EXPECT_EQ(file_path.value(), last_actual_monitoring_file_path().value()); | |
| 601 } | |
| 602 | |
| 603 // See http://crbug.com/392446 | |
| 604 #if defined(OS_ANDROID) | |
| 605 #define MAYBE_EnableCaptureAndStopMonitoringWithEmptyFileAndNullCallback \ | |
| 606 DISABLED_EnableCaptureAndStopMonitoringWithEmptyFileAndNullCallback | |
| 607 #else | |
| 608 #define MAYBE_EnableCaptureAndStopMonitoringWithEmptyFileAndNullCallback \ | |
| 609 EnableCaptureAndStopMonitoringWithEmptyFileAndNullCallback | |
| 610 #endif | |
| 611 IN_PROC_BROWSER_TEST_F( | |
| 612 TracingControllerTest, | |
| 613 MAYBE_EnableCaptureAndStopMonitoringWithEmptyFileAndNullCallback) { | |
| 614 Navigate(shell()); | |
| 615 | |
| 616 TracingController* controller = TracingController::GetInstance(); | |
| 617 TraceConfig trace_config("*", ""); | |
| 618 trace_config.EnableSampling(); | |
| 619 EXPECT_TRUE(controller->StartMonitoring( | |
| 620 trace_config, | |
| 621 TracingController::StartMonitoringDoneCallback())); | |
| 622 controller->CaptureMonitoringSnapshot(NULL); | |
| 623 base::RunLoop().RunUntilIdle(); | |
| 624 EXPECT_TRUE(controller->StopMonitoring( | |
| 625 TracingController::StopMonitoringDoneCallback())); | |
| 626 base::RunLoop().RunUntilIdle(); | |
| 627 } | |
| 628 | |
| 629 } // namespace content | 463 } // namespace content |
| OLD | NEW |