OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SimRequest_h | 5 #ifndef SimRequest_h |
6 #define SimRequest_h | 6 #define SimRequest_h |
7 | 7 |
8 #include "public/platform/WebURLError.h" | 8 #include "public/platform/WebURLError.h" |
9 #include "public/platform/WebURLResponse.h" | 9 #include "public/platform/WebURLResponse.h" |
10 #include "wtf/text/WTFString.h" | 10 #include "wtf/text/WTFString.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 class SimNetwork; | 14 class SimNetwork; |
15 class WebURLLoader; | 15 class WebURLLoader; |
16 class WebURLLoaderClient; | 16 class WebURLLoaderClient; |
17 | 17 |
18 class SimRequest { | 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 { |
19 public: | 23 public: |
20 SimRequest(String url, String mimeType); | 24 SimRequest(String url, String mimeType); |
| 25 ~SimRequest(); |
21 | 26 |
22 void didReceiveResponse(WebURLLoaderClient*, WebURLLoader*, const WebURLResp
onse&); | 27 // Starts the response from the server, this is as if the headers and 200 OK |
23 void didFail(const WebURLError&); | 28 // reply had been received but no response body yet. |
| 29 void start(); |
24 | 30 |
25 void start(); | 31 // Write a chunk of the response body. |
26 void write(const String& data); | 32 void write(const String& data); |
| 33 |
| 34 // Finish the response, this is as if the server closed the connection. |
27 void finish(); | 35 void finish(); |
28 | 36 |
29 bool isReady() const { return m_isReady; } | |
30 const String& url() const { return m_url; } | 37 const String& url() const { return m_url; } |
31 const WebURLError& error() const { return m_error; } | 38 const WebURLError& error() const { return m_error; } |
32 const WebURLResponse& response() const { return m_response; } | 39 const WebURLResponse& response() const { return m_response; } |
33 | 40 |
| 41 private: |
| 42 friend class SimNetwork; |
| 43 |
34 void reset(); | 44 void reset(); |
35 | 45 |
36 private: | 46 // Used by SimNetwork. |
| 47 void didReceiveResponse(WebURLLoaderClient*, WebURLLoader*, const WebURLResp
onse&); |
| 48 void didFail(const WebURLError&); |
| 49 |
37 String m_url; | 50 String m_url; |
38 WebURLLoader* m_loader; | 51 WebURLLoader* m_loader; |
39 WebURLResponse m_response; | 52 WebURLResponse m_response; |
40 WebURLError m_error; | 53 WebURLError m_error; |
41 WebURLLoaderClient* m_client; | 54 WebURLLoaderClient* m_client; |
42 unsigned m_totalEncodedDataLength; | 55 unsigned m_totalEncodedDataLength; |
43 bool m_isReady; | 56 bool m_isReady; |
44 }; | 57 }; |
45 | 58 |
46 } // namespace blink | 59 } // namespace blink |
47 | 60 |
48 #endif | 61 #endif |
OLD | NEW |