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

Side by Side Diff: handler/win/registration_test_base.h

Issue 1126783004: Introduce RegistrationServer. (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: One extra comment. Created 5 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
« no previous file with comments | « handler/win/registration_server_test.cc ('k') | handler/win/registration_test_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <windows.h>
16
17 #include "base/basictypes.h"
18 #include "base/strings/string16.h"
19 #include "client/registration_protocol_win.h"
20 #include "gtest/gtest.h"
21 #include "handler/win/registration_server.h"
22 #include "util/stdlib/pointer_container.h"
23 #include "util/win/address_types.h"
24 #include "util/win/scoped_handle.h"
25
26 namespace crashpad {
27 namespace test {
28
29 class RegistrationTestBase : public testing::Test {
30 public:
31 // Simulates a registrar to collect requests from and feed responses to the
32 // RegistrationServer.
33 class MockDelegate : public RegistrationServer::Delegate {
34 public:
35 // Records a single simulated client registration.
36 struct Entry {
37 Entry(ScopedKernelHANDLE client_process,
38 WinVMAddress crashpad_info_address,
39 uint32_t fake_request_dump_event,
40 uint32_t fake_dump_complete_event);
41
42 ScopedKernelHANDLE client_process;
43 WinVMAddress crashpad_info_address;
44 uint32_t fake_request_dump_event;
45 uint32_t fake_dump_complete_event;
46 };
47
48 MockDelegate();
49 ~MockDelegate() override;
50
51 // Blocks until RegistrationServer::Delegate::OnStarted is invoked.
52 void WaitForStart();
53
54 // RegistrationServer::Delegate:
55 void OnStarted() override;
56
57 bool RegisterClient(ScopedKernelHANDLE client_process,
58 WinVMAddress crashpad_info_address,
59 HANDLE* request_dump_event,
60 HANDLE* dump_complete_event) override;
61
62 // Provides access to the registered process data.
63 const std::vector<Entry*> registered_processes() {
64 return registered_processes_;
65 }
66
67 // If true, causes RegisterClient to simulate registration failure.
68 void set_fail_mode(bool fail) { fail_ = fail; }
69
70 private:
71 ScopedKernelHANDLE started_event_;
72 PointerVector<Entry> registered_processes_;
73 uint32_t next_fake_handle_;
74 bool fail_;
75
76 DISALLOW_COPY_AND_ASSIGN(MockDelegate);
77 };
78
79 RegistrationTestBase();
80 ~RegistrationTestBase() override;
81
82 MockDelegate& delegate() { return delegate_; }
83 base::string16 pipe_name() { return pipe_name_; }
84
85 // Returns a pipe handle connected to the RegistrationServer.
86 ScopedFileHANDLE Connect();
87
88 // Sends the provided request and receives a response via the provided pipe.
89 bool SendRequest(ScopedFileHANDLE pipe,
90 const void* request_buffer,
91 size_t request_size,
92 RegistrationResponse* response);
93
94 bool WriteRequest(HANDLE pipe,
95 const void* request_buffer,
96 size_t request_size);
97
98 bool ReadResponse(HANDLE pipe, RegistrationResponse* response);
99
100 // Verifies that the request and response match what was received and sent by
101 // the MockDelegate.
102 void VerifyRegistration(const MockDelegate::Entry& registered_process,
103 const RegistrationRequest& request,
104 const RegistrationResponse& response);
105
106 private:
107 base::string16 pipe_name_;
108 MockDelegate delegate_;
109
110 DISALLOW_COPY_AND_ASSIGN(RegistrationTestBase);
111 };
112
113 } // namespace test
114 } // namespace crashpad
OLDNEW
« no previous file with comments | « handler/win/registration_server_test.cc ('k') | handler/win/registration_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698