Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: Source/web/tests/sim/SimRequest.cpp

Issue 1313013005: Add a test that we resume commits after inserting the body. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: dcheng@ review Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/web/tests/sim/SimRequest.h ('k') | Source/web/tests/sim/SimWebViewClient.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "config.h"
6 #include "web/tests/sim/SimRequest.h"
7
8 #include "platform/weborigin/KURL.h"
9 #include "public/platform/Platform.h"
10 #include "public/platform/WebURLLoaderClient.h"
11 #include "public/platform/WebUnitTestSupport.h"
12 #include "web/tests/sim/SimNetwork.h"
13
14 namespace blink {
15
16 SimRequest::SimRequest(String url, String mimeType)
17 : m_url(url)
18 , m_loader(nullptr)
19 , m_client(nullptr)
20 , m_totalEncodedDataLength(0)
21 , m_isReady(false)
22 {
23 KURL fullUrl(ParsedURLString, url);
24 WebURLResponse response(fullUrl);
25 response.setMIMEType(mimeType);
26 response.setHTTPStatusCode(200);
27 Platform::current()->unitTestSupport()->registerMockedURL(fullUrl, response, "");
28 SimNetwork::current().addRequest(*this);
29 }
30
31 void SimRequest::didReceiveResponse(WebURLLoaderClient* client, WebURLLoader* lo ader, const WebURLResponse& response)
32 {
33 m_client = client;
34 m_loader = loader;
35 m_response = response;
36 m_isReady = true;
37 }
38
39 void SimRequest::didFail(const WebURLError& error)
40 {
41 m_error = error;
42 }
43
44 void SimRequest::start()
45 {
46 SimNetwork::current().servePendingRequests();
47 ASSERT(m_isReady);
48 m_client->didReceiveResponse(m_loader, m_response);
49 }
50
51 void SimRequest::write(const String& data)
52 {
53 ASSERT(m_isReady && !m_error.reason);
54 m_totalEncodedDataLength += data.length();
55 m_client->didReceiveData(m_loader, data.utf8().data(), data.length(), data.l ength());
56 }
57
58 void SimRequest::finish()
59 {
60 ASSERT(m_isReady);
61 if (m_error.reason) {
62 m_client->didFail(m_loader, m_error);
63 } else {
64 // TODO(esprehn): Is claiming a request time of 0 okay for tests?
65 m_client->didFinishLoading(m_loader, 0, m_totalEncodedDataLength);
66 }
67 reset();
68 }
69
70 void SimRequest::reset()
71 {
72 m_isReady = false;
73 m_client = nullptr;
74 m_loader = nullptr;
75 SimNetwork::current().removeRequest(*this);
76 }
77
78 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/tests/sim/SimRequest.h ('k') | Source/web/tests/sim/SimWebViewClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698