Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Unified Diff: components/browser_watcher/postmortem_report_collector_unittest.cc

Issue 2554423002: Collect log messages from stability files (Closed)
Patch Set: Enum fixup Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 e9ba3e543391250fdb4aa1504615affac395a140..eda5e886c9ba6be82107775c505c8fd28444e8f3 100644
--- a/components/browser_watcher/postmortem_report_collector_unittest.cc
+++ b/components/browser_watcher/postmortem_report_collector_unittest.cc
@@ -339,6 +339,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.
@@ -483,4 +486,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

Powered by Google App Engine
This is Rietveld 408576698