| Index: components/browser_watcher/stability_report_extractor_unittest.cc
|
| diff --git a/components/browser_watcher/postmortem_report_collector_unittest.cc b/components/browser_watcher/stability_report_extractor_unittest.cc
|
| similarity index 47%
|
| copy from components/browser_watcher/postmortem_report_collector_unittest.cc
|
| copy to components/browser_watcher/stability_report_extractor_unittest.cc
|
| index bd615e6eb536bc8d20cb8e73ba0e8a731efd9c63..63dd24d4511174b9e5ff0c5fa0568277dd4241a0 100644
|
| --- a/components/browser_watcher/postmortem_report_collector_unittest.cc
|
| +++ b/components/browser_watcher/stability_report_extractor_unittest.cc
|
| @@ -1,34 +1,20 @@
|
| -// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "components/browser_watcher/postmortem_report_collector.h"
|
| -
|
| -#include <stdint.h>
|
| +#include "components/browser_watcher/stability_report_extractor.h"
|
|
|
| #include <memory>
|
| -#include <set>
|
| -#include <string>
|
| #include <utility>
|
| -#include <vector>
|
|
|
| -#include "base/debug/activity_analyzer.h"
|
| #include "base/debug/activity_tracker.h"
|
| #include "base/files/file.h"
|
| #include "base/files/file_path.h"
|
| -#include "base/files/file_util.h"
|
| #include "base/files/memory_mapped_file.h"
|
| -#include "base/files/scoped_file.h"
|
| #include "base/files/scoped_temp_dir.h"
|
| #include "base/memory/ptr_util.h"
|
| #include "base/metrics/persistent_memory_allocator.h"
|
| -#include "base/process/process_handle.h"
|
| #include "base/stl_util.h"
|
| -#include "base/test/histogram_tester.h"
|
| -#include "base/threading/platform_thread.h"
|
| -#include "components/browser_watcher/stability_data_names.h"
|
| -#include "components/browser_watcher/stability_report_extractor.h"
|
| -#include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "third_party/crashpad/crashpad/client/crash_report_database.h"
|
|
|
| @@ -45,330 +31,12 @@ using base::FilePersistentMemoryAllocator;
|
| using base::MemoryMappedFile;
|
| using base::PersistentMemoryAllocator;
|
| using base::WrapUnique;
|
| -using crashpad::CrashReportDatabase;
|
| -using crashpad::Settings;
|
| -using crashpad::UUID;
|
| -using testing::_;
|
| -using testing::DoAll;
|
| -using testing::Return;
|
| -using testing::SetArgPointee;
|
|
|
| namespace {
|
|
|
| -TEST(PostmortemDeleterTest, BasicTest) {
|
| - base::HistogramTester histogram_tester;
|
| - base::ScopedTempDir temp_dir;
|
| - ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
|
| -
|
| - // Create three files.
|
| - FilePath path_one = temp_dir.GetPath().AppendASCII("a.pma");
|
| - FilePath path_two = temp_dir.GetPath().AppendASCII("b.pma");
|
| - FilePath path_three = temp_dir.GetPath().AppendASCII("c.pma");
|
| -
|
| - std::vector<FilePath> stability_files = {path_one, path_two, path_three};
|
| -
|
| - for (const FilePath& path : stability_files) {
|
| - {
|
| - base::ScopedFILE file(base::OpenFile(path, "w"));
|
| - ASSERT_NE(file.get(), nullptr);
|
| - }
|
| - ASSERT_TRUE(base::PathExists(path));
|
| - }
|
| -
|
| - // Open one stability file to prevent its deletion.
|
| - base::ScopedFILE file(base::OpenFile(path_two, "w"));
|
| - ASSERT_NE(file.get(), nullptr);
|
| -
|
| - // Validate deletion and metrics.
|
| - PostmortemDeleter deleter;
|
| - deleter.Process(stability_files);
|
| -
|
| - ASSERT_FALSE(base::PathExists(path_one));
|
| - ASSERT_FALSE(base::PathExists(path_three));
|
| - histogram_tester.ExpectBucketCount("ActivityTracker.Collect.Status",
|
| - UNCLEAN_SHUTDOWN, 2);
|
| -
|
| - ASSERT_TRUE(base::PathExists(path_two));
|
| - histogram_tester.ExpectBucketCount("ActivityTracker.Collect.Status",
|
| - DEBUG_FILE_DELETION_FAILED, 1);
|
| -
|
| - std::vector<CollectionStatus> unexpected_statuses = {
|
| - NONE,
|
| - SUCCESS,
|
| - ANALYZER_CREATION_FAILED,
|
| - DEBUG_FILE_NO_DATA,
|
| - PREPARE_NEW_CRASH_REPORT_FAILED,
|
| - WRITE_TO_MINIDUMP_FAILED,
|
| - FINISHED_WRITING_CRASH_REPORT_FAILED,
|
| - COLLECTION_ATTEMPT};
|
| - for (CollectionStatus status : unexpected_statuses) {
|
| - histogram_tester.ExpectBucketCount("ActivityTracker.Collect.Status", status,
|
| - 0);
|
| - }
|
| -}
|
| -
|
| -const char kProductName[] = "TestProduct";
|
| -const char kVersionNumber[] = "TestVersionNumber";
|
| -const char kChannelName[] = "TestChannel";
|
| -
|
| // The tracker creates some data entries internally.
|
| const size_t kInternalProcessDatums = 1;
|
|
|
| -void ContainsKeyValue(
|
| - const google::protobuf::Map<std::string, TypedValue>& data,
|
| - const std::string& key,
|
| - const std::string& value) {
|
| - auto it = data.find(key);
|
| - ASSERT_TRUE(it != data.end());
|
| - EXPECT_EQ(TypedValue::kStringValue, it->second.value_case());
|
| - EXPECT_EQ(value, it->second.string_value());
|
| -}
|
| -
|
| -// Exposes a public constructor in order to create a dummy database.
|
| -class MockCrashReportDatabase : public CrashReportDatabase {
|
| - public:
|
| - MockCrashReportDatabase() {}
|
| - MOCK_METHOD0(GetSettings, Settings*());
|
| - MOCK_METHOD1(PrepareNewCrashReport,
|
| - CrashReportDatabase::CrashReportDatabase::OperationStatus(
|
| - NewReport** report));
|
| - MOCK_METHOD2(FinishedWritingCrashReport,
|
| - CrashReportDatabase::CrashReportDatabase::OperationStatus(
|
| - CrashReportDatabase::NewReport* report,
|
| - crashpad::UUID* uuid));
|
| - MOCK_METHOD1(ErrorWritingCrashReport,
|
| - CrashReportDatabase::CrashReportDatabase::OperationStatus(
|
| - NewReport* report));
|
| - MOCK_METHOD2(LookUpCrashReport,
|
| - CrashReportDatabase::CrashReportDatabase::OperationStatus(
|
| - const UUID& uuid,
|
| - Report* report));
|
| - MOCK_METHOD1(
|
| - GetPendingReports,
|
| - CrashReportDatabase::OperationStatus(std::vector<Report>* reports));
|
| - MOCK_METHOD1(
|
| - GetCompletedReports,
|
| - CrashReportDatabase::OperationStatus(std::vector<Report>* reports));
|
| - MOCK_METHOD2(GetReportForUploading,
|
| - CrashReportDatabase::OperationStatus(const UUID& uuid,
|
| - const Report** report));
|
| - MOCK_METHOD3(RecordUploadAttempt,
|
| - CrashReportDatabase::OperationStatus(const Report* report,
|
| - bool successful,
|
| - const std::string& id));
|
| - MOCK_METHOD2(SkipReportUpload,
|
| - CrashReportDatabase::OperationStatus(
|
| - const UUID& uuid,
|
| - crashpad::Metrics::CrashSkippedReason reason));
|
| - MOCK_METHOD1(DeleteReport,
|
| - CrashReportDatabase::OperationStatus(const UUID& uuid));
|
| - MOCK_METHOD1(RequestUpload,
|
| - CrashReportDatabase::OperationStatus(const UUID& uuid));
|
| -};
|
| -
|
| -class MockPostmortemReportCollector : public PostmortemReportCollector {
|
| - public:
|
| - explicit MockPostmortemReportCollector(CrashReportDatabase* crash_database)
|
| - : PostmortemReportCollector(kProductName,
|
| - kVersionNumber,
|
| - kChannelName,
|
| - crash_database,
|
| - nullptr) {}
|
| -
|
| - MOCK_METHOD2(CollectOneReport,
|
| - CollectionStatus(const FilePath&, StabilityReport* report));
|
| - MOCK_METHOD4(WriteReportToMinidump,
|
| - bool(StabilityReport* report,
|
| - const crashpad::UUID& client_id,
|
| - const crashpad::UUID& report_id,
|
| - base::PlatformFile minidump_file));
|
| -};
|
| -
|
| -class MockSystemSessionAnalyzer : public SystemSessionAnalyzer {
|
| - public:
|
| - MockSystemSessionAnalyzer() : SystemSessionAnalyzer(10U) {}
|
| - MOCK_METHOD1(IsSessionUnclean, Status(base::Time timestamp));
|
| -};
|
| -
|
| -// Checks if two proto messages are the same based on their serializations. Note
|
| -// this only works if serialization is deterministic, which is not guaranteed.
|
| -// In practice, serialization is deterministic (even for protocol buffers with
|
| -// maps) and such matchers are common in the Chromium code base. Also note that
|
| -// in the context of this test, false positive matches are the problem and these
|
| -// are not possible (otherwise serialization would be ambiguous). False
|
| -// negatives would lead to test failure and developer action. Alternatives are:
|
| -// 1) a generic matcher (likely not possible without reflections, missing from
|
| -// lite runtime), 2) a specialized matcher or 3) implementing deterministic
|
| -// serialization.
|
| -// TODO(manzagop): switch a matcher with guarantees.
|
| -MATCHER_P(EqualsProto, message, "") {
|
| - std::string expected_serialized;
|
| - std::string actual_serialized;
|
| - message.SerializeToString(&expected_serialized);
|
| - arg.SerializeToString(&actual_serialized);
|
| - return expected_serialized == actual_serialized;
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| -class PostmortemReportCollectorProcessTest : public testing::Test {
|
| - public:
|
| - void SetUpTest(bool system_session_clean, bool expect_write_dump) {
|
| - collector_.reset(new MockPostmortemReportCollector(&database_));
|
| -
|
| - // Create a dummy debug file.
|
| - ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
|
| - debug_file_ = temp_dir_.GetPath().AppendASCII("foo-1.pma");
|
| - {
|
| - base::ScopedFILE file(base::OpenFile(debug_file_, "w"));
|
| - ASSERT_NE(file.get(), nullptr);
|
| - }
|
| - ASSERT_TRUE(base::PathExists(debug_file_));
|
| -
|
| - EXPECT_CALL(database_, GetSettings()).Times(1).WillOnce(Return(nullptr));
|
| -
|
| - // Expect a single collection call.
|
| - StabilityReport report;
|
| - report.mutable_system_state()->set_session_state(
|
| - system_session_clean ? SystemState::CLEAN : SystemState::UNCLEAN);
|
| - EXPECT_CALL(*collector_, CollectOneReport(debug_file_, _))
|
| - .Times(1)
|
| - .WillOnce(DoAll(SetArgPointee<1>(report), Return(SUCCESS)));
|
| -
|
| - if (!expect_write_dump)
|
| - return;
|
| -
|
| - // Expect the call to write the proto to a minidump. This involves
|
| - // requesting a report from the crashpad database, writing the report, then
|
| - // finalizing it with the database.
|
| - FilePath minidump_path = temp_dir_.GetPath().AppendASCII("foo-1.dmp");
|
| - base::File minidump_file(
|
| - minidump_path, base::File::FLAG_CREATE | base::File::File::FLAG_WRITE);
|
| - crashpad::UUID new_report_uuid;
|
| - new_report_uuid.InitializeWithNew();
|
| - crashpad_report_ = {minidump_file.GetPlatformFile(), new_report_uuid,
|
| - minidump_path};
|
| - EXPECT_CALL(database_, PrepareNewCrashReport(_))
|
| - .Times(1)
|
| - .WillOnce(DoAll(SetArgPointee<0>(&crashpad_report_),
|
| - Return(CrashReportDatabase::kNoError)));
|
| -
|
| - EXPECT_CALL(*collector_,
|
| - WriteReportToMinidump(_, _, _, minidump_file.GetPlatformFile()))
|
| - .Times(1)
|
| - .WillOnce(Return(true));
|
| - }
|
| - void ValidateHistograms(int unclean_cnt, int unclean_system_cnt) {
|
| - histogram_tester_.ExpectBucketCount("ActivityTracker.Collect.Status",
|
| - UNCLEAN_SHUTDOWN, unclean_cnt);
|
| - histogram_tester_.ExpectBucketCount("ActivityTracker.Collect.Status",
|
| - UNCLEAN_SESSION, unclean_system_cnt);
|
| - }
|
| - void CollectReports(bool is_session_clean) {
|
| - SetUpTest(is_session_clean, true);
|
| -
|
| - EXPECT_CALL(database_, FinishedWritingCrashReport(&crashpad_report_, _))
|
| - .Times(1)
|
| - .WillOnce(Return(CrashReportDatabase::kNoError));
|
| -
|
| - // Run the test.
|
| - std::vector<FilePath> debug_files{debug_file_};
|
| - collector_->Process(debug_files);
|
| - ASSERT_FALSE(base::PathExists(debug_file_));
|
| - }
|
| -
|
| - protected:
|
| - base::HistogramTester histogram_tester_;
|
| - base::ScopedTempDir temp_dir_;
|
| - FilePath debug_file_;
|
| - MockCrashReportDatabase database_;
|
| - std::unique_ptr<MockPostmortemReportCollector> collector_;
|
| - CrashReportDatabase::NewReport crashpad_report_;
|
| -};
|
| -
|
| -TEST_F(PostmortemReportCollectorProcessTest, ProcessCleanSession) {
|
| - CollectReports(true);
|
| - int expected_unclean = 1;
|
| - int expected_system_unclean = 0;
|
| - ValidateHistograms(expected_unclean, expected_system_unclean);
|
| -}
|
| -
|
| -TEST_F(PostmortemReportCollectorProcessTest, ProcessUncleanSession) {
|
| - CollectReports(false);
|
| - int expected_unclean = 1;
|
| - int expected_system_unclean = 1;
|
| - ValidateHistograms(expected_unclean, expected_system_unclean);
|
| -}
|
| -
|
| -TEST_F(PostmortemReportCollectorProcessTest, ProcessStuckFile) {
|
| - bool system_session_clean = true;
|
| - bool expect_write_dump = false;
|
| - SetUpTest(system_session_clean, expect_write_dump);
|
| -
|
| - // Open the stability debug file to prevent its deletion.
|
| - base::ScopedFILE file(base::OpenFile(debug_file_, "w"));
|
| - ASSERT_NE(file.get(), nullptr);
|
| -
|
| - // Run the test.
|
| - std::vector<FilePath> debug_files{debug_file_};
|
| - collector_->Process(debug_files);
|
| - ASSERT_TRUE(base::PathExists(debug_file_));
|
| -
|
| - histogram_tester_.ExpectBucketCount("ActivityTracker.Collect.Status",
|
| - DEBUG_FILE_DELETION_FAILED, 1);
|
| - int expected_unclean = 0;
|
| - int expected_system_unclean = 0;
|
| - ValidateHistograms(expected_unclean, expected_system_unclean);
|
| -}
|
| -
|
| -TEST(PostmortemReportCollectorTest, CollectEmptyFile) {
|
| - // Create an empty file.
|
| - base::ScopedTempDir temp_dir;
|
| - ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
|
| - FilePath file_path = temp_dir.GetPath().AppendASCII("empty.pma");
|
| - {
|
| - base::ScopedFILE file(base::OpenFile(file_path, "w"));
|
| - ASSERT_NE(file.get(), nullptr);
|
| - }
|
| - ASSERT_TRUE(PathExists(file_path));
|
| -
|
| - // Validate collection: an empty file cannot suppport an analyzer.
|
| - MockCrashReportDatabase crash_db;
|
| - PostmortemReportCollector collector(kProductName, kVersionNumber,
|
| - kChannelName, &crash_db, nullptr);
|
| - StabilityReport report;
|
| - ASSERT_EQ(ANALYZER_CREATION_FAILED,
|
| - collector.CollectOneReport(file_path, &report));
|
| -}
|
| -
|
| -TEST(PostmortemReportCollectorTest, CollectRandomFile) {
|
| - // Create a file with content we don't expect to be valid for a debug file.
|
| - base::ScopedTempDir temp_dir;
|
| - ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
|
| - FilePath file_path = temp_dir.GetPath().AppendASCII("invalid_content.pma");
|
| - {
|
| - base::ScopedFILE file(base::OpenFile(file_path, "w"));
|
| - ASSERT_NE(file.get(), nullptr);
|
| - // Assuming this size is greater than the minimum size of a debug file.
|
| - std::vector<uint8_t> data(1024);
|
| - for (size_t i = 0; i < data.size(); ++i)
|
| - data[i] = i % UINT8_MAX;
|
| - ASSERT_EQ(data.size(),
|
| - fwrite(&data.at(0), sizeof(uint8_t), data.size(), file.get()));
|
| - }
|
| - ASSERT_TRUE(PathExists(file_path));
|
| -
|
| - // Validate collection: random content appears as though there is not
|
| - // stability data.
|
| - MockCrashReportDatabase crash_db;
|
| - PostmortemReportCollector collector(kProductName, kVersionNumber,
|
| - kChannelName, &crash_db, nullptr);
|
| - StabilityReport report;
|
| - ASSERT_NE(SUCCESS, collector.CollectOneReport(file_path, &report));
|
| -}
|
| -
|
| -namespace {
|
| -
|
| // Parameters for the activity tracking.
|
| const size_t kFileSize = 64 << 10; // 64 KiB
|
| const int kStackDepth = 6;
|
| @@ -389,7 +57,7 @@ const int32_t kGenericData = 47;
|
| // Sets up a file backed thread tracker for direct access. A
|
| // GlobalActivityTracker is not created, meaning there is no risk of
|
| // the instrumentation interfering with the file's content.
|
| -class PostmortemReportCollectorCollectionTest : public testing::Test {
|
| +class StabilityReportExtractorThreadTrackerTest : public testing::Test {
|
| public:
|
| // Create a proper debug file.
|
| void SetUp() override {
|
| @@ -461,7 +129,7 @@ class PostmortemReportCollectorCollectionTest : public testing::Test {
|
| std::unique_ptr<ThreadActivityTracker> tracker_;
|
| };
|
|
|
| -TEST_F(PostmortemReportCollectorCollectionTest, CollectSuccess) {
|
| +TEST_F(StabilityReportExtractorThreadTrackerTest, CollectSuccess) {
|
| // Create some activity data.
|
| tracker_->PushActivity(reinterpret_cast<void*>(kTaskOrigin),
|
| base::debug::Activity::ACT_TASK_RUN,
|
| @@ -491,11 +159,8 @@ TEST_F(PostmortemReportCollectorCollectionTest, CollectSuccess) {
|
| user_data->SetInt("some_int", 42);
|
|
|
| // Validate collection returns the expected report.
|
| - MockCrashReportDatabase crash_db;
|
| - PostmortemReportCollector collector(kProductName, kVersionNumber,
|
| - kChannelName, &crash_db, nullptr);
|
| StabilityReport report;
|
| - ASSERT_EQ(SUCCESS, collector.CollectOneReport(debug_file_path(), &report));
|
| + ASSERT_EQ(SUCCESS, Extract(debug_file_path(), &report));
|
|
|
| // Validate the report.
|
| ASSERT_EQ(1, report.process_states_size());
|
| @@ -558,13 +223,13 @@ TEST_F(PostmortemReportCollectorCollectionTest, CollectSuccess) {
|
| }
|
| }
|
|
|
| -class PostmortemReportCollectorCollectionFromGlobalTrackerTest
|
| - : public testing::Test {
|
| +// Tests stability report extraction.
|
| +class StabilityReportExtractorTest : public testing::Test {
|
| public:
|
| const int kMemorySize = 1 << 20; // 1MiB
|
|
|
| - PostmortemReportCollectorCollectionFromGlobalTrackerTest() {}
|
| - ~PostmortemReportCollectorCollectionFromGlobalTrackerTest() override {
|
| + StabilityReportExtractorTest() {}
|
| + ~StabilityReportExtractorTest() override {
|
| GlobalActivityTracker* global_tracker = GlobalActivityTracker::Get();
|
| if (global_tracker) {
|
| global_tracker->ReleaseTrackerForCurrentThreadForTesting();
|
| @@ -587,8 +252,7 @@ class PostmortemReportCollectorCollectionFromGlobalTrackerTest
|
| FilePath debug_file_path_;
|
| };
|
|
|
| -TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest,
|
| - LogCollection) {
|
| +TEST_F(StabilityReportExtractorTest, LogCollection) {
|
| // Record some log messages.
|
| GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL,
|
| "", 3);
|
| @@ -596,11 +260,8 @@ TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest,
|
| GlobalActivityTracker::Get()->RecordLogMessage("foo bar");
|
|
|
| // Collect the stability report.
|
| - MockCrashReportDatabase crash_db;
|
| - PostmortemReportCollector collector(kProductName, kVersionNumber,
|
| - kChannelName, &crash_db, nullptr);
|
| StabilityReport report;
|
| - ASSERT_EQ(SUCCESS, collector.CollectOneReport(debug_file_path(), &report));
|
| + ASSERT_EQ(SUCCESS, Extract(debug_file_path(), &report));
|
|
|
| // Validate the report's log content.
|
| ASSERT_EQ(2, report.log_messages_size());
|
| @@ -608,8 +269,7 @@ TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest,
|
| ASSERT_EQ("foo bar", report.log_messages(1));
|
| }
|
|
|
| -TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest,
|
| - ProcessUserDataCollection) {
|
| +TEST_F(StabilityReportExtractorTest, ProcessUserDataCollection) {
|
| const char string1[] = "foo";
|
| const char string2[] = "bar";
|
|
|
| @@ -630,15 +290,12 @@ TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest,
|
| process_data.SetStringReference("sref", string2);
|
|
|
| // Collect the stability report.
|
| - MockCrashReportDatabase crash_db;
|
| - PostmortemReportCollector collector(kProductName, kVersionNumber,
|
| - kChannelName, &crash_db, nullptr);
|
| StabilityReport report;
|
| - ASSERT_EQ(SUCCESS, collector.CollectOneReport(debug_file_path(), &report));
|
| + ASSERT_EQ(SUCCESS, Extract(debug_file_path(), &report));
|
|
|
| // Validate the report's user data.
|
| const auto& collected_data = report.global_data();
|
| - ASSERT_EQ(kInternalProcessDatums + 12U, collected_data.size());
|
| + ASSERT_EQ(kInternalProcessDatums + 8U, collected_data.size());
|
|
|
| ASSERT_TRUE(base::ContainsKey(collected_data, "raw"));
|
| EXPECT_EQ(TypedValue::kBytesValue, collected_data.at("raw").value_case());
|
| @@ -677,20 +334,9 @@ TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest,
|
| collected_data.at("sref").string_reference();
|
| EXPECT_EQ(reinterpret_cast<uintptr_t>(string2), sref.address());
|
| EXPECT_EQ(strlen(string2), static_cast<uint64_t>(sref.size()));
|
| -
|
| - // Reporter's version details.
|
| - ContainsKeyValue(collected_data, kStabilityReporterProduct, kProductName);
|
| - ContainsKeyValue(collected_data, kStabilityReporterChannel, kChannelName);
|
| -#if defined(ARCH_CPU_X86)
|
| - ContainsKeyValue(collected_data, kStabilityReporterPlatform, "Win32");
|
| -#elif defined(ARCH_CPU_X86_64)
|
| - ContainsKeyValue(collected_data, kStabilityReporterPlatform, "Win64");
|
| -#endif
|
| - ContainsKeyValue(collected_data, kStabilityReporterVersion, kVersionNumber);
|
| }
|
|
|
| -TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest,
|
| - FieldTrialCollection) {
|
| +TEST_F(StabilityReportExtractorTest, FieldTrialCollection) {
|
| // Record some data.
|
| GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL,
|
| "", 3);
|
| @@ -700,11 +346,8 @@ TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest,
|
| process_data.SetString("FieldTrial.foo", "bar");
|
|
|
| // Collect the stability report.
|
| - MockCrashReportDatabase crash_db;
|
| - PostmortemReportCollector collector(kProductName, kVersionNumber,
|
| - kChannelName, &crash_db, nullptr);
|
| StabilityReport report;
|
| - ASSERT_EQ(SUCCESS, collector.CollectOneReport(debug_file_path(), &report));
|
| + ASSERT_EQ(SUCCESS, Extract(debug_file_path(), &report));
|
|
|
| // Validate the report's experiment and global data.
|
| ASSERT_EQ(2, report.field_trials_size());
|
| @@ -714,14 +357,13 @@ TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest,
|
| EXPECT_EQ(report.field_trials(0).group_id(),
|
| report.field_trials(1).group_id());
|
|
|
| - // Expect 5 key/value pairs (including product details).
|
| + // Expect 1 key/value pair.
|
| const auto& collected_data = report.global_data();
|
| - EXPECT_EQ(kInternalProcessDatums + 5U, collected_data.size());
|
| + EXPECT_EQ(kInternalProcessDatums + 1U, collected_data.size());
|
| EXPECT_TRUE(base::ContainsKey(collected_data, "string"));
|
| }
|
|
|
| -TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest,
|
| - ModuleCollection) {
|
| +TEST_F(StabilityReportExtractorTest, ModuleCollection) {
|
| // Record some module information.
|
| GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL,
|
| "", 3);
|
| @@ -742,11 +384,8 @@ TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest,
|
| GlobalActivityTracker::Get()->RecordModuleInfo(module_info);
|
|
|
| // Collect the stability report.
|
| - MockCrashReportDatabase crash_db;
|
| - PostmortemReportCollector collector(kProductName, kVersionNumber,
|
| - kChannelName, &crash_db, nullptr);
|
| StabilityReport report;
|
| - ASSERT_EQ(SUCCESS, collector.CollectOneReport(debug_file_path(), &report));
|
| + ASSERT_EQ(SUCCESS, Extract(debug_file_path(), &report));
|
|
|
| // Validate the report's modules content.
|
| ASSERT_EQ(1, report.process_states_size());
|
| @@ -767,28 +406,4 @@ TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest,
|
| EXPECT_EQ(!module_info.is_loaded, collected_module.is_unloaded());
|
| }
|
|
|
| -TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest,
|
| - SystemStateTest) {
|
| - // Setup.
|
| - GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL,
|
| - "", 3);
|
| - ActivityUserData& process_data = GlobalActivityTracker::Get()->process_data();
|
| - process_data.SetInt(kStabilityStartTimestamp, 12345LL);
|
| -
|
| - // Collect.
|
| - MockSystemSessionAnalyzer analyzer;
|
| - EXPECT_CALL(analyzer,
|
| - IsSessionUnclean(base::Time::FromInternalValue(12345LL)))
|
| - .Times(1)
|
| - .WillOnce(Return(SystemSessionAnalyzer::CLEAN));
|
| - MockCrashReportDatabase crash_db;
|
| - PostmortemReportCollector collector(kProductName, kVersionNumber,
|
| - kChannelName, &crash_db, &analyzer);
|
| - StabilityReport report;
|
| - ASSERT_EQ(SUCCESS, collector.CollectOneReport(debug_file_path(), &report));
|
| -
|
| - // Validate the report.
|
| - ASSERT_EQ(SystemState::CLEAN, report.system_state().session_state());
|
| -}
|
| -
|
| } // namespace browser_watcher
|
|
|