| 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" |  | 
| 7 #include "base/metrics/histogram_macros.h" | 6 #include "base/metrics/histogram_macros.h" | 
| 8 #include "base/strings/pattern.h" | 7 #include "base/strings/pattern.h" | 
| 9 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" | 
| 10 #include "content/browser/tracing/background_tracing_manager_impl.h" | 9 #include "content/browser/tracing/background_tracing_manager_impl.h" | 
| 11 #include "content/browser/tracing/background_tracing_rule.h" | 10 #include "content/browser/tracing/background_tracing_rule.h" | 
| 12 #include "content/public/common/content_switches.h" |  | 
| 13 #include "content/public/test/content_browser_test.h" | 11 #include "content/public/test/content_browser_test.h" | 
| 14 #include "content/public/test/content_browser_test_utils.h" | 12 #include "content/public/test/content_browser_test_utils.h" | 
| 15 #include "content/public/test/test_utils.h" | 13 #include "content/public/test/test_utils.h" | 
| 16 #include "third_party/zlib/zlib.h" | 14 #include "third_party/zlib/zlib.h" | 
| 17 | 15 | 
| 18 namespace content { | 16 namespace content { | 
| 19 | 17 | 
| 20 class BackgroundTracingManagerBrowserTest : public ContentBrowserTest { | 18 class BackgroundTracingManagerBrowserTest : public ContentBrowserTest { | 
| 21  public: | 19  public: | 
| 22   BackgroundTracingManagerBrowserTest() {} | 20   BackgroundTracingManagerBrowserTest() {} | 
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 410     BackgroundTracingManager::GetInstance()->TriggerNamedEvent( | 408     BackgroundTracingManager::GetInstance()->TriggerNamedEvent( | 
| 411         handle2, | 409         handle2, | 
| 412         base::Bind(&StartedFinalizingCallback, base::Closure(), false)); | 410         base::Bind(&StartedFinalizingCallback, base::Closure(), false)); | 
| 413 | 411 | 
| 414     run_loop.Run(); | 412     run_loop.Run(); | 
| 415 | 413 | 
| 416     EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1); | 414     EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1); | 
| 417   } | 415   } | 
| 418 } | 416 } | 
| 419 | 417 | 
| 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 |  | 
| 508 // This tests that delayed histogram triggers triggers work as expected | 418 // This tests that delayed histogram triggers triggers work as expected | 
| 509 // with preemptive scenarios. | 419 // with preemptive scenarios. | 
| 510 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest, | 420 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest, | 
| 511                        CallPreemptiveTriggerWithDelay) { | 421                        CallPreemptiveTriggerWithDelay) { | 
| 512   { | 422   { | 
| 513     SetupBackgroundTracingManager(); | 423     SetupBackgroundTracingManager(); | 
| 514 | 424 | 
| 515     base::RunLoop run_loop; | 425     base::RunLoop run_loop; | 
| 516     BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper( | 426     BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper( | 
| 517         run_loop.QuitClosure()); | 427         run_loop.QuitClosure()); | 
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 998     BackgroundTracingManager::GetInstance()->TriggerNamedEvent( | 908     BackgroundTracingManager::GetInstance()->TriggerNamedEvent( | 
| 999         handle, base::Bind(&StartedFinalizingCallback, base::Closure(), false)); | 909         handle, base::Bind(&StartedFinalizingCallback, base::Closure(), false)); | 
| 1000 | 910 | 
| 1001     run_loop.Run(); | 911     run_loop.Run(); | 
| 1002 | 912 | 
| 1003     EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1); | 913     EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1); | 
| 1004   } | 914   } | 
| 1005 } | 915 } | 
| 1006 | 916 | 
| 1007 }  // namespace content | 917 }  // namespace content | 
| OLD | NEW | 
|---|