crash_keys_android_unittest.cc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2018 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/crash/android/crash_keys_android.h"
  5. #include "components/crash/core/common/crash_key.h"
  6. #include "testing/gtest/include/gtest/gtest.h"
  7. using crash_reporter::GetCrashKeyValue;
  8. class CrashKeysAndroidTest : public testing::Test {
  9. public:
  10. void SetUp() override {
  11. crash_reporter::ResetCrashKeysForTesting();
  12. crash_reporter::InitializeCrashKeys();
  13. }
  14. void TearDown() override { crash_reporter::ResetCrashKeysForTesting(); }
  15. };
  16. TEST_F(CrashKeysAndroidTest, Default) {
  17. EXPECT_TRUE(GetCrashKeyValue("loaded_dynamic_module").empty());
  18. EXPECT_TRUE(GetCrashKeyValue("active_dynamic_module").empty());
  19. }
  20. TEST_F(CrashKeysAndroidTest, SetAndClear) {
  21. SetAndroidCrashKey(CrashKeyIndex::LOADED_DYNAMIC_MODULE, "foobar");
  22. SetAndroidCrashKey(CrashKeyIndex::ACTIVE_DYNAMIC_MODULE, "blurp");
  23. EXPECT_TRUE(GetCrashKeyValue("loaded_dynamic_module").empty());
  24. EXPECT_TRUE(GetCrashKeyValue("active_dynamic_module").empty());
  25. ClearAndroidCrashKey(CrashKeyIndex::ACTIVE_DYNAMIC_MODULE);
  26. FlushAndroidCrashKeys();
  27. EXPECT_EQ(GetCrashKeyValue("loaded_dynamic_module"), "foobar");
  28. EXPECT_TRUE(GetCrashKeyValue("active_dynamic_module").empty());
  29. ClearAndroidCrashKey(CrashKeyIndex::LOADED_DYNAMIC_MODULE);
  30. EXPECT_TRUE(GetCrashKeyValue("loaded_dynamic_module").empty());
  31. EXPECT_TRUE(GetCrashKeyValue("active_dynamic_module").empty());
  32. }