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

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

Issue 425593002: Refactor trace_event_impl's SetEnabled to use TraceOptions. Propagate this through the whole stack. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address joechan's comments Created 6 years, 4 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/file_util.h" 5 #include "base/file_util.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "content/browser/tracing/tracing_controller_impl.h" 7 #include "content/browser/tracing/tracing_controller_impl.h"
8 #include "content/public/test/browser_test_utils.h" 8 #include "content/public/test/browser_test_utils.h"
9 #include "content/public/test/content_browser_test.h" 9 #include "content/public/test/content_browser_test.h"
10 #include "content/public/test/content_browser_test_utils.h" 10 #include "content/public/test/content_browser_test_utils.h"
11 #include "content/shell/browser/shell.h" 11 #include "content/shell/browser/shell.h"
12 12
13 using base::debug::CategoryFilter;
14 using base::debug::TraceOptions;
15 using base::debug::RECORD_CONTINUOUSLY;
16 using base::debug::RECORD_UNTIL_FULL;
17
13 namespace content { 18 namespace content {
14 19
15 class TracingControllerTest : public ContentBrowserTest { 20 class TracingControllerTest : public ContentBrowserTest {
16 public: 21 public:
17 TracingControllerTest() {} 22 TracingControllerTest() {}
18 23
19 virtual void SetUp() OVERRIDE { 24 virtual void SetUp() OVERRIDE {
20 get_categories_done_callback_count_ = 0; 25 get_categories_done_callback_count_ = 0;
21 enable_recording_done_callback_count_ = 0; 26 enable_recording_done_callback_count_ = 0;
22 disable_recording_done_callback_count_ = 0; 27 disable_recording_done_callback_count_ = 0;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 120
116 TracingController* controller = TracingController::GetInstance(); 121 TracingController* controller = TracingController::GetInstance();
117 122
118 { 123 {
119 base::RunLoop run_loop; 124 base::RunLoop run_loop;
120 TracingController::EnableRecordingDoneCallback callback = 125 TracingController::EnableRecordingDoneCallback callback =
121 base::Bind(&TracingControllerTest::EnableRecordingDoneCallbackTest, 126 base::Bind(&TracingControllerTest::EnableRecordingDoneCallbackTest,
122 base::Unretained(this), 127 base::Unretained(this),
123 run_loop.QuitClosure()); 128 run_loop.QuitClosure());
124 bool result = controller->EnableRecording( 129 bool result = controller->EnableRecording(
125 "", TracingController::DEFAULT_OPTIONS, callback); 130 CategoryFilter(), TraceOptions(), callback);
126 ASSERT_TRUE(result); 131 ASSERT_TRUE(result);
127 run_loop.Run(); 132 run_loop.Run();
128 EXPECT_EQ(enable_recording_done_callback_count(), 1); 133 EXPECT_EQ(enable_recording_done_callback_count(), 1);
129 } 134 }
130 135
131 { 136 {
132 base::RunLoop run_loop; 137 base::RunLoop run_loop;
133 TracingController::TracingFileResultCallback callback = 138 TracingController::TracingFileResultCallback callback =
134 base::Bind(&TracingControllerTest::DisableRecordingDoneCallbackTest, 139 base::Bind(&TracingControllerTest::DisableRecordingDoneCallbackTest,
135 base::Unretained(this), 140 base::Unretained(this),
136 run_loop.QuitClosure()); 141 run_loop.QuitClosure());
137 bool result = controller->DisableRecording(result_file_path, callback); 142 bool result = controller->DisableRecording(result_file_path, callback);
138 ASSERT_TRUE(result); 143 ASSERT_TRUE(result);
139 run_loop.Run(); 144 run_loop.Run();
140 EXPECT_EQ(disable_recording_done_callback_count(), 1); 145 EXPECT_EQ(disable_recording_done_callback_count(), 1);
141 } 146 }
142 } 147 }
143 148
144 void TestEnableCaptureAndDisableMonitoring( 149 void TestEnableCaptureAndDisableMonitoring(
145 const base::FilePath& result_file_path) { 150 const base::FilePath& result_file_path) {
146 Navigate(shell()); 151 Navigate(shell());
147 152
148 TracingController* controller = TracingController::GetInstance(); 153 TracingController* controller = TracingController::GetInstance();
149 154
150 { 155 {
151 bool is_monitoring; 156 bool is_monitoring;
152 std::string category_filter; 157 CategoryFilter category_filter("");
153 TracingController::Options options; 158 TraceOptions options;
154 controller->GetMonitoringStatus(&is_monitoring, 159 controller->GetMonitoringStatus(
155 &category_filter, 160 &is_monitoring, &category_filter, &options);
156 &options);
157 EXPECT_FALSE(is_monitoring); 161 EXPECT_FALSE(is_monitoring);
158 EXPECT_EQ("-*Debug,-*Test", category_filter); 162 EXPECT_EQ("-*Debug,-*Test", category_filter.ToString());
159 EXPECT_FALSE(options & TracingController::ENABLE_SYSTRACE); 163 EXPECT_FALSE(options.record_mode == RECORD_CONTINUOUSLY);
160 EXPECT_FALSE(options & TracingController::RECORD_CONTINUOUSLY); 164 EXPECT_FALSE(options.enable_sampling);
161 EXPECT_FALSE(options & TracingController::ENABLE_SAMPLING); 165 EXPECT_FALSE(options.enable_systrace);
162 } 166 }
163 167
164 { 168 {
165 base::RunLoop run_loop; 169 base::RunLoop run_loop;
166 TracingController::EnableMonitoringDoneCallback callback = 170 TracingController::EnableMonitoringDoneCallback callback =
167 base::Bind(&TracingControllerTest::EnableMonitoringDoneCallbackTest, 171 base::Bind(&TracingControllerTest::EnableMonitoringDoneCallbackTest,
168 base::Unretained(this), 172 base::Unretained(this),
169 run_loop.QuitClosure()); 173 run_loop.QuitClosure());
174
175 TraceOptions trace_options;
176 trace_options.enable_sampling = true;
177
170 bool result = controller->EnableMonitoring( 178 bool result = controller->EnableMonitoring(
171 "*", TracingController::ENABLE_SAMPLING, callback); 179 CategoryFilter("*"),
180 trace_options,
181 callback);
172 ASSERT_TRUE(result); 182 ASSERT_TRUE(result);
173 run_loop.Run(); 183 run_loop.Run();
174 EXPECT_EQ(enable_monitoring_done_callback_count(), 1); 184 EXPECT_EQ(enable_monitoring_done_callback_count(), 1);
175 } 185 }
176 186
177 { 187 {
178 bool is_monitoring; 188 bool is_monitoring;
179 std::string category_filter; 189 CategoryFilter category_filter("");
180 TracingController::Options options; 190 TraceOptions options;
181 controller->GetMonitoringStatus(&is_monitoring, 191 controller->GetMonitoringStatus(
182 &category_filter, 192 &is_monitoring, &category_filter, &options);
183 &options);
184 EXPECT_TRUE(is_monitoring); 193 EXPECT_TRUE(is_monitoring);
185 EXPECT_EQ("*", category_filter); 194 EXPECT_EQ("*", category_filter.ToString());
186 EXPECT_FALSE(options & TracingController::ENABLE_SYSTRACE); 195 EXPECT_FALSE(options.record_mode == RECORD_CONTINUOUSLY);
187 EXPECT_FALSE(options & TracingController::RECORD_CONTINUOUSLY); 196 EXPECT_TRUE(options.enable_sampling);
188 EXPECT_TRUE(options & TracingController::ENABLE_SAMPLING); 197 EXPECT_FALSE(options.enable_systrace);
189 } 198 }
190 199
191 { 200 {
192 base::RunLoop run_loop; 201 base::RunLoop run_loop;
193 TracingController::TracingFileResultCallback callback = 202 TracingController::TracingFileResultCallback callback =
194 base::Bind(&TracingControllerTest:: 203 base::Bind(&TracingControllerTest::
195 CaptureMonitoringSnapshotDoneCallbackTest, 204 CaptureMonitoringSnapshotDoneCallbackTest,
196 base::Unretained(this), 205 base::Unretained(this),
197 run_loop.QuitClosure()); 206 run_loop.QuitClosure());
198 ASSERT_TRUE(controller->CaptureMonitoringSnapshot(result_file_path, 207 ASSERT_TRUE(controller->CaptureMonitoringSnapshot(result_file_path,
199 callback)); 208 callback));
200 run_loop.Run(); 209 run_loop.Run();
201 EXPECT_EQ(capture_monitoring_snapshot_done_callback_count(), 1); 210 EXPECT_EQ(capture_monitoring_snapshot_done_callback_count(), 1);
202 } 211 }
203 212
204 { 213 {
205 base::RunLoop run_loop; 214 base::RunLoop run_loop;
206 TracingController::DisableMonitoringDoneCallback callback = 215 TracingController::DisableMonitoringDoneCallback callback =
207 base::Bind(&TracingControllerTest::DisableMonitoringDoneCallbackTest, 216 base::Bind(&TracingControllerTest::DisableMonitoringDoneCallbackTest,
208 base::Unretained(this), 217 base::Unretained(this),
209 run_loop.QuitClosure()); 218 run_loop.QuitClosure());
210 bool result = controller->DisableMonitoring(callback); 219 bool result = controller->DisableMonitoring(callback);
211 ASSERT_TRUE(result); 220 ASSERT_TRUE(result);
212 run_loop.Run(); 221 run_loop.Run();
213 EXPECT_EQ(disable_monitoring_done_callback_count(), 1); 222 EXPECT_EQ(disable_monitoring_done_callback_count(), 1);
214 } 223 }
215 224
216 { 225 {
217 bool is_monitoring; 226 bool is_monitoring;
218 std::string category_filter; 227 CategoryFilter category_filter("");
219 TracingController::Options options; 228 TraceOptions options;
220 controller->GetMonitoringStatus(&is_monitoring, 229 controller->GetMonitoringStatus(&is_monitoring,
221 &category_filter, 230 &category_filter,
222 &options); 231 &options);
223 EXPECT_FALSE(is_monitoring); 232 EXPECT_FALSE(is_monitoring);
224 EXPECT_EQ("", category_filter); 233 EXPECT_EQ("", category_filter.ToString());
225 EXPECT_FALSE(options & TracingController::ENABLE_SYSTRACE); 234 EXPECT_FALSE(options.record_mode == RECORD_CONTINUOUSLY);
226 EXPECT_FALSE(options & TracingController::RECORD_CONTINUOUSLY); 235 EXPECT_FALSE(options.enable_sampling);
227 EXPECT_FALSE(options & TracingController::ENABLE_SAMPLING); 236 EXPECT_FALSE(options.enable_systrace);
228 } 237 }
229 } 238 }
230 239
231 private: 240 private:
232 int get_categories_done_callback_count_; 241 int get_categories_done_callback_count_;
233 int enable_recording_done_callback_count_; 242 int enable_recording_done_callback_count_;
234 int disable_recording_done_callback_count_; 243 int disable_recording_done_callback_count_;
235 int enable_monitoring_done_callback_count_; 244 int enable_monitoring_done_callback_count_;
236 int disable_monitoring_done_callback_count_; 245 int disable_monitoring_done_callback_count_;
237 int capture_monitoring_snapshot_done_callback_count_; 246 int capture_monitoring_snapshot_done_callback_count_;
(...skipping 27 matching lines...) Expand all
265 TestEnableAndDisableRecording(file_path); 274 TestEnableAndDisableRecording(file_path);
266 EXPECT_EQ(file_path.value(), last_actual_recording_file_path().value()); 275 EXPECT_EQ(file_path.value(), last_actual_recording_file_path().value());
267 } 276 }
268 277
269 IN_PROC_BROWSER_TEST_F(TracingControllerTest, 278 IN_PROC_BROWSER_TEST_F(TracingControllerTest,
270 EnableAndDisableRecordingWithEmptyFileAndNullCallback) { 279 EnableAndDisableRecordingWithEmptyFileAndNullCallback) {
271 Navigate(shell()); 280 Navigate(shell());
272 281
273 TracingController* controller = TracingController::GetInstance(); 282 TracingController* controller = TracingController::GetInstance();
274 EXPECT_TRUE(controller->EnableRecording( 283 EXPECT_TRUE(controller->EnableRecording(
275 "", TracingController::DEFAULT_OPTIONS, 284 CategoryFilter(),
285 TraceOptions(),
276 TracingController::EnableRecordingDoneCallback())); 286 TracingController::EnableRecordingDoneCallback()));
277 EXPECT_TRUE(controller->DisableRecording( 287 EXPECT_TRUE(controller->DisableRecording(
278 base::FilePath(), TracingController::TracingFileResultCallback())); 288 base::FilePath(), TracingController::TracingFileResultCallback()));
279 base::RunLoop().RunUntilIdle(); 289 base::RunLoop().RunUntilIdle();
280 } 290 }
281 291
282 IN_PROC_BROWSER_TEST_F(TracingControllerTest, 292 IN_PROC_BROWSER_TEST_F(TracingControllerTest,
283 EnableCaptureAndDisableMonitoring) { 293 EnableCaptureAndDisableMonitoring) {
284 TestEnableCaptureAndDisableMonitoring(base::FilePath()); 294 TestEnableCaptureAndDisableMonitoring(base::FilePath());
285 } 295 }
286 296
287 IN_PROC_BROWSER_TEST_F(TracingControllerTest, 297 IN_PROC_BROWSER_TEST_F(TracingControllerTest,
288 EnableCaptureAndDisableMonitoringWithFilePath) { 298 EnableCaptureAndDisableMonitoringWithFilePath) {
289 base::FilePath file_path; 299 base::FilePath file_path;
290 base::CreateTemporaryFile(&file_path); 300 base::CreateTemporaryFile(&file_path);
291 TestEnableCaptureAndDisableMonitoring(file_path); 301 TestEnableCaptureAndDisableMonitoring(file_path);
292 EXPECT_EQ(file_path.value(), last_actual_monitoring_file_path().value()); 302 EXPECT_EQ(file_path.value(), last_actual_monitoring_file_path().value());
293 } 303 }
294 304
295 IN_PROC_BROWSER_TEST_F( 305 IN_PROC_BROWSER_TEST_F(
296 TracingControllerTest, 306 TracingControllerTest,
297 EnableCaptureAndDisableMonitoringWithEmptyFileAndNullCallback) { 307 EnableCaptureAndDisableMonitoringWithEmptyFileAndNullCallback) {
298 Navigate(shell()); 308 Navigate(shell());
299 309
300 TracingController* controller = TracingController::GetInstance(); 310 TracingController* controller = TracingController::GetInstance();
311 TraceOptions trace_options;
312 trace_options.enable_sampling = true;
301 EXPECT_TRUE(controller->EnableMonitoring( 313 EXPECT_TRUE(controller->EnableMonitoring(
302 "*", TracingController::ENABLE_SAMPLING, 314 CategoryFilter("*"),
315 trace_options,
303 TracingController::EnableMonitoringDoneCallback())); 316 TracingController::EnableMonitoringDoneCallback()));
304 controller->CaptureMonitoringSnapshot( 317 controller->CaptureMonitoringSnapshot(
305 base::FilePath(), TracingController::TracingFileResultCallback()); 318 base::FilePath(), TracingController::TracingFileResultCallback());
306 base::RunLoop().RunUntilIdle(); 319 base::RunLoop().RunUntilIdle();
307 EXPECT_TRUE(controller->DisableMonitoring( 320 EXPECT_TRUE(controller->DisableMonitoring(
308 TracingController::DisableMonitoringDoneCallback())); 321 TracingController::DisableMonitoringDoneCallback()));
309 base::RunLoop().RunUntilIdle(); 322 base::RunLoop().RunUntilIdle();
310 } 323 }
311 324
312 } // namespace content 325 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/tracing/trace_message_filter.cc ('k') | content/browser/tracing/tracing_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698