| Index: components/browser_watcher/postmortem_report_collector_unittest.cc
|
| diff --git a/components/browser_watcher/postmortem_report_collector_unittest.cc b/components/browser_watcher/postmortem_report_collector_unittest.cc
|
| index f6b84a5ebebbfe4267cd5a57e31e63fb52d658a9..9b19bdb5c5f377064009f4633085ebc468e6a7d7 100644
|
| --- a/components/browser_watcher/postmortem_report_collector_unittest.cc
|
| +++ b/components/browser_watcher/postmortem_report_collector_unittest.cc
|
| @@ -340,6 +340,9 @@ const int kAnotherThreadId = 45;
|
|
|
| } // namespace
|
|
|
| +// 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 {
|
| public:
|
| // Create a proper debug file.
|
| @@ -484,4 +487,55 @@ TEST_F(PostmortemReportCollectorCollectionTest, CollectSuccess) {
|
| }
|
| }
|
|
|
| +class PostmortemReportCollectorCollectionFromGlobalTrackerTest
|
| + : public testing::Test {
|
| + public:
|
| + const int kMemorySize = 1 << 20; // 1MiB
|
| +
|
| + PostmortemReportCollectorCollectionFromGlobalTrackerTest() {}
|
| + ~PostmortemReportCollectorCollectionFromGlobalTrackerTest() override {
|
| + GlobalActivityTracker* global_tracker = GlobalActivityTracker::Get();
|
| + if (global_tracker) {
|
| + global_tracker->ReleaseTrackerForCurrentThreadForTesting();
|
| + delete global_tracker;
|
| + }
|
| + }
|
| +
|
| + void SetUp() override {
|
| + testing::Test::SetUp();
|
| +
|
| + // Set up a debug file path.
|
| + ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
|
| + debug_file_path_ = temp_dir_.GetPath().AppendASCII("debug.pma");
|
| + }
|
| +
|
| + const base::FilePath& debug_file_path() { return debug_file_path_; }
|
| +
|
| + protected:
|
| + base::ScopedTempDir temp_dir_;
|
| + base::FilePath debug_file_path_;
|
| +};
|
| +
|
| +TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest,
|
| + LogCollection) {
|
| + // Record some log messages.
|
| + GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL,
|
| + "", 3);
|
| + GlobalActivityTracker::Get()->RecordLogMessage("hello world");
|
| + GlobalActivityTracker::Get()->RecordLogMessage("foo bar");
|
| +
|
| + // Collect the stability report.
|
| + PostmortemReportCollector collector(kProductName, kVersionNumber,
|
| + kChannelName);
|
| + std::unique_ptr<StabilityReport> report;
|
| + ASSERT_EQ(PostmortemReportCollector::SUCCESS,
|
| + collector.Collect(debug_file_path(), &report));
|
| + ASSERT_NE(nullptr, report);
|
| +
|
| + // Validate the report's log content.
|
| + ASSERT_EQ(2, report->log_messages_size());
|
| + ASSERT_EQ("hello world", report->log_messages(0));
|
| + ASSERT_EQ("foo bar", report->log_messages(1));
|
| +}
|
| +
|
| } // namespace browser_watcher
|
|
|