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 <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 Loading... |
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); | |
135 rules_dict->SetString("category", "BENCHMARK"); | 134 rules_dict->SetString("category", "BENCHMARK"); |
136 rules_list->Append(std::move(rules_dict)); | 135 rules_list->Append(std::move(rules_dict)); |
137 } | 136 } |
138 dict.Set("configs", std::move(rules_list)); | 137 dict.Set("configs", std::move(rules_list)); |
139 | 138 |
140 std::unique_ptr<BackgroundTracingConfig> config( | 139 std::unique_ptr<BackgroundTracingConfig> config( |
141 BackgroundTracingConfigImpl::FromDict(&dict)); | 140 BackgroundTracingConfigImpl::FromDict(&dict)); |
142 | 141 |
143 EXPECT_TRUE(config); | 142 EXPECT_TRUE(config); |
144 return config; | 143 return config; |
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 base::DictionaryValue dict; | 1092 base::DictionaryValue dict; |
1094 dict.SetString("mode", "REACTIVE_TRACING_MODE"); | 1093 dict.SetString("mode", "REACTIVE_TRACING_MODE"); |
1095 | 1094 |
1096 std::unique_ptr<base::ListValue> rules_list(new base::ListValue()); | 1095 std::unique_ptr<base::ListValue> rules_list(new base::ListValue()); |
1097 { | 1096 { |
1098 std::unique_ptr<base::DictionaryValue> rules_dict( | 1097 std::unique_ptr<base::DictionaryValue> rules_dict( |
1099 new base::DictionaryValue()); | 1098 new base::DictionaryValue()); |
1100 rules_dict->SetString("rule", | 1099 rules_dict->SetString("rule", |
1101 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL"); | 1100 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL"); |
1102 rules_dict->SetString("trigger_name", "reactive_test1"); | 1101 rules_dict->SetString("trigger_name", "reactive_test1"); |
1103 rules_dict->SetBoolean("stop_tracing_on_repeated_reactive", true); | |
1104 rules_dict->SetInteger("trigger_delay", 10); | |
1105 rules_dict->SetString("category", "BENCHMARK"); | 1102 rules_dict->SetString("category", "BENCHMARK"); |
1106 rules_list->Append(std::move(rules_dict)); | 1103 rules_list->Append(std::move(rules_dict)); |
1107 } | 1104 } |
1108 { | 1105 { |
1109 std::unique_ptr<base::DictionaryValue> rules_dict( | 1106 std::unique_ptr<base::DictionaryValue> rules_dict( |
1110 new base::DictionaryValue()); | 1107 new base::DictionaryValue()); |
1111 rules_dict->SetString("rule", | 1108 rules_dict->SetString("rule", |
1112 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL"); | 1109 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL"); |
1113 rules_dict->SetString("trigger_name", "reactive_test2"); | 1110 rules_dict->SetString("trigger_name", "reactive_test2"); |
1114 rules_dict->SetBoolean("stop_tracing_on_repeated_reactive", true); | |
1115 rules_dict->SetInteger("trigger_delay", 10); | |
1116 rules_dict->SetString("category", "BENCHMARK"); | 1111 rules_dict->SetString("category", "BENCHMARK"); |
1117 rules_list->Append(std::move(rules_dict)); | 1112 rules_list->Append(std::move(rules_dict)); |
1118 } | 1113 } |
1119 dict.Set("configs", std::move(rules_list)); | 1114 dict.Set("configs", std::move(rules_list)); |
1120 | 1115 |
1121 std::unique_ptr<BackgroundTracingConfig> config( | 1116 std::unique_ptr<BackgroundTracingConfig> config( |
1122 BackgroundTracingConfigImpl::FromDict(&dict)); | 1117 BackgroundTracingConfigImpl::FromDict(&dict)); |
1123 | 1118 |
1124 BackgroundTracingManager::TriggerHandle handle1 = | 1119 BackgroundTracingManager::TriggerHandle handle1 = |
1125 BackgroundTracingManager::GetInstance()->RegisterTriggerType( | 1120 BackgroundTracingManager::GetInstance()->RegisterTriggerType( |
(...skipping 20 matching lines...) Expand all Loading... |
1146 // second trigger to terminate. | 1141 // second trigger to terminate. |
1147 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( | 1142 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( |
1148 handle1, base::Bind(&StartedFinalizingCallback, base::Closure(), true)); | 1143 handle1, base::Bind(&StartedFinalizingCallback, base::Closure(), true)); |
1149 | 1144 |
1150 run_loop.Run(); | 1145 run_loop.Run(); |
1151 | 1146 |
1152 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1); | 1147 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1); |
1153 } | 1148 } |
1154 } | 1149 } |
1155 | 1150 |
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 | |
1223 // This tests a third trigger in reactive more does not start another trace. | 1151 // This tests a third trigger in reactive more does not start another trace. |
1224 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest, | 1152 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest, |
1225 ReactiveThirdTriggerTimeout) { | 1153 ReactiveThirdTriggerTimeout) { |
1226 { | 1154 { |
1227 SetupBackgroundTracingManager(); | 1155 SetupBackgroundTracingManager(); |
1228 | 1156 |
1229 base::RunLoop run_loop; | 1157 base::RunLoop run_loop; |
1230 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper( | 1158 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper( |
1231 run_loop.QuitClosure()); | 1159 run_loop.QuitClosure()); |
1232 | 1160 |
(...skipping 19 matching lines...) Expand all Loading... |
1252 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( | 1180 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( |
1253 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), false)); | 1181 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), false)); |
1254 | 1182 |
1255 run_loop.Run(); | 1183 run_loop.Run(); |
1256 | 1184 |
1257 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1); | 1185 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1); |
1258 } | 1186 } |
1259 } | 1187 } |
1260 | 1188 |
1261 } // namespace content | 1189 } // namespace content |
OLD | NEW |