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

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 Nat and Dan's comments. Use CategoryFilter for tracing_controller.h's APIs 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());
170 bool result = controller->EnableMonitoring( 174 bool result = controller->EnableMonitoring(
171 "*", TracingController::ENABLE_SAMPLING, callback); 175 CategoryFilter("*"),
176 TraceOptions(RECORD_UNTIL_FULL).EnableSampling(true),
177 callback);
172 ASSERT_TRUE(result); 178 ASSERT_TRUE(result);
173 run_loop.Run(); 179 run_loop.Run();
174 EXPECT_EQ(enable_monitoring_done_callback_count(), 1); 180 EXPECT_EQ(enable_monitoring_done_callback_count(), 1);
175 } 181 }
176 182
177 { 183 {
178 bool is_monitoring; 184 bool is_monitoring;
179 std::string category_filter; 185 CategoryFilter category_filter("");
180 TracingController::Options options; 186 TraceOptions options;
181 controller->GetMonitoringStatus(&is_monitoring, 187 controller->GetMonitoringStatus(
182 &category_filter, 188 &is_monitoring, &category_filter, &options);
183 &options);
184 EXPECT_TRUE(is_monitoring); 189 EXPECT_TRUE(is_monitoring);
185 EXPECT_EQ("*", category_filter); 190 EXPECT_EQ("*", category_filter.ToString());
186 EXPECT_FALSE(options & TracingController::ENABLE_SYSTRACE); 191 EXPECT_FALSE(options.record_mode == RECORD_CONTINUOUSLY);
187 EXPECT_FALSE(options & TracingController::RECORD_CONTINUOUSLY); 192 EXPECT_TRUE(options.enable_sampling);
188 EXPECT_TRUE(options & TracingController::ENABLE_SAMPLING); 193 EXPECT_FALSE(options.enable_systrace);
189 } 194 }
190 195
191 { 196 {
192 base::RunLoop run_loop; 197 base::RunLoop run_loop;
193 TracingController::TracingFileResultCallback callback = 198 TracingController::TracingFileResultCallback callback =
194 base::Bind(&TracingControllerTest:: 199 base::Bind(&TracingControllerTest::
195 CaptureMonitoringSnapshotDoneCallbackTest, 200 CaptureMonitoringSnapshotDoneCallbackTest,
196 base::Unretained(this), 201 base::Unretained(this),
197 run_loop.QuitClosure()); 202 run_loop.QuitClosure());
198 ASSERT_TRUE(controller->CaptureMonitoringSnapshot(result_file_path, 203 ASSERT_TRUE(controller->CaptureMonitoringSnapshot(result_file_path,
199 callback)); 204 callback));
200 run_loop.Run(); 205 run_loop.Run();
201 EXPECT_EQ(capture_monitoring_snapshot_done_callback_count(), 1); 206 EXPECT_EQ(capture_monitoring_snapshot_done_callback_count(), 1);
202 } 207 }
203 208
204 { 209 {
205 base::RunLoop run_loop; 210 base::RunLoop run_loop;
206 TracingController::DisableMonitoringDoneCallback callback = 211 TracingController::DisableMonitoringDoneCallback callback =
207 base::Bind(&TracingControllerTest::DisableMonitoringDoneCallbackTest, 212 base::Bind(&TracingControllerTest::DisableMonitoringDoneCallbackTest,
208 base::Unretained(this), 213 base::Unretained(this),
209 run_loop.QuitClosure()); 214 run_loop.QuitClosure());
210 bool result = controller->DisableMonitoring(callback); 215 bool result = controller->DisableMonitoring(callback);
211 ASSERT_TRUE(result); 216 ASSERT_TRUE(result);
212 run_loop.Run(); 217 run_loop.Run();
213 EXPECT_EQ(disable_monitoring_done_callback_count(), 1); 218 EXPECT_EQ(disable_monitoring_done_callback_count(), 1);
214 } 219 }
215 220
216 { 221 {
217 bool is_monitoring; 222 bool is_monitoring;
218 std::string category_filter; 223 CategoryFilter category_filter("");
219 TracingController::Options options; 224 TraceOptions options;
220 controller->GetMonitoringStatus(&is_monitoring, 225 controller->GetMonitoringStatus(&is_monitoring,
221 &category_filter, 226 &category_filter,
222 &options); 227 &options);
223 EXPECT_FALSE(is_monitoring); 228 EXPECT_FALSE(is_monitoring);
224 EXPECT_EQ("", category_filter); 229 EXPECT_EQ("", category_filter.ToString());
225 EXPECT_FALSE(options & TracingController::ENABLE_SYSTRACE); 230 EXPECT_FALSE(options.record_mode == RECORD_CONTINUOUSLY);
226 EXPECT_FALSE(options & TracingController::RECORD_CONTINUOUSLY); 231 EXPECT_FALSE(options.enable_sampling);
227 EXPECT_FALSE(options & TracingController::ENABLE_SAMPLING); 232 EXPECT_FALSE(options.enable_systrace);
228 } 233 }
229 } 234 }
230 235
231 private: 236 private:
232 int get_categories_done_callback_count_; 237 int get_categories_done_callback_count_;
233 int enable_recording_done_callback_count_; 238 int enable_recording_done_callback_count_;
234 int disable_recording_done_callback_count_; 239 int disable_recording_done_callback_count_;
235 int enable_monitoring_done_callback_count_; 240 int enable_monitoring_done_callback_count_;
236 int disable_monitoring_done_callback_count_; 241 int disable_monitoring_done_callback_count_;
237 int capture_monitoring_snapshot_done_callback_count_; 242 int capture_monitoring_snapshot_done_callback_count_;
(...skipping 27 matching lines...) Expand all
265 TestEnableAndDisableRecording(file_path); 270 TestEnableAndDisableRecording(file_path);
266 EXPECT_EQ(file_path.value(), last_actual_recording_file_path().value()); 271 EXPECT_EQ(file_path.value(), last_actual_recording_file_path().value());
267 } 272 }
268 273
269 IN_PROC_BROWSER_TEST_F(TracingControllerTest, 274 IN_PROC_BROWSER_TEST_F(TracingControllerTest,
270 EnableAndDisableRecordingWithEmptyFileAndNullCallback) { 275 EnableAndDisableRecordingWithEmptyFileAndNullCallback) {
271 Navigate(shell()); 276 Navigate(shell());
272 277
273 TracingController* controller = TracingController::GetInstance(); 278 TracingController* controller = TracingController::GetInstance();
274 EXPECT_TRUE(controller->EnableRecording( 279 EXPECT_TRUE(controller->EnableRecording(
275 "", TracingController::DEFAULT_OPTIONS, 280 CategoryFilter(""),
281 TraceOptions(),
276 TracingController::EnableRecordingDoneCallback())); 282 TracingController::EnableRecordingDoneCallback()));
277 EXPECT_TRUE(controller->DisableRecording( 283 EXPECT_TRUE(controller->DisableRecording(
278 base::FilePath(), TracingController::TracingFileResultCallback())); 284 base::FilePath(), TracingController::TracingFileResultCallback()));
279 base::RunLoop().RunUntilIdle(); 285 base::RunLoop().RunUntilIdle();
280 } 286 }
281 287
282 IN_PROC_BROWSER_TEST_F(TracingControllerTest, 288 IN_PROC_BROWSER_TEST_F(TracingControllerTest,
283 EnableCaptureAndDisableMonitoring) { 289 EnableCaptureAndDisableMonitoring) {
284 TestEnableCaptureAndDisableMonitoring(base::FilePath()); 290 TestEnableCaptureAndDisableMonitoring(base::FilePath());
285 } 291 }
286 292
287 IN_PROC_BROWSER_TEST_F(TracingControllerTest, 293 IN_PROC_BROWSER_TEST_F(TracingControllerTest,
288 EnableCaptureAndDisableMonitoringWithFilePath) { 294 EnableCaptureAndDisableMonitoringWithFilePath) {
289 base::FilePath file_path; 295 base::FilePath file_path;
290 base::CreateTemporaryFile(&file_path); 296 base::CreateTemporaryFile(&file_path);
291 TestEnableCaptureAndDisableMonitoring(file_path); 297 TestEnableCaptureAndDisableMonitoring(file_path);
292 EXPECT_EQ(file_path.value(), last_actual_monitoring_file_path().value()); 298 EXPECT_EQ(file_path.value(), last_actual_monitoring_file_path().value());
293 } 299 }
294 300
295 IN_PROC_BROWSER_TEST_F( 301 IN_PROC_BROWSER_TEST_F(
296 TracingControllerTest, 302 TracingControllerTest,
297 EnableCaptureAndDisableMonitoringWithEmptyFileAndNullCallback) { 303 EnableCaptureAndDisableMonitoringWithEmptyFileAndNullCallback) {
298 Navigate(shell()); 304 Navigate(shell());
299 305
300 TracingController* controller = TracingController::GetInstance(); 306 TracingController* controller = TracingController::GetInstance();
301 EXPECT_TRUE(controller->EnableMonitoring( 307 EXPECT_TRUE(controller->EnableMonitoring(
302 "*", TracingController::ENABLE_SAMPLING, 308 CategoryFilter("*"),
309 TraceOptions(RECORD_UNTIL_FULL).EnableSampling(true),
303 TracingController::EnableMonitoringDoneCallback())); 310 TracingController::EnableMonitoringDoneCallback()));
304 controller->CaptureMonitoringSnapshot( 311 controller->CaptureMonitoringSnapshot(
305 base::FilePath(), TracingController::TracingFileResultCallback()); 312 base::FilePath(), TracingController::TracingFileResultCallback());
306 base::RunLoop().RunUntilIdle(); 313 base::RunLoop().RunUntilIdle();
307 EXPECT_TRUE(controller->DisableMonitoring( 314 EXPECT_TRUE(controller->DisableMonitoring(
308 TracingController::DisableMonitoringDoneCallback())); 315 TracingController::DisableMonitoringDoneCallback()));
309 base::RunLoop().RunUntilIdle(); 316 base::RunLoop().RunUntilIdle();
310 } 317 }
311 318
312 } // namespace content 319 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698