| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 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 "components/breakpad/app/crash_keys_win.h" |
| 6 |
| 7 #include "base/files/file_path.h" |
| 8 #include "base/strings/stringprintf.h" |
| 9 #include "components/breakpad/app/breakpad_client.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 namespace breakpad { |
| 14 |
| 15 using testing::_; |
| 16 using testing::DoAll; |
| 17 using testing::Return; |
| 18 using testing::SetArgPointee; |
| 19 |
| 20 class MockBreakpadClient : public BreakpadClient { |
| 21 public: |
| 22 MOCK_METHOD1(GetAlternativeCrashDumpLocation, |
| 23 bool(base::FilePath* crash_dir)); |
| 24 MOCK_METHOD5(GetProductNameAndVersion, void(const base::FilePath& exe_path, |
| 25 base::string16* product_name, |
| 26 base::string16* version, |
| 27 base::string16* special_build, |
| 28 base::string16* channel_name)); |
| 29 MOCK_METHOD3(ShouldShowRestartDialog, bool(base::string16* title, |
| 30 base::string16* message, |
| 31 bool* is_rtl_locale)); |
| 32 MOCK_METHOD0(AboutToRestart, bool()); |
| 33 MOCK_METHOD1(GetDeferredUploadsSupported, bool(bool is_per_user_install)); |
| 34 MOCK_METHOD1(GetIsPerUserInstall, bool(const base::FilePath& exe_path)); |
| 35 MOCK_METHOD1(GetShouldDumpLargerDumps, bool(bool is_per_user_install)); |
| 36 MOCK_METHOD0(GetResultCodeRespawnFailed, int()); |
| 37 MOCK_METHOD0(InitBrowserCrashDumpsRegKey, void()); |
| 38 MOCK_METHOD1(RecordCrashDumpAttempt, void(bool is_real_crash)); |
| 39 |
| 40 MOCK_METHOD2(GetProductNameAndVersion, void(std::string* product_name, |
| 41 std::string* version)); |
| 42 MOCK_METHOD0(GetReporterLogFilename, base::FilePath()); |
| 43 MOCK_METHOD1(GetCrashDumpLocation, bool(base::FilePath* crash_dir)); |
| 44 MOCK_METHOD0(RegisterCrashKeys, size_t()); |
| 45 MOCK_METHOD0(IsRunningUnattended, bool()); |
| 46 MOCK_METHOD0(GetCollectStatsConsent, bool()); |
| 47 MOCK_METHOD1(ReportingIsEnforcedByPolicy, bool(bool* breakpad_enabled)); |
| 48 MOCK_METHOD0(GetAndroidMinidumpDescriptor, int()); |
| 49 #if defined(OS_MACOSX) |
| 50 MOCK_METHOD1(InstallAdditionalFilters, void(BreakpadRef breakpad)); |
| 51 #endif |
| 52 MOCK_METHOD1(EnableBreakpadForProcess, bool(const std::string& process_type)); |
| 53 }; |
| 54 |
| 55 class CrashKeysWinTest : public testing::Test { |
| 56 public: |
| 57 |
| 58 size_t CountKeyValueOccurences( |
| 59 const google_breakpad::CustomClientInfo* client_info, |
| 60 const wchar_t* key, const wchar_t* value); |
| 61 |
| 62 protected: |
| 63 testing::StrictMock<MockBreakpadClient> breakpad_client_; |
| 64 }; |
| 65 |
| 66 size_t CrashKeysWinTest::CountKeyValueOccurences( |
| 67 const google_breakpad::CustomClientInfo* client_info, |
| 68 const wchar_t* key, const wchar_t* value) { |
| 69 size_t occurrences = 0; |
| 70 for (size_t i = 0; i < client_info->count; ++i) { |
| 71 if (wcscmp(client_info->entries[i].name, key) == 0 && |
| 72 wcscmp(client_info->entries[i].value, value) == 0) { |
| 73 ++occurrences; |
| 74 } |
| 75 } |
| 76 |
| 77 return occurrences; |
| 78 } |
| 79 |
| 80 TEST_F(CrashKeysWinTest, RecordsSelf) { |
| 81 ASSERT_EQ(static_cast<CrashKeysWin*>(NULL), CrashKeysWin::keeper()); |
| 82 |
| 83 { |
| 84 CrashKeysWin crash_keys; |
| 85 |
| 86 ASSERT_EQ(&crash_keys, CrashKeysWin::keeper()); |
| 87 } |
| 88 |
| 89 ASSERT_EQ(static_cast<CrashKeysWin*>(NULL), CrashKeysWin::keeper()); |
| 90 } |
| 91 |
| 92 // Tests the crash keys set up for the most common official build consumer |
| 93 // scenario. No policy controls, not running unattended and no explicit |
| 94 // switches. |
| 95 TEST_F(CrashKeysWinTest, OfficialLikeKeys) { |
| 96 CrashKeysWin crash_keys; |
| 97 |
| 98 const base::FilePath kExePath(L"C:\\temp\\exe_path.exe"); |
| 99 // The exe path ought to get passed through to the breakpad client. |
| 100 EXPECT_CALL(breakpad_client_, GetProductNameAndVersion(kExePath, _, _, _, _)) |
| 101 .WillRepeatedly(DoAll( |
| 102 SetArgPointee<1>(L"SomeProdName"), |
| 103 SetArgPointee<2>(L"1.2.3.4"), |
| 104 SetArgPointee<3>(L""), |
| 105 SetArgPointee<4>(L"-devm"))); |
| 106 |
| 107 EXPECT_CALL(breakpad_client_, GetAlternativeCrashDumpLocation(_)) |
| 108 .WillRepeatedly(DoAll( |
| 109 SetArgPointee<0>(base::FilePath(L"C:\\temp")), |
| 110 Return(false))); |
| 111 |
| 112 EXPECT_CALL(breakpad_client_, ReportingIsEnforcedByPolicy(_)) |
| 113 .WillRepeatedly(Return(false)); |
| 114 |
| 115 EXPECT_CALL(breakpad_client_, IsRunningUnattended()) |
| 116 .WillRepeatedly(Return(false)); |
| 117 |
| 118 // Provide an empty command line. |
| 119 base::CommandLine cmd_line(base::CommandLine::NO_PROGRAM); |
| 120 google_breakpad::CustomClientInfo* info = |
| 121 crash_keys.GetCustomInfo(kExePath.value(), |
| 122 L"made_up_type", |
| 123 L"temporary", |
| 124 &cmd_line, |
| 125 &breakpad_client_); |
| 126 |
| 127 ASSERT_TRUE(info != NULL); |
| 128 ASSERT_TRUE(info->entries != NULL); |
| 129 |
| 130 // We expect 7 fixed keys and a "freeboard" of 256 keys for dynamic entries. |
| 131 EXPECT_EQ(256U + 7U, info->count); |
| 132 |
| 133 EXPECT_EQ(1, CountKeyValueOccurences(info, L"ver", L"1.2.3.4")); |
| 134 EXPECT_EQ(1, CountKeyValueOccurences(info, L"prod", L"SomeProdName")); |
| 135 EXPECT_EQ(1, CountKeyValueOccurences(info, L"plat", L"Win32")); |
| 136 EXPECT_EQ(1, CountKeyValueOccurences(info, L"ptype", L"made_up_type")); |
| 137 std::wstring pid_str(base::StringPrintf(L"%d", ::GetCurrentProcessId())); |
| 138 EXPECT_EQ(1, CountKeyValueOccurences(info, L"pid", pid_str.c_str())); |
| 139 EXPECT_EQ(1, CountKeyValueOccurences(info, L"channel", L"-devm")); |
| 140 EXPECT_EQ(1, CountKeyValueOccurences(info, L"profile-type", L"temporary")); |
| 141 EXPECT_EQ(256, CountKeyValueOccurences(info, L"unspecified-crash-key", L"")); |
| 142 } |
| 143 |
| 144 } // namespace breakpad |
| OLD | NEW |