activity_tracker_annotation_unittest.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/browser_watcher/activity_tracker_annotation.h"
  5. #include "components/crash/core/common/crash_key.h"
  6. #include "testing/gtest/include/gtest/gtest.h"
  7. namespace browser_watcher {
  8. class ActivityTrackerAnnotationTest : public testing::Test {
  9. public:
  10. void SetUp() override { crash_reporter::InitializeCrashKeysForTesting(); }
  11. void TearDown() override { crash_reporter::ResetCrashKeysForTesting(); }
  12. };
  13. TEST_F(ActivityTrackerAnnotationTest, RegistersOnFirstSet) {
  14. static const char* kBuffer[128];
  15. ActivityTrackerAnnotation* annotation =
  16. ActivityTrackerAnnotation::GetInstance();
  17. // Validate that the annotation doesn't register on construction.
  18. EXPECT_EQ("", crash_reporter::GetCrashKeyValue(
  19. ActivityTrackerAnnotation::kAnnotationName));
  20. annotation->SetValue(&kBuffer, sizeof(kBuffer));
  21. std::string string_value = crash_reporter::GetCrashKeyValue(
  22. ActivityTrackerAnnotation::kAnnotationName);
  23. ASSERT_EQ(sizeof(ActivityTrackerAnnotation::ValueType), string_value.size());
  24. ActivityTrackerAnnotation::ValueType value = {};
  25. memcpy(&value, string_value.data(), sizeof(value));
  26. EXPECT_EQ(value.address, reinterpret_cast<uint64_t>(&kBuffer));
  27. EXPECT_EQ(value.size, sizeof(kBuffer));
  28. }
  29. } // namespace browser_watcher