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

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

Issue 1874893002: Convert //content/browser from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
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 "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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 52 }
53 return false; 53 return false;
54 } 54 }
55 55
56 } // namespace 56 } // namespace
57 57
58 class TracingControllerTestEndpoint 58 class TracingControllerTestEndpoint
59 : public TracingController::TraceDataEndpoint { 59 : public TracingController::TraceDataEndpoint {
60 public: 60 public:
61 TracingControllerTestEndpoint( 61 TracingControllerTestEndpoint(
62 base::Callback<void(scoped_ptr<const base::DictionaryValue>, 62 base::Callback<void(std::unique_ptr<const base::DictionaryValue>,
63 base::RefCountedString*)> done_callback) 63 base::RefCountedString*)> done_callback)
64 : done_callback_(done_callback) {} 64 : done_callback_(done_callback) {}
65 65
66 void ReceiveTraceChunk(const std::string& chunk) override { 66 void ReceiveTraceChunk(const std::string& chunk) override {
67 EXPECT_FALSE(chunk.empty()); 67 EXPECT_FALSE(chunk.empty());
68 trace_ += chunk; 68 trace_ += chunk;
69 } 69 }
70 70
71 void ReceiveTraceFinalContents( 71 void ReceiveTraceFinalContents(
72 scoped_ptr<const base::DictionaryValue> metadata, 72 std::unique_ptr<const base::DictionaryValue> metadata,
73 const std::string& contents) override { 73 const std::string& contents) override {
74 EXPECT_EQ(trace_, contents); 74 EXPECT_EQ(trace_, contents);
75 75
76 std::string tmp = contents; 76 std::string tmp = contents;
77 scoped_refptr<base::RefCountedString> chunk_ptr = 77 scoped_refptr<base::RefCountedString> chunk_ptr =
78 base::RefCountedString::TakeString(&tmp); 78 base::RefCountedString::TakeString(&tmp);
79 79
80 BrowserThread::PostTask( 80 BrowserThread::PostTask(
81 BrowserThread::UI, FROM_HERE, 81 BrowserThread::UI, FROM_HERE,
82 base::Bind(done_callback_, base::Passed(std::move(metadata)), 82 base::Bind(done_callback_, base::Passed(std::move(metadata)),
83 base::RetainedRef(chunk_ptr))); 83 base::RetainedRef(chunk_ptr)));
84 } 84 }
85 85
86 protected: 86 protected:
87 ~TracingControllerTestEndpoint() override {} 87 ~TracingControllerTestEndpoint() override {}
88 88
89 std::string trace_; 89 std::string trace_;
90 base::Callback<void(scoped_ptr<const base::DictionaryValue>, 90 base::Callback<void(std::unique_ptr<const base::DictionaryValue>,
91 base::RefCountedString*)> done_callback_; 91 base::RefCountedString*)>
92 done_callback_;
92 }; 93 };
93 94
94 class TracingControllerTest : public ContentBrowserTest { 95 class TracingControllerTest : public ContentBrowserTest {
95 public: 96 public:
96 TracingControllerTest() {} 97 TracingControllerTest() {}
97 98
98 void SetUp() override { 99 void SetUp() override {
99 get_categories_done_callback_count_ = 0; 100 get_categories_done_callback_count_ = 0;
100 enable_recording_done_callback_count_ = 0; 101 enable_recording_done_callback_count_ = 0;
101 disable_recording_done_callback_count_ = 0; 102 disable_recording_done_callback_count_ = 0;
(...skipping 13 matching lines...) Expand all
115 quit_callback.Run(); 116 quit_callback.Run();
116 } 117 }
117 118
118 void StartTracingDoneCallbackTest(base::Closure quit_callback) { 119 void StartTracingDoneCallbackTest(base::Closure quit_callback) {
119 enable_recording_done_callback_count_++; 120 enable_recording_done_callback_count_++;
120 quit_callback.Run(); 121 quit_callback.Run();
121 } 122 }
122 123
123 void StopTracingStringDoneCallbackTest( 124 void StopTracingStringDoneCallbackTest(
124 base::Closure quit_callback, 125 base::Closure quit_callback,
125 scoped_ptr<const base::DictionaryValue> metadata, 126 std::unique_ptr<const base::DictionaryValue> metadata,
126 base::RefCountedString* data) { 127 base::RefCountedString* data) {
127 disable_recording_done_callback_count_++; 128 disable_recording_done_callback_count_++;
128 last_metadata_.reset(metadata.release()); 129 last_metadata_.reset(metadata.release());
129 last_data_ = data->data(); 130 last_data_ = data->data();
130 EXPECT_TRUE(data->size() > 0); 131 EXPECT_TRUE(data->size() > 0);
131 quit_callback.Run(); 132 quit_callback.Run();
132 } 133 }
133 134
134 void StopTracingFileDoneCallbackTest(base::Closure quit_callback, 135 void StopTracingFileDoneCallbackTest(base::Closure quit_callback,
135 const base::FilePath& file_path) { 136 const base::FilePath& file_path) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 run_loop.QuitClosure()); 180 run_loop.QuitClosure());
180 bool result = controller->StartTracing( 181 bool result = controller->StartTracing(
181 TraceConfig(), callback); 182 TraceConfig(), callback);
182 ASSERT_TRUE(result); 183 ASSERT_TRUE(result);
183 run_loop.Run(); 184 run_loop.Run();
184 EXPECT_EQ(enable_recording_done_callback_count(), 1); 185 EXPECT_EQ(enable_recording_done_callback_count(), 1);
185 } 186 }
186 187
187 { 188 {
188 base::RunLoop run_loop; 189 base::RunLoop run_loop;
189 base::Callback<void(scoped_ptr<const base::DictionaryValue>, 190 base::Callback<void(std::unique_ptr<const base::DictionaryValue>,
190 base::RefCountedString*)> callback = base::Bind( 191 base::RefCountedString*)>
191 &TracingControllerTest::StopTracingStringDoneCallbackTest, 192 callback = base::Bind(
192 base::Unretained(this), 193 &TracingControllerTest::StopTracingStringDoneCallbackTest,
193 run_loop.QuitClosure()); 194 base::Unretained(this), run_loop.QuitClosure());
194 bool result = controller->StopTracing( 195 bool result = controller->StopTracing(
195 TracingController::CreateStringSink(callback)); 196 TracingController::CreateStringSink(callback));
196 ASSERT_TRUE(result); 197 ASSERT_TRUE(result);
197 run_loop.Run(); 198 run_loop.Run();
198 EXPECT_EQ(disable_recording_done_callback_count(), 1); 199 EXPECT_EQ(disable_recording_done_callback_count(), 1);
199 } 200 }
200 } 201 }
201 202
202 void TestStartAndStopTracingStringWithFilter() { 203 void TestStartAndStopTracingStringWithFilter() {
203 Navigate(shell()); 204 Navigate(shell());
(...skipping 13 matching lines...) Expand all
217 config.EnableArgumentFilter(); 218 config.EnableArgumentFilter();
218 219
219 bool result = controller->StartTracing(config, callback); 220 bool result = controller->StartTracing(config, callback);
220 ASSERT_TRUE(result); 221 ASSERT_TRUE(result);
221 run_loop.Run(); 222 run_loop.Run();
222 EXPECT_EQ(enable_recording_done_callback_count(), 1); 223 EXPECT_EQ(enable_recording_done_callback_count(), 1);
223 } 224 }
224 225
225 { 226 {
226 base::RunLoop run_loop; 227 base::RunLoop run_loop;
227 base::Callback<void(scoped_ptr<const base::DictionaryValue>, 228 base::Callback<void(std::unique_ptr<const base::DictionaryValue>,
228 base::RefCountedString*)> callback = base::Bind( 229 base::RefCountedString*)>
229 &TracingControllerTest::StopTracingStringDoneCallbackTest, 230 callback = base::Bind(
230 base::Unretained(this), 231 &TracingControllerTest::StopTracingStringDoneCallbackTest,
231 run_loop.QuitClosure()); 232 base::Unretained(this), run_loop.QuitClosure());
232 233
233 scoped_refptr<TracingController::TraceDataSink> trace_data_sink = 234 scoped_refptr<TracingController::TraceDataSink> trace_data_sink =
234 TracingController::CreateStringSink(callback); 235 TracingController::CreateStringSink(callback);
235 236
236 trace_data_sink->SetMetadataFilterPredicate( 237 trace_data_sink->SetMetadataFilterPredicate(
237 base::Bind(&IsMetadataWhitelisted)); 238 base::Bind(&IsMetadataWhitelisted));
238 base::DictionaryValue metadata; 239 base::DictionaryValue metadata;
239 metadata.SetString("not-whitelisted", "this_not_found"); 240 metadata.SetString("not-whitelisted", "this_not_found");
240 trace_data_sink->AddMetadata(metadata); 241 trace_data_sink->AddMetadata(metadata);
241 242
(...skipping 15 matching lines...) Expand all
257 base::Bind(&TracingControllerTest::StartTracingDoneCallbackTest, 258 base::Bind(&TracingControllerTest::StartTracingDoneCallbackTest,
258 base::Unretained(this), run_loop.QuitClosure()); 259 base::Unretained(this), run_loop.QuitClosure());
259 bool result = controller->StartTracing(TraceConfig(), callback); 260 bool result = controller->StartTracing(TraceConfig(), callback);
260 ASSERT_TRUE(result); 261 ASSERT_TRUE(result);
261 run_loop.Run(); 262 run_loop.Run();
262 EXPECT_EQ(enable_recording_done_callback_count(), 1); 263 EXPECT_EQ(enable_recording_done_callback_count(), 1);
263 } 264 }
264 265
265 { 266 {
266 base::RunLoop run_loop; 267 base::RunLoop run_loop;
267 base::Callback<void(scoped_ptr<const base::DictionaryValue>, 268 base::Callback<void(std::unique_ptr<const base::DictionaryValue>,
268 base::RefCountedString*)> callback = base::Bind( 269 base::RefCountedString*)>
269 &TracingControllerTest::StopTracingStringDoneCallbackTest, 270 callback = base::Bind(
270 base::Unretained(this), run_loop.QuitClosure()); 271 &TracingControllerTest::StopTracingStringDoneCallbackTest,
272 base::Unretained(this), run_loop.QuitClosure());
271 bool result = controller->StopTracing( 273 bool result = controller->StopTracing(
272 TracingController::CreateCompressedStringSink( 274 TracingController::CreateCompressedStringSink(
273 new TracingControllerTestEndpoint(callback))); 275 new TracingControllerTestEndpoint(callback)));
274 ASSERT_TRUE(result); 276 ASSERT_TRUE(result);
275 run_loop.Run(); 277 run_loop.Run();
276 EXPECT_EQ(disable_recording_done_callback_count(), 1); 278 EXPECT_EQ(disable_recording_done_callback_count(), 1);
277 } 279 }
278 } 280 }
279 281
280 void TestStartAndStopTracingCompressedFile( 282 void TestStartAndStopTracingCompressedFile(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 run_loop.Run(); 342 run_loop.Run();
341 EXPECT_EQ(disable_recording_done_callback_count(), 1); 343 EXPECT_EQ(disable_recording_done_callback_count(), 1);
342 } 344 }
343 } 345 }
344 346
345 private: 347 private:
346 int get_categories_done_callback_count_; 348 int get_categories_done_callback_count_;
347 int enable_recording_done_callback_count_; 349 int enable_recording_done_callback_count_;
348 int disable_recording_done_callback_count_; 350 int disable_recording_done_callback_count_;
349 base::FilePath last_actual_recording_file_path_; 351 base::FilePath last_actual_recording_file_path_;
350 scoped_ptr<const base::DictionaryValue> last_metadata_; 352 std::unique_ptr<const base::DictionaryValue> last_metadata_;
351 std::string last_data_; 353 std::string last_data_;
352 }; 354 };
353 355
354 IN_PROC_BROWSER_TEST_F(TracingControllerTest, GetCategories) { 356 IN_PROC_BROWSER_TEST_F(TracingControllerTest, GetCategories) {
355 Navigate(shell()); 357 Navigate(shell());
356 358
357 TracingController* controller = TracingController::GetInstance(); 359 TracingController* controller = TracingController::GetInstance();
358 360
359 base::RunLoop run_loop; 361 base::RunLoop run_loop;
360 TracingController::GetCategoriesDoneCallback callback = 362 TracingController::GetCategoriesDoneCallback callback =
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 456
455 TracingController* controller = TracingController::GetInstance(); 457 TracingController* controller = TracingController::GetInstance();
456 EXPECT_TRUE(controller->StartTracing( 458 EXPECT_TRUE(controller->StartTracing(
457 TraceConfig(), 459 TraceConfig(),
458 TracingController::StartTracingDoneCallback())); 460 TracingController::StartTracingDoneCallback()));
459 EXPECT_TRUE(controller->StopTracing(NULL)); 461 EXPECT_TRUE(controller->StopTracing(NULL));
460 base::RunLoop().RunUntilIdle(); 462 base::RunLoop().RunUntilIdle();
461 } 463 }
462 464
463 } // namespace content 465 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/tracing/power_tracing_agent.h ('k') | content/browser/tracing/tracing_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698