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

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: Pull enable_systrace to TraceOptions 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::TraceOptions;
14
13 namespace content { 15 namespace content {
14 16
15 class TracingControllerTest : public ContentBrowserTest { 17 class TracingControllerTest : public ContentBrowserTest {
16 public: 18 public:
17 TracingControllerTest() {} 19 TracingControllerTest() {}
18 20
19 virtual void SetUp() OVERRIDE { 21 virtual void SetUp() OVERRIDE {
20 get_categories_done_callback_count_ = 0; 22 get_categories_done_callback_count_ = 0;
21 enable_recording_done_callback_count_ = 0; 23 enable_recording_done_callback_count_ = 0;
22 disable_recording_done_callback_count_ = 0; 24 disable_recording_done_callback_count_ = 0;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 Navigate(shell()); 116 Navigate(shell());
115 117
116 TracingController* controller = TracingController::GetInstance(); 118 TracingController* controller = TracingController::GetInstance();
117 119
118 { 120 {
119 base::RunLoop run_loop; 121 base::RunLoop run_loop;
120 TracingController::EnableRecordingDoneCallback callback = 122 TracingController::EnableRecordingDoneCallback callback =
121 base::Bind(&TracingControllerTest::EnableRecordingDoneCallbackTest, 123 base::Bind(&TracingControllerTest::EnableRecordingDoneCallbackTest,
122 base::Unretained(this), 124 base::Unretained(this),
123 run_loop.QuitClosure()); 125 run_loop.QuitClosure());
124 bool result = controller->EnableRecording( 126 bool result =
125 "", TracingController::DEFAULT_OPTIONS, callback); 127 controller->EnableRecording("", TraceOptions(), callback);
126 ASSERT_TRUE(result); 128 ASSERT_TRUE(result);
127 run_loop.Run(); 129 run_loop.Run();
128 EXPECT_EQ(enable_recording_done_callback_count(), 1); 130 EXPECT_EQ(enable_recording_done_callback_count(), 1);
129 } 131 }
130 132
131 { 133 {
132 base::RunLoop run_loop; 134 base::RunLoop run_loop;
133 TracingController::TracingFileResultCallback callback = 135 TracingController::TracingFileResultCallback callback =
134 base::Bind(&TracingControllerTest::DisableRecordingDoneCallbackTest, 136 base::Bind(&TracingControllerTest::DisableRecordingDoneCallbackTest,
135 base::Unretained(this), 137 base::Unretained(this),
136 run_loop.QuitClosure()); 138 run_loop.QuitClosure());
137 bool result = controller->DisableRecording(result_file_path, callback); 139 bool result = controller->DisableRecording(result_file_path, callback);
138 ASSERT_TRUE(result); 140 ASSERT_TRUE(result);
139 run_loop.Run(); 141 run_loop.Run();
140 EXPECT_EQ(disable_recording_done_callback_count(), 1); 142 EXPECT_EQ(disable_recording_done_callback_count(), 1);
141 } 143 }
142 } 144 }
143 145
144 void TestEnableCaptureAndDisableMonitoring( 146 void TestEnableCaptureAndDisableMonitoring(
145 const base::FilePath& result_file_path) { 147 const base::FilePath& result_file_path) {
146 Navigate(shell()); 148 Navigate(shell());
147 149
148 TracingController* controller = TracingController::GetInstance(); 150 TracingController* controller = TracingController::GetInstance();
149 151
150 { 152 {
151 bool is_monitoring; 153 bool is_monitoring;
152 std::string category_filter; 154 std::string category_filter;
153 TracingController::Options options; 155 TraceOptions options;
154 controller->GetMonitoringStatus(&is_monitoring, 156 controller->GetMonitoringStatus(
155 &category_filter, 157 &is_monitoring, &category_filter, &options);
156 &options);
157 EXPECT_FALSE(is_monitoring); 158 EXPECT_FALSE(is_monitoring);
158 EXPECT_EQ("-*Debug,-*Test", category_filter); 159 EXPECT_EQ("-*Debug,-*Test", category_filter);
159 EXPECT_FALSE(options & TracingController::ENABLE_SYSTRACE); 160 EXPECT_FALSE(options.record_mode == TraceOptions::RECORD_CONTINUOUSLY);
160 EXPECT_FALSE(options & TracingController::RECORD_CONTINUOUSLY); 161 EXPECT_FALSE(options.enable_sampling);
161 EXPECT_FALSE(options & TracingController::ENABLE_SAMPLING); 162 EXPECT_FALSE(options.enable_systrace);
162 } 163 }
163 164
164 { 165 {
165 base::RunLoop run_loop; 166 base::RunLoop run_loop;
166 TracingController::EnableMonitoringDoneCallback callback = 167 TracingController::EnableMonitoringDoneCallback callback =
167 base::Bind(&TracingControllerTest::EnableMonitoringDoneCallbackTest, 168 base::Bind(&TracingControllerTest::EnableMonitoringDoneCallbackTest,
168 base::Unretained(this), 169 base::Unretained(this),
169 run_loop.QuitClosure()); 170 run_loop.QuitClosure());
170 bool result = controller->EnableMonitoring( 171 bool result = controller->EnableMonitoring(
171 "*", TracingController::ENABLE_SAMPLING, callback); 172 "*",
173 TraceOptions(TraceOptions::RECORD_UNTIL_FULL).EnableSampling(true),
174 callback);
172 ASSERT_TRUE(result); 175 ASSERT_TRUE(result);
173 run_loop.Run(); 176 run_loop.Run();
174 EXPECT_EQ(enable_monitoring_done_callback_count(), 1); 177 EXPECT_EQ(enable_monitoring_done_callback_count(), 1);
175 } 178 }
176 179
177 { 180 {
178 bool is_monitoring; 181 bool is_monitoring;
179 std::string category_filter; 182 std::string category_filter;
180 TracingController::Options options; 183 TraceOptions options;
181 controller->GetMonitoringStatus(&is_monitoring, 184 controller->GetMonitoringStatus(
182 &category_filter, 185 &is_monitoring, &category_filter, &options);
183 &options);
184 EXPECT_TRUE(is_monitoring); 186 EXPECT_TRUE(is_monitoring);
185 EXPECT_EQ("*", category_filter); 187 EXPECT_EQ("*", category_filter);
186 EXPECT_FALSE(options & TracingController::ENABLE_SYSTRACE); 188 EXPECT_FALSE(options.record_mode == TraceOptions::RECORD_CONTINUOUSLY);
187 EXPECT_FALSE(options & TracingController::RECORD_CONTINUOUSLY); 189 EXPECT_TRUE(options.enable_sampling);
188 EXPECT_TRUE(options & TracingController::ENABLE_SAMPLING); 190 EXPECT_FALSE(options.enable_systrace);
189 } 191 }
190 192
191 { 193 {
192 base::RunLoop run_loop; 194 base::RunLoop run_loop;
193 TracingController::TracingFileResultCallback callback = 195 TracingController::TracingFileResultCallback callback =
194 base::Bind(&TracingControllerTest:: 196 base::Bind(&TracingControllerTest::
195 CaptureMonitoringSnapshotDoneCallbackTest, 197 CaptureMonitoringSnapshotDoneCallbackTest,
196 base::Unretained(this), 198 base::Unretained(this),
197 run_loop.QuitClosure()); 199 run_loop.QuitClosure());
198 ASSERT_TRUE(controller->CaptureMonitoringSnapshot(result_file_path, 200 ASSERT_TRUE(controller->CaptureMonitoringSnapshot(result_file_path,
(...skipping 10 matching lines...) Expand all
209 run_loop.QuitClosure()); 211 run_loop.QuitClosure());
210 bool result = controller->DisableMonitoring(callback); 212 bool result = controller->DisableMonitoring(callback);
211 ASSERT_TRUE(result); 213 ASSERT_TRUE(result);
212 run_loop.Run(); 214 run_loop.Run();
213 EXPECT_EQ(disable_monitoring_done_callback_count(), 1); 215 EXPECT_EQ(disable_monitoring_done_callback_count(), 1);
214 } 216 }
215 217
216 { 218 {
217 bool is_monitoring; 219 bool is_monitoring;
218 std::string category_filter; 220 std::string category_filter;
219 TracingController::Options options; 221 TraceOptions options;
220 controller->GetMonitoringStatus(&is_monitoring, 222 controller->GetMonitoringStatus(&is_monitoring,
221 &category_filter, 223 &category_filter,
222 &options); 224 &options);
223 EXPECT_FALSE(is_monitoring); 225 EXPECT_FALSE(is_monitoring);
224 EXPECT_EQ("", category_filter); 226 EXPECT_EQ("", category_filter);
225 EXPECT_FALSE(options & TracingController::ENABLE_SYSTRACE); 227 EXPECT_FALSE(options.record_mode == TraceOptions::RECORD_CONTINUOUSLY);
226 EXPECT_FALSE(options & TracingController::RECORD_CONTINUOUSLY); 228 EXPECT_FALSE(options.enable_sampling);
227 EXPECT_FALSE(options & TracingController::ENABLE_SAMPLING); 229 EXPECT_FALSE(options.enable_systrace);
228 } 230 }
229 } 231 }
230 232
231 private: 233 private:
232 int get_categories_done_callback_count_; 234 int get_categories_done_callback_count_;
233 int enable_recording_done_callback_count_; 235 int enable_recording_done_callback_count_;
234 int disable_recording_done_callback_count_; 236 int disable_recording_done_callback_count_;
235 int enable_monitoring_done_callback_count_; 237 int enable_monitoring_done_callback_count_;
236 int disable_monitoring_done_callback_count_; 238 int disable_monitoring_done_callback_count_;
237 int capture_monitoring_snapshot_done_callback_count_; 239 int capture_monitoring_snapshot_done_callback_count_;
(...skipping 27 matching lines...) Expand all
265 TestEnableAndDisableRecording(file_path); 267 TestEnableAndDisableRecording(file_path);
266 EXPECT_EQ(file_path.value(), last_actual_recording_file_path().value()); 268 EXPECT_EQ(file_path.value(), last_actual_recording_file_path().value());
267 } 269 }
268 270
269 IN_PROC_BROWSER_TEST_F(TracingControllerTest, 271 IN_PROC_BROWSER_TEST_F(TracingControllerTest,
270 EnableAndDisableRecordingWithEmptyFileAndNullCallback) { 272 EnableAndDisableRecordingWithEmptyFileAndNullCallback) {
271 Navigate(shell()); 273 Navigate(shell());
272 274
273 TracingController* controller = TracingController::GetInstance(); 275 TracingController* controller = TracingController::GetInstance();
274 EXPECT_TRUE(controller->EnableRecording( 276 EXPECT_TRUE(controller->EnableRecording(
275 "", TracingController::DEFAULT_OPTIONS, 277 "", TraceOptions(), TracingController::EnableRecordingDoneCallback()));
276 TracingController::EnableRecordingDoneCallback()));
277 EXPECT_TRUE(controller->DisableRecording( 278 EXPECT_TRUE(controller->DisableRecording(
278 base::FilePath(), TracingController::TracingFileResultCallback())); 279 base::FilePath(), TracingController::TracingFileResultCallback()));
279 base::RunLoop().RunUntilIdle(); 280 base::RunLoop().RunUntilIdle();
280 } 281 }
281 282
282 IN_PROC_BROWSER_TEST_F(TracingControllerTest, 283 IN_PROC_BROWSER_TEST_F(TracingControllerTest,
283 EnableCaptureAndDisableMonitoring) { 284 EnableCaptureAndDisableMonitoring) {
284 TestEnableCaptureAndDisableMonitoring(base::FilePath()); 285 TestEnableCaptureAndDisableMonitoring(base::FilePath());
285 } 286 }
286 287
287 IN_PROC_BROWSER_TEST_F(TracingControllerTest, 288 IN_PROC_BROWSER_TEST_F(TracingControllerTest,
288 EnableCaptureAndDisableMonitoringWithFilePath) { 289 EnableCaptureAndDisableMonitoringWithFilePath) {
289 base::FilePath file_path; 290 base::FilePath file_path;
290 base::CreateTemporaryFile(&file_path); 291 base::CreateTemporaryFile(&file_path);
291 TestEnableCaptureAndDisableMonitoring(file_path); 292 TestEnableCaptureAndDisableMonitoring(file_path);
292 EXPECT_EQ(file_path.value(), last_actual_monitoring_file_path().value()); 293 EXPECT_EQ(file_path.value(), last_actual_monitoring_file_path().value());
293 } 294 }
294 295
295 IN_PROC_BROWSER_TEST_F( 296 IN_PROC_BROWSER_TEST_F(
296 TracingControllerTest, 297 TracingControllerTest,
297 EnableCaptureAndDisableMonitoringWithEmptyFileAndNullCallback) { 298 EnableCaptureAndDisableMonitoringWithEmptyFileAndNullCallback) {
298 Navigate(shell()); 299 Navigate(shell());
299 300
300 TracingController* controller = TracingController::GetInstance(); 301 TracingController* controller = TracingController::GetInstance();
301 EXPECT_TRUE(controller->EnableMonitoring( 302 EXPECT_TRUE(controller->EnableMonitoring(
302 "*", TracingController::ENABLE_SAMPLING, 303 "*",
304 TraceOptions(TraceOptions::RECORD_UNTIL_FULL).EnableSampling(true),
303 TracingController::EnableMonitoringDoneCallback())); 305 TracingController::EnableMonitoringDoneCallback()));
304 controller->CaptureMonitoringSnapshot( 306 controller->CaptureMonitoringSnapshot(
305 base::FilePath(), TracingController::TracingFileResultCallback()); 307 base::FilePath(), TracingController::TracingFileResultCallback());
306 base::RunLoop().RunUntilIdle(); 308 base::RunLoop().RunUntilIdle();
307 EXPECT_TRUE(controller->DisableMonitoring( 309 EXPECT_TRUE(controller->DisableMonitoring(
308 TracingController::DisableMonitoringDoneCallback())); 310 TracingController::DisableMonitoringDoneCallback()));
309 base::RunLoop().RunUntilIdle(); 311 base::RunLoop().RunUntilIdle();
310 } 312 }
311 313
312 } // namespace content 314 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698