test_protocol_handler_registry_delegate.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2019 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 COMPONENTS_CUSTOM_HANDLERS_TEST_PROTOCOL_HANDLER_REGISTRY_DELEGATE_H_
  5. #define COMPONENTS_CUSTOM_HANDLERS_TEST_PROTOCOL_HANDLER_REGISTRY_DELEGATE_H_
  6. #include <set>
  7. #include <string>
  8. #include "components/custom_handlers/protocol_handler_registry.h"
  9. namespace custom_handlers {
  10. // A test ProtocolHandlerRegistry::Delegate implementation that keeps track of
  11. // registered protocols and doesn't change any OS settings.
  12. class TestProtocolHandlerRegistryDelegate
  13. : public custom_handlers::ProtocolHandlerRegistry::Delegate {
  14. public:
  15. TestProtocolHandlerRegistryDelegate();
  16. ~TestProtocolHandlerRegistryDelegate() override;
  17. TestProtocolHandlerRegistryDelegate(
  18. const TestProtocolHandlerRegistryDelegate& other) = delete;
  19. TestProtocolHandlerRegistryDelegate& operator=(
  20. const TestProtocolHandlerRegistryDelegate& other) = delete;
  21. // ProtocolHandlerRegistry::Delegate:
  22. void RegisterExternalHandler(const std::string& protocol) override;
  23. void DeregisterExternalHandler(const std::string& protocol) override;
  24. bool IsExternalHandlerRegistered(const std::string& protocol) override;
  25. void RegisterWithOSAsDefaultClient(const std::string& protocol,
  26. DefaultClientCallback callback) override;
  27. void CheckDefaultClientWithOS(const std::string& protocol,
  28. DefaultClientCallback callback) override;
  29. bool ShouldRemoveHandlersNotInOS() override;
  30. bool IsFakeRegistered(const std::string& protocol);
  31. bool IsFakeRegisteredWithOS(const std::string& protocol);
  32. void set_force_os_failure(bool force) { force_os_failure_ = force; }
  33. bool force_os_failure() { return force_os_failure_; }
  34. void Reset();
  35. private:
  36. // Holds registered protocols.
  37. std::set<std::string> registered_protocols_;
  38. std::set<std::string> os_registered_protocols_;
  39. bool force_os_failure_{false};
  40. };
  41. } // namespace custom_handlers
  42. #endif // COMPONENTS_CUSTOM_HANDLERS_TEST_PROTOCOL_HANDLER_REGISTRY_DELEGATE_H_