| 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 <memory> |
| 6 |
| 5 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 6 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "base/values.h" | 9 #include "base/values.h" |
| 9 #include "content/browser/tracing/background_tracing_config_impl.h" | 10 #include "content/browser/tracing/background_tracing_config_impl.h" |
| 10 #include "content/browser/tracing/background_tracing_rule.h" | 11 #include "content/browser/tracing/background_tracing_rule.h" |
| 11 #include "content/public/test/test_browser_thread.h" | 12 #include "content/public/test/test_browser_thread.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| 16 class BackgroundTracingConfigTest : public testing::Test { | 17 class BackgroundTracingConfigTest : public testing::Test { |
| 17 public: | 18 public: |
| 18 BackgroundTracingConfigTest() | 19 BackgroundTracingConfigTest() |
| 19 : ui_thread_(BrowserThread::UI, &message_loop_) {} | 20 : ui_thread_(BrowserThread::UI, &message_loop_) {} |
| 20 | 21 |
| 21 protected: | 22 protected: |
| 22 base::MessageLoop message_loop_; | 23 base::MessageLoop message_loop_; |
| 23 TestBrowserThread ui_thread_; | 24 TestBrowserThread ui_thread_; |
| 24 }; | 25 }; |
| 25 | 26 |
| 26 scoped_ptr<BackgroundTracingConfigImpl> ReadFromJSONString( | 27 std::unique_ptr<BackgroundTracingConfigImpl> ReadFromJSONString( |
| 27 const std::string& json_text) { | 28 const std::string& json_text) { |
| 28 scoped_ptr<base::Value> json_value(base::JSONReader::Read(json_text)); | 29 std::unique_ptr<base::Value> json_value(base::JSONReader::Read(json_text)); |
| 29 | 30 |
| 30 base::DictionaryValue* dict = NULL; | 31 base::DictionaryValue* dict = NULL; |
| 31 if (json_value) | 32 if (json_value) |
| 32 json_value->GetAsDictionary(&dict); | 33 json_value->GetAsDictionary(&dict); |
| 33 | 34 |
| 34 scoped_ptr<BackgroundTracingConfigImpl> config( | 35 std::unique_ptr<BackgroundTracingConfigImpl> config( |
| 35 static_cast<BackgroundTracingConfigImpl*>( | 36 static_cast<BackgroundTracingConfigImpl*>( |
| 36 BackgroundTracingConfig::FromDict(dict).release())); | 37 BackgroundTracingConfig::FromDict(dict).release())); |
| 37 return config; | 38 return config; |
| 38 } | 39 } |
| 39 | 40 |
| 40 std::string ConfigToString(const BackgroundTracingConfig* config) { | 41 std::string ConfigToString(const BackgroundTracingConfig* config) { |
| 41 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 42 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 42 | 43 |
| 43 config->IntoDict(dict.get()); | 44 config->IntoDict(dict.get()); |
| 44 | 45 |
| 45 std::string results; | 46 std::string results; |
| 46 if (base::JSONWriter::Write(*dict.get(), &results)) | 47 if (base::JSONWriter::Write(*dict.get(), &results)) |
| 47 return results; | 48 return results; |
| 48 return ""; | 49 return ""; |
| 49 } | 50 } |
| 50 | 51 |
| 51 std::string RuleToString(const BackgroundTracingRule* rule) { | 52 std::string RuleToString(const BackgroundTracingRule* rule) { |
| 52 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 53 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 53 | 54 |
| 54 rule->IntoDict(dict.get()); | 55 rule->IntoDict(dict.get()); |
| 55 | 56 |
| 56 std::string results; | 57 std::string results; |
| 57 if (base::JSONWriter::Write(*dict.get(), &results)) | 58 if (base::JSONWriter::Write(*dict.get(), &results)) |
| 58 return results; | 59 return results; |
| 59 return ""; | 60 return ""; |
| 60 } | 61 } |
| 61 | 62 |
| 62 TEST_F(BackgroundTracingConfigTest, ConfigFromInvalidString) { | 63 TEST_F(BackgroundTracingConfigTest, ConfigFromInvalidString) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 "\"TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL\", \"category\": " | 161 "\"TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL\", \"category\": " |
| 161 "\"benchmark\", \"trigger_name\": []}]}")); | 162 "\"benchmark\", \"trigger_name\": []}]}")); |
| 162 EXPECT_FALSE(ReadFromJSONString( | 163 EXPECT_FALSE(ReadFromJSONString( |
| 163 "{\"mode\":\"reactive\"," | 164 "{\"mode\":\"reactive\"," |
| 164 "\"configs\": [{\"rule\": " | 165 "\"configs\": [{\"rule\": " |
| 165 "\"TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL\", \"category\": " | 166 "\"TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL\", \"category\": " |
| 166 "\"benchmark\", \"trigger_name\": 0}]}")); | 167 "\"benchmark\", \"trigger_name\": 0}]}")); |
| 167 } | 168 } |
| 168 | 169 |
| 169 TEST_F(BackgroundTracingConfigTest, PreemptiveConfigFromValidString) { | 170 TEST_F(BackgroundTracingConfigTest, PreemptiveConfigFromValidString) { |
| 170 scoped_ptr<BackgroundTracingConfigImpl> config; | 171 std::unique_ptr<BackgroundTracingConfigImpl> config; |
| 171 | 172 |
| 172 config = ReadFromJSONString( | 173 config = ReadFromJSONString( |
| 173 "{\"mode\":\"PREEMPTIVE_TRACING_MODE\", \"category\": " | 174 "{\"mode\":\"PREEMPTIVE_TRACING_MODE\", \"category\": " |
| 174 "\"BENCHMARK\",\"configs\": [{\"rule\": " | 175 "\"BENCHMARK\",\"configs\": [{\"rule\": " |
| 175 "\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\", \"trigger_name\":\"foo\"}]}"); | 176 "\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\", \"trigger_name\":\"foo\"}]}"); |
| 176 EXPECT_TRUE(config); | 177 EXPECT_TRUE(config); |
| 177 EXPECT_EQ(config->tracing_mode(), BackgroundTracingConfig::PREEMPTIVE); | 178 EXPECT_EQ(config->tracing_mode(), BackgroundTracingConfig::PREEMPTIVE); |
| 178 EXPECT_EQ(config->category_preset(), BackgroundTracingConfigImpl::BENCHMARK); | 179 EXPECT_EQ(config->category_preset(), BackgroundTracingConfigImpl::BENCHMARK); |
| 179 EXPECT_EQ(config->rules().size(), 1u); | 180 EXPECT_EQ(config->rules().size(), 1u); |
| 180 EXPECT_EQ(RuleToString(config->rules()[0]), | 181 EXPECT_EQ(RuleToString(config->rules()[0]), |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 "\"foo1\"}],\"disable_blink_features\":\"SlowerWeb1,SlowerWeb2\"," | 264 "\"foo1\"}],\"disable_blink_features\":\"SlowerWeb1,SlowerWeb2\"," |
| 264 "\"enable_blink_features\":\"FasterWeb1,FasterWeb2\"," | 265 "\"enable_blink_features\":\"FasterWeb1,FasterWeb2\"," |
| 265 "\"mode\":\"PREEMPTIVE_TRACING_MODE\"," | 266 "\"mode\":\"PREEMPTIVE_TRACING_MODE\"," |
| 266 "\"scenario_name\":\"my_awesome_experiment\"}"); | 267 "\"scenario_name\":\"my_awesome_experiment\"}"); |
| 267 EXPECT_EQ(config->enable_blink_features(), "FasterWeb1,FasterWeb2"); | 268 EXPECT_EQ(config->enable_blink_features(), "FasterWeb1,FasterWeb2"); |
| 268 EXPECT_EQ(config->disable_blink_features(), "SlowerWeb1,SlowerWeb2"); | 269 EXPECT_EQ(config->disable_blink_features(), "SlowerWeb1,SlowerWeb2"); |
| 269 EXPECT_EQ(config->scenario_name(), "my_awesome_experiment"); | 270 EXPECT_EQ(config->scenario_name(), "my_awesome_experiment"); |
| 270 } | 271 } |
| 271 | 272 |
| 272 TEST_F(BackgroundTracingConfigTest, ValidPreemptiveCategoryToString) { | 273 TEST_F(BackgroundTracingConfigTest, ValidPreemptiveCategoryToString) { |
| 273 scoped_ptr<BackgroundTracingConfigImpl> config = ReadFromJSONString( | 274 std::unique_ptr<BackgroundTracingConfigImpl> config = ReadFromJSONString( |
| 274 "{\"mode\":\"PREEMPTIVE_TRACING_MODE\", \"category\": " | 275 "{\"mode\":\"PREEMPTIVE_TRACING_MODE\", \"category\": " |
| 275 "\"BENCHMARK\",\"configs\": [{\"rule\": " | 276 "\"BENCHMARK\",\"configs\": [{\"rule\": " |
| 276 "\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\", \"trigger_name\":\"foo\"}]}"); | 277 "\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\", \"trigger_name\":\"foo\"}]}"); |
| 277 | 278 |
| 278 BackgroundTracingConfigImpl::CategoryPreset categories[] = { | 279 BackgroundTracingConfigImpl::CategoryPreset categories[] = { |
| 279 BackgroundTracingConfigImpl::BENCHMARK, | 280 BackgroundTracingConfigImpl::BENCHMARK, |
| 280 BackgroundTracingConfigImpl::BENCHMARK_DEEP, | 281 BackgroundTracingConfigImpl::BENCHMARK_DEEP, |
| 281 BackgroundTracingConfigImpl::BENCHMARK_GPU, | 282 BackgroundTracingConfigImpl::BENCHMARK_GPU, |
| 282 BackgroundTracingConfigImpl::BENCHMARK_IPC, | 283 BackgroundTracingConfigImpl::BENCHMARK_IPC, |
| 283 BackgroundTracingConfigImpl::BENCHMARK_STARTUP, | 284 BackgroundTracingConfigImpl::BENCHMARK_STARTUP, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 294 sizeof(categories) / sizeof(BackgroundTracingConfigImpl::CategoryPreset); | 295 sizeof(categories) / sizeof(BackgroundTracingConfigImpl::CategoryPreset); |
| 295 i++) { | 296 i++) { |
| 296 config->set_category_preset(categories[i]); | 297 config->set_category_preset(categories[i]); |
| 297 std::string expected = | 298 std::string expected = |
| 298 std::string("{\"category\":\"") + category_strings[i] + | 299 std::string("{\"category\":\"") + category_strings[i] + |
| 299 std::string( | 300 std::string( |
| 300 "\",\"configs\":[{\"rule\":" | 301 "\",\"configs\":[{\"rule\":" |
| 301 "\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\",\"trigger_name\":" | 302 "\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\",\"trigger_name\":" |
| 302 "\"foo\"}],\"mode\":\"PREEMPTIVE_TRACING_MODE\"}"); | 303 "\"foo\"}],\"mode\":\"PREEMPTIVE_TRACING_MODE\"}"); |
| 303 EXPECT_EQ(ConfigToString(config.get()), expected.c_str()); | 304 EXPECT_EQ(ConfigToString(config.get()), expected.c_str()); |
| 304 scoped_ptr<BackgroundTracingConfigImpl> config2 = | 305 std::unique_ptr<BackgroundTracingConfigImpl> config2 = |
| 305 ReadFromJSONString(expected); | 306 ReadFromJSONString(expected); |
| 306 EXPECT_EQ(config->category_preset(), config2->category_preset()); | 307 EXPECT_EQ(config->category_preset(), config2->category_preset()); |
| 307 } | 308 } |
| 308 } | 309 } |
| 309 | 310 |
| 310 TEST_F(BackgroundTracingConfigTest, ReactiveConfigFromValidString) { | 311 TEST_F(BackgroundTracingConfigTest, ReactiveConfigFromValidString) { |
| 311 scoped_ptr<BackgroundTracingConfigImpl> config; | 312 std::unique_ptr<BackgroundTracingConfigImpl> config; |
| 312 | 313 |
| 313 config = ReadFromJSONString( | 314 config = ReadFromJSONString( |
| 314 "{\"mode\":\"REACTIVE_TRACING_MODE\",\"configs\": [{\"rule\": " | 315 "{\"mode\":\"REACTIVE_TRACING_MODE\",\"configs\": [{\"rule\": " |
| 315 "\"TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL\", " | 316 "\"TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL\", " |
| 316 "\"category\": \"BENCHMARK\", \"trigger_name\": \"foo\"}]}"); | 317 "\"category\": \"BENCHMARK\", \"trigger_name\": \"foo\"}]}"); |
| 317 EXPECT_TRUE(config); | 318 EXPECT_TRUE(config); |
| 318 EXPECT_EQ(config->tracing_mode(), BackgroundTracingConfig::REACTIVE); | 319 EXPECT_EQ(config->tracing_mode(), BackgroundTracingConfig::REACTIVE); |
| 319 EXPECT_EQ(config->rules().size(), 1u); | 320 EXPECT_EQ(config->rules().size(), 1u); |
| 320 EXPECT_EQ(RuleToString(config->rules()[0]), | 321 EXPECT_EQ(RuleToString(config->rules()[0]), |
| 321 "{\"category\":\"BENCHMARK\"," | 322 "{\"category\":\"BENCHMARK\"," |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 "\"timeout_min\":10, \"timeout_max\":20}]}"); | 372 "\"timeout_min\":10, \"timeout_max\":20}]}"); |
| 372 EXPECT_TRUE(config); | 373 EXPECT_TRUE(config); |
| 373 EXPECT_EQ(config->tracing_mode(), BackgroundTracingConfig::REACTIVE); | 374 EXPECT_EQ(config->tracing_mode(), BackgroundTracingConfig::REACTIVE); |
| 374 EXPECT_EQ(config->rules().size(), 1u); | 375 EXPECT_EQ(config->rules().size(), 1u); |
| 375 EXPECT_EQ(RuleToString(config->rules()[0]), | 376 EXPECT_EQ(RuleToString(config->rules()[0]), |
| 376 "{\"category\":\"BENCHMARK_DEEP\",\"rule\":\"TRACE_AT_RANDOM_" | 377 "{\"category\":\"BENCHMARK_DEEP\",\"rule\":\"TRACE_AT_RANDOM_" |
| 377 "INTERVALS\",\"timeout_max\":20,\"timeout_min\":10}"); | 378 "INTERVALS\",\"timeout_max\":20,\"timeout_min\":10}"); |
| 378 } | 379 } |
| 379 | 380 |
| 380 TEST_F(BackgroundTracingConfigTest, ValidPreemptiveConfigToString) { | 381 TEST_F(BackgroundTracingConfigTest, ValidPreemptiveConfigToString) { |
| 381 scoped_ptr<BackgroundTracingConfigImpl> config( | 382 std::unique_ptr<BackgroundTracingConfigImpl> config( |
| 382 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); | 383 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); |
| 383 | 384 |
| 384 // Default values | 385 // Default values |
| 385 EXPECT_EQ(ConfigToString(config.get()), | 386 EXPECT_EQ(ConfigToString(config.get()), |
| 386 "{\"category\":\"BENCHMARK\",\"configs\":[],\"mode\":\"PREEMPTIVE_" | 387 "{\"category\":\"BENCHMARK\",\"configs\":[],\"mode\":\"PREEMPTIVE_" |
| 387 "TRACING_MODE\"}"); | 388 "TRACING_MODE\"}"); |
| 388 | 389 |
| 389 // Change category_preset | 390 // Change category_preset |
| 390 config->set_category_preset(BackgroundTracingConfigImpl::BENCHMARK_DEEP); | 391 config->set_category_preset(BackgroundTracingConfigImpl::BENCHMARK_DEEP); |
| 391 EXPECT_EQ(ConfigToString(config.get()), | 392 EXPECT_EQ(ConfigToString(config.get()), |
| 392 "{\"category\":\"BENCHMARK_DEEP\",\"configs\":[],\"mode\":" | 393 "{\"category\":\"BENCHMARK_DEEP\",\"configs\":[],\"mode\":" |
| 393 "\"PREEMPTIVE_TRACING_MODE\"}"); | 394 "\"PREEMPTIVE_TRACING_MODE\"}"); |
| 394 | 395 |
| 395 { | 396 { |
| 396 config.reset( | 397 config.reset( |
| 397 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); | 398 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); |
| 398 config->set_category_preset(BackgroundTracingConfigImpl::BENCHMARK_DEEP); | 399 config->set_category_preset(BackgroundTracingConfigImpl::BENCHMARK_DEEP); |
| 399 | 400 |
| 400 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 401 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 401 dict->SetString("rule", "MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED"); | 402 dict->SetString("rule", "MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED"); |
| 402 dict->SetString("trigger_name", "foo"); | 403 dict->SetString("trigger_name", "foo"); |
| 403 config->AddPreemptiveRule(dict.get()); | 404 config->AddPreemptiveRule(dict.get()); |
| 404 | 405 |
| 405 EXPECT_EQ(ConfigToString(config.get()), | 406 EXPECT_EQ(ConfigToString(config.get()), |
| 406 "{\"category\":\"BENCHMARK_DEEP\",\"configs\":[{\"rule\":" | 407 "{\"category\":\"BENCHMARK_DEEP\",\"configs\":[{\"rule\":" |
| 407 "\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\",\"trigger_name\":" | 408 "\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\",\"trigger_name\":" |
| 408 "\"foo\"}],\"mode\":\"PREEMPTIVE_TRACING_MODE\"}"); | 409 "\"foo\"}],\"mode\":\"PREEMPTIVE_TRACING_MODE\"}"); |
| 409 } | 410 } |
| 410 | 411 |
| 411 { | 412 { |
| 412 config.reset( | 413 config.reset( |
| 413 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); | 414 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); |
| 414 config->set_category_preset(BackgroundTracingConfigImpl::BENCHMARK_DEEP); | 415 config->set_category_preset(BackgroundTracingConfigImpl::BENCHMARK_DEEP); |
| 415 | 416 |
| 416 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 417 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 417 dict->SetString("rule", "MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED"); | 418 dict->SetString("rule", "MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED"); |
| 418 dict->SetString("trigger_name", "foo"); | 419 dict->SetString("trigger_name", "foo"); |
| 419 dict->SetDouble("trigger_chance", 0.5); | 420 dict->SetDouble("trigger_chance", 0.5); |
| 420 config->AddPreemptiveRule(dict.get()); | 421 config->AddPreemptiveRule(dict.get()); |
| 421 | 422 |
| 422 EXPECT_EQ( | 423 EXPECT_EQ( |
| 423 ConfigToString(config.get()), | 424 ConfigToString(config.get()), |
| 424 "{\"category\":\"BENCHMARK_DEEP\",\"configs\":[{\"rule\":" | 425 "{\"category\":\"BENCHMARK_DEEP\",\"configs\":[{\"rule\":" |
| 425 "\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\",\"trigger_chance\":0.5," | 426 "\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\",\"trigger_chance\":0.5," |
| 426 "\"trigger_name\":\"foo\"}],\"mode\":\"PREEMPTIVE_TRACING_MODE\"}"); | 427 "\"trigger_name\":\"foo\"}],\"mode\":\"PREEMPTIVE_TRACING_MODE\"}"); |
| 427 } | 428 } |
| 428 | 429 |
| 429 { | 430 { |
| 430 config.reset( | 431 config.reset( |
| 431 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); | 432 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); |
| 432 config->set_category_preset(BackgroundTracingConfigImpl::BENCHMARK_DEEP); | 433 config->set_category_preset(BackgroundTracingConfigImpl::BENCHMARK_DEEP); |
| 433 | 434 |
| 434 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 435 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 435 dict->SetString("rule", "MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED"); | 436 dict->SetString("rule", "MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED"); |
| 436 dict->SetString("trigger_name", "foo1"); | 437 dict->SetString("trigger_name", "foo1"); |
| 437 config->AddPreemptiveRule(dict.get()); | 438 config->AddPreemptiveRule(dict.get()); |
| 438 | 439 |
| 439 dict->SetString("trigger_name", "foo2"); | 440 dict->SetString("trigger_name", "foo2"); |
| 440 config->AddPreemptiveRule(dict.get()); | 441 config->AddPreemptiveRule(dict.get()); |
| 441 | 442 |
| 442 EXPECT_EQ(ConfigToString(config.get()), | 443 EXPECT_EQ(ConfigToString(config.get()), |
| 443 "{\"category\":\"BENCHMARK_DEEP\",\"configs\":[{\"rule\":" | 444 "{\"category\":\"BENCHMARK_DEEP\",\"configs\":[{\"rule\":" |
| 444 "\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\",\"trigger_name\":" | 445 "\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\",\"trigger_name\":" |
| 445 "\"foo1\"},{\"rule\":\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\"," | 446 "\"foo1\"},{\"rule\":\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\"," |
| 446 "\"trigger_name\":\"foo2\"}],\"mode\":\"PREEMPTIVE_TRACING_" | 447 "\"trigger_name\":\"foo2\"}],\"mode\":\"PREEMPTIVE_TRACING_" |
| 447 "MODE\"}"); | 448 "MODE\"}"); |
| 448 } | 449 } |
| 449 | 450 |
| 450 { | 451 { |
| 451 config.reset( | 452 config.reset( |
| 452 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); | 453 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); |
| 453 | 454 |
| 454 scoped_ptr<base::DictionaryValue> second_dict(new base::DictionaryValue()); | 455 std::unique_ptr<base::DictionaryValue> second_dict( |
| 456 new base::DictionaryValue()); |
| 455 second_dict->SetString( | 457 second_dict->SetString( |
| 456 "rule", "MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE"); | 458 "rule", "MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE"); |
| 457 second_dict->SetString("histogram_name", "foo"); | 459 second_dict->SetString("histogram_name", "foo"); |
| 458 second_dict->SetInteger("histogram_lower_value", 1); | 460 second_dict->SetInteger("histogram_lower_value", 1); |
| 459 second_dict->SetInteger("histogram_upper_value", 2); | 461 second_dict->SetInteger("histogram_upper_value", 2); |
| 460 config->AddPreemptiveRule(second_dict.get()); | 462 config->AddPreemptiveRule(second_dict.get()); |
| 461 | 463 |
| 462 EXPECT_EQ(ConfigToString(config.get()), | 464 EXPECT_EQ(ConfigToString(config.get()), |
| 463 "{\"category\":\"BENCHMARK\",\"configs\":[{\"histogram_lower_" | 465 "{\"category\":\"BENCHMARK\",\"configs\":[{\"histogram_lower_" |
| 464 "value\":1,\"histogram_name\":\"foo\",\"histogram_repeat\":true," | 466 "value\":1,\"histogram_name\":\"foo\",\"histogram_repeat\":true," |
| 465 "\"histogram_upper_value\":2,\"rule\":\"MONITOR_AND_DUMP_WHEN_" | 467 "\"histogram_upper_value\":2,\"rule\":\"MONITOR_AND_DUMP_WHEN_" |
| 466 "SPECIFIC_HISTOGRAM_AND_VALUE\"}],\"mode\":\"PREEMPTIVE_TRACING_" | 468 "SPECIFIC_HISTOGRAM_AND_VALUE\"}],\"mode\":\"PREEMPTIVE_TRACING_" |
| 467 "MODE\"}"); | 469 "MODE\"}"); |
| 468 } | 470 } |
| 469 | 471 |
| 470 { | 472 { |
| 471 config.reset( | 473 config.reset( |
| 472 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); | 474 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); |
| 473 | 475 |
| 474 scoped_ptr<base::DictionaryValue> second_dict(new base::DictionaryValue()); | 476 std::unique_ptr<base::DictionaryValue> second_dict( |
| 477 new base::DictionaryValue()); |
| 475 second_dict->SetString( | 478 second_dict->SetString( |
| 476 "rule", "MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE"); | 479 "rule", "MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE"); |
| 477 second_dict->SetString("histogram_name", "foo"); | 480 second_dict->SetString("histogram_name", "foo"); |
| 478 second_dict->SetInteger("histogram_lower_value", 1); | 481 second_dict->SetInteger("histogram_lower_value", 1); |
| 479 second_dict->SetInteger("histogram_upper_value", 2); | 482 second_dict->SetInteger("histogram_upper_value", 2); |
| 480 second_dict->SetInteger("trigger_delay", 10); | 483 second_dict->SetInteger("trigger_delay", 10); |
| 481 config->AddPreemptiveRule(second_dict.get()); | 484 config->AddPreemptiveRule(second_dict.get()); |
| 482 | 485 |
| 483 EXPECT_EQ(ConfigToString(config.get()), | 486 EXPECT_EQ(ConfigToString(config.get()), |
| 484 "{\"category\":\"BENCHMARK\",\"configs\":[{\"histogram_lower_" | 487 "{\"category\":\"BENCHMARK\",\"configs\":[{\"histogram_lower_" |
| 485 "value\":1,\"histogram_name\":\"foo\",\"histogram_repeat\":true," | 488 "value\":1,\"histogram_name\":\"foo\",\"histogram_repeat\":true," |
| 486 "\"histogram_upper_value\":2,\"rule\":\"MONITOR_AND_DUMP_WHEN_" | 489 "\"histogram_upper_value\":2,\"rule\":\"MONITOR_AND_DUMP_WHEN_" |
| 487 "SPECIFIC_HISTOGRAM_AND_VALUE\",\"trigger_delay\":10}],\"mode\":" | 490 "SPECIFIC_HISTOGRAM_AND_VALUE\",\"trigger_delay\":10}],\"mode\":" |
| 488 "\"PREEMPTIVE_TRACING_MODE\"}"); | 491 "\"PREEMPTIVE_TRACING_MODE\"}"); |
| 489 } | 492 } |
| 490 | 493 |
| 491 { | 494 { |
| 492 config.reset( | 495 config.reset( |
| 493 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); | 496 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); |
| 494 config->set_category_preset(BackgroundTracingConfigImpl::BENCHMARK_DEEP); | 497 config->set_category_preset(BackgroundTracingConfigImpl::BENCHMARK_DEEP); |
| 495 | 498 |
| 496 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 499 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 497 dict->SetString("rule", "MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED"); | 500 dict->SetString("rule", "MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED"); |
| 498 dict->SetString("trigger_name", "foo1"); | 501 dict->SetString("trigger_name", "foo1"); |
| 499 config->AddPreemptiveRule(dict.get()); | 502 config->AddPreemptiveRule(dict.get()); |
| 500 | 503 |
| 501 config->scenario_name_ = "my_awesome_experiment"; | 504 config->scenario_name_ = "my_awesome_experiment"; |
| 502 config->enable_blink_features_ = "FasterWeb1,FasterWeb2"; | 505 config->enable_blink_features_ = "FasterWeb1,FasterWeb2"; |
| 503 config->disable_blink_features_ = "SlowerWeb1,SlowerWeb2"; | 506 config->disable_blink_features_ = "SlowerWeb1,SlowerWeb2"; |
| 504 | 507 |
| 505 EXPECT_EQ(ConfigToString(config.get()), | 508 EXPECT_EQ(ConfigToString(config.get()), |
| 506 "{\"category\":\"BENCHMARK_DEEP\",\"configs\":[{\"rule\":" | 509 "{\"category\":\"BENCHMARK_DEEP\",\"configs\":[{\"rule\":" |
| 507 "\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\",\"trigger_name\":" | 510 "\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\",\"trigger_name\":" |
| 508 "\"foo1\"}],\"disable_blink_features\":\"SlowerWeb1,SlowerWeb2\"," | 511 "\"foo1\"}],\"disable_blink_features\":\"SlowerWeb1,SlowerWeb2\"," |
| 509 "\"enable_blink_features\":\"FasterWeb1,FasterWeb2\"," | 512 "\"enable_blink_features\":\"FasterWeb1,FasterWeb2\"," |
| 510 "\"mode\":\"PREEMPTIVE_TRACING_MODE\"," | 513 "\"mode\":\"PREEMPTIVE_TRACING_MODE\"," |
| 511 "\"scenario_name\":\"my_awesome_experiment\"}"); | 514 "\"scenario_name\":\"my_awesome_experiment\"}"); |
| 512 } | 515 } |
| 513 } | 516 } |
| 514 | 517 |
| 515 TEST_F(BackgroundTracingConfigTest, InvalidPreemptiveConfigToString) { | 518 TEST_F(BackgroundTracingConfigTest, InvalidPreemptiveConfigToString) { |
| 516 scoped_ptr<BackgroundTracingConfigImpl> config; | 519 std::unique_ptr<BackgroundTracingConfigImpl> config; |
| 517 | 520 |
| 518 { | 521 { |
| 519 config.reset( | 522 config.reset( |
| 520 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); | 523 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); |
| 521 | 524 |
| 522 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 525 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 523 dict->SetString("rule", "MONITOR_AND_DUMP_WHEN_BROWSER_STARTUP_COMPLETE"); | 526 dict->SetString("rule", "MONITOR_AND_DUMP_WHEN_BROWSER_STARTUP_COMPLETE"); |
| 524 config->AddPreemptiveRule(dict.get()); | 527 config->AddPreemptiveRule(dict.get()); |
| 525 | 528 |
| 526 EXPECT_EQ(ConfigToString(config.get()), | 529 EXPECT_EQ(ConfigToString(config.get()), |
| 527 "{\"category\":\"BENCHMARK\",\"configs\":[],\"mode\":" | 530 "{\"category\":\"BENCHMARK\",\"configs\":[],\"mode\":" |
| 528 "\"PREEMPTIVE_TRACING_MODE\"}"); | 531 "\"PREEMPTIVE_TRACING_MODE\"}"); |
| 529 } | 532 } |
| 530 | 533 |
| 531 { | 534 { |
| 532 config.reset( | 535 config.reset( |
| 533 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); | 536 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); |
| 534 | 537 |
| 535 scoped_ptr<base::DictionaryValue> second_dict(new base::DictionaryValue()); | 538 std::unique_ptr<base::DictionaryValue> second_dict( |
| 539 new base::DictionaryValue()); |
| 536 second_dict->SetString( | 540 second_dict->SetString( |
| 537 "rule", "MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE"); | 541 "rule", "MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE"); |
| 538 second_dict->SetString("histogram_name", "foo"); | 542 second_dict->SetString("histogram_name", "foo"); |
| 539 second_dict->SetInteger("histogram_lower_value", 1); | 543 second_dict->SetInteger("histogram_lower_value", 1); |
| 540 | 544 |
| 541 EXPECT_EQ(ConfigToString(config.get()), | 545 EXPECT_EQ(ConfigToString(config.get()), |
| 542 "{\"category\":\"BENCHMARK\",\"configs\":[],\"mode\":" | 546 "{\"category\":\"BENCHMARK\",\"configs\":[],\"mode\":" |
| 543 "\"PREEMPTIVE_TRACING_MODE\"}"); | 547 "\"PREEMPTIVE_TRACING_MODE\"}"); |
| 544 } | 548 } |
| 545 | 549 |
| 546 { | 550 { |
| 547 config.reset( | 551 config.reset( |
| 548 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); | 552 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); |
| 549 | 553 |
| 550 scoped_ptr<base::DictionaryValue> second_dict(new base::DictionaryValue()); | 554 std::unique_ptr<base::DictionaryValue> second_dict( |
| 555 new base::DictionaryValue()); |
| 551 second_dict->SetString( | 556 second_dict->SetString( |
| 552 "rule", "MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE"); | 557 "rule", "MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE"); |
| 553 second_dict->SetString("histogram_name", "foo"); | 558 second_dict->SetString("histogram_name", "foo"); |
| 554 second_dict->SetInteger("histogram_lower_value", 1); | 559 second_dict->SetInteger("histogram_lower_value", 1); |
| 555 second_dict->SetInteger("histogram_upper_value", 1); | 560 second_dict->SetInteger("histogram_upper_value", 1); |
| 556 | 561 |
| 557 EXPECT_EQ(ConfigToString(config.get()), | 562 EXPECT_EQ(ConfigToString(config.get()), |
| 558 "{\"category\":\"BENCHMARK\",\"configs\":[],\"mode\":" | 563 "{\"category\":\"BENCHMARK\",\"configs\":[],\"mode\":" |
| 559 "\"PREEMPTIVE_TRACING_MODE\"}"); | 564 "\"PREEMPTIVE_TRACING_MODE\"}"); |
| 560 } | 565 } |
| 561 } | 566 } |
| 562 | 567 |
| 563 TEST_F(BackgroundTracingConfigTest, ValidReactiveConfigToString) { | 568 TEST_F(BackgroundTracingConfigTest, ValidReactiveConfigToString) { |
| 564 scoped_ptr<BackgroundTracingConfigImpl> config( | 569 std::unique_ptr<BackgroundTracingConfigImpl> config( |
| 565 new BackgroundTracingConfigImpl(BackgroundTracingConfig::REACTIVE)); | 570 new BackgroundTracingConfigImpl(BackgroundTracingConfig::REACTIVE)); |
| 566 | 571 |
| 567 // Default values | 572 // Default values |
| 568 EXPECT_EQ(ConfigToString(config.get()), | 573 EXPECT_EQ(ConfigToString(config.get()), |
| 569 "{\"configs\":[],\"mode\":\"REACTIVE_TRACING_MODE\"}"); | 574 "{\"configs\":[],\"mode\":\"REACTIVE_TRACING_MODE\"}"); |
| 570 | 575 |
| 571 { | 576 { |
| 572 config.reset( | 577 config.reset( |
| 573 new BackgroundTracingConfigImpl(BackgroundTracingConfig::REACTIVE)); | 578 new BackgroundTracingConfigImpl(BackgroundTracingConfig::REACTIVE)); |
| 574 | 579 |
| 575 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 580 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 576 dict->SetString("rule", "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL"); | 581 dict->SetString("rule", "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL"); |
| 577 dict->SetString("trigger_name", "foo"); | 582 dict->SetString("trigger_name", "foo"); |
| 578 config->AddReactiveRule(dict.get(), | 583 config->AddReactiveRule(dict.get(), |
| 579 BackgroundTracingConfigImpl::BENCHMARK_DEEP); | 584 BackgroundTracingConfigImpl::BENCHMARK_DEEP); |
| 580 | 585 |
| 581 EXPECT_EQ(ConfigToString(config.get()), | 586 EXPECT_EQ(ConfigToString(config.get()), |
| 582 "{\"configs\":[{\"category\":\"BENCHMARK_DEEP\",\"rule\":\"TRACE_" | 587 "{\"configs\":[{\"category\":\"BENCHMARK_DEEP\",\"rule\":\"TRACE_" |
| 583 "ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL\",\"trigger_name\":\"foo\"}]" | 588 "ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL\",\"trigger_name\":\"foo\"}]" |
| 584 ",\"mode\":\"REACTIVE_TRACING_MODE\"}"); | 589 ",\"mode\":\"REACTIVE_TRACING_MODE\"}"); |
| 585 } | 590 } |
| 586 | 591 |
| 587 { | 592 { |
| 588 config.reset( | 593 config.reset( |
| 589 new BackgroundTracingConfigImpl(BackgroundTracingConfig::REACTIVE)); | 594 new BackgroundTracingConfigImpl(BackgroundTracingConfig::REACTIVE)); |
| 590 | 595 |
| 591 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 596 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 592 dict->SetString("rule", "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL"); | 597 dict->SetString("rule", "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL"); |
| 593 dict->SetString("trigger_name", "foo1"); | 598 dict->SetString("trigger_name", "foo1"); |
| 594 config->AddReactiveRule(dict.get(), | 599 config->AddReactiveRule(dict.get(), |
| 595 BackgroundTracingConfigImpl::BENCHMARK_DEEP); | 600 BackgroundTracingConfigImpl::BENCHMARK_DEEP); |
| 596 | 601 |
| 597 dict->SetString("trigger_name", "foo2"); | 602 dict->SetString("trigger_name", "foo2"); |
| 598 config->AddReactiveRule(dict.get(), | 603 config->AddReactiveRule(dict.get(), |
| 599 BackgroundTracingConfigImpl::BENCHMARK_DEEP); | 604 BackgroundTracingConfigImpl::BENCHMARK_DEEP); |
| 600 | 605 |
| 601 EXPECT_EQ( | 606 EXPECT_EQ( |
| 602 ConfigToString(config.get()), | 607 ConfigToString(config.get()), |
| 603 "{\"configs\":[{\"category\":\"BENCHMARK_DEEP\",\"rule\":\"TRACE_" | 608 "{\"configs\":[{\"category\":\"BENCHMARK_DEEP\",\"rule\":\"TRACE_" |
| 604 "ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL\",\"trigger_name\":\"foo1\"},{" | 609 "ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL\",\"trigger_name\":\"foo1\"},{" |
| 605 "\"category\":\"BENCHMARK_DEEP\",\"rule\":" | 610 "\"category\":\"BENCHMARK_DEEP\",\"rule\":" |
| 606 "\"TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL\",\"trigger_name\":" | 611 "\"TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL\",\"trigger_name\":" |
| 607 "\"foo2\"}],\"mode\":\"REACTIVE_TRACING_MODE\"}"); | 612 "\"foo2\"}],\"mode\":\"REACTIVE_TRACING_MODE\"}"); |
| 608 } | 613 } |
| 609 } | 614 } |
| 610 | 615 |
| 611 } // namspace content | 616 } // namspace content |
| OLD | NEW |