Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: remoting/host/breakpad_win_unittest.cc

Issue 10495003: Make Chromoting Host report crashes to Breakpad (Windows only). The user must enable crash dumps co… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 <stdio.h>
6
7 #include "base/compiler_specific.h"
8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/string16.h"
11 #include "breakpad/src/client/windows/crash_generation/client_info.h"
12 #include "breakpad/src/client/windows/crash_generation/crash_generation_server.h "
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace remoting {
17
18 namespace {
19
20 // The crash server pipe name. It was generated using uuidgen for the sole
21 // purpose of being unique.
22 const wchar_t kPipeName[] = L"\\\\.\\pipe\\16b7918a4019425b96e5d6c8c2ae7fe2";
23
24 class MockCrashServerCallbacks {
25 public:
26 MockCrashServerCallbacks() {}
27 virtual ~MockCrashServerCallbacks() {}
28
29 MOCK_METHOD0(OnClientConnected, void());
30 MOCK_METHOD0(OnClientDumpRequested, void());
31 MOCK_METHOD0(OnClientExited, void());
32
33 static void OnClientConnectedCallback(
34 void* context,
35 const google_breakpad::ClientInfo* client_info) {
36 reinterpret_cast<MockCrashServerCallbacks*>(context)->OnClientConnected();
37 }
38
39 static void OnClientDumpRequestCallback(
40 void* context,
41 const google_breakpad::ClientInfo* client_info,
42 const string16* file_path) {
43 reinterpret_cast<MockCrashServerCallbacks*>(context)->
44 OnClientDumpRequested();
45 }
46
47 static void OnClientExitedCallback(
48 void* context,
49 const google_breakpad::ClientInfo* client_info) {
50 reinterpret_cast<MockCrashServerCallbacks*>(context)->OnClientExited();
51 }
52 };
53
54 } // namespace
55
56 void InitializeCrashReportingForTest(const wchar_t*);
57
58 class BreakpadWinDeathTest : public testing::Test {
59 public:
60 BreakpadWinDeathTest() {}
61 virtual void SetUp() OVERRIDE {
62 if (::testing::internal::InDeathTestChild()) {
63 // Initialize crash dump reporting to the dummy crash dump server.
64 ::remoting::InitializeCrashReportingForTest(kPipeName);
65 } else {
66 // Setup a dummy crash dump server.
67 callbacks_.reset(new MockCrashServerCallbacks());
68 crash_server_.reset(
69 new google_breakpad::CrashGenerationServer(
70 kPipeName, NULL,
71 MockCrashServerCallbacks::OnClientConnectedCallback,
72 callbacks_.get(),
73 MockCrashServerCallbacks::OnClientDumpRequestCallback,
74 callbacks_.get(),
75 MockCrashServerCallbacks::OnClientExitedCallback,
76 callbacks_.get(),
77 false, NULL));
78
79 bool result = crash_server_->Start();
80 ASSERT_TRUE(result);
81 }
82 }
83
84 protected:
85 scoped_ptr<google_breakpad::CrashGenerationServer> crash_server_;
86 scoped_ptr<MockCrashServerCallbacks> callbacks_;
87 };
88
89 TEST_F(BreakpadWinDeathTest, TestAccessViolation) {
90 if (callbacks_.get()) {
91 ::testing::Sequence s;
92 EXPECT_CALL(*callbacks_, OnClientConnected())
93 .InSequence(s);
94 EXPECT_CALL(*callbacks_, OnClientDumpRequested())
95 .InSequence(s);
96 EXPECT_CALL(*callbacks_, OnClientExited())
97 .InSequence(s);
98 }
99
100 // Generate access violation exception.
101 ASSERT_DEATH(*reinterpret_cast<int*>(0) = 1, "");
102 }
103
104 TEST_F(BreakpadWinDeathTest, TestInvalidParameter) {
105 if (callbacks_.get()) {
106 ::testing::Sequence s;
107 EXPECT_CALL(*callbacks_, OnClientConnected())
108 .InSequence(s);
109 EXPECT_CALL(*callbacks_, OnClientDumpRequested())
110 .InSequence(s);
111 EXPECT_CALL(*callbacks_, OnClientExited())
112 .InSequence(s);
113 }
114
115 // Cause the invalid parameter callback to be called.
116 ASSERT_EXIT(printf(NULL), ::testing::ExitedWithCode(0), "");
117 }
118
119 TEST_F(BreakpadWinDeathTest, TestDebugbreak) {
120 if (callbacks_.get()) {
121 ::testing::Sequence s;
122 EXPECT_CALL(*callbacks_, OnClientConnected())
123 .InSequence(s);
124 EXPECT_CALL(*callbacks_, OnClientDumpRequested())
125 .InSequence(s);
126 EXPECT_CALL(*callbacks_, OnClientExited())
127 .InSequence(s);
128 }
129
130 // See if __debugbreak() is intercepted.
131 ASSERT_DEATH(__debugbreak(), "");
132 }
133
134 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698