resource_request_allowed_notifier_test_util.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2013 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_WEB_RESOURCE_RESOURCE_REQUEST_ALLOWED_NOTIFIER_TEST_UTIL_H_
  5. #define COMPONENTS_WEB_RESOURCE_RESOURCE_REQUEST_ALLOWED_NOTIFIER_TEST_UTIL_H_
  6. #include <memory>
  7. #include "components/web_resource/resource_request_allowed_notifier.h"
  8. class PrefService;
  9. namespace web_resource {
  10. // A subclass of ResourceRequestAllowedNotifier used to expose some
  11. // functionality for testing.
  12. //
  13. // By default, the constructor sets this class to override
  14. // ResourceRequestsAllowed, so its state can be set with SetRequestsAllowed.
  15. // This is meant for higher level tests of services to ensure they adhere to the
  16. // notifications of the ResourceRequestAllowedNotifier. Lower level tests can
  17. // disable this by calling SetRequestsAllowedOverride with the value they want
  18. // it to return.
  19. class TestRequestAllowedNotifier : public ResourceRequestAllowedNotifier {
  20. public:
  21. TestRequestAllowedNotifier(
  22. PrefService* local_state,
  23. network::NetworkConnectionTracker* network_connection_tracker);
  24. TestRequestAllowedNotifier(const TestRequestAllowedNotifier&) = delete;
  25. TestRequestAllowedNotifier& operator=(const TestRequestAllowedNotifier&) =
  26. delete;
  27. ~TestRequestAllowedNotifier() override;
  28. // A version of |Init()| that accepts a custom EulaAcceptedNotifier.
  29. void InitWithEulaAcceptNotifier(
  30. Observer* observer,
  31. std::unique_ptr<EulaAcceptedNotifier> eula_notifier);
  32. // Makes ResourceRequestsAllowed return |allowed| when it is called.
  33. void SetRequestsAllowedOverride(bool allowed);
  34. // Notify observers that requests are allowed. This will only work if
  35. // the observer is expecting a notification.
  36. void NotifyObserver();
  37. // ResourceRequestAllowedNotifier overrides:
  38. State GetResourceRequestsAllowedState() override;
  39. EulaAcceptedNotifier* CreateEulaNotifier() override;
  40. private:
  41. std::unique_ptr<EulaAcceptedNotifier> test_eula_notifier_;
  42. bool override_requests_allowed_;
  43. bool requests_allowed_;
  44. };
  45. } // namespace web_resource
  46. #endif // COMPONENTS_WEB_RESOURCE_RESOURCE_REQUEST_ALLOWED_NOTIFIER_TEST_UTIL_H_