Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 | |
| 5 #include "chrome/app/mash/mash_crash_keys.h" | |
| 6 | |
| 7 #include <stdint.h> | |
| 8 | |
| 9 #include "base/debug/crash_logging.h" | |
| 10 #include "base/files/file_path.h" | |
| 11 #include "base/files/file_util.h" | |
| 12 #include "base/strings/stringprintf.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 TEST(MashCrashKeys, Basics) { | |
| 16 EXPECT_EQ(-1, mash_crash_keys::GetSharedMemoryFdForTesting()); | |
| 17 | |
| 18 mash_crash_keys::Initialize(); | |
| 19 | |
| 20 // Shared memory was allocated. | |
| 21 EXPECT_NE(-1, mash_crash_keys::GetSharedMemoryFdForTesting()); | |
| 22 const base::FilePath expected_shm_path( | |
| 23 base::StringPrintf("/dev/shm/chrome_crash_keys_%d", getpid())); | |
| 24 EXPECT_TRUE(base::PathExists(expected_shm_path)); | |
| 25 int64_t file_size; | |
| 26 EXPECT_TRUE(base::GetFileSize(expected_shm_path, &file_size)); | |
| 27 // Hard-code size because the OS-level crash_reporter needs to be updated | |
| 28 // if breakpad changes the size of SimpleStringDictionary. | |
| 29 EXPECT_EQ(32768, file_size); | |
| 30 | |
| 31 // Crash keys were registered and can be used. | |
| 32 base::debug::SetCrashKeyValue("url-chunk", "http://example.com"); | |
|
hashimoto
2017/03/02 07:42:23
Please use the constant name kActiveUrl.
| |
| 33 EXPECT_EQ(1u, mash_crash_keys::GetCrashKeyCountForTesting()); | |
| 34 base::debug::ClearCrashKey("url-chunk"); | |
|
hashimoto
2017/03/02 07:42:23
ditto.
| |
| 35 EXPECT_EQ(0u, mash_crash_keys::GetCrashKeyCountForTesting()); | |
| 36 | |
| 37 mash_crash_keys::Shutdown(); | |
| 38 | |
| 39 // Shared memory was cleaned up. | |
| 40 EXPECT_EQ(-1, mash_crash_keys::GetSharedMemoryFdForTesting()); | |
| 41 EXPECT_FALSE(base::PathExists(expected_shm_path)); | |
| 42 } | |
| OLD | NEW |