| 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 "base/threading/thread_restrictions.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "content/browser/tracing/tracing_controller_impl.h" | 16 #include "content/browser/tracing/tracing_controller_impl.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/trace_uploader.h" | 18 #include "content/public/browser/trace_uploader.h" |
| 18 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
| 19 #include "content/public/test/content_browser_test.h" | 20 #include "content/public/test/content_browser_test.h" |
| 20 #include "content/public/test/content_browser_test_utils.h" | 21 #include "content/public/test/content_browser_test_utils.h" |
| 21 #include "content/shell/browser/shell.h" | 22 #include "content/shell/browser/shell.h" |
| 22 #include "content/test/test_content_browser_client.h" | 23 #include "content/test/test_content_browser_client.h" |
| 23 | 24 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 disable_recording_done_callback_count_++; | 146 disable_recording_done_callback_count_++; |
| 146 last_metadata_.reset(metadata.release()); | 147 last_metadata_.reset(metadata.release()); |
| 147 last_data_ = data->data(); | 148 last_data_ = data->data(); |
| 148 EXPECT_TRUE(data->size() > 0); | 149 EXPECT_TRUE(data->size() > 0); |
| 149 quit_callback.Run(); | 150 quit_callback.Run(); |
| 150 } | 151 } |
| 151 | 152 |
| 152 void StopTracingFileDoneCallbackTest(base::Closure quit_callback, | 153 void StopTracingFileDoneCallbackTest(base::Closure quit_callback, |
| 153 const base::FilePath& file_path) { | 154 const base::FilePath& file_path) { |
| 154 disable_recording_done_callback_count_++; | 155 disable_recording_done_callback_count_++; |
| 155 EXPECT_TRUE(PathExists(file_path)); | 156 { |
| 156 int64_t file_size; | 157 base::ThreadRestrictions::ScopedAllowIO allow_io_for_test_verifications; |
| 157 base::GetFileSize(file_path, &file_size); | 158 EXPECT_TRUE(PathExists(file_path)); |
| 158 EXPECT_TRUE(file_size > 0); | 159 int64_t file_size; |
| 160 base::GetFileSize(file_path, &file_size); |
| 161 EXPECT_GT(file_size, 0); |
| 162 } |
| 159 quit_callback.Run(); | 163 quit_callback.Run(); |
| 160 last_actual_recording_file_path_ = file_path; | 164 last_actual_recording_file_path_ = file_path; |
| 161 } | 165 } |
| 162 | 166 |
| 163 int get_categories_done_callback_count() const { | 167 int get_categories_done_callback_count() const { |
| 164 return get_categories_done_callback_count_; | 168 return get_categories_done_callback_count_; |
| 165 } | 169 } |
| 166 | 170 |
| 167 int enable_recording_done_callback_count() const { | 171 int enable_recording_done_callback_count() const { |
| 168 return enable_recording_done_callback_count_; | 172 return enable_recording_done_callback_count_; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 EXPECT_TRUE(last_data().find("os-name") != std::string::npos); | 416 EXPECT_TRUE(last_data().find("os-name") != std::string::npos); |
| 413 EXPECT_TRUE(last_data().find("user-agent") != std::string::npos); | 417 EXPECT_TRUE(last_data().find("user-agent") != std::string::npos); |
| 414 | 418 |
| 415 EXPECT_TRUE(last_data().find("not-whitelisted") != std::string::npos); | 419 EXPECT_TRUE(last_data().find("not-whitelisted") != std::string::npos); |
| 416 EXPECT_TRUE(last_data().find("this_not_found") == std::string::npos); | 420 EXPECT_TRUE(last_data().find("this_not_found") == std::string::npos); |
| 417 } | 421 } |
| 418 | 422 |
| 419 IN_PROC_BROWSER_TEST_F(TracingControllerTest, | 423 IN_PROC_BROWSER_TEST_F(TracingControllerTest, |
| 420 EnableAndStopTracingWithFilePath) { | 424 EnableAndStopTracingWithFilePath) { |
| 421 base::FilePath file_path; | 425 base::FilePath file_path; |
| 422 base::CreateTemporaryFile(&file_path); | 426 { |
| 427 base::ThreadRestrictions::ScopedAllowIO allow_io_for_creating_test_file; |
| 428 base::CreateTemporaryFile(&file_path); |
| 429 } |
| 423 TestStartAndStopTracingFile(file_path); | 430 TestStartAndStopTracingFile(file_path); |
| 424 EXPECT_EQ(file_path.value(), last_actual_recording_file_path().value()); | 431 EXPECT_EQ(file_path.value(), last_actual_recording_file_path().value()); |
| 425 } | 432 } |
| 426 | 433 |
| 427 IN_PROC_BROWSER_TEST_F(TracingControllerTest, | 434 IN_PROC_BROWSER_TEST_F(TracingControllerTest, |
| 428 EnableAndStopTracingWithCompression) { | 435 EnableAndStopTracingWithCompression) { |
| 429 TestStartAndStopTracingCompressed(); | 436 TestStartAndStopTracingCompressed(); |
| 430 } | 437 } |
| 431 | 438 |
| 432 IN_PROC_BROWSER_TEST_F(TracingControllerTest, | 439 IN_PROC_BROWSER_TEST_F(TracingControllerTest, |
| 433 EnableAndStopTracingWithEmptyFileAndNullCallback) { | 440 EnableAndStopTracingWithEmptyFileAndNullCallback) { |
| 434 Navigate(shell()); | 441 Navigate(shell()); |
| 435 | 442 |
| 436 TracingController* controller = TracingController::GetInstance(); | 443 TracingController* controller = TracingController::GetInstance(); |
| 437 EXPECT_TRUE(controller->StartTracing( | 444 EXPECT_TRUE(controller->StartTracing( |
| 438 TraceConfig(), | 445 TraceConfig(), |
| 439 TracingController::StartTracingDoneCallback())); | 446 TracingController::StartTracingDoneCallback())); |
| 440 EXPECT_TRUE(controller->StopTracing(NULL)); | 447 EXPECT_TRUE(controller->StopTracing(NULL)); |
| 441 base::RunLoop().RunUntilIdle(); | 448 base::RunLoop().RunUntilIdle(); |
| 442 } | 449 } |
| 443 | 450 |
| 444 } // namespace content | 451 } // namespace content |
| OLD | NEW |