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 "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/memory/ref_counted_memory.h" |
6 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
7 #include "content/browser/tracing/tracing_controller_impl.h" | 8 #include "content/browser/tracing/tracing_controller_impl.h" |
8 #include "content/public/test/browser_test_utils.h" | 9 #include "content/public/test/browser_test_utils.h" |
9 #include "content/public/test/content_browser_test.h" | 10 #include "content/public/test/content_browser_test.h" |
10 #include "content/public/test/content_browser_test_utils.h" | 11 #include "content/public/test/content_browser_test_utils.h" |
11 #include "content/shell/browser/shell.h" | 12 #include "content/shell/browser/shell.h" |
12 | 13 |
13 using base::debug::CategoryFilter; | 14 using base::debug::CategoryFilter; |
14 using base::debug::TraceOptions; | 15 using base::debug::TraceOptions; |
15 using base::debug::RECORD_CONTINUOUSLY; | 16 using base::debug::RECORD_CONTINUOUSLY; |
(...skipping 28 matching lines...) Expand all Loading... |
44 get_categories_done_callback_count_++; | 45 get_categories_done_callback_count_++; |
45 EXPECT_TRUE(categories.size() > 0); | 46 EXPECT_TRUE(categories.size() > 0); |
46 quit_callback.Run(); | 47 quit_callback.Run(); |
47 } | 48 } |
48 | 49 |
49 void EnableRecordingDoneCallbackTest(base::Closure quit_callback) { | 50 void EnableRecordingDoneCallbackTest(base::Closure quit_callback) { |
50 enable_recording_done_callback_count_++; | 51 enable_recording_done_callback_count_++; |
51 quit_callback.Run(); | 52 quit_callback.Run(); |
52 } | 53 } |
53 | 54 |
54 void DisableRecordingDoneCallbackTest(base::Closure quit_callback, | 55 void DisableRecordingStringDoneCallbackTest(base::Closure quit_callback, |
55 const base::FilePath& file_path) { | 56 base::RefCountedMemory* data) { |
| 57 disable_recording_done_callback_count_++; |
| 58 EXPECT_TRUE(data->size() > 0); |
| 59 quit_callback.Run(); |
| 60 } |
| 61 |
| 62 void DisableRecordingFileDoneCallbackTest(base::Closure quit_callback, |
| 63 const base::FilePath& file_path) { |
56 disable_recording_done_callback_count_++; | 64 disable_recording_done_callback_count_++; |
57 EXPECT_TRUE(PathExists(file_path)); | 65 EXPECT_TRUE(PathExists(file_path)); |
58 int64 file_size; | 66 int64 file_size; |
59 base::GetFileSize(file_path, &file_size); | 67 base::GetFileSize(file_path, &file_size); |
60 EXPECT_TRUE(file_size > 0); | 68 EXPECT_TRUE(file_size > 0); |
61 quit_callback.Run(); | 69 quit_callback.Run(); |
62 last_actual_recording_file_path_ = file_path; | 70 last_actual_recording_file_path_ = file_path; |
63 } | 71 } |
64 | 72 |
65 void EnableMonitoringDoneCallbackTest(base::Closure quit_callback) { | 73 void EnableMonitoringDoneCallbackTest(base::Closure quit_callback) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 } | 116 } |
109 | 117 |
110 base::FilePath last_actual_recording_file_path() const { | 118 base::FilePath last_actual_recording_file_path() const { |
111 return last_actual_recording_file_path_; | 119 return last_actual_recording_file_path_; |
112 } | 120 } |
113 | 121 |
114 base::FilePath last_actual_monitoring_file_path() const { | 122 base::FilePath last_actual_monitoring_file_path() const { |
115 return last_actual_monitoring_file_path_; | 123 return last_actual_monitoring_file_path_; |
116 } | 124 } |
117 | 125 |
118 void TestEnableAndDisableRecording(const base::FilePath& result_file_path) { | 126 void TestEnableAndDisableRecordingString() { |
119 Navigate(shell()); | 127 Navigate(shell()); |
120 | 128 |
121 TracingController* controller = TracingController::GetInstance(); | 129 TracingController* controller = TracingController::GetInstance(); |
122 | 130 |
123 { | 131 { |
124 base::RunLoop run_loop; | 132 base::RunLoop run_loop; |
125 TracingController::EnableRecordingDoneCallback callback = | 133 TracingController::EnableRecordingDoneCallback callback = |
126 base::Bind(&TracingControllerTest::EnableRecordingDoneCallbackTest, | 134 base::Bind(&TracingControllerTest::EnableRecordingDoneCallbackTest, |
127 base::Unretained(this), | 135 base::Unretained(this), |
128 run_loop.QuitClosure()); | 136 run_loop.QuitClosure()); |
129 bool result = controller->EnableRecording( | 137 bool result = controller->EnableRecording( |
130 CategoryFilter(), TraceOptions(), callback); | 138 CategoryFilter(), TraceOptions(), callback); |
131 ASSERT_TRUE(result); | 139 ASSERT_TRUE(result); |
132 run_loop.Run(); | 140 run_loop.Run(); |
133 EXPECT_EQ(enable_recording_done_callback_count(), 1); | 141 EXPECT_EQ(enable_recording_done_callback_count(), 1); |
134 } | 142 } |
135 | 143 |
136 { | 144 { |
137 base::RunLoop run_loop; | 145 base::RunLoop run_loop; |
138 TracingController::TracingFileResultCallback callback = | 146 base::Callback<void(base::RefCountedMemory*)> callback = |
139 base::Bind(&TracingControllerTest::DisableRecordingDoneCallbackTest, | 147 base::Bind(&TracingControllerTest |
| 148 ::DisableRecordingStringDoneCallbackTest, |
140 base::Unretained(this), | 149 base::Unretained(this), |
141 run_loop.QuitClosure()); | 150 run_loop.QuitClosure()); |
142 bool result = controller->DisableRecording(result_file_path, callback); | 151 bool result = controller->DisableRecording( |
| 152 TracingControllerImpl::CreateStringSink(callback)); |
143 ASSERT_TRUE(result); | 153 ASSERT_TRUE(result); |
144 run_loop.Run(); | 154 run_loop.Run(); |
145 EXPECT_EQ(disable_recording_done_callback_count(), 1); | 155 EXPECT_EQ(disable_recording_done_callback_count(), 1); |
| 156 } |
| 157 } |
| 158 |
| 159 void TestEnableAndDisableRecordingFile( |
| 160 const base::FilePath& result_file_path) { |
| 161 Navigate(shell()); |
| 162 |
| 163 TracingController* controller = TracingController::GetInstance(); |
| 164 |
| 165 { |
| 166 base::RunLoop run_loop; |
| 167 TracingController::EnableRecordingDoneCallback callback = |
| 168 base::Bind(&TracingControllerTest::EnableRecordingDoneCallbackTest, |
| 169 base::Unretained(this), |
| 170 run_loop.QuitClosure()); |
| 171 bool result = controller->EnableRecording( |
| 172 CategoryFilter(), TraceOptions(), callback); |
| 173 ASSERT_TRUE(result); |
| 174 run_loop.Run(); |
| 175 EXPECT_EQ(enable_recording_done_callback_count(), 1); |
| 176 } |
| 177 |
| 178 { |
| 179 base::RunLoop run_loop; |
| 180 base::Closure callback = |
| 181 base::Bind(&TracingControllerTest |
| 182 ::DisableRecordingFileDoneCallbackTest, |
| 183 base::Unretained(this), |
| 184 run_loop.QuitClosure(), |
| 185 result_file_path); |
| 186 bool result = controller->DisableRecording( |
| 187 TracingControllerImpl::CreateFileSink(result_file_path, callback)); |
| 188 ASSERT_TRUE(result); |
| 189 run_loop.Run(); |
| 190 EXPECT_EQ(disable_recording_done_callback_count(), 1); |
146 } | 191 } |
147 } | 192 } |
148 | 193 |
149 void TestEnableCaptureAndDisableMonitoring( | 194 void TestEnableCaptureAndDisableMonitoring( |
150 const base::FilePath& result_file_path) { | 195 const base::FilePath& result_file_path) { |
151 Navigate(shell()); | 196 Navigate(shell()); |
152 | 197 |
153 TracingController* controller = TracingController::GetInstance(); | 198 TracingController* controller = TracingController::GetInstance(); |
154 | 199 |
155 { | 200 { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 &is_monitoring, &category_filter, &options); | 237 &is_monitoring, &category_filter, &options); |
193 EXPECT_TRUE(is_monitoring); | 238 EXPECT_TRUE(is_monitoring); |
194 EXPECT_EQ("*", category_filter.ToString()); | 239 EXPECT_EQ("*", category_filter.ToString()); |
195 EXPECT_FALSE(options.record_mode == RECORD_CONTINUOUSLY); | 240 EXPECT_FALSE(options.record_mode == RECORD_CONTINUOUSLY); |
196 EXPECT_TRUE(options.enable_sampling); | 241 EXPECT_TRUE(options.enable_sampling); |
197 EXPECT_FALSE(options.enable_systrace); | 242 EXPECT_FALSE(options.enable_systrace); |
198 } | 243 } |
199 | 244 |
200 { | 245 { |
201 base::RunLoop run_loop; | 246 base::RunLoop run_loop; |
202 TracingController::TracingFileResultCallback callback = | 247 base::Closure callback = |
203 base::Bind(&TracingControllerTest:: | 248 base::Bind(&TracingControllerTest:: |
204 CaptureMonitoringSnapshotDoneCallbackTest, | 249 CaptureMonitoringSnapshotDoneCallbackTest, |
205 base::Unretained(this), | 250 base::Unretained(this), |
206 run_loop.QuitClosure()); | 251 run_loop.QuitClosure(), |
207 ASSERT_TRUE(controller->CaptureMonitoringSnapshot(result_file_path, | 252 result_file_path); |
208 callback)); | 253 ASSERT_TRUE(controller->CaptureMonitoringSnapshot( |
| 254 TracingControllerImpl::CreateFileSink(result_file_path, callback))); |
209 run_loop.Run(); | 255 run_loop.Run(); |
210 EXPECT_EQ(capture_monitoring_snapshot_done_callback_count(), 1); | 256 EXPECT_EQ(capture_monitoring_snapshot_done_callback_count(), 1); |
211 } | 257 } |
212 | 258 |
213 { | 259 { |
214 base::RunLoop run_loop; | 260 base::RunLoop run_loop; |
215 TracingController::DisableMonitoringDoneCallback callback = | 261 TracingController::DisableMonitoringDoneCallback callback = |
216 base::Bind(&TracingControllerTest::DisableMonitoringDoneCallbackTest, | 262 base::Bind(&TracingControllerTest::DisableMonitoringDoneCallbackTest, |
217 base::Unretained(this), | 263 base::Unretained(this), |
218 run_loop.QuitClosure()); | 264 run_loop.QuitClosure()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 TracingController::GetCategoriesDoneCallback callback = | 303 TracingController::GetCategoriesDoneCallback callback = |
258 base::Bind(&TracingControllerTest::GetCategoriesDoneCallbackTest, | 304 base::Bind(&TracingControllerTest::GetCategoriesDoneCallbackTest, |
259 base::Unretained(this), | 305 base::Unretained(this), |
260 run_loop.QuitClosure()); | 306 run_loop.QuitClosure()); |
261 ASSERT_TRUE(controller->GetCategories(callback)); | 307 ASSERT_TRUE(controller->GetCategories(callback)); |
262 run_loop.Run(); | 308 run_loop.Run(); |
263 EXPECT_EQ(get_categories_done_callback_count(), 1); | 309 EXPECT_EQ(get_categories_done_callback_count(), 1); |
264 } | 310 } |
265 | 311 |
266 IN_PROC_BROWSER_TEST_F(TracingControllerTest, EnableAndDisableRecording) { | 312 IN_PROC_BROWSER_TEST_F(TracingControllerTest, EnableAndDisableRecording) { |
267 TestEnableAndDisableRecording(base::FilePath()); | 313 TestEnableAndDisableRecordingString(); |
268 } | 314 } |
269 | 315 |
270 IN_PROC_BROWSER_TEST_F(TracingControllerTest, | 316 IN_PROC_BROWSER_TEST_F(TracingControllerTest, |
271 EnableAndDisableRecordingWithFilePath) { | 317 EnableAndDisableRecordingWithFilePath) { |
272 base::FilePath file_path; | 318 base::FilePath file_path; |
273 base::CreateTemporaryFile(&file_path); | 319 base::CreateTemporaryFile(&file_path); |
274 TestEnableAndDisableRecording(file_path); | 320 TestEnableAndDisableRecordingFile(file_path); |
275 EXPECT_EQ(file_path.value(), last_actual_recording_file_path().value()); | 321 EXPECT_EQ(file_path.value(), last_actual_recording_file_path().value()); |
276 } | 322 } |
277 | 323 |
278 IN_PROC_BROWSER_TEST_F(TracingControllerTest, | 324 IN_PROC_BROWSER_TEST_F(TracingControllerTest, |
279 EnableAndDisableRecordingWithEmptyFileAndNullCallback) { | 325 EnableAndDisableRecordingWithEmptyFileAndNullCallback) { |
280 Navigate(shell()); | 326 Navigate(shell()); |
281 | 327 |
282 TracingController* controller = TracingController::GetInstance(); | 328 TracingController* controller = TracingController::GetInstance(); |
283 EXPECT_TRUE(controller->EnableRecording( | 329 EXPECT_TRUE(controller->EnableRecording( |
284 CategoryFilter(), | 330 CategoryFilter(), |
285 TraceOptions(), | 331 TraceOptions(), |
286 TracingController::EnableRecordingDoneCallback())); | 332 TracingController::EnableRecordingDoneCallback())); |
287 EXPECT_TRUE(controller->DisableRecording( | 333 EXPECT_TRUE(controller->DisableRecording(NULL)); |
288 base::FilePath(), TracingController::TracingFileResultCallback())); | |
289 base::RunLoop().RunUntilIdle(); | 334 base::RunLoop().RunUntilIdle(); |
290 } | 335 } |
291 | 336 |
292 IN_PROC_BROWSER_TEST_F(TracingControllerTest, | 337 IN_PROC_BROWSER_TEST_F(TracingControllerTest, |
293 EnableCaptureAndDisableMonitoring) { | 338 EnableCaptureAndDisableMonitoring) { |
294 TestEnableCaptureAndDisableMonitoring(base::FilePath()); | 339 base::FilePath file_path; |
| 340 base::CreateTemporaryFile(&file_path); |
| 341 TestEnableCaptureAndDisableMonitoring(file_path); |
295 } | 342 } |
296 | 343 |
297 IN_PROC_BROWSER_TEST_F(TracingControllerTest, | 344 IN_PROC_BROWSER_TEST_F(TracingControllerTest, |
298 EnableCaptureAndDisableMonitoringWithFilePath) { | 345 EnableCaptureAndDisableMonitoringWithFilePath) { |
299 base::FilePath file_path; | 346 base::FilePath file_path; |
300 base::CreateTemporaryFile(&file_path); | 347 base::CreateTemporaryFile(&file_path); |
301 TestEnableCaptureAndDisableMonitoring(file_path); | 348 TestEnableCaptureAndDisableMonitoring(file_path); |
302 EXPECT_EQ(file_path.value(), last_actual_monitoring_file_path().value()); | 349 EXPECT_EQ(file_path.value(), last_actual_monitoring_file_path().value()); |
303 } | 350 } |
304 | 351 |
(...skipping 10 matching lines...) Expand all Loading... |
315 MAYBE_EnableCaptureAndDisableMonitoringWithEmptyFileAndNullCallback) { | 362 MAYBE_EnableCaptureAndDisableMonitoringWithEmptyFileAndNullCallback) { |
316 Navigate(shell()); | 363 Navigate(shell()); |
317 | 364 |
318 TracingController* controller = TracingController::GetInstance(); | 365 TracingController* controller = TracingController::GetInstance(); |
319 TraceOptions trace_options; | 366 TraceOptions trace_options; |
320 trace_options.enable_sampling = true; | 367 trace_options.enable_sampling = true; |
321 EXPECT_TRUE(controller->EnableMonitoring( | 368 EXPECT_TRUE(controller->EnableMonitoring( |
322 CategoryFilter("*"), | 369 CategoryFilter("*"), |
323 trace_options, | 370 trace_options, |
324 TracingController::EnableMonitoringDoneCallback())); | 371 TracingController::EnableMonitoringDoneCallback())); |
325 controller->CaptureMonitoringSnapshot( | 372 controller->CaptureMonitoringSnapshot(NULL); |
326 base::FilePath(), TracingController::TracingFileResultCallback()); | |
327 base::RunLoop().RunUntilIdle(); | 373 base::RunLoop().RunUntilIdle(); |
328 EXPECT_TRUE(controller->DisableMonitoring( | 374 EXPECT_TRUE(controller->DisableMonitoring( |
329 TracingController::DisableMonitoringDoneCallback())); | 375 TracingController::DisableMonitoringDoneCallback())); |
330 base::RunLoop().RunUntilIdle(); | 376 base::RunLoop().RunUntilIdle(); |
331 } | 377 } |
332 | 378 |
333 } // namespace content | 379 } // namespace content |
OLD | NEW |