scoped_mock_context.h 953 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright 2021 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. #ifndef CHROME_ELEVATION_SERVICE_SCOPED_MOCK_CONTEXT_H_
  5. #define CHROME_ELEVATION_SERVICE_SCOPED_MOCK_CONTEXT_H_
  6. #include <unknwn.h>
  7. #include <wrl/client.h>
  8. namespace elevation_service {
  9. // Installs an implementation of IServerSecurity that allows code under test to
  10. // successfully call ::CoImpersonateClient().
  11. class ScopedMockContext {
  12. public:
  13. ScopedMockContext();
  14. ScopedMockContext(const ScopedMockContext&) = delete;
  15. ScopedMockContext& operator=(const ScopedMockContext&) = delete;
  16. ~ScopedMockContext();
  17. bool Succeeded() const { return mock_call_context_; }
  18. private:
  19. Microsoft::WRL::ComPtr<IUnknown> mock_call_context_;
  20. IUnknown* original_call_context_ = nullptr;
  21. };
  22. } // namespace elevation_service
  23. #endif // CHROME_ELEVATION_SERVICE_SCOPED_MOCK_CONTEXT_H_