fake_url_checker_client.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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_SAFE_SEARCH_API_FAKE_URL_CHECKER_CLIENT_H_
  5. #define COMPONENTS_SAFE_SEARCH_API_FAKE_URL_CHECKER_CLIENT_H_
  6. #include "base/callback.h"
  7. #include "components/safe_search_api/url_checker_client.h"
  8. namespace safe_search_api {
  9. // Helper class with fake URLCheckerClient for use with URLChecker. This
  10. // lets tests control the response the URLChecker will receive from the
  11. // URLCheckerClient. Used to test URLChecker.
  12. class FakeURLCheckerClient : public URLCheckerClient {
  13. public:
  14. FakeURLCheckerClient();
  15. FakeURLCheckerClient(const FakeURLCheckerClient&) = delete;
  16. FakeURLCheckerClient& operator=(const FakeURLCheckerClient&) = delete;
  17. ~FakeURLCheckerClient() override;
  18. // Fake override that simply holds references of |url| and |callback|.
  19. //
  20. // See RunCallback() method documentation below on how to run the callback.
  21. void CheckURL(const GURL& url, ClientCheckCallback callback) override;
  22. // Runs the callback function input by the last call of CheckURL() with the
  23. // result input with the last call of SetResult().
  24. void RunCallback(ClientClassification classification);
  25. // Asynchronous version of RunCallback().
  26. void RunCallbackAsync(ClientClassification classification);
  27. private:
  28. ClientCheckCallback callback_;
  29. GURL url_;
  30. };
  31. } // namespace safe_search_api
  32. #endif // COMPONENTS_SAFE_SEARCH_API_FAKE_URL_CHECKER_CLIENT_H_