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); |
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 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1279 base::DictionaryValue dict; | 1280 base::DictionaryValue dict; |
1280 dict.SetString("mode", "REACTIVE_TRACING_MODE"); | 1281 dict.SetString("mode", "REACTIVE_TRACING_MODE"); |
1281 | 1282 |
1282 std::unique_ptr<base::ListValue> rules_list(new base::ListValue()); | 1283 std::unique_ptr<base::ListValue> rules_list(new base::ListValue()); |
1283 { | 1284 { |
1284 std::unique_ptr<base::DictionaryValue> rules_dict( | 1285 std::unique_ptr<base::DictionaryValue> rules_dict( |
1285 new base::DictionaryValue()); | 1286 new base::DictionaryValue()); |
1286 rules_dict->SetString("rule", | 1287 rules_dict->SetString("rule", |
1287 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL"); | 1288 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL"); |
1288 rules_dict->SetString("trigger_name", "reactive_test1"); | 1289 rules_dict->SetString("trigger_name", "reactive_test1"); |
| 1290 rules_dict->SetBoolean("stop_tracing_on_repeated_reactive", true); |
| 1291 rules_dict->SetInteger("trigger_delay", 10); |
1289 rules_dict->SetString("category", "BENCHMARK"); | 1292 rules_dict->SetString("category", "BENCHMARK"); |
1290 rules_list->Append(std::move(rules_dict)); | 1293 rules_list->Append(std::move(rules_dict)); |
1291 } | 1294 } |
1292 { | 1295 { |
1293 std::unique_ptr<base::DictionaryValue> rules_dict( | 1296 std::unique_ptr<base::DictionaryValue> rules_dict( |
1294 new base::DictionaryValue()); | 1297 new base::DictionaryValue()); |
1295 rules_dict->SetString("rule", | 1298 rules_dict->SetString("rule", |
1296 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL"); | 1299 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL"); |
1297 rules_dict->SetString("trigger_name", "reactive_test2"); | 1300 rules_dict->SetString("trigger_name", "reactive_test2"); |
| 1301 rules_dict->SetBoolean("stop_tracing_on_repeated_reactive", true); |
| 1302 rules_dict->SetInteger("trigger_delay", 10); |
1298 rules_dict->SetString("category", "BENCHMARK"); | 1303 rules_dict->SetString("category", "BENCHMARK"); |
1299 rules_list->Append(std::move(rules_dict)); | 1304 rules_list->Append(std::move(rules_dict)); |
1300 } | 1305 } |
1301 dict.Set("configs", std::move(rules_list)); | 1306 dict.Set("configs", std::move(rules_list)); |
1302 | 1307 |
1303 std::unique_ptr<BackgroundTracingConfig> config( | 1308 std::unique_ptr<BackgroundTracingConfig> config( |
1304 BackgroundTracingConfigImpl::FromDict(&dict)); | 1309 BackgroundTracingConfigImpl::FromDict(&dict)); |
1305 | 1310 |
1306 BackgroundTracingManager::TriggerHandle handle1 = | 1311 BackgroundTracingManager::TriggerHandle handle1 = |
1307 BackgroundTracingManager::GetInstance()->RegisterTriggerType( | 1312 BackgroundTracingManager::GetInstance()->RegisterTriggerType( |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1373 // third trigger to trigger again, fails as it is still gathering. | 1378 // third trigger to trigger again, fails as it is still gathering. |
1374 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( | 1379 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( |
1375 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), false)); | 1380 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), false)); |
1376 | 1381 |
1377 run_loop.Run(); | 1382 run_loop.Run(); |
1378 | 1383 |
1379 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1); | 1384 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1); |
1380 } | 1385 } |
1381 } | 1386 } |
1382 | 1387 |
| 1388 // This tests that reactive mode only terminates with a repeated trigger |
| 1389 // if the config specifies that it should. |
| 1390 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest, |
| 1391 ReactiveSecondTriggerIgnored) { |
| 1392 { |
| 1393 SetupBackgroundTracingManager(); |
| 1394 |
| 1395 base::RunLoop run_loop; |
| 1396 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper( |
| 1397 run_loop.QuitClosure()); |
| 1398 |
| 1399 base::DictionaryValue dict; |
| 1400 dict.SetString("mode", "REACTIVE_TRACING_MODE"); |
| 1401 |
| 1402 std::unique_ptr<base::ListValue> rules_list(new base::ListValue()); |
| 1403 { |
| 1404 std::unique_ptr<base::DictionaryValue> rules_dict( |
| 1405 new base::DictionaryValue()); |
| 1406 rules_dict->SetString("rule", |
| 1407 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL"); |
| 1408 rules_dict->SetString("trigger_name", "reactive_test"); |
| 1409 rules_dict->SetBoolean("stop_tracing_on_repeated_reactive", false); |
| 1410 rules_dict->SetInteger("trigger_delay", 10); |
| 1411 rules_dict->SetString("category", "BENCHMARK"); |
| 1412 rules_list->Append(std::move(rules_dict)); |
| 1413 } |
| 1414 dict.Set("configs", std::move(rules_list)); |
| 1415 |
| 1416 std::unique_ptr<BackgroundTracingConfig> config( |
| 1417 BackgroundTracingConfigImpl::FromDict(&dict)); |
| 1418 |
| 1419 BackgroundTracingManager::TriggerHandle trigger_handle = |
| 1420 BackgroundTracingManager::GetInstance()->RegisterTriggerType( |
| 1421 "reactive_test"); |
| 1422 |
| 1423 EXPECT_TRUE(BackgroundTracingManager::GetInstance()->SetActiveScenario( |
| 1424 std::move(config), upload_config_wrapper.get_receive_callback(), |
| 1425 BackgroundTracingManager::NO_DATA_FILTERING)); |
| 1426 |
| 1427 BackgroundTracingManager::GetInstance()->WhenIdle( |
| 1428 base::Bind(&DisableScenarioWhenIdle)); |
| 1429 |
| 1430 base::RunLoop wait_for_tracing_enabled; |
| 1431 static_cast<BackgroundTracingManagerImpl*>( |
| 1432 BackgroundTracingManager::GetInstance()) |
| 1433 ->SetTracingEnabledCallbackForTesting( |
| 1434 wait_for_tracing_enabled.QuitClosure()); |
| 1435 |
| 1436 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( |
| 1437 trigger_handle, |
| 1438 base::Bind(&StartedFinalizingCallback, base::Closure(), true)); |
| 1439 |
| 1440 wait_for_tracing_enabled.Run(); |
| 1441 |
| 1442 // This is expected to fail since we already triggered. |
| 1443 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( |
| 1444 trigger_handle, |
| 1445 base::Bind(&StartedFinalizingCallback, base::Closure(), false)); |
| 1446 |
| 1447 // Since we specified a delay in the scenario, we should still be tracing |
| 1448 // at this point. |
| 1449 EXPECT_TRUE( |
| 1450 BackgroundTracingManagerImpl::GetInstance()->IsTracingForTesting()); |
| 1451 |
| 1452 BackgroundTracingManager::GetInstance()->FireTimerForTesting(); |
| 1453 |
| 1454 EXPECT_FALSE( |
| 1455 BackgroundTracingManagerImpl::GetInstance()->IsTracingForTesting()); |
| 1456 |
| 1457 run_loop.Run(); |
| 1458 |
| 1459 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1); |
| 1460 } |
| 1461 } |
| 1462 |
1383 } // namespace content | 1463 } // namespace content |
OLD | NEW |