OLD | NEW |
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 Loading... |
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(), false, 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; |
| 156 bool enable_systrace; |
154 controller->GetMonitoringStatus(&is_monitoring, | 157 controller->GetMonitoringStatus(&is_monitoring, |
155 &category_filter, | 158 &category_filter, |
156 &options); | 159 &options, |
| 160 &enable_systrace); |
157 EXPECT_FALSE(is_monitoring); | 161 EXPECT_FALSE(is_monitoring); |
158 EXPECT_EQ("-*Debug,-*Test", category_filter); | 162 EXPECT_EQ("-*Debug,-*Test", category_filter); |
159 EXPECT_FALSE(options & TracingController::ENABLE_SYSTRACE); | 163 EXPECT_FALSE(enable_systrace); |
160 EXPECT_FALSE(options & TracingController::RECORD_CONTINUOUSLY); | 164 EXPECT_FALSE(options.record_mode == TraceOptions::RECORD_CONTINUOUSLY); |
161 EXPECT_FALSE(options & TracingController::ENABLE_SAMPLING); | 165 EXPECT_FALSE(options.enable_sampling); |
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 "*", TraceOptions(TraceOptions::RECORD_UNTIL_FULL, true), callback); |
172 ASSERT_TRUE(result); | 176 ASSERT_TRUE(result); |
173 run_loop.Run(); | 177 run_loop.Run(); |
174 EXPECT_EQ(enable_monitoring_done_callback_count(), 1); | 178 EXPECT_EQ(enable_monitoring_done_callback_count(), 1); |
175 } | 179 } |
176 | 180 |
177 { | 181 { |
178 bool is_monitoring; | 182 bool is_monitoring; |
179 std::string category_filter; | 183 std::string category_filter; |
180 TracingController::Options options; | 184 TraceOptions options; |
| 185 bool enable_systrace; |
181 controller->GetMonitoringStatus(&is_monitoring, | 186 controller->GetMonitoringStatus(&is_monitoring, |
182 &category_filter, | 187 &category_filter, |
183 &options); | 188 &options, |
| 189 &enable_systrace); |
184 EXPECT_TRUE(is_monitoring); | 190 EXPECT_TRUE(is_monitoring); |
185 EXPECT_EQ("*", category_filter); | 191 EXPECT_EQ("*", category_filter); |
186 EXPECT_FALSE(options & TracingController::ENABLE_SYSTRACE); | 192 EXPECT_FALSE(enable_systrace); |
187 EXPECT_FALSE(options & TracingController::RECORD_CONTINUOUSLY); | 193 EXPECT_FALSE(options.record_mode == TraceOptions::RECORD_CONTINUOUSLY); |
188 EXPECT_TRUE(options & TracingController::ENABLE_SAMPLING); | 194 EXPECT_TRUE(options.enable_sampling); |
189 } | 195 } |
190 | 196 |
191 { | 197 { |
192 base::RunLoop run_loop; | 198 base::RunLoop run_loop; |
193 TracingController::TracingFileResultCallback callback = | 199 TracingController::TracingFileResultCallback callback = |
194 base::Bind(&TracingControllerTest:: | 200 base::Bind(&TracingControllerTest:: |
195 CaptureMonitoringSnapshotDoneCallbackTest, | 201 CaptureMonitoringSnapshotDoneCallbackTest, |
196 base::Unretained(this), | 202 base::Unretained(this), |
197 run_loop.QuitClosure()); | 203 run_loop.QuitClosure()); |
198 ASSERT_TRUE(controller->CaptureMonitoringSnapshot(result_file_path, | 204 ASSERT_TRUE(controller->CaptureMonitoringSnapshot(result_file_path, |
(...skipping 10 matching lines...) Expand all Loading... |
209 run_loop.QuitClosure()); | 215 run_loop.QuitClosure()); |
210 bool result = controller->DisableMonitoring(callback); | 216 bool result = controller->DisableMonitoring(callback); |
211 ASSERT_TRUE(result); | 217 ASSERT_TRUE(result); |
212 run_loop.Run(); | 218 run_loop.Run(); |
213 EXPECT_EQ(disable_monitoring_done_callback_count(), 1); | 219 EXPECT_EQ(disable_monitoring_done_callback_count(), 1); |
214 } | 220 } |
215 | 221 |
216 { | 222 { |
217 bool is_monitoring; | 223 bool is_monitoring; |
218 std::string category_filter; | 224 std::string category_filter; |
219 TracingController::Options options; | 225 TraceOptions options; |
| 226 bool enable_systrace; |
220 controller->GetMonitoringStatus(&is_monitoring, | 227 controller->GetMonitoringStatus(&is_monitoring, |
221 &category_filter, | 228 &category_filter, |
222 &options); | 229 &options, |
| 230 &enable_systrace); |
223 EXPECT_FALSE(is_monitoring); | 231 EXPECT_FALSE(is_monitoring); |
224 EXPECT_EQ("", category_filter); | 232 EXPECT_EQ("", category_filter); |
225 EXPECT_FALSE(options & TracingController::ENABLE_SYSTRACE); | 233 EXPECT_FALSE(enable_systrace); |
226 EXPECT_FALSE(options & TracingController::RECORD_CONTINUOUSLY); | 234 EXPECT_FALSE(options.record_mode == TraceOptions::RECORD_CONTINUOUSLY); |
227 EXPECT_FALSE(options & TracingController::ENABLE_SAMPLING); | 235 EXPECT_FALSE(options.enable_sampling); |
228 } | 236 } |
229 } | 237 } |
230 | 238 |
231 private: | 239 private: |
232 int get_categories_done_callback_count_; | 240 int get_categories_done_callback_count_; |
233 int enable_recording_done_callback_count_; | 241 int enable_recording_done_callback_count_; |
234 int disable_recording_done_callback_count_; | 242 int disable_recording_done_callback_count_; |
235 int enable_monitoring_done_callback_count_; | 243 int enable_monitoring_done_callback_count_; |
236 int disable_monitoring_done_callback_count_; | 244 int disable_monitoring_done_callback_count_; |
237 int capture_monitoring_snapshot_done_callback_count_; | 245 int capture_monitoring_snapshot_done_callback_count_; |
(...skipping 27 matching lines...) Expand all Loading... |
265 TestEnableAndDisableRecording(file_path); | 273 TestEnableAndDisableRecording(file_path); |
266 EXPECT_EQ(file_path.value(), last_actual_recording_file_path().value()); | 274 EXPECT_EQ(file_path.value(), last_actual_recording_file_path().value()); |
267 } | 275 } |
268 | 276 |
269 IN_PROC_BROWSER_TEST_F(TracingControllerTest, | 277 IN_PROC_BROWSER_TEST_F(TracingControllerTest, |
270 EnableAndDisableRecordingWithEmptyFileAndNullCallback) { | 278 EnableAndDisableRecordingWithEmptyFileAndNullCallback) { |
271 Navigate(shell()); | 279 Navigate(shell()); |
272 | 280 |
273 TracingController* controller = TracingController::GetInstance(); | 281 TracingController* controller = TracingController::GetInstance(); |
274 EXPECT_TRUE(controller->EnableRecording( | 282 EXPECT_TRUE(controller->EnableRecording( |
275 "", TracingController::DEFAULT_OPTIONS, | 283 "", |
| 284 TraceOptions(), |
| 285 false, |
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(); |
301 EXPECT_TRUE(controller->EnableMonitoring( | 311 EXPECT_TRUE(controller->EnableMonitoring( |
302 "*", TracingController::ENABLE_SAMPLING, | 312 "*", TraceOptions(TraceOptions::RECORD_UNTIL_FULL, true), |
303 TracingController::EnableMonitoringDoneCallback())); | 313 TracingController::EnableMonitoringDoneCallback())); |
304 controller->CaptureMonitoringSnapshot( | 314 controller->CaptureMonitoringSnapshot( |
305 base::FilePath(), TracingController::TracingFileResultCallback()); | 315 base::FilePath(), TracingController::TracingFileResultCallback()); |
306 base::RunLoop().RunUntilIdle(); | 316 base::RunLoop().RunUntilIdle(); |
307 EXPECT_TRUE(controller->DisableMonitoring( | 317 EXPECT_TRUE(controller->DisableMonitoring( |
308 TracingController::DisableMonitoringDoneCallback())); | 318 TracingController::DisableMonitoringDoneCallback())); |
309 base::RunLoop().RunUntilIdle(); | 319 base::RunLoop().RunUntilIdle(); |
310 } | 320 } |
311 | 321 |
312 } // namespace content | 322 } // namespace content |
OLD | NEW |