mock_pac_file_fetcher.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) 2012 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 NET_PROXY_RESOLUTION_MOCK_PAC_FILE_FETCHER_H_
  5. #define NET_PROXY_RESOLUTION_MOCK_PAC_FILE_FETCHER_H_
  6. #include "base/compiler_specific.h"
  7. #include "base/memory/raw_ptr.h"
  8. #include "net/base/completion_once_callback.h"
  9. #include "net/proxy_resolution/pac_file_fetcher.h"
  10. #include "net/traffic_annotation/network_traffic_annotation.h"
  11. #include "url/gurl.h"
  12. #include <string>
  13. namespace net {
  14. class URLRequestContext;
  15. // A mock PacFileFetcher. No result will be returned to the fetch client
  16. // until we call NotifyFetchCompletion() to set the results.
  17. class MockPacFileFetcher : public PacFileFetcher {
  18. public:
  19. MockPacFileFetcher();
  20. ~MockPacFileFetcher() override;
  21. // PacFileFetcher implementation.
  22. int Fetch(const GURL& url,
  23. std::u16string* text,
  24. CompletionOnceCallback callback,
  25. const NetworkTrafficAnnotationTag traffic_annotation) override;
  26. void Cancel() override;
  27. void OnShutdown() override;
  28. URLRequestContext* GetRequestContext() const override;
  29. void NotifyFetchCompletion(int result, const std::string& ascii_text);
  30. const GURL& pending_request_url() const;
  31. bool has_pending_request() const;
  32. // Spins the message loop until this->Fetch() is invoked.
  33. void WaitUntilFetch();
  34. private:
  35. GURL pending_request_url_;
  36. CompletionOnceCallback pending_request_callback_;
  37. raw_ptr<std::u16string> pending_request_text_ = nullptr;
  38. base::OnceClosure on_fetch_complete_;
  39. bool is_shutdown_ = false;
  40. };
  41. } // namespace net
  42. #endif // NET_PROXY_RESOLUTION_MOCK_PAC_FILE_FETCHER_H_