Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(746)

Side by Side Diff: content/browser/tracing/tracing_controller_browsertest.cc

Issue 541763002: tracing: get rid of files in TracingController interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed system trace collection Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/files/file_util.h" 5 #include "base/files/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/public/browser/tracing_controller.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;
16 using base::debug::RECORD_UNTIL_FULL; 17 using base::debug::RECORD_UNTIL_FULL;
17 18
(...skipping 26 matching lines...) Expand all
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::RefCountedString* 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
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::RefCountedString*)> callback = base::Bind(
139 base::Bind(&TracingControllerTest::DisableRecordingDoneCallbackTest, 147 &TracingControllerTest::DisableRecordingStringDoneCallbackTest,
140 base::Unretained(this), 148 base::Unretained(this),
141 run_loop.QuitClosure()); 149 run_loop.QuitClosure());
142 bool result = controller->DisableRecording(result_file_path, callback); 150 bool result = controller->DisableRecording(
151 TracingController::CreateStringSink(callback));
143 ASSERT_TRUE(result); 152 ASSERT_TRUE(result);
144 run_loop.Run(); 153 run_loop.Run();
145 EXPECT_EQ(disable_recording_done_callback_count(), 1); 154 EXPECT_EQ(disable_recording_done_callback_count(), 1);
155 }
156 }
157
158 void TestEnableAndDisableRecordingFile(
159 const base::FilePath& result_file_path) {
160 Navigate(shell());
161
162 TracingController* controller = TracingController::GetInstance();
163
164 {
165 base::RunLoop run_loop;
166 TracingController::EnableRecordingDoneCallback callback =
167 base::Bind(&TracingControllerTest::EnableRecordingDoneCallbackTest,
168 base::Unretained(this),
169 run_loop.QuitClosure());
170 bool result = controller->EnableRecording(
171 CategoryFilter(), TraceOptions(), callback);
172 ASSERT_TRUE(result);
173 run_loop.Run();
174 EXPECT_EQ(enable_recording_done_callback_count(), 1);
175 }
176
177 {
178 base::RunLoop run_loop;
179 base::Closure callback = base::Bind(
180 &TracingControllerTest::DisableRecordingFileDoneCallbackTest,
181 base::Unretained(this),
182 run_loop.QuitClosure(),
183 result_file_path);
184 bool result = controller->DisableRecording(
185 TracingController::CreateFileSink(result_file_path, callback));
186 ASSERT_TRUE(result);
187 run_loop.Run();
188 EXPECT_EQ(disable_recording_done_callback_count(), 1);
146 } 189 }
147 } 190 }
148 191
149 void TestEnableCaptureAndDisableMonitoring( 192 void TestEnableCaptureAndDisableMonitoring(
150 const base::FilePath& result_file_path) { 193 const base::FilePath& result_file_path) {
151 Navigate(shell()); 194 Navigate(shell());
152 195
153 TracingController* controller = TracingController::GetInstance(); 196 TracingController* controller = TracingController::GetInstance();
154 197
155 { 198 {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 &is_monitoring, &category_filter, &options); 235 &is_monitoring, &category_filter, &options);
193 EXPECT_TRUE(is_monitoring); 236 EXPECT_TRUE(is_monitoring);
194 EXPECT_EQ("*", category_filter.ToString()); 237 EXPECT_EQ("*", category_filter.ToString());
195 EXPECT_FALSE(options.record_mode == RECORD_CONTINUOUSLY); 238 EXPECT_FALSE(options.record_mode == RECORD_CONTINUOUSLY);
196 EXPECT_TRUE(options.enable_sampling); 239 EXPECT_TRUE(options.enable_sampling);
197 EXPECT_FALSE(options.enable_systrace); 240 EXPECT_FALSE(options.enable_systrace);
198 } 241 }
199 242
200 { 243 {
201 base::RunLoop run_loop; 244 base::RunLoop run_loop;
202 TracingController::TracingFileResultCallback callback = 245 base::Closure callback = base::Bind(
203 base::Bind(&TracingControllerTest:: 246 &TracingControllerTest::CaptureMonitoringSnapshotDoneCallbackTest,
204 CaptureMonitoringSnapshotDoneCallbackTest, 247 base::Unretained(this),
205 base::Unretained(this), 248 run_loop.QuitClosure(),
206 run_loop.QuitClosure()); 249 result_file_path);
207 ASSERT_TRUE(controller->CaptureMonitoringSnapshot(result_file_path, 250 ASSERT_TRUE(controller->CaptureMonitoringSnapshot(
208 callback)); 251 TracingController::CreateFileSink(result_file_path, callback)));
209 run_loop.Run(); 252 run_loop.Run();
210 EXPECT_EQ(capture_monitoring_snapshot_done_callback_count(), 1); 253 EXPECT_EQ(capture_monitoring_snapshot_done_callback_count(), 1);
211 } 254 }
212 255
213 { 256 {
214 base::RunLoop run_loop; 257 base::RunLoop run_loop;
215 TracingController::DisableMonitoringDoneCallback callback = 258 TracingController::DisableMonitoringDoneCallback callback =
216 base::Bind(&TracingControllerTest::DisableMonitoringDoneCallbackTest, 259 base::Bind(&TracingControllerTest::DisableMonitoringDoneCallbackTest,
217 base::Unretained(this), 260 base::Unretained(this),
218 run_loop.QuitClosure()); 261 run_loop.QuitClosure());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 TracingController::GetCategoriesDoneCallback callback = 300 TracingController::GetCategoriesDoneCallback callback =
258 base::Bind(&TracingControllerTest::GetCategoriesDoneCallbackTest, 301 base::Bind(&TracingControllerTest::GetCategoriesDoneCallbackTest,
259 base::Unretained(this), 302 base::Unretained(this),
260 run_loop.QuitClosure()); 303 run_loop.QuitClosure());
261 ASSERT_TRUE(controller->GetCategories(callback)); 304 ASSERT_TRUE(controller->GetCategories(callback));
262 run_loop.Run(); 305 run_loop.Run();
263 EXPECT_EQ(get_categories_done_callback_count(), 1); 306 EXPECT_EQ(get_categories_done_callback_count(), 1);
264 } 307 }
265 308
266 IN_PROC_BROWSER_TEST_F(TracingControllerTest, EnableAndDisableRecording) { 309 IN_PROC_BROWSER_TEST_F(TracingControllerTest, EnableAndDisableRecording) {
267 TestEnableAndDisableRecording(base::FilePath()); 310 TestEnableAndDisableRecordingString();
268 } 311 }
269 312
270 IN_PROC_BROWSER_TEST_F(TracingControllerTest, 313 IN_PROC_BROWSER_TEST_F(TracingControllerTest,
271 EnableAndDisableRecordingWithFilePath) { 314 EnableAndDisableRecordingWithFilePath) {
272 base::FilePath file_path; 315 base::FilePath file_path;
273 base::CreateTemporaryFile(&file_path); 316 base::CreateTemporaryFile(&file_path);
274 TestEnableAndDisableRecording(file_path); 317 TestEnableAndDisableRecordingFile(file_path);
275 EXPECT_EQ(file_path.value(), last_actual_recording_file_path().value()); 318 EXPECT_EQ(file_path.value(), last_actual_recording_file_path().value());
276 } 319 }
277 320
278 IN_PROC_BROWSER_TEST_F(TracingControllerTest, 321 IN_PROC_BROWSER_TEST_F(TracingControllerTest,
279 EnableAndDisableRecordingWithEmptyFileAndNullCallback) { 322 EnableAndDisableRecordingWithEmptyFileAndNullCallback) {
280 Navigate(shell()); 323 Navigate(shell());
281 324
282 TracingController* controller = TracingController::GetInstance(); 325 TracingController* controller = TracingController::GetInstance();
283 EXPECT_TRUE(controller->EnableRecording( 326 EXPECT_TRUE(controller->EnableRecording(
284 CategoryFilter(), 327 CategoryFilter(),
285 TraceOptions(), 328 TraceOptions(),
286 TracingController::EnableRecordingDoneCallback())); 329 TracingController::EnableRecordingDoneCallback()));
287 EXPECT_TRUE(controller->DisableRecording( 330 EXPECT_TRUE(controller->DisableRecording(NULL));
288 base::FilePath(), TracingController::TracingFileResultCallback()));
289 base::RunLoop().RunUntilIdle(); 331 base::RunLoop().RunUntilIdle();
290 } 332 }
291 333
292 IN_PROC_BROWSER_TEST_F(TracingControllerTest, 334 IN_PROC_BROWSER_TEST_F(TracingControllerTest,
293 EnableCaptureAndDisableMonitoring) { 335 EnableCaptureAndDisableMonitoring) {
294 TestEnableCaptureAndDisableMonitoring(base::FilePath()); 336 base::FilePath file_path;
337 base::CreateTemporaryFile(&file_path);
338 TestEnableCaptureAndDisableMonitoring(file_path);
295 } 339 }
296 340
297 IN_PROC_BROWSER_TEST_F(TracingControllerTest, 341 IN_PROC_BROWSER_TEST_F(TracingControllerTest,
298 EnableCaptureAndDisableMonitoringWithFilePath) { 342 EnableCaptureAndDisableMonitoringWithFilePath) {
299 base::FilePath file_path; 343 base::FilePath file_path;
300 base::CreateTemporaryFile(&file_path); 344 base::CreateTemporaryFile(&file_path);
301 TestEnableCaptureAndDisableMonitoring(file_path); 345 TestEnableCaptureAndDisableMonitoring(file_path);
302 EXPECT_EQ(file_path.value(), last_actual_monitoring_file_path().value()); 346 EXPECT_EQ(file_path.value(), last_actual_monitoring_file_path().value());
303 } 347 }
304 348
(...skipping 10 matching lines...) Expand all
315 MAYBE_EnableCaptureAndDisableMonitoringWithEmptyFileAndNullCallback) { 359 MAYBE_EnableCaptureAndDisableMonitoringWithEmptyFileAndNullCallback) {
316 Navigate(shell()); 360 Navigate(shell());
317 361
318 TracingController* controller = TracingController::GetInstance(); 362 TracingController* controller = TracingController::GetInstance();
319 TraceOptions trace_options; 363 TraceOptions trace_options;
320 trace_options.enable_sampling = true; 364 trace_options.enable_sampling = true;
321 EXPECT_TRUE(controller->EnableMonitoring( 365 EXPECT_TRUE(controller->EnableMonitoring(
322 CategoryFilter("*"), 366 CategoryFilter("*"),
323 trace_options, 367 trace_options,
324 TracingController::EnableMonitoringDoneCallback())); 368 TracingController::EnableMonitoringDoneCallback()));
325 controller->CaptureMonitoringSnapshot( 369 controller->CaptureMonitoringSnapshot(NULL);
326 base::FilePath(), TracingController::TracingFileResultCallback());
327 base::RunLoop().RunUntilIdle(); 370 base::RunLoop().RunUntilIdle();
328 EXPECT_TRUE(controller->DisableMonitoring( 371 EXPECT_TRUE(controller->DisableMonitoring(
329 TracingController::DisableMonitoringDoneCallback())); 372 TracingController::DisableMonitoringDoneCallback()));
330 base::RunLoop().RunUntilIdle(); 373 base::RunLoop().RunUntilIdle();
331 } 374 }
332 375
333 } // namespace content 376 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/devtools_tracing_handler.cc ('k') | content/browser/tracing/tracing_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698