OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/crash/app/crash_keys_win.h" | 5 #include "components/crash/app/crash_keys_win.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "components/crash/app/breakpad_client.h" | 10 #include "components/crash/app/crash_reporter_client.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace breakpad { | 14 namespace breakpad { |
15 | 15 |
16 using testing::_; | 16 using testing::_; |
17 using testing::DoAll; | 17 using testing::DoAll; |
18 using testing::Return; | 18 using testing::Return; |
19 using testing::SetArgPointee; | 19 using testing::SetArgPointee; |
20 | 20 |
21 class MockBreakpadClient : public BreakpadClient { | 21 class MockCrashReporterClient : public crash_reporter::CrashReporterClient { |
22 public: | 22 public: |
23 MOCK_METHOD1(GetAlternativeCrashDumpLocation, | 23 MOCK_METHOD1(GetAlternativeCrashDumpLocation, |
24 bool(base::FilePath* crash_dir)); | 24 bool(base::FilePath* crash_dir)); |
25 MOCK_METHOD5(GetProductNameAndVersion, void(const base::FilePath& exe_path, | 25 MOCK_METHOD5(GetProductNameAndVersion, void(const base::FilePath& exe_path, |
26 base::string16* product_name, | 26 base::string16* product_name, |
27 base::string16* version, | 27 base::string16* version, |
28 base::string16* special_build, | 28 base::string16* special_build, |
29 base::string16* channel_name)); | 29 base::string16* channel_name)); |
30 MOCK_METHOD3(ShouldShowRestartDialog, bool(base::string16* title, | 30 MOCK_METHOD3(ShouldShowRestartDialog, bool(base::string16* title, |
31 base::string16* message, | 31 base::string16* message, |
(...skipping 22 matching lines...) Expand all Loading... |
54 }; | 54 }; |
55 | 55 |
56 class CrashKeysWinTest : public testing::Test { | 56 class CrashKeysWinTest : public testing::Test { |
57 public: | 57 public: |
58 | 58 |
59 size_t CountKeyValueOccurences( | 59 size_t CountKeyValueOccurences( |
60 const google_breakpad::CustomClientInfo* client_info, | 60 const google_breakpad::CustomClientInfo* client_info, |
61 const wchar_t* key, const wchar_t* value); | 61 const wchar_t* key, const wchar_t* value); |
62 | 62 |
63 protected: | 63 protected: |
64 testing::StrictMock<MockBreakpadClient> breakpad_client_; | 64 testing::StrictMock<MockCrashReporterClient> crash_client_; |
65 }; | 65 }; |
66 | 66 |
67 size_t CrashKeysWinTest::CountKeyValueOccurences( | 67 size_t CrashKeysWinTest::CountKeyValueOccurences( |
68 const google_breakpad::CustomClientInfo* client_info, | 68 const google_breakpad::CustomClientInfo* client_info, |
69 const wchar_t* key, const wchar_t* value) { | 69 const wchar_t* key, const wchar_t* value) { |
70 size_t occurrences = 0; | 70 size_t occurrences = 0; |
71 for (size_t i = 0; i < client_info->count; ++i) { | 71 for (size_t i = 0; i < client_info->count; ++i) { |
72 if (wcscmp(client_info->entries[i].name, key) == 0 && | 72 if (wcscmp(client_info->entries[i].name, key) == 0 && |
73 wcscmp(client_info->entries[i].value, value) == 0) { | 73 wcscmp(client_info->entries[i].value, value) == 0) { |
74 ++occurrences; | 74 ++occurrences; |
(...skipping 16 matching lines...) Expand all Loading... |
91 } | 91 } |
92 | 92 |
93 // Tests the crash keys set up for the most common official build consumer | 93 // Tests the crash keys set up for the most common official build consumer |
94 // scenario. No policy controls, not running unattended and no explicit | 94 // scenario. No policy controls, not running unattended and no explicit |
95 // switches. | 95 // switches. |
96 TEST_F(CrashKeysWinTest, OfficialLikeKeys) { | 96 TEST_F(CrashKeysWinTest, OfficialLikeKeys) { |
97 CrashKeysWin crash_keys; | 97 CrashKeysWin crash_keys; |
98 | 98 |
99 const base::FilePath kExePath(L"C:\\temp\\exe_path.exe"); | 99 const base::FilePath kExePath(L"C:\\temp\\exe_path.exe"); |
100 // The exe path ought to get passed through to the breakpad client. | 100 // The exe path ought to get passed through to the breakpad client. |
101 EXPECT_CALL(breakpad_client_, GetProductNameAndVersion(kExePath, _, _, _, _)) | 101 EXPECT_CALL(crash_client_, GetProductNameAndVersion(kExePath, _, _, _, _)) |
102 .WillRepeatedly(DoAll( | 102 .WillRepeatedly(DoAll( |
103 SetArgPointee<1>(L"SomeProdName"), | 103 SetArgPointee<1>(L"SomeProdName"), |
104 SetArgPointee<2>(L"1.2.3.4"), | 104 SetArgPointee<2>(L"1.2.3.4"), |
105 SetArgPointee<3>(L""), | 105 SetArgPointee<3>(L""), |
106 SetArgPointee<4>(L"-devm"))); | 106 SetArgPointee<4>(L"-devm"))); |
107 | 107 |
108 EXPECT_CALL(breakpad_client_, GetAlternativeCrashDumpLocation(_)) | 108 EXPECT_CALL(crash_client_, GetAlternativeCrashDumpLocation(_)) |
109 .WillRepeatedly(DoAll( | 109 .WillRepeatedly(DoAll( |
110 SetArgPointee<0>(base::FilePath(L"C:\\temp")), | 110 SetArgPointee<0>(base::FilePath(L"C:\\temp")), |
111 Return(false))); | 111 Return(false))); |
112 | 112 |
113 EXPECT_CALL(breakpad_client_, ReportingIsEnforcedByPolicy(_)) | 113 EXPECT_CALL(crash_client_, ReportingIsEnforcedByPolicy(_)) |
114 .WillRepeatedly(Return(false)); | 114 .WillRepeatedly(Return(false)); |
115 | 115 |
116 EXPECT_CALL(breakpad_client_, IsRunningUnattended()) | 116 EXPECT_CALL(crash_client_, IsRunningUnattended()) |
117 .WillRepeatedly(Return(false)); | 117 .WillRepeatedly(Return(false)); |
118 | 118 |
119 // Provide an empty command line. | 119 // Provide an empty command line. |
120 base::CommandLine cmd_line(base::CommandLine::NO_PROGRAM); | 120 base::CommandLine cmd_line(base::CommandLine::NO_PROGRAM); |
121 google_breakpad::CustomClientInfo* info = | 121 google_breakpad::CustomClientInfo* info = |
122 crash_keys.GetCustomInfo(kExePath.value(), | 122 crash_keys.GetCustomInfo(kExePath.value(), |
123 L"made_up_type", | 123 L"made_up_type", |
124 L"temporary", | 124 L"temporary", |
125 &cmd_line, | 125 &cmd_line, |
126 &breakpad_client_); | 126 &crash_client_); |
127 | 127 |
128 ASSERT_TRUE(info != NULL); | 128 ASSERT_TRUE(info != NULL); |
129 ASSERT_TRUE(info->entries != NULL); | 129 ASSERT_TRUE(info->entries != NULL); |
130 | 130 |
131 // We expect 7 fixed keys and a "freeboard" of 256 keys for dynamic entries. | 131 // We expect 7 fixed keys and a "freeboard" of 256 keys for dynamic entries. |
132 EXPECT_EQ(256U + 7U, info->count); | 132 EXPECT_EQ(256U + 7U, info->count); |
133 | 133 |
134 EXPECT_EQ(1, CountKeyValueOccurences(info, L"ver", L"1.2.3.4")); | 134 EXPECT_EQ(1, CountKeyValueOccurences(info, L"ver", L"1.2.3.4")); |
135 EXPECT_EQ(1, CountKeyValueOccurences(info, L"prod", L"SomeProdName")); | 135 EXPECT_EQ(1, CountKeyValueOccurences(info, L"prod", L"SomeProdName")); |
136 EXPECT_EQ(1, CountKeyValueOccurences(info, L"plat", L"Win32")); | 136 EXPECT_EQ(1, CountKeyValueOccurences(info, L"plat", L"Win32")); |
137 EXPECT_EQ(1, CountKeyValueOccurences(info, L"ptype", L"made_up_type")); | 137 EXPECT_EQ(1, CountKeyValueOccurences(info, L"ptype", L"made_up_type")); |
138 std::wstring pid_str(base::StringPrintf(L"%d", ::GetCurrentProcessId())); | 138 std::wstring pid_str(base::StringPrintf(L"%d", ::GetCurrentProcessId())); |
139 EXPECT_EQ(1, CountKeyValueOccurences(info, L"pid", pid_str.c_str())); | 139 EXPECT_EQ(1, CountKeyValueOccurences(info, L"pid", pid_str.c_str())); |
140 EXPECT_EQ(1, CountKeyValueOccurences(info, L"channel", L"-devm")); | 140 EXPECT_EQ(1, CountKeyValueOccurences(info, L"channel", L"-devm")); |
141 EXPECT_EQ(1, CountKeyValueOccurences(info, L"profile-type", L"temporary")); | 141 EXPECT_EQ(1, CountKeyValueOccurences(info, L"profile-type", L"temporary")); |
142 EXPECT_EQ(256, CountKeyValueOccurences(info, L"unspecified-crash-key", L"")); | 142 EXPECT_EQ(256, CountKeyValueOccurences(info, L"unspecified-crash-key", L"")); |
143 } | 143 } |
144 | 144 |
145 } // namespace breakpad | 145 } // namespace breakpad |
OLD | NEW |