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

Side by Side Diff: Source/web/tests/mocks/MockRequest.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: remove extra incs. 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
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/mocks/MockRequest.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/mocks/MockNetwork.h"
13
14 namespace blink {
15
16 MockRequest::MockRequest(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
29 MockNetwork::current().addMockRequest(*this);
30 }
31
32 void MockRequest::didReceiveResponse(WebURLLoaderClient* client, WebURLLoader* l oader, const WebURLResponse& response)
33 {
34 m_client = client;
35 m_loader = loader;
36 m_response = response;
37 m_isReady = true;
38 }
39
40 void MockRequest::didFail(const WebURLError& error)
41 {
42 m_error = error;
43 }
44
45 void MockRequest::start()
46 {
47 MockNetwork::current().servePendingRequests();
48 ASSERT(m_isReady);
49 m_client->didReceiveResponse(m_loader, m_response);
50 }
51
52 void MockRequest::write(const String& data)
53 {
54 ASSERT(m_isReady && !m_error.reason);
55 m_totalEncodedDataLength += data.length();
56 m_client->didReceiveData(m_loader, data.utf8().data(), data.length(), data.l ength());
57 }
58
59 void MockRequest::finish()
60 {
61 ASSERT(m_isReady);
62 if (m_error.reason) {
63 m_client->didFail(m_loader, m_error);
64 } else {
65 // TODO(esprehn): Is claiming a request time of 0 okay for tests?
66 m_client->didFinishLoading(m_loader, 0, m_totalEncodedDataLength);
67 }
68 MockNetwork::current().removeMockRequest(*this);
69 reset();
70 }
71
72 void MockRequest::reset()
73 {
74 m_isReady = false;
75 m_client = nullptr;
76 m_loader = nullptr;
77 }
78
79 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698