1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "base/metrics/histogram_macros.h"
7 #include "base/strings/pattern.h"
8 #include "base/trace_event/trace_event.h"
9 #include "content/public/browser/background_tracing_manager.h"
10 #include "content/public/browser/background_tracing_preemptive_config.h"
11 #include "content/public/browser/background_tracing_reactive_config.h"
12 #include "content/public/test/content_browser_test.h"
13 #include "content/public/test/content_browser_test_utils.h"
14 #include "content/public/test/test_utils.h"
15 #include "third_party/zlib/zlib.h"
19 class BackgroundTracingManagerBrowserTest
: public ContentBrowserTest
{
21 BackgroundTracingManagerBrowserTest() {}
24 DISALLOW_COPY_AND_ASSIGN(BackgroundTracingManagerBrowserTest
);
27 class BackgroundTracingManagerUploadConfigWrapper
{
29 BackgroundTracingManagerUploadConfigWrapper(const base::Closure
& callback
)
30 : callback_(callback
), receive_count_(0) {
32 base::Bind(&BackgroundTracingManagerUploadConfigWrapper::Upload
,
33 base::Unretained(this));
36 void Upload(const scoped_refptr
<base::RefCountedString
>& file_contents
,
37 scoped_ptr
<base::DictionaryValue
> metadata
,
38 base::Callback
<void()> done_callback
) {
40 EXPECT_TRUE(file_contents
);
42 size_t compressed_length
= file_contents
->data().length();
43 const size_t kOutputBufferLength
= 10 * 1024 * 1024;
44 std::vector
<char> output_str(kOutputBufferLength
);
46 z_stream stream
= {0};
47 stream
.avail_in
= compressed_length
;
48 stream
.avail_out
= kOutputBufferLength
;
49 stream
.next_in
= (Bytef
*)&file_contents
->data()[0];
50 stream
.next_out
= (Bytef
*)vector_as_array(&output_str
);
52 // 16 + MAX_WBITS means only decoding gzip encoded streams, and using
53 // the biggest window size, according to zlib.h
54 int result
= inflateInit2(&stream
, 16 + MAX_WBITS
);
55 EXPECT_EQ(Z_OK
, result
);
56 result
= inflate(&stream
, Z_FINISH
);
57 int bytes_written
= kOutputBufferLength
- stream
.avail_out
;
60 EXPECT_EQ(Z_STREAM_END
, result
);
62 last_file_contents_
.assign(vector_as_array(&output_str
), bytes_written
);
63 BrowserThread::PostTask(BrowserThread::UI
, FROM_HERE
,
64 base::Bind(done_callback
));
65 BrowserThread::PostTask(BrowserThread::UI
, FROM_HERE
,
66 base::Bind(callback_
));
69 bool TraceHasMatchingString(const char* str
) {
70 return last_file_contents_
.find(str
) != std::string::npos
;
73 int get_receive_count() const { return receive_count_
; }
75 const BackgroundTracingManager::ReceiveCallback
& get_receive_callback()
77 return receive_callback_
;
81 BackgroundTracingManager::ReceiveCallback receive_callback_
;
82 base::Closure callback_
;
84 std::string last_file_contents_
;
87 void StartedFinalizingCallback(base::Closure callback
,
90 EXPECT_EQ(expected
, value
);
91 if (!callback
.is_null())
95 scoped_ptr
<BackgroundTracingPreemptiveConfig
> CreatePreemptiveConfig() {
96 scoped_ptr
<BackgroundTracingPreemptiveConfig
> config(
97 new BackgroundTracingPreemptiveConfig());
99 BackgroundTracingPreemptiveConfig::MonitoringRule rule
;
101 BackgroundTracingPreemptiveConfig::MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED
;
102 rule
.named_trigger_info
.trigger_name
= "preemptive_test";
104 config
->configs
.push_back(rule
);
106 return config
.Pass();
109 scoped_ptr
<BackgroundTracingReactiveConfig
> CreateReactiveConfig() {
110 scoped_ptr
<BackgroundTracingReactiveConfig
> config(
111 new BackgroundTracingReactiveConfig());
113 BackgroundTracingReactiveConfig::TracingRule rule
;
115 BackgroundTracingReactiveConfig::TRACE_FOR_10S_OR_TRIGGER_OR_FULL
;
116 rule
.trigger_name
= "reactive_test";
117 rule
.category_preset
=
118 BackgroundTracingConfig::CategoryPreset::BENCHMARK_DEEP
;
120 config
->configs
.push_back(rule
);
122 return config
.Pass();
125 void SetupBackgroundTracingManager() {
126 content::BackgroundTracingManager::GetInstance()
127 ->InvalidateTriggerHandlesForTesting();
130 void DisableScenarioWhenIdle() {
131 BackgroundTracingManager::GetInstance()->SetActiveScenario(
132 NULL
, BackgroundTracingManager::ReceiveCallback(),
133 BackgroundTracingManager::NO_DATA_FILTERING
);
136 // This tests that the endpoint receives the final trace data.
137 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest
,
138 ReceiveTraceFinalContentsOnTrigger
) {
140 SetupBackgroundTracingManager();
142 base::RunLoop run_loop
;
143 BackgroundTracingManagerUploadConfigWrapper
upload_config_wrapper(
144 run_loop
.QuitClosure());
146 scoped_ptr
<BackgroundTracingPreemptiveConfig
> config
=
147 CreatePreemptiveConfig();
149 BackgroundTracingManager::TriggerHandle handle
=
150 BackgroundTracingManager::
151 GetInstance()->RegisterTriggerType("preemptive_test");
153 BackgroundTracingManager::GetInstance()->SetActiveScenario(
154 config
.Pass(), upload_config_wrapper
.get_receive_callback(),
155 BackgroundTracingManager::NO_DATA_FILTERING
);
157 BackgroundTracingManager::GetInstance()->WhenIdle(
158 base::Bind(&DisableScenarioWhenIdle
));
160 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
161 handle
, base::Bind(&StartedFinalizingCallback
, base::Closure(), true));
165 EXPECT_TRUE(upload_config_wrapper
.get_receive_count() == 1);
169 // This tests triggering more than once still only gathers once.
170 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest
,
171 CallTriggersMoreThanOnceOnlyGatherOnce
) {
173 SetupBackgroundTracingManager();
175 base::RunLoop run_loop
;
176 BackgroundTracingManagerUploadConfigWrapper
upload_config_wrapper(
177 run_loop
.QuitClosure());
179 scoped_ptr
<BackgroundTracingPreemptiveConfig
> config
=
180 CreatePreemptiveConfig();
182 content::BackgroundTracingManager::TriggerHandle handle
=
183 content::BackgroundTracingManager::GetInstance()->RegisterTriggerType(
186 BackgroundTracingManager::GetInstance()->SetActiveScenario(
187 config
.Pass(), upload_config_wrapper
.get_receive_callback(),
188 BackgroundTracingManager::NO_DATA_FILTERING
);
190 BackgroundTracingManager::GetInstance()->WhenIdle(
191 base::Bind(&DisableScenarioWhenIdle
));
193 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
194 handle
, base::Bind(&StartedFinalizingCallback
, base::Closure(), true));
195 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
196 handle
, base::Bind(&StartedFinalizingCallback
, base::Closure(), false));
200 EXPECT_TRUE(upload_config_wrapper
.get_receive_count() == 1);
206 bool IsTraceEventArgsWhitelisted(const char* category_group_name
,
207 const char* event_name
) {
208 if (base::MatchPattern(category_group_name
, "benchmark") &&
209 base::MatchPattern(event_name
, "whitelisted")) {
218 // This tests that non-whitelisted args get stripped if required.
219 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest
,
220 NoWhitelistedArgsStripped
) {
221 SetupBackgroundTracingManager();
223 base::trace_event::TraceLog::GetInstance()->SetArgumentFilterPredicate(
224 base::Bind(&IsTraceEventArgsWhitelisted
));
226 base::RunLoop wait_for_upload
;
227 BackgroundTracingManagerUploadConfigWrapper
upload_config_wrapper(
228 wait_for_upload
.QuitClosure());
230 scoped_ptr
<BackgroundTracingPreemptiveConfig
> config
=
231 CreatePreemptiveConfig();
233 content::BackgroundTracingManager::TriggerHandle handle
=
234 content::BackgroundTracingManager::GetInstance()->RegisterTriggerType(
237 base::RunLoop wait_for_activated
;
238 BackgroundTracingManager::GetInstance()->SetTracingEnabledCallbackForTesting(
239 wait_for_activated
.QuitClosure());
240 EXPECT_TRUE(BackgroundTracingManager::GetInstance()->SetActiveScenario(
241 config
.Pass(), upload_config_wrapper
.get_receive_callback(),
242 BackgroundTracingManager::ANONYMIZE_DATA
));
244 wait_for_activated
.Run();
246 TRACE_EVENT1("benchmark", "whitelisted", "find_this", 1);
247 TRACE_EVENT1("benchmark", "not_whitelisted", "this_not_found", 1);
249 BackgroundTracingManager::GetInstance()->WhenIdle(
250 base::Bind(&DisableScenarioWhenIdle
));
252 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
253 handle
, base::Bind(&StartedFinalizingCallback
, base::Closure(), true));
255 wait_for_upload
.Run();
257 EXPECT_TRUE(upload_config_wrapper
.get_receive_count() == 1);
258 EXPECT_TRUE(upload_config_wrapper
.TraceHasMatchingString("{"));
259 EXPECT_TRUE(upload_config_wrapper
.TraceHasMatchingString("find_this"));
260 EXPECT_TRUE(!upload_config_wrapper
.TraceHasMatchingString("this_not_found"));
263 // This tests subprocesses (like a navigating renderer) which gets told to
264 // provide a argument-filtered trace and has no predicate in place to do the
265 // filtering (in this case, only the browser process gets it set), will crash
266 // rather than return potential PII.
267 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest
,
268 CrashWhenSubprocessWithoutArgumentFilter
) {
269 SetupBackgroundTracingManager();
271 base::trace_event::TraceLog::GetInstance()->SetArgumentFilterPredicate(
272 base::Bind(&IsTraceEventArgsWhitelisted
));
274 base::RunLoop wait_for_upload
;
275 BackgroundTracingManagerUploadConfigWrapper
upload_config_wrapper(
276 wait_for_upload
.QuitClosure());
278 scoped_ptr
<BackgroundTracingPreemptiveConfig
> config
=
279 CreatePreemptiveConfig();
281 content::BackgroundTracingManager::TriggerHandle handle
=
282 content::BackgroundTracingManager::GetInstance()->RegisterTriggerType(
285 base::RunLoop wait_for_activated
;
286 BackgroundTracingManager::GetInstance()->SetTracingEnabledCallbackForTesting(
287 wait_for_activated
.QuitClosure());
288 EXPECT_TRUE(BackgroundTracingManager::GetInstance()->SetActiveScenario(
289 config
.Pass(), upload_config_wrapper
.get_receive_callback(),
290 BackgroundTracingManager::ANONYMIZE_DATA
));
292 wait_for_activated
.Run();
294 NavigateToURL(shell(), GetTestUrl("", "about:blank"));
296 BackgroundTracingManager::GetInstance()->WhenIdle(
297 base::Bind(&DisableScenarioWhenIdle
));
299 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
300 handle
, base::Bind(&StartedFinalizingCallback
, base::Closure(), true));
302 wait_for_upload
.Run();
304 EXPECT_TRUE(upload_config_wrapper
.get_receive_count() == 1);
305 // We should *not* receive anything at all from the renderer,
306 // the process should've crashed rather than letting that happen.
307 EXPECT_TRUE(!upload_config_wrapper
.TraceHasMatchingString("CrRendererMain"));
310 // This tests multiple triggers still only gathers once.
311 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest
,
312 CallMultipleTriggersOnlyGatherOnce
) {
314 SetupBackgroundTracingManager();
316 base::RunLoop run_loop
;
317 BackgroundTracingManagerUploadConfigWrapper
upload_config_wrapper(
318 run_loop
.QuitClosure());
320 scoped_ptr
<BackgroundTracingPreemptiveConfig
> config
=
321 CreatePreemptiveConfig();
323 BackgroundTracingPreemptiveConfig::MonitoringRule rule
;
325 BackgroundTracingPreemptiveConfig::MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED
;
326 rule
.named_trigger_info
.trigger_name
= "test1";
327 config
->configs
.push_back(rule
);
329 rule
.named_trigger_info
.trigger_name
= "test2";
330 config
->configs
.push_back(rule
);
332 BackgroundTracingManager::TriggerHandle handle1
=
333 BackgroundTracingManager::GetInstance()->RegisterTriggerType("test1");
334 BackgroundTracingManager::TriggerHandle handle2
=
335 BackgroundTracingManager::GetInstance()->RegisterTriggerType("test2");
337 BackgroundTracingManager::GetInstance()->SetActiveScenario(
338 config
.Pass(), upload_config_wrapper
.get_receive_callback(),
339 BackgroundTracingManager::NO_DATA_FILTERING
);
341 BackgroundTracingManager::GetInstance()->WhenIdle(
342 base::Bind(&DisableScenarioWhenIdle
));
344 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
345 handle1
, base::Bind(&StartedFinalizingCallback
, base::Closure(), true));
346 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
348 base::Bind(&StartedFinalizingCallback
, base::Closure(), false));
352 EXPECT_TRUE(upload_config_wrapper
.get_receive_count() == 1);
356 // This tests that you can't trigger without a scenario set.
357 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest
,
358 CannotTriggerWithoutScenarioSet
) {
360 SetupBackgroundTracingManager();
362 base::RunLoop run_loop
;
363 BackgroundTracingManagerUploadConfigWrapper
upload_config_wrapper(
366 scoped_ptr
<BackgroundTracingConfig
> config
= CreatePreemptiveConfig();
368 content::BackgroundTracingManager::TriggerHandle handle
=
369 content::BackgroundTracingManager::GetInstance()->RegisterTriggerType(
372 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
374 base::Bind(&StartedFinalizingCallback
, run_loop
.QuitClosure(), false));
378 EXPECT_TRUE(upload_config_wrapper
.get_receive_count() == 0);
382 // This tests that no trace is triggered with a handle that isn't specified
384 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest
,
385 DoesNotTriggerWithWrongHandle
) {
387 SetupBackgroundTracingManager();
389 base::RunLoop run_loop
;
390 BackgroundTracingManagerUploadConfigWrapper
upload_config_wrapper(
393 scoped_ptr
<BackgroundTracingPreemptiveConfig
> config
=
394 CreatePreemptiveConfig();
396 content::BackgroundTracingManager::TriggerHandle handle
=
397 content::BackgroundTracingManager::GetInstance()->RegisterTriggerType(
400 BackgroundTracingManager::GetInstance()->SetActiveScenario(
401 config
.Pass(), upload_config_wrapper
.get_receive_callback(),
402 BackgroundTracingManager::NO_DATA_FILTERING
);
404 BackgroundTracingManager::GetInstance()->WhenIdle(
405 base::Bind(&DisableScenarioWhenIdle
));
407 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
409 base::Bind(&StartedFinalizingCallback
, run_loop
.QuitClosure(), false));
413 EXPECT_TRUE(upload_config_wrapper
.get_receive_count() == 0);
417 // This tests that no trace is triggered with an invalid handle.
418 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest
,
419 DoesNotTriggerWithInvalidHandle
) {
421 SetupBackgroundTracingManager();
423 base::RunLoop run_loop
;
424 BackgroundTracingManagerUploadConfigWrapper
upload_config_wrapper(
427 scoped_ptr
<BackgroundTracingPreemptiveConfig
> config
=
428 CreatePreemptiveConfig();
430 content::BackgroundTracingManager::TriggerHandle handle
=
431 content::BackgroundTracingManager::GetInstance()->RegisterTriggerType(
434 content::BackgroundTracingManager::GetInstance()
435 ->InvalidateTriggerHandlesForTesting();
437 BackgroundTracingManager::GetInstance()->SetActiveScenario(
438 config
.Pass(), upload_config_wrapper
.get_receive_callback(),
439 BackgroundTracingManager::NO_DATA_FILTERING
);
441 BackgroundTracingManager::GetInstance()->WhenIdle(
442 base::Bind(&DisableScenarioWhenIdle
));
444 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
446 base::Bind(&StartedFinalizingCallback
, run_loop
.QuitClosure(), false));
450 EXPECT_TRUE(upload_config_wrapper
.get_receive_count() == 0);
454 // This tests that histogram triggers for preemptive mode configs.
455 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest
,
456 ReceiveTraceSucceedsOnHigherHistogramSample
) {
458 SetupBackgroundTracingManager();
460 base::RunLoop run_loop
;
462 BackgroundTracingManagerUploadConfigWrapper
upload_config_wrapper(
463 run_loop
.QuitClosure());
465 scoped_ptr
<BackgroundTracingPreemptiveConfig
> config(
466 new content::BackgroundTracingPreemptiveConfig());
468 BackgroundTracingPreemptiveConfig::MonitoringRule rule
;
469 rule
.type
= BackgroundTracingPreemptiveConfig::
470 MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE
;
471 rule
.histogram_trigger_info
.histogram_name
= "fake";
472 rule
.histogram_trigger_info
.histogram_value
= 1;
473 config
->configs
.push_back(rule
);
475 BackgroundTracingManager::GetInstance()->SetActiveScenario(
476 config
.Pass(), upload_config_wrapper
.get_receive_callback(),
477 BackgroundTracingManager::NO_DATA_FILTERING
);
479 // Our reference value is "1", so a value of "2" should trigger a trace.
480 LOCAL_HISTOGRAM_COUNTS("fake", 2);
484 EXPECT_TRUE(upload_config_wrapper
.get_receive_count() == 1);
488 // This tests that histogram values < reference value don't trigger.
489 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest
,
490 ReceiveTraceFailsOnLowerHistogramSample
) {
492 SetupBackgroundTracingManager();
494 base::RunLoop run_loop
;
496 BackgroundTracingManagerUploadConfigWrapper
upload_config_wrapper(
497 run_loop
.QuitClosure());
499 scoped_ptr
<BackgroundTracingPreemptiveConfig
> config(
500 new content::BackgroundTracingPreemptiveConfig());
502 BackgroundTracingPreemptiveConfig::MonitoringRule rule
;
503 rule
.type
= BackgroundTracingPreemptiveConfig::
504 MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE
;
505 rule
.histogram_trigger_info
.histogram_name
= "fake";
506 rule
.histogram_trigger_info
.histogram_value
= 1;
507 config
->configs
.push_back(rule
);
509 BackgroundTracingManager::GetInstance()->SetActiveScenario(
510 config
.Pass(), upload_config_wrapper
.get_receive_callback(),
511 BackgroundTracingManager::NO_DATA_FILTERING
);
513 // This should fail to trigger a trace since the sample value < the
514 // the reference value above.
515 LOCAL_HISTOGRAM_COUNTS("fake", 0);
517 run_loop
.RunUntilIdle();
519 EXPECT_TRUE(upload_config_wrapper
.get_receive_count() == 0);
523 // This tests that invalid preemptive mode configs will fail.
524 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest
,
525 SetActiveScenarioFailsWithInvalidPreemptiveConfig
) {
527 SetupBackgroundTracingManager();
529 BackgroundTracingManagerUploadConfigWrapper
upload_config_wrapper(
532 scoped_ptr
<BackgroundTracingPreemptiveConfig
> config(
533 new content::BackgroundTracingPreemptiveConfig());
535 BackgroundTracingPreemptiveConfig::MonitoringRule rule
;
536 rule
.type
= BackgroundTracingPreemptiveConfig::
537 MONITOR_AND_DUMP_WHEN_BROWSER_STARTUP_COMPLETE
;
538 config
->configs
.push_back(rule
);
540 bool result
= BackgroundTracingManager::GetInstance()->SetActiveScenario(
541 config
.Pass(), upload_config_wrapper
.get_receive_callback(),
542 BackgroundTracingManager::NO_DATA_FILTERING
);
544 EXPECT_FALSE(result
);
548 // This tests that reactive mode records and terminates with timeout.
549 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest
,
550 ReactiveTimeoutTermination
) {
552 SetupBackgroundTracingManager();
554 base::RunLoop run_loop
;
555 BackgroundTracingManagerUploadConfigWrapper
upload_config_wrapper(
556 run_loop
.QuitClosure());
558 scoped_ptr
<BackgroundTracingReactiveConfig
> config
=
559 CreateReactiveConfig();
561 BackgroundTracingManager::TriggerHandle handle
=
562 BackgroundTracingManager::
563 GetInstance()->RegisterTriggerType("reactive_test");
565 BackgroundTracingManager::GetInstance()->SetActiveScenario(
566 config
.Pass(), upload_config_wrapper
.get_receive_callback(),
567 BackgroundTracingManager::NO_DATA_FILTERING
);
569 BackgroundTracingManager::GetInstance()->WhenIdle(
570 base::Bind(&DisableScenarioWhenIdle
));
572 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
573 handle
, base::Bind(&StartedFinalizingCallback
, base::Closure(), true));
575 BackgroundTracingManager::GetInstance()->FireTimerForTesting();
579 EXPECT_TRUE(upload_config_wrapper
.get_receive_count() == 1);
583 // This tests that reactive mode records and terminates with a second trigger.
584 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest
,
585 ReactiveSecondTriggerTermination
) {
587 SetupBackgroundTracingManager();
589 base::RunLoop run_loop
;
590 BackgroundTracingManagerUploadConfigWrapper
upload_config_wrapper(
591 run_loop
.QuitClosure());
593 scoped_ptr
<BackgroundTracingReactiveConfig
> config
=
594 CreateReactiveConfig();
596 BackgroundTracingManager::TriggerHandle handle
=
597 BackgroundTracingManager::
598 GetInstance()->RegisterTriggerType("reactive_test");
600 BackgroundTracingManager::GetInstance()->SetActiveScenario(
601 config
.Pass(), upload_config_wrapper
.get_receive_callback(),
602 BackgroundTracingManager::NO_DATA_FILTERING
);
604 BackgroundTracingManager::GetInstance()->WhenIdle(
605 base::Bind(&DisableScenarioWhenIdle
));
607 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
608 handle
, base::Bind(&StartedFinalizingCallback
, base::Closure(), true));
609 // second trigger to terminate.
610 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
611 handle
, base::Bind(&StartedFinalizingCallback
, base::Closure(), true));
615 EXPECT_TRUE(upload_config_wrapper
.get_receive_count() == 1);
619 // This tests a third trigger in reactive more does not start another trace.
620 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest
,
621 ReactiveThirdTriggerTimeout
) {
623 SetupBackgroundTracingManager();
625 base::RunLoop run_loop
;
626 BackgroundTracingManagerUploadConfigWrapper
upload_config_wrapper(
627 run_loop
.QuitClosure());
629 scoped_ptr
<BackgroundTracingReactiveConfig
> config
=
630 CreateReactiveConfig();
632 BackgroundTracingManager::TriggerHandle handle
=
633 BackgroundTracingManager::
634 GetInstance()->RegisterTriggerType("reactive_test");
636 BackgroundTracingManager::GetInstance()->SetActiveScenario(
637 config
.Pass(), upload_config_wrapper
.get_receive_callback(),
638 BackgroundTracingManager::NO_DATA_FILTERING
);
640 BackgroundTracingManager::GetInstance()->WhenIdle(
641 base::Bind(&DisableScenarioWhenIdle
));
643 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
644 handle
, base::Bind(&StartedFinalizingCallback
, base::Closure(), true));
645 // second trigger to terminate.
646 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
647 handle
, base::Bind(&StartedFinalizingCallback
, base::Closure(), true));
648 // third trigger to trigger again, fails as it is still gathering.
649 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
650 handle
, base::Bind(&StartedFinalizingCallback
, base::Closure(), false));
654 EXPECT_TRUE(upload_config_wrapper
.get_receive_count() == 1);
658 } // namespace content