| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" |
| 6 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 7 #include "base/strings/pattern.h" | 8 #include "base/strings/pattern.h" |
| 8 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 9 #include "content/browser/tracing/background_tracing_manager_impl.h" | 10 #include "content/browser/tracing/background_tracing_manager_impl.h" |
| 10 #include "content/browser/tracing/background_tracing_rule.h" | 11 #include "content/browser/tracing/background_tracing_rule.h" |
| 12 #include "content/public/common/content_switches.h" |
| 11 #include "content/public/test/content_browser_test.h" | 13 #include "content/public/test/content_browser_test.h" |
| 12 #include "content/public/test/content_browser_test_utils.h" | 14 #include "content/public/test/content_browser_test_utils.h" |
| 13 #include "content/public/test/test_utils.h" | 15 #include "content/public/test/test_utils.h" |
| 14 #include "third_party/zlib/zlib.h" | 16 #include "third_party/zlib/zlib.h" |
| 15 | 17 |
| 16 namespace content { | 18 namespace content { |
| 17 | 19 |
| 18 class BackgroundTracingManagerBrowserTest : public ContentBrowserTest { | 20 class BackgroundTracingManagerBrowserTest : public ContentBrowserTest { |
| 19 public: | 21 public: |
| 20 BackgroundTracingManagerBrowserTest() {} | 22 BackgroundTracingManagerBrowserTest() {} |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( | 410 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( |
| 409 handle2, | 411 handle2, |
| 410 base::Bind(&StartedFinalizingCallback, base::Closure(), false)); | 412 base::Bind(&StartedFinalizingCallback, base::Closure(), false)); |
| 411 | 413 |
| 412 run_loop.Run(); | 414 run_loop.Run(); |
| 413 | 415 |
| 414 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1); | 416 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1); |
| 415 } | 417 } |
| 416 } | 418 } |
| 417 | 419 |
| 420 // This tests that toggling Blink scenarios in the config alters the |
| 421 // command-line. |
| 422 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest, |
| 423 ToggleBlinkScenarios) { |
| 424 { |
| 425 SetupBackgroundTracingManager(); |
| 426 |
| 427 base::RunLoop run_loop; |
| 428 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper( |
| 429 run_loop.QuitClosure()); |
| 430 |
| 431 base::DictionaryValue dict; |
| 432 dict.SetString("mode", "PREEMPTIVE_TRACING_MODE"); |
| 433 dict.SetString("category", "BENCHMARK"); |
| 434 |
| 435 scoped_ptr<base::ListValue> rules_list(new base::ListValue()); |
| 436 { |
| 437 scoped_ptr<base::DictionaryValue> rules_dict(new base::DictionaryValue()); |
| 438 rules_dict->SetString("rule", "MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED"); |
| 439 rules_dict->SetString("trigger_name", "test2"); |
| 440 rules_list->Append(rules_dict.Pass()); |
| 441 } |
| 442 |
| 443 dict.Set("configs", rules_list.Pass()); |
| 444 dict.SetString("enable_blink_features", "FasterWeb1,FasterWeb2"); |
| 445 dict.SetString("disable_blink_features", "SlowerWeb1,SlowerWeb2"); |
| 446 scoped_ptr<BackgroundTracingConfig> config( |
| 447 BackgroundTracingConfigImpl::FromDict(&dict)); |
| 448 EXPECT_TRUE(config); |
| 449 |
| 450 bool scenario_activated = |
| 451 BackgroundTracingManager::GetInstance()->SetActiveScenario( |
| 452 config.Pass(), upload_config_wrapper.get_receive_callback(), |
| 453 BackgroundTracingManager::NO_DATA_FILTERING); |
| 454 |
| 455 EXPECT_TRUE(scenario_activated); |
| 456 |
| 457 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 458 EXPECT_TRUE(command_line); |
| 459 |
| 460 EXPECT_EQ(command_line->GetSwitchValueASCII(switches::kEnableBlinkFeatures), |
| 461 "FasterWeb1,FasterWeb2"); |
| 462 EXPECT_EQ( |
| 463 command_line->GetSwitchValueASCII(switches::kDisableBlinkFeatures), |
| 464 "SlowerWeb1,SlowerWeb2"); |
| 465 } |
| 466 } |
| 467 |
| 468 // This tests that toggling Blink scenarios in a scenario won't activate |
| 469 // if there's already Blink features toggled by something else (about://flags) |
| 470 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest, |
| 471 ToggleBlinkScenariosNotOverridingSwitches) { |
| 472 SetupBackgroundTracingManager(); |
| 473 |
| 474 base::RunLoop run_loop; |
| 475 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper( |
| 476 run_loop.QuitClosure()); |
| 477 |
| 478 base::DictionaryValue dict; |
| 479 dict.SetString("mode", "PREEMPTIVE_TRACING_MODE"); |
| 480 dict.SetString("category", "BENCHMARK"); |
| 481 |
| 482 scoped_ptr<base::ListValue> rules_list(new base::ListValue()); |
| 483 { |
| 484 scoped_ptr<base::DictionaryValue> rules_dict(new base::DictionaryValue()); |
| 485 rules_dict->SetString("rule", "MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED"); |
| 486 rules_dict->SetString("trigger_name", "test2"); |
| 487 rules_list->Append(rules_dict.Pass()); |
| 488 } |
| 489 |
| 490 dict.Set("configs", rules_list.Pass()); |
| 491 dict.SetString("enable_blink_features", "FasterWeb1,FasterWeb2"); |
| 492 dict.SetString("disable_blink_features", "SlowerWeb1,SlowerWeb2"); |
| 493 scoped_ptr<BackgroundTracingConfig> config( |
| 494 BackgroundTracingConfigImpl::FromDict(&dict)); |
| 495 EXPECT_TRUE(config); |
| 496 |
| 497 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 498 switches::kEnableBlinkFeatures, "FooFeature"); |
| 499 |
| 500 bool scenario_activated = |
| 501 BackgroundTracingManager::GetInstance()->SetActiveScenario( |
| 502 config.Pass(), upload_config_wrapper.get_receive_callback(), |
| 503 BackgroundTracingManager::NO_DATA_FILTERING); |
| 504 |
| 505 EXPECT_FALSE(scenario_activated); |
| 506 } |
| 507 |
| 418 // This tests that delayed histogram triggers triggers work as expected | 508 // This tests that delayed histogram triggers triggers work as expected |
| 419 // with preemptive scenarios. | 509 // with preemptive scenarios. |
| 420 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest, | 510 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest, |
| 421 CallPreemptiveTriggerWithDelay) { | 511 CallPreemptiveTriggerWithDelay) { |
| 422 { | 512 { |
| 423 SetupBackgroundTracingManager(); | 513 SetupBackgroundTracingManager(); |
| 424 | 514 |
| 425 base::RunLoop run_loop; | 515 base::RunLoop run_loop; |
| 426 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper( | 516 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper( |
| 427 run_loop.QuitClosure()); | 517 run_loop.QuitClosure()); |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( | 998 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( |
| 909 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), false)); | 999 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), false)); |
| 910 | 1000 |
| 911 run_loop.Run(); | 1001 run_loop.Run(); |
| 912 | 1002 |
| 913 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1); | 1003 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1); |
| 914 } | 1004 } |
| 915 } | 1005 } |
| 916 | 1006 |
| 917 } // namespace content | 1007 } // namespace content |
| OLD | NEW |