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

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

Issue 2294093002: Reland of Background tracing: Added config option for repeated trigger behavior (patchset #1 id:1 o… (Closed)
Patch Set: Created 4 years, 3 months 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 <stddef.h> 5 #include <stddef.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 base::DictionaryValue dict; 124 base::DictionaryValue dict;
125 125
126 dict.SetString("mode", "REACTIVE_TRACING_MODE"); 126 dict.SetString("mode", "REACTIVE_TRACING_MODE");
127 127
128 std::unique_ptr<base::ListValue> rules_list(new base::ListValue()); 128 std::unique_ptr<base::ListValue> rules_list(new base::ListValue());
129 { 129 {
130 std::unique_ptr<base::DictionaryValue> rules_dict( 130 std::unique_ptr<base::DictionaryValue> rules_dict(
131 new base::DictionaryValue()); 131 new base::DictionaryValue());
132 rules_dict->SetString("rule", "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL"); 132 rules_dict->SetString("rule", "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL");
133 rules_dict->SetString("trigger_name", "reactive_test"); 133 rules_dict->SetString("trigger_name", "reactive_test");
134 rules_dict->SetBoolean("stop_tracing_on_repeated_reactive", true);
134 rules_dict->SetString("category", "BENCHMARK"); 135 rules_dict->SetString("category", "BENCHMARK");
135 rules_list->Append(std::move(rules_dict)); 136 rules_list->Append(std::move(rules_dict));
136 } 137 }
137 dict.Set("configs", std::move(rules_list)); 138 dict.Set("configs", std::move(rules_list));
138 139
139 std::unique_ptr<BackgroundTracingConfig> config( 140 std::unique_ptr<BackgroundTracingConfig> config(
140 BackgroundTracingConfigImpl::FromDict(&dict)); 141 BackgroundTracingConfigImpl::FromDict(&dict));
141 142
142 EXPECT_TRUE(config); 143 EXPECT_TRUE(config);
143 return config; 144 return config;
(...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 base::DictionaryValue dict; 1102 base::DictionaryValue dict;
1102 dict.SetString("mode", "REACTIVE_TRACING_MODE"); 1103 dict.SetString("mode", "REACTIVE_TRACING_MODE");
1103 1104
1104 std::unique_ptr<base::ListValue> rules_list(new base::ListValue()); 1105 std::unique_ptr<base::ListValue> rules_list(new base::ListValue());
1105 { 1106 {
1106 std::unique_ptr<base::DictionaryValue> rules_dict( 1107 std::unique_ptr<base::DictionaryValue> rules_dict(
1107 new base::DictionaryValue()); 1108 new base::DictionaryValue());
1108 rules_dict->SetString("rule", 1109 rules_dict->SetString("rule",
1109 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL"); 1110 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL");
1110 rules_dict->SetString("trigger_name", "reactive_test1"); 1111 rules_dict->SetString("trigger_name", "reactive_test1");
1112 rules_dict->SetBoolean("stop_tracing_on_repeated_reactive", true);
1113 rules_dict->SetInteger("trigger_delay", 10);
1111 rules_dict->SetString("category", "BENCHMARK"); 1114 rules_dict->SetString("category", "BENCHMARK");
1112 rules_list->Append(std::move(rules_dict)); 1115 rules_list->Append(std::move(rules_dict));
1113 } 1116 }
1114 { 1117 {
1115 std::unique_ptr<base::DictionaryValue> rules_dict( 1118 std::unique_ptr<base::DictionaryValue> rules_dict(
1116 new base::DictionaryValue()); 1119 new base::DictionaryValue());
1117 rules_dict->SetString("rule", 1120 rules_dict->SetString("rule",
1118 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL"); 1121 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL");
1119 rules_dict->SetString("trigger_name", "reactive_test2"); 1122 rules_dict->SetString("trigger_name", "reactive_test2");
1123 rules_dict->SetBoolean("stop_tracing_on_repeated_reactive", true);
1124 rules_dict->SetInteger("trigger_delay", 10);
1120 rules_dict->SetString("category", "BENCHMARK"); 1125 rules_dict->SetString("category", "BENCHMARK");
1121 rules_list->Append(std::move(rules_dict)); 1126 rules_list->Append(std::move(rules_dict));
1122 } 1127 }
1123 dict.Set("configs", std::move(rules_list)); 1128 dict.Set("configs", std::move(rules_list));
1124 1129
1125 std::unique_ptr<BackgroundTracingConfig> config( 1130 std::unique_ptr<BackgroundTracingConfig> config(
1126 BackgroundTracingConfigImpl::FromDict(&dict)); 1131 BackgroundTracingConfigImpl::FromDict(&dict));
1127 1132
1128 BackgroundTracingManager::TriggerHandle handle1 = 1133 BackgroundTracingManager::TriggerHandle handle1 =
1129 BackgroundTracingManager::GetInstance()->RegisterTriggerType( 1134 BackgroundTracingManager::GetInstance()->RegisterTriggerType(
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 // third trigger to trigger again, fails as it is still gathering. 1193 // third trigger to trigger again, fails as it is still gathering.
1189 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( 1194 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
1190 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), false)); 1195 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), false));
1191 1196
1192 run_loop.Run(); 1197 run_loop.Run();
1193 1198
1194 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1); 1199 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1);
1195 } 1200 }
1196 } 1201 }
1197 1202
1203 // This tests that reactive mode only terminates with a repeated trigger
1204 // if the config specifies that it should.
1205 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
1206 ReactiveSecondTriggerIgnored) {
1207 {
1208 SetupBackgroundTracingManager();
1209
1210 base::RunLoop run_loop;
1211 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper(
1212 run_loop.QuitClosure());
1213
1214 base::DictionaryValue dict;
1215 dict.SetString("mode", "REACTIVE_TRACING_MODE");
1216
1217 std::unique_ptr<base::ListValue> rules_list(new base::ListValue());
1218 {
1219 std::unique_ptr<base::DictionaryValue> rules_dict(
1220 new base::DictionaryValue());
1221 rules_dict->SetString("rule",
1222 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL");
1223 rules_dict->SetString("trigger_name", "reactive_test");
1224 rules_dict->SetBoolean("stop_tracing_on_repeated_reactive", false);
1225 rules_dict->SetInteger("trigger_delay", 10);
1226 rules_dict->SetString("category", "BENCHMARK");
1227 rules_list->Append(std::move(rules_dict));
1228 }
1229 dict.Set("configs", std::move(rules_list));
1230
1231 std::unique_ptr<BackgroundTracingConfig> config(
1232 BackgroundTracingConfigImpl::FromDict(&dict));
1233
1234 BackgroundTracingManager::TriggerHandle trigger_handle =
1235 BackgroundTracingManager::GetInstance()->RegisterTriggerType(
1236 "reactive_test");
1237
1238 EXPECT_TRUE(BackgroundTracingManager::GetInstance()->SetActiveScenario(
1239 std::move(config), upload_config_wrapper.get_receive_callback(),
1240 BackgroundTracingManager::NO_DATA_FILTERING));
1241
1242 BackgroundTracingManager::GetInstance()->WhenIdle(
1243 base::Bind(&DisableScenarioWhenIdle));
1244
1245 base::RunLoop wait_for_tracing_enabled;
1246 static_cast<BackgroundTracingManagerImpl*>(
1247 BackgroundTracingManager::GetInstance())
1248 ->SetTracingEnabledCallbackForTesting(
1249 wait_for_tracing_enabled.QuitClosure());
1250
1251 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
1252 trigger_handle,
1253 base::Bind(&StartedFinalizingCallback, base::Closure(), true));
1254
1255 wait_for_tracing_enabled.Run();
1256
1257 // This is expected to fail since we already triggered.
1258 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
1259 trigger_handle,
1260 base::Bind(&StartedFinalizingCallback, base::Closure(), false));
1261
1262 // Since we specified a delay in the scenario, we should still be tracing
1263 // at this point.
1264 EXPECT_TRUE(
1265 BackgroundTracingManagerImpl::GetInstance()->IsTracingForTesting());
1266
1267 BackgroundTracingManager::GetInstance()->FireTimerForTesting();
1268
1269 EXPECT_FALSE(
1270 BackgroundTracingManagerImpl::GetInstance()->IsTracingForTesting());
1271
1272 run_loop.Run();
1273
1274 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1);
1275 }
1276 }
1277
1198 } // namespace content 1278 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698