| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "components/browser_watcher/stability_report_extractor.h" | 5 #include "components/browser_watcher/stability_report_extractor.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/debug/activity_tracker.h" | 10 #include "base/debug/activity_tracker.h" |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 process_data.SetInt("int", -9999); | 334 process_data.SetInt("int", -9999); |
| 335 process_data.SetUint("uint", 9999); | 335 process_data.SetUint("uint", 9999); |
| 336 process_data.SetBool("bool", true); | 336 process_data.SetBool("bool", true); |
| 337 process_data.SetReference("ref", string1, strlen(string1)); | 337 process_data.SetReference("ref", string1, strlen(string1)); |
| 338 process_data.SetStringReference("sref", string2); | 338 process_data.SetStringReference("sref", string2); |
| 339 | 339 |
| 340 // Collect the stability report. | 340 // Collect the stability report. |
| 341 StabilityReport report; | 341 StabilityReport report; |
| 342 ASSERT_EQ(SUCCESS, Extract(debug_file_path(), &report)); | 342 ASSERT_EQ(SUCCESS, Extract(debug_file_path(), &report)); |
| 343 | 343 |
| 344 // Validate the report's user data. | 344 // We expect a single process. |
| 345 const auto& collected_data = report.global_data(); | 345 ASSERT_EQ(1, report.process_states_size()); |
| 346 |
| 347 // Validate the report contains the process' data. |
| 348 const auto& collected_data = report.process_states(0).data(); |
| 346 ASSERT_EQ(kInternalProcessDatums + 8U, collected_data.size()); | 349 ASSERT_EQ(kInternalProcessDatums + 8U, collected_data.size()); |
| 347 | 350 |
| 348 ASSERT_TRUE(base::ContainsKey(collected_data, "raw")); | 351 ASSERT_TRUE(base::ContainsKey(collected_data, "raw")); |
| 349 EXPECT_EQ(TypedValue::kBytesValue, collected_data.at("raw").value_case()); | 352 EXPECT_EQ(TypedValue::kBytesValue, collected_data.at("raw").value_case()); |
| 350 EXPECT_EQ("foo", collected_data.at("raw").bytes_value()); | 353 EXPECT_EQ("foo", collected_data.at("raw").bytes_value()); |
| 351 | 354 |
| 352 ASSERT_TRUE(base::ContainsKey(collected_data, "string")); | 355 ASSERT_TRUE(base::ContainsKey(collected_data, "string")); |
| 353 EXPECT_EQ(TypedValue::kStringValue, collected_data.at("string").value_case()); | 356 EXPECT_EQ(TypedValue::kStringValue, collected_data.at("string").value_case()); |
| 354 EXPECT_EQ("bar", collected_data.at("string").string_value()); | 357 EXPECT_EQ("bar", collected_data.at("string").string_value()); |
| 355 | 358 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL, | 392 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL, |
| 390 "", 3); | 393 "", 3); |
| 391 ActivityUserData& process_data = GlobalActivityTracker::Get()->process_data(); | 394 ActivityUserData& process_data = GlobalActivityTracker::Get()->process_data(); |
| 392 process_data.SetString("string", "bar"); | 395 process_data.SetString("string", "bar"); |
| 393 process_data.SetString("FieldTrial.string", "bar"); | 396 process_data.SetString("FieldTrial.string", "bar"); |
| 394 process_data.SetString("FieldTrial.foo", "bar"); | 397 process_data.SetString("FieldTrial.foo", "bar"); |
| 395 | 398 |
| 396 // Collect the stability report. | 399 // Collect the stability report. |
| 397 StabilityReport report; | 400 StabilityReport report; |
| 398 ASSERT_EQ(SUCCESS, Extract(debug_file_path(), &report)); | 401 ASSERT_EQ(SUCCESS, Extract(debug_file_path(), &report)); |
| 402 ASSERT_EQ(1, report.process_states_size()); |
| 399 | 403 |
| 400 // Validate the report's experiment and global data. | 404 // Validate the report's experiment and global data. |
| 401 ASSERT_EQ(2, report.field_trials_size()); | 405 ASSERT_EQ(2, report.field_trials_size()); |
| 402 EXPECT_NE(0U, report.field_trials(0).name_id()); | 406 EXPECT_NE(0U, report.field_trials(0).name_id()); |
| 403 EXPECT_NE(0U, report.field_trials(0).group_id()); | 407 EXPECT_NE(0U, report.field_trials(0).group_id()); |
| 404 EXPECT_NE(0U, report.field_trials(1).name_id()); | 408 EXPECT_NE(0U, report.field_trials(1).name_id()); |
| 405 EXPECT_EQ(report.field_trials(0).group_id(), | 409 EXPECT_EQ(report.field_trials(0).group_id(), |
| 406 report.field_trials(1).group_id()); | 410 report.field_trials(1).group_id()); |
| 407 | 411 |
| 408 // Expect 1 key/value pair. | 412 // Expect 1 key/value pair. |
| 409 const auto& collected_data = report.global_data(); | 413 const auto& collected_data = report.process_states(0).data(); |
| 410 EXPECT_EQ(kInternalProcessDatums + 1U, collected_data.size()); | 414 EXPECT_EQ(kInternalProcessDatums + 1U, collected_data.size()); |
| 411 EXPECT_TRUE(base::ContainsKey(collected_data, "string")); | 415 EXPECT_TRUE(base::ContainsKey(collected_data, "string")); |
| 412 } | 416 } |
| 413 | 417 |
| 414 TEST_F(StabilityReportExtractorTest, ModuleCollection) { | 418 TEST_F(StabilityReportExtractorTest, ModuleCollection) { |
| 415 // Record some module information. | 419 // Record some module information. |
| 416 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL, | 420 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL, |
| 417 "", 3); | 421 "", 3); |
| 418 | 422 |
| 419 base::debug::GlobalActivityTracker::ModuleInfo module_info = {}; | 423 base::debug::GlobalActivityTracker::ModuleInfo module_info = {}; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 448 EXPECT_EQ("CAFECAFE2d000", collected_module.code_identifier()); | 452 EXPECT_EQ("CAFECAFE2d000", collected_module.code_identifier()); |
| 449 EXPECT_EQ(module_info.debug_file, collected_module.debug_file()); | 453 EXPECT_EQ(module_info.debug_file, collected_module.debug_file()); |
| 450 EXPECT_EQ("1122334455667788ABCD0123456789AB1", | 454 EXPECT_EQ("1122334455667788ABCD0123456789AB1", |
| 451 collected_module.debug_identifier()); | 455 collected_module.debug_identifier()); |
| 452 EXPECT_EQ("", collected_module.version()); | 456 EXPECT_EQ("", collected_module.version()); |
| 453 EXPECT_EQ(0LL, collected_module.shrink_down_delta()); | 457 EXPECT_EQ(0LL, collected_module.shrink_down_delta()); |
| 454 EXPECT_EQ(!module_info.is_loaded, collected_module.is_unloaded()); | 458 EXPECT_EQ(!module_info.is_loaded, collected_module.is_unloaded()); |
| 455 } | 459 } |
| 456 | 460 |
| 457 } // namespace browser_watcher | 461 } // namespace browser_watcher |
| OLD | NEW |