Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Side by Side Diff: content/browser/tracing/background_tracing_config_unittest.cc

Issue 1420033003: Background tracing: Tracing scenarios can now enable/disable Blink features, for A/B testing purpos… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review fixes Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/json/json_reader.h" 5 #include "base/json/json_reader.h"
6 #include "base/json/json_writer.h" 6 #include "base/json/json_writer.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "content/browser/tracing/background_tracing_config_impl.h" 9 #include "content/browser/tracing/background_tracing_config_impl.h"
10 #include "content/browser/tracing/background_tracing_rule.h" 10 #include "content/browser/tracing/background_tracing_rule.h"
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 EXPECT_TRUE(config); 249 EXPECT_TRUE(config);
250 EXPECT_EQ(config->tracing_mode(), BackgroundTracingConfig::PREEMPTIVE); 250 EXPECT_EQ(config->tracing_mode(), BackgroundTracingConfig::PREEMPTIVE);
251 EXPECT_EQ(config->category_preset(), BackgroundTracingConfigImpl::BENCHMARK); 251 EXPECT_EQ(config->category_preset(), BackgroundTracingConfigImpl::BENCHMARK);
252 EXPECT_EQ(config->rules().size(), 2u); 252 EXPECT_EQ(config->rules().size(), 2u);
253 EXPECT_EQ(RuleToString(config->rules()[0]), 253 EXPECT_EQ(RuleToString(config->rules()[0]),
254 "{\"rule\":\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\"," 254 "{\"rule\":\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\","
255 "\"trigger_name\":\"foo1\"}"); 255 "\"trigger_name\":\"foo1\"}");
256 EXPECT_EQ(RuleToString(config->rules()[1]), 256 EXPECT_EQ(RuleToString(config->rules()[1]),
257 "{\"rule\":\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\"," 257 "{\"rule\":\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\","
258 "\"trigger_name\":\"foo2\"}"); 258 "\"trigger_name\":\"foo2\"}");
259
260 config = ReadFromJSONString(
261 "{\"category\":\"BENCHMARK_DEEP\",\"configs\":[{\"rule\":"
262 "\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\",\"trigger_name\":"
263 "\"foo1\"}],\"disable_blink_features\":\"SlowerWeb1,SlowerWeb2\","
264 "\"enable_blink_features\":\"FasterWeb1,FasterWeb2\","
265 "\"mode\":\"PREEMPTIVE_TRACING_MODE\","
266 "\"scenario_name\":\"my_awesome_experiment\"}");
267 EXPECT_EQ(config->enable_blink_features(), "FasterWeb1,FasterWeb2");
268 EXPECT_EQ(config->disable_blink_features(), "SlowerWeb1,SlowerWeb2");
269 EXPECT_EQ(config->scenario_name(), "my_awesome_experiment");
259 } 270 }
260 271
261 TEST_F(BackgroundTracingConfigTest, ReactiveConfigFromValidString) { 272 TEST_F(BackgroundTracingConfigTest, ReactiveConfigFromValidString) {
262 scoped_ptr<BackgroundTracingConfigImpl> config; 273 scoped_ptr<BackgroundTracingConfigImpl> config;
263 274
264 config = ReadFromJSONString( 275 config = ReadFromJSONString(
265 "{\"mode\":\"REACTIVE_TRACING_MODE\",\"configs\": [{\"rule\": " 276 "{\"mode\":\"REACTIVE_TRACING_MODE\",\"configs\": [{\"rule\": "
266 "\"TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL\", " 277 "\"TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL\", "
267 "\"category\": \"BENCHMARK\", \"trigger_name\": \"foo\"}]}"); 278 "\"category\": \"BENCHMARK\", \"trigger_name\": \"foo\"}]}");
268 EXPECT_TRUE(config); 279 EXPECT_TRUE(config);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 second_dict->SetInteger("trigger_delay", 10); 410 second_dict->SetInteger("trigger_delay", 10);
400 config->AddPreemptiveRule(second_dict.get()); 411 config->AddPreemptiveRule(second_dict.get());
401 412
402 EXPECT_EQ(ConfigToString(config.get()), 413 EXPECT_EQ(ConfigToString(config.get()),
403 "{\"category\":\"BENCHMARK\",\"configs\":[{\"histogram_lower_" 414 "{\"category\":\"BENCHMARK\",\"configs\":[{\"histogram_lower_"
404 "value\":1,\"histogram_name\":\"foo\",\"histogram_repeat\":true," 415 "value\":1,\"histogram_name\":\"foo\",\"histogram_repeat\":true,"
405 "\"histogram_upper_value\":2,\"rule\":\"MONITOR_AND_DUMP_WHEN_" 416 "\"histogram_upper_value\":2,\"rule\":\"MONITOR_AND_DUMP_WHEN_"
406 "SPECIFIC_HISTOGRAM_AND_VALUE\",\"trigger_delay\":10}],\"mode\":" 417 "SPECIFIC_HISTOGRAM_AND_VALUE\",\"trigger_delay\":10}],\"mode\":"
407 "\"PREEMPTIVE_TRACING_MODE\"}"); 418 "\"PREEMPTIVE_TRACING_MODE\"}");
408 } 419 }
420
421 {
422 config.reset(
423 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE));
424 config->set_category_preset(BackgroundTracingConfigImpl::BENCHMARK_DEEP);
425
426 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
427 dict->SetString("rule", "MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED");
428 dict->SetString("trigger_name", "foo1");
429 config->AddPreemptiveRule(dict.get());
430
431 config->scenario_name_ = "my_awesome_experiment";
432 config->enable_blink_features_ = "FasterWeb1,FasterWeb2";
433 config->disable_blink_features_ = "SlowerWeb1,SlowerWeb2";
434
435 EXPECT_EQ(ConfigToString(config.get()),
436 "{\"category\":\"BENCHMARK_DEEP\",\"configs\":[{\"rule\":"
437 "\"MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED\",\"trigger_name\":"
438 "\"foo1\"}],\"disable_blink_features\":\"SlowerWeb1,SlowerWeb2\","
439 "\"enable_blink_features\":\"FasterWeb1,FasterWeb2\","
440 "\"mode\":\"PREEMPTIVE_TRACING_MODE\","
441 "\"scenario_name\":\"my_awesome_experiment\"}");
442 }
409 } 443 }
410 444
411 TEST_F(BackgroundTracingConfigTest, InvalidPreemptiveConfigToString) { 445 TEST_F(BackgroundTracingConfigTest, InvalidPreemptiveConfigToString) {
412 scoped_ptr<BackgroundTracingConfigImpl> config; 446 scoped_ptr<BackgroundTracingConfigImpl> config;
413 447
414 { 448 {
415 config.reset( 449 config.reset(
416 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE)); 450 new BackgroundTracingConfigImpl(BackgroundTracingConfig::PREEMPTIVE));
417 451
418 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 452 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 ConfigToString(config.get()), 532 ConfigToString(config.get()),
499 "{\"configs\":[{\"category\":\"BENCHMARK_DEEP\",\"rule\":\"TRACE_" 533 "{\"configs\":[{\"category\":\"BENCHMARK_DEEP\",\"rule\":\"TRACE_"
500 "ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL\",\"trigger_name\":\"foo1\"},{" 534 "ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL\",\"trigger_name\":\"foo1\"},{"
501 "\"category\":\"BENCHMARK_DEEP\",\"rule\":" 535 "\"category\":\"BENCHMARK_DEEP\",\"rule\":"
502 "\"TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL\",\"trigger_name\":" 536 "\"TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL\",\"trigger_name\":"
503 "\"foo2\"}],\"mode\":\"REACTIVE_TRACING_MODE\"}"); 537 "\"foo2\"}],\"mode\":\"REACTIVE_TRACING_MODE\"}");
504 } 538 }
505 } 539 }
506 540
507 } // namspace content 541 } // namspace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698