Chromium Code Reviews| Index: chrome/app/mash/mash_crash_keys_unittest.cc |
| diff --git a/chrome/app/mash/mash_crash_keys_unittest.cc b/chrome/app/mash/mash_crash_keys_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7e7f7b04c29eac2aec83fa7852c7851c1589bd0e |
| --- /dev/null |
| +++ b/chrome/app/mash/mash_crash_keys_unittest.cc |
| @@ -0,0 +1,42 @@ |
| +// 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 "chrome/app/mash/mash_crash_keys.h" |
| + |
| +#include <stdint.h> |
| + |
| +#include "base/debug/crash_logging.h" |
| +#include "base/files/file_path.h" |
| +#include "base/files/file_util.h" |
| +#include "base/strings/stringprintf.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +TEST(MashCrashKeys, Basics) { |
| + EXPECT_EQ(-1, mash_crash_keys::GetSharedMemoryFdForTesting()); |
| + |
| + mash_crash_keys::Initialize(); |
| + |
| + // Shared memory was allocated. |
| + EXPECT_NE(-1, mash_crash_keys::GetSharedMemoryFdForTesting()); |
| + const base::FilePath expected_shm_path( |
| + base::StringPrintf("/dev/shm/chrome_crash_keys_%d", getpid())); |
| + EXPECT_TRUE(base::PathExists(expected_shm_path)); |
| + int64_t file_size; |
| + EXPECT_TRUE(base::GetFileSize(expected_shm_path, &file_size)); |
| + // Hard-code size because the OS-level crash_reporter needs to be updated |
| + // if breakpad changes the size of SimpleStringDictionary. |
| + EXPECT_EQ(32768, file_size); |
| + |
| + // Crash keys were registered and can be used. |
| + base::debug::SetCrashKeyValue("url-chunk", "http://example.com"); |
|
hashimoto
2017/03/02 07:42:23
Please use the constant name kActiveUrl.
|
| + EXPECT_EQ(1u, mash_crash_keys::GetCrashKeyCountForTesting()); |
| + base::debug::ClearCrashKey("url-chunk"); |
|
hashimoto
2017/03/02 07:42:23
ditto.
|
| + EXPECT_EQ(0u, mash_crash_keys::GetCrashKeyCountForTesting()); |
| + |
| + mash_crash_keys::Shutdown(); |
| + |
| + // Shared memory was cleaned up. |
| + EXPECT_EQ(-1, mash_crash_keys::GetSharedMemoryFdForTesting()); |
| + EXPECT_FALSE(base::PathExists(expected_shm_path)); |
| +} |