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

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

Issue 1088673003: CompressedStringDataSink for trace_controller. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix win compile and tests. Created 5 years, 8 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
« no previous file with comments | « no previous file | content/browser/tracing/tracing_controller_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/memory/ref_counted_memory.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "content/public/browser/browser_thread.h"
8 #include "content/public/browser/tracing_controller.h" 9 #include "content/public/browser/tracing_controller.h"
9 #include "content/public/test/browser_test_utils.h" 10 #include "content/public/test/browser_test_utils.h"
10 #include "content/public/test/content_browser_test.h" 11 #include "content/public/test/content_browser_test.h"
11 #include "content/public/test/content_browser_test_utils.h" 12 #include "content/public/test/content_browser_test_utils.h"
12 #include "content/shell/browser/shell.h" 13 #include "content/shell/browser/shell.h"
13 14
14 using base::trace_event::CategoryFilter; 15 using base::trace_event::CategoryFilter;
15 using base::trace_event::TraceOptions; 16 using base::trace_event::TraceOptions;
16 using base::trace_event::RECORD_CONTINUOUSLY; 17 using base::trace_event::RECORD_CONTINUOUSLY;
17 using base::trace_event::RECORD_UNTIL_FULL; 18 using base::trace_event::RECORD_UNTIL_FULL;
18 19
19 namespace content { 20 namespace content {
20 21
22 class TracingControllerTestEndpoint
23 : public TracingController::TraceDataEndpoint {
24 public:
25 TracingControllerTestEndpoint(
26 base::Callback<void(base::RefCountedString*)> done_callback)
27 : done_callback_(done_callback) {}
28
29 void ReceiveTraceChunk(const std::string& chunk) override {
30 EXPECT_FALSE(chunk.empty());
31 trace_ += chunk;
32 }
33
34 void ReceiveTraceFinalContents(const std::string& contents) override {
35 EXPECT_EQ(trace_, contents);
36
37 std::string tmp = contents;
38 scoped_refptr<base::RefCountedString> chunk_ptr =
39 base::RefCountedString::TakeString(&tmp);
40
41 BrowserThread::PostTask(
42 BrowserThread::UI, FROM_HERE,
43 base::Bind(done_callback_, chunk_ptr));
44 }
45
46 protected:
47 ~TracingControllerTestEndpoint() override {}
48
49 std::string trace_;
50 base::Callback<void(base::RefCountedString*)> done_callback_;
51 };
52
21 class TracingControllerTest : public ContentBrowserTest { 53 class TracingControllerTest : public ContentBrowserTest {
22 public: 54 public:
23 TracingControllerTest() {} 55 TracingControllerTest() {}
24 56
25 void SetUp() override { 57 void SetUp() override {
26 get_categories_done_callback_count_ = 0; 58 get_categories_done_callback_count_ = 0;
27 enable_recording_done_callback_count_ = 0; 59 enable_recording_done_callback_count_ = 0;
28 disable_recording_done_callback_count_ = 0; 60 disable_recording_done_callback_count_ = 0;
29 enable_monitoring_done_callback_count_ = 0; 61 enable_monitoring_done_callback_count_ = 0;
30 disable_monitoring_done_callback_count_ = 0; 62 disable_monitoring_done_callback_count_ = 0;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 base::Unretained(this), 178 base::Unretained(this),
147 run_loop.QuitClosure()); 179 run_loop.QuitClosure());
148 bool result = controller->DisableRecording( 180 bool result = controller->DisableRecording(
149 TracingController::CreateStringSink(callback)); 181 TracingController::CreateStringSink(callback));
150 ASSERT_TRUE(result); 182 ASSERT_TRUE(result);
151 run_loop.Run(); 183 run_loop.Run();
152 EXPECT_EQ(disable_recording_done_callback_count(), 1); 184 EXPECT_EQ(disable_recording_done_callback_count(), 1);
153 } 185 }
154 } 186 }
155 187
188 void TestEnableAndDisableRecordingCompressed() {
189 Navigate(shell());
190
191 TracingController* controller = TracingController::GetInstance();
192
193 {
194 base::RunLoop run_loop;
195 TracingController::EnableRecordingDoneCallback callback =
196 base::Bind(&TracingControllerTest::EnableRecordingDoneCallbackTest,
197 base::Unretained(this), run_loop.QuitClosure());
198 bool result = controller->EnableRecording(CategoryFilter(),
199 TraceOptions(), callback);
200 ASSERT_TRUE(result);
201 run_loop.Run();
202 EXPECT_EQ(enable_recording_done_callback_count(), 1);
203 }
204
205 {
206 base::RunLoop run_loop;
207 base::Callback<void(base::RefCountedString*)> callback = base::Bind(
208 &TracingControllerTest::DisableRecordingStringDoneCallbackTest,
209 base::Unretained(this), run_loop.QuitClosure());
210 bool result = controller->DisableRecording(
211 TracingController::CreateCompressedStringSink(
212 new TracingControllerTestEndpoint(callback)));
213 ASSERT_TRUE(result);
214 run_loop.Run();
215 EXPECT_EQ(disable_recording_done_callback_count(), 1);
216 }
217 }
218
156 void TestEnableAndDisableRecordingFile( 219 void TestEnableAndDisableRecordingFile(
157 const base::FilePath& result_file_path) { 220 const base::FilePath& result_file_path) {
158 Navigate(shell()); 221 Navigate(shell());
159 222
160 TracingController* controller = TracingController::GetInstance(); 223 TracingController* controller = TracingController::GetInstance();
161 224
162 { 225 {
163 base::RunLoop run_loop; 226 base::RunLoop run_loop;
164 TracingController::EnableRecordingDoneCallback callback = 227 TracingController::EnableRecordingDoneCallback callback =
165 base::Bind(&TracingControllerTest::EnableRecordingDoneCallbackTest, 228 base::Bind(&TracingControllerTest::EnableRecordingDoneCallbackTest,
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 373
311 IN_PROC_BROWSER_TEST_F(TracingControllerTest, 374 IN_PROC_BROWSER_TEST_F(TracingControllerTest,
312 EnableAndDisableRecordingWithFilePath) { 375 EnableAndDisableRecordingWithFilePath) {
313 base::FilePath file_path; 376 base::FilePath file_path;
314 base::CreateTemporaryFile(&file_path); 377 base::CreateTemporaryFile(&file_path);
315 TestEnableAndDisableRecordingFile(file_path); 378 TestEnableAndDisableRecordingFile(file_path);
316 EXPECT_EQ(file_path.value(), last_actual_recording_file_path().value()); 379 EXPECT_EQ(file_path.value(), last_actual_recording_file_path().value());
317 } 380 }
318 381
319 IN_PROC_BROWSER_TEST_F(TracingControllerTest, 382 IN_PROC_BROWSER_TEST_F(TracingControllerTest,
383 EnableAndDisableRecordingWithCompression) {
384 TestEnableAndDisableRecordingCompressed();
385 }
386
387 IN_PROC_BROWSER_TEST_F(TracingControllerTest,
320 EnableAndDisableRecordingWithEmptyFileAndNullCallback) { 388 EnableAndDisableRecordingWithEmptyFileAndNullCallback) {
321 Navigate(shell()); 389 Navigate(shell());
322 390
323 TracingController* controller = TracingController::GetInstance(); 391 TracingController* controller = TracingController::GetInstance();
324 EXPECT_TRUE(controller->EnableRecording( 392 EXPECT_TRUE(controller->EnableRecording(
325 CategoryFilter(), 393 CategoryFilter(),
326 TraceOptions(), 394 TraceOptions(),
327 TracingController::EnableRecordingDoneCallback())); 395 TracingController::EnableRecordingDoneCallback()));
328 EXPECT_TRUE(controller->DisableRecording(NULL)); 396 EXPECT_TRUE(controller->DisableRecording(NULL));
329 base::RunLoop().RunUntilIdle(); 397 base::RunLoop().RunUntilIdle();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 trace_options, 433 trace_options,
366 TracingController::EnableMonitoringDoneCallback())); 434 TracingController::EnableMonitoringDoneCallback()));
367 controller->CaptureMonitoringSnapshot(NULL); 435 controller->CaptureMonitoringSnapshot(NULL);
368 base::RunLoop().RunUntilIdle(); 436 base::RunLoop().RunUntilIdle();
369 EXPECT_TRUE(controller->DisableMonitoring( 437 EXPECT_TRUE(controller->DisableMonitoring(
370 TracingController::DisableMonitoringDoneCallback())); 438 TracingController::DisableMonitoringDoneCallback()));
371 base::RunLoop().RunUntilIdle(); 439 base::RunLoop().RunUntilIdle();
372 } 440 }
373 441
374 } // namespace content 442 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/tracing/tracing_controller_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698