Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / web / tests / sim / SimNetwork.h
bloba8914e1c19fba17a8b96c3aa349f6731a0974781
1 // Copyright 2015 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.
5 #ifndef SimNetwork_h
6 #define SimNetwork_h
8 #include "public/platform/WebURLLoaderTestDelegate.h"
9 #include "wtf/HashMap.h"
10 #include "wtf/text/StringHash.h"
11 #include "wtf/text/WTFString.h"
13 namespace blink {
15 class SimRequest;
16 class WebURLLoader;
17 class WebURLLoaderClient;
18 class WebURLResponse;
20 // Simulates a network with precise flow control so you can make requests
21 // return, write data, and finish in a specific order in a unit test. One of
22 // these must be created before using the SimRequest to issue requests.
23 class SimNetwork final : public WebURLLoaderTestDelegate {
24 public:
25 SimNetwork();
26 ~SimNetwork();
28 private:
29 friend class SimRequest;
31 static SimNetwork& current();
33 void servePendingRequests();
34 void addRequest(SimRequest&);
35 void removeRequest(SimRequest&);
37 // WebURLLoaderTestDelegate
38 void didReceiveResponse(WebURLLoaderClient*, WebURLLoader*, const WebURLResponse&) override;
39 void didReceiveData(WebURLLoaderClient*, WebURLLoader*, const char* data, int dataLength, int encodedDataLength) override;
40 void didFail(WebURLLoaderClient*, WebURLLoader*, const WebURLError&) override;
41 void didFinishLoading(WebURLLoaderClient*, WebURLLoader*, double finishTime, int64_t totalEncodedDataLength) override;
43 SimRequest* m_currentRequest;
44 HashMap<String, SimRequest*> m_requests;
47 } // namespace blink
49 #endif