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

Side by Side Diff: Source/web/tests/sim/SimNetwork.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/SimNetwork.h ('k') | Source/web/tests/sim/SimRequest.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/SimNetwork.h"
7
8 #include "public/platform/Platform.h"
9 #include "public/platform/WebURLError.h"
10 #include "public/platform/WebURLLoader.h"
11 #include "public/platform/WebURLLoaderClient.h"
12 #include "public/platform/WebURLResponse.h"
13 #include "public/platform/WebUnitTestSupport.h"
14 #include "web/tests/sim/SimRequest.h"
15
16 namespace blink {
17
18 static SimNetwork* s_network = nullptr;
19
20 SimNetwork::SimNetwork()
21 : m_currentRequest(nullptr)
22 {
23 Platform::current()->unitTestSupport()->setLoaderDelegate(this);
24 ASSERT(!s_network);
25 s_network = this;
26 }
27
28 SimNetwork::~SimNetwork()
29 {
30 Platform::current()->unitTestSupport()->setLoaderDelegate(nullptr);
31 Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
32 s_network = nullptr;
33 }
34
35 SimNetwork& SimNetwork::current()
36 {
37 ASSERT(s_network);
38 return *s_network;
39 }
40
41 void SimNetwork::servePendingRequests()
42 {
43 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
44 }
45
46 void SimNetwork::didReceiveResponse(WebURLLoaderClient* client, WebURLLoader* lo ader, const WebURLResponse& response)
47 {
48 auto it = m_requests.find(response.url().string());
49 if (it == m_requests.end()) {
50 client->didReceiveResponse(loader, response);
51 return;
52 }
53 ASSERT(it->value);
54 m_currentRequest = it->value;
55 m_currentRequest->didReceiveResponse(client, loader, response);
56 }
57
58 void SimNetwork::didReceiveData(WebURLLoaderClient* client, WebURLLoader* loader , const char* data, int dataLength, int encodedDataLength)
59 {
60 if (!m_currentRequest)
61 client->didReceiveData(loader, data, dataLength, encodedDataLength);
62 }
63
64 void SimNetwork::didFail(WebURLLoaderClient* client, WebURLLoader* loader, const WebURLError& error)
65 {
66 if (!m_currentRequest) {
67 client->didFail(loader, error);
68 return;
69 }
70 m_currentRequest->didFail(error);
71 }
72
73 void SimNetwork::didFinishLoading(WebURLLoaderClient* client, WebURLLoader* load er, double finishTime, int64_t totalEncodedDataLength)
74 {
75 if (!m_currentRequest) {
76 client->didFinishLoading(loader, finishTime, totalEncodedDataLength);
77 return;
78 }
79 m_currentRequest = nullptr;
80 }
81
82 void SimNetwork::addRequest(SimRequest& request)
83 {
84 m_requests.add(request.url(), &request);
85 }
86
87 void SimNetwork::removeRequest(SimRequest& request)
88 {
89 m_requests.remove(request.url());
90 }
91
92 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/tests/sim/SimNetwork.h ('k') | Source/web/tests/sim/SimRequest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698