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

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

Issue 2247033005: Background tracing: Added config option for repeated trigger behavior (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 948 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 base::DictionaryValue dict; 1093 base::DictionaryValue dict;
1093 dict.SetString("mode", "REACTIVE_TRACING_MODE"); 1094 dict.SetString("mode", "REACTIVE_TRACING_MODE");
1094 1095
1095 std::unique_ptr<base::ListValue> rules_list(new base::ListValue()); 1096 std::unique_ptr<base::ListValue> rules_list(new base::ListValue());
1096 { 1097 {
1097 std::unique_ptr<base::DictionaryValue> rules_dict( 1098 std::unique_ptr<base::DictionaryValue> rules_dict(
1098 new base::DictionaryValue()); 1099 new base::DictionaryValue());
1099 rules_dict->SetString("rule", 1100 rules_dict->SetString("rule",
1100 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL"); 1101 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL");
1101 rules_dict->SetString("trigger_name", "reactive_test1"); 1102 rules_dict->SetString("trigger_name", "reactive_test1");
1103 rules_dict->SetBoolean("stop_tracing_on_repeated_reactive", true);
1104 rules_dict->SetInteger("trigger_delay", 10);
1102 rules_dict->SetString("category", "BENCHMARK"); 1105 rules_dict->SetString("category", "BENCHMARK");
1103 rules_list->Append(std::move(rules_dict)); 1106 rules_list->Append(std::move(rules_dict));
1104 } 1107 }
1105 { 1108 {
1106 std::unique_ptr<base::DictionaryValue> rules_dict( 1109 std::unique_ptr<base::DictionaryValue> rules_dict(
1107 new base::DictionaryValue()); 1110 new base::DictionaryValue());
1108 rules_dict->SetString("rule", 1111 rules_dict->SetString("rule",
1109 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL"); 1112 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL");
1110 rules_dict->SetString("trigger_name", "reactive_test2"); 1113 rules_dict->SetString("trigger_name", "reactive_test2");
1114 rules_dict->SetBoolean("stop_tracing_on_repeated_reactive", true);
1115 rules_dict->SetInteger("trigger_delay", 10);
1111 rules_dict->SetString("category", "BENCHMARK"); 1116 rules_dict->SetString("category", "BENCHMARK");
1112 rules_list->Append(std::move(rules_dict)); 1117 rules_list->Append(std::move(rules_dict));
1113 } 1118 }
1114 dict.Set("configs", std::move(rules_list)); 1119 dict.Set("configs", std::move(rules_list));
1115 1120
1116 std::unique_ptr<BackgroundTracingConfig> config( 1121 std::unique_ptr<BackgroundTracingConfig> config(
1117 BackgroundTracingConfigImpl::FromDict(&dict)); 1122 BackgroundTracingConfigImpl::FromDict(&dict));
1118 1123
1119 BackgroundTracingManager::TriggerHandle handle1 = 1124 BackgroundTracingManager::TriggerHandle handle1 =
1120 BackgroundTracingManager::GetInstance()->RegisterTriggerType( 1125 BackgroundTracingManager::GetInstance()->RegisterTriggerType(
(...skipping 20 matching lines...) Expand all
1141 // second trigger to terminate. 1146 // second trigger to terminate.
1142 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( 1147 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
1143 handle1, base::Bind(&StartedFinalizingCallback, base::Closure(), true)); 1148 handle1, base::Bind(&StartedFinalizingCallback, base::Closure(), true));
1144 1149
1145 run_loop.Run(); 1150 run_loop.Run();
1146 1151
1147 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1); 1152 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1);
1148 } 1153 }
1149 } 1154 }
1150 1155
1156 // This tests that reactive mode only terminates with a repeated trigger
1157 // if the config specifies that it should.
1158 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
1159 ReactiveSecondTriggerIgnored) {
1160 {
1161 SetupBackgroundTracingManager();
1162
1163 base::RunLoop run_loop;
1164 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper(
1165 run_loop.QuitClosure());
1166
1167 base::DictionaryValue dict;
1168 dict.SetString("mode", "REACTIVE_TRACING_MODE");
1169
1170 std::unique_ptr<base::ListValue> rules_list(new base::ListValue());
1171 {
1172 std::unique_ptr<base::DictionaryValue> rules_dict(
1173 new base::DictionaryValue());
1174 rules_dict->SetString("rule",
1175 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL");
1176 rules_dict->SetString("trigger_name", "reactive_test");
1177 rules_dict->SetBoolean("stop_tracing_on_repeated_reactive", false);
1178 rules_dict->SetInteger("trigger_delay", 10);
1179 rules_dict->SetString("category", "BENCHMARK");
1180 rules_list->Append(std::move(rules_dict));
1181 }
1182 dict.Set("configs", std::move(rules_list));
1183
1184 std::unique_ptr<BackgroundTracingConfig> config(
1185 BackgroundTracingConfigImpl::FromDict(&dict));
1186
1187 BackgroundTracingManager::TriggerHandle trigger_handle =
1188 BackgroundTracingManager::GetInstance()->RegisterTriggerType(
1189 "reactive_test");
1190
1191 EXPECT_TRUE(BackgroundTracingManager::GetInstance()->SetActiveScenario(
1192 std::move(config), upload_config_wrapper.get_receive_callback(),
1193 BackgroundTracingManager::NO_DATA_FILTERING));
1194
1195 BackgroundTracingManager::GetInstance()->WhenIdle(
1196 base::Bind(&DisableScenarioWhenIdle));
1197
1198 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
1199 trigger_handle,
1200 base::Bind(&StartedFinalizingCallback, base::Closure(), true));
1201
1202 // This is expected to fail since we already triggered.
1203 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
1204 trigger_handle,
1205 base::Bind(&StartedFinalizingCallback, base::Closure(), false));
1206
1207 // Since we specified a delay in the scenario, we should still be tracing
1208 // at this point.
1209 EXPECT_TRUE(
1210 BackgroundTracingManagerImpl::GetInstance()->IsTracingForTesting());
1211
1212 BackgroundTracingManager::GetInstance()->FireTimerForTesting();
1213
1214 EXPECT_FALSE(
1215 BackgroundTracingManagerImpl::GetInstance()->IsTracingForTesting());
1216
1217 run_loop.Run();
1218
1219 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1);
1220 }
1221 }
1222
1151 // This tests a third trigger in reactive more does not start another trace. 1223 // This tests a third trigger in reactive more does not start another trace.
1152 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest, 1224 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
1153 ReactiveThirdTriggerTimeout) { 1225 ReactiveThirdTriggerTimeout) {
1154 { 1226 {
1155 SetupBackgroundTracingManager(); 1227 SetupBackgroundTracingManager();
1156 1228
1157 base::RunLoop run_loop; 1229 base::RunLoop run_loop;
1158 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper( 1230 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper(
1159 run_loop.QuitClosure()); 1231 run_loop.QuitClosure());
1160 1232
(...skipping 19 matching lines...) Expand all
1180 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( 1252 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
1181 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), false)); 1253 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), false));
1182 1254
1183 run_loop.Run(); 1255 run_loop.Run();
1184 1256
1185 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1); 1257 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1);
1186 } 1258 }
1187 } 1259 }
1188 1260
1189 } // namespace content 1261 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698