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

Unified 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, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/web/tests/sim/SimNetwork.h ('k') | Source/web/tests/sim/SimRequest.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/web/tests/sim/SimNetwork.cpp
diff --git a/Source/web/tests/sim/SimNetwork.cpp b/Source/web/tests/sim/SimNetwork.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..dbf3324ec1926f1068fe55af0eaf03e435567af5
--- /dev/null
+++ b/Source/web/tests/sim/SimNetwork.cpp
@@ -0,0 +1,92 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "web/tests/sim/SimNetwork.h"
+
+#include "public/platform/Platform.h"
+#include "public/platform/WebURLError.h"
+#include "public/platform/WebURLLoader.h"
+#include "public/platform/WebURLLoaderClient.h"
+#include "public/platform/WebURLResponse.h"
+#include "public/platform/WebUnitTestSupport.h"
+#include "web/tests/sim/SimRequest.h"
+
+namespace blink {
+
+static SimNetwork* s_network = nullptr;
+
+SimNetwork::SimNetwork()
+ : m_currentRequest(nullptr)
+{
+ Platform::current()->unitTestSupport()->setLoaderDelegate(this);
+ ASSERT(!s_network);
+ s_network = this;
+}
+
+SimNetwork::~SimNetwork()
+{
+ Platform::current()->unitTestSupport()->setLoaderDelegate(nullptr);
+ Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
+ s_network = nullptr;
+}
+
+SimNetwork& SimNetwork::current()
+{
+ ASSERT(s_network);
+ return *s_network;
+}
+
+void SimNetwork::servePendingRequests()
+{
+ Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
+}
+
+void SimNetwork::didReceiveResponse(WebURLLoaderClient* client, WebURLLoader* loader, const WebURLResponse& response)
+{
+ auto it = m_requests.find(response.url().string());
+ if (it == m_requests.end()) {
+ client->didReceiveResponse(loader, response);
+ return;
+ }
+ ASSERT(it->value);
+ m_currentRequest = it->value;
+ m_currentRequest->didReceiveResponse(client, loader, response);
+}
+
+void SimNetwork::didReceiveData(WebURLLoaderClient* client, WebURLLoader* loader, const char* data, int dataLength, int encodedDataLength)
+{
+ if (!m_currentRequest)
+ client->didReceiveData(loader, data, dataLength, encodedDataLength);
+}
+
+void SimNetwork::didFail(WebURLLoaderClient* client, WebURLLoader* loader, const WebURLError& error)
+{
+ if (!m_currentRequest) {
+ client->didFail(loader, error);
+ return;
+ }
+ m_currentRequest->didFail(error);
+}
+
+void SimNetwork::didFinishLoading(WebURLLoaderClient* client, WebURLLoader* loader, double finishTime, int64_t totalEncodedDataLength)
+{
+ if (!m_currentRequest) {
+ client->didFinishLoading(loader, finishTime, totalEncodedDataLength);
+ return;
+ }
+ m_currentRequest = nullptr;
+}
+
+void SimNetwork::addRequest(SimRequest& request)
+{
+ m_requests.add(request.url(), &request);
+}
+
+void SimNetwork::removeRequest(SimRequest& request)
+{
+ m_requests.remove(request.url());
+}
+
+} // namespace blink
« 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