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

Unified 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, 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/SimRequest.h ('k') | Source/web/tests/sim/SimWebViewClient.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/web/tests/sim/SimRequest.cpp
diff --git a/Source/web/tests/sim/SimRequest.cpp b/Source/web/tests/sim/SimRequest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..84e11e74d1cca77e6596af32c8f1848bb3ae095b
--- /dev/null
+++ b/Source/web/tests/sim/SimRequest.cpp
@@ -0,0 +1,78 @@
+// 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/SimRequest.h"
+
+#include "platform/weborigin/KURL.h"
+#include "public/platform/Platform.h"
+#include "public/platform/WebURLLoaderClient.h"
+#include "public/platform/WebUnitTestSupport.h"
+#include "web/tests/sim/SimNetwork.h"
+
+namespace blink {
+
+SimRequest::SimRequest(String url, String mimeType)
+ : m_url(url)
+ , m_loader(nullptr)
+ , m_client(nullptr)
+ , m_totalEncodedDataLength(0)
+ , m_isReady(false)
+{
+ KURL fullUrl(ParsedURLString, url);
+ WebURLResponse response(fullUrl);
+ response.setMIMEType(mimeType);
+ response.setHTTPStatusCode(200);
+ Platform::current()->unitTestSupport()->registerMockedURL(fullUrl, response, "");
+ SimNetwork::current().addRequest(*this);
+}
+
+void SimRequest::didReceiveResponse(WebURLLoaderClient* client, WebURLLoader* loader, const WebURLResponse& response)
+{
+ m_client = client;
+ m_loader = loader;
+ m_response = response;
+ m_isReady = true;
+}
+
+void SimRequest::didFail(const WebURLError& error)
+{
+ m_error = error;
+}
+
+void SimRequest::start()
+{
+ SimNetwork::current().servePendingRequests();
+ ASSERT(m_isReady);
+ m_client->didReceiveResponse(m_loader, m_response);
+}
+
+void SimRequest::write(const String& data)
+{
+ ASSERT(m_isReady && !m_error.reason);
+ m_totalEncodedDataLength += data.length();
+ m_client->didReceiveData(m_loader, data.utf8().data(), data.length(), data.length());
+}
+
+void SimRequest::finish()
+{
+ ASSERT(m_isReady);
+ if (m_error.reason) {
+ m_client->didFail(m_loader, m_error);
+ } else {
+ // TODO(esprehn): Is claiming a request time of 0 okay for tests?
+ m_client->didFinishLoading(m_loader, 0, m_totalEncodedDataLength);
+ }
+ reset();
+}
+
+void SimRequest::reset()
+{
+ m_isReady = false;
+ m_client = nullptr;
+ m_loader = nullptr;
+ SimNetwork::current().removeRequest(*this);
+}
+
+} // namespace blink
« 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