Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / web / tests / sim / SimRequest.h
blob197f2c1bfd2c09c7a91f0b70788a4eb8cb494268
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 SimRequest_h
6 #define SimRequest_h
8 #include "public/platform/WebURLError.h"
9 #include "public/platform/WebURLResponse.h"
10 #include "wtf/text/WTFString.h"
12 namespace blink {
14 class SimNetwork;
15 class WebURLLoader;
16 class WebURLLoaderClient;
18 // Simulates a single request for a resource from the server. Requires a
19 // SimNetwork to have been created first. Use the start(), write() and finish()
20 // methods to simulate the response from the server. Note that all started
21 // requests must be finished.
22 class SimRequest final {
23 public:
24 SimRequest(String url, String mimeType);
25 ~SimRequest();
27 // Starts the response from the server, this is as if the headers and 200 OK
28 // reply had been received but no response body yet.
29 void start();
31 // Write a chunk of the response body.
32 void write(const String& data);
34 // Finish the response, this is as if the server closed the connection.
35 void finish();
37 const String& url() const { return m_url; }
38 const WebURLError& error() const { return m_error; }
39 const WebURLResponse& response() const { return m_response; }
41 private:
42 friend class SimNetwork;
44 void reset();
46 // Used by SimNetwork.
47 void didReceiveResponse(WebURLLoaderClient*, WebURLLoader*, const WebURLResponse&);
48 void didFail(const WebURLError&);
50 String m_url;
51 WebURLLoader* m_loader;
52 WebURLResponse m_response;
53 WebURLError m_error;
54 WebURLLoaderClient* m_client;
55 unsigned m_totalEncodedDataLength;
56 bool m_isReady;
59 } // namespace blink
61 #endif