xref: /aosp_15_r20/external/cronet/net/proxy_resolution/mock_pac_file_fetcher.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_PROXY_RESOLUTION_MOCK_PAC_FILE_FETCHER_H_
6 #define NET_PROXY_RESOLUTION_MOCK_PAC_FILE_FETCHER_H_
7 
8 #include "base/compiler_specific.h"
9 #include "base/memory/raw_ptr.h"
10 #include "net/base/completion_once_callback.h"
11 #include "net/proxy_resolution/pac_file_fetcher.h"
12 #include "net/traffic_annotation/network_traffic_annotation.h"
13 #include "url/gurl.h"
14 
15 #include <string>
16 
17 namespace net {
18 
19 class URLRequestContext;
20 
21 // A mock PacFileFetcher. No result will be returned to the fetch client
22 // until we call NotifyFetchCompletion() to set the results.
23 class MockPacFileFetcher : public PacFileFetcher {
24  public:
25   MockPacFileFetcher();
26   ~MockPacFileFetcher() override;
27 
28   // PacFileFetcher implementation.
29   int Fetch(const GURL& url,
30             std::u16string* text,
31             CompletionOnceCallback callback,
32             const NetworkTrafficAnnotationTag traffic_annotation) override;
33   void Cancel() override;
34   void OnShutdown() override;
35   URLRequestContext* GetRequestContext() const override;
36 
37   void NotifyFetchCompletion(int result, const std::string& ascii_text);
38   const GURL& pending_request_url() const;
39   bool has_pending_request() const;
40 
41   // Spins the message loop until this->Fetch() is invoked.
42   void WaitUntilFetch();
43 
44  private:
45   GURL pending_request_url_;
46   CompletionOnceCallback pending_request_callback_;
47   raw_ptr<std::u16string, AcrossTasksDanglingUntriaged> pending_request_text_ =
48       nullptr;
49   base::OnceClosure on_fetch_complete_;
50   bool is_shutdown_ = false;
51 };
52 
53 }  // namespace net
54 
55 #endif  // NET_PROXY_RESOLUTION_MOCK_PAC_FILE_FETCHER_H_
56