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

Unified 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, 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
Index: Source/web/tests/mocks/MockRequest.cpp
diff --git a/Source/web/tests/mocks/MockRequest.cpp b/Source/web/tests/mocks/MockRequest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f4e459d47a366eed6ea19ec4974a919a6b1bab19
--- /dev/null
+++ b/Source/web/tests/mocks/MockRequest.cpp
@@ -0,0 +1,79 @@
+// 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/mocks/MockRequest.h"
+
+#include "platform/weborigin/KURL.h"
+#include "public/platform/Platform.h"
+#include "public/platform/WebURLLoaderClient.h"
+#include "public/platform/WebUnitTestSupport.h"
+#include "web/tests/mocks/MockNetwork.h"
+
+namespace blink {
+
+MockRequest::MockRequest(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, "");
+
+ MockNetwork::current().addMockRequest(*this);
+}
+
+void MockRequest::didReceiveResponse(WebURLLoaderClient* client, WebURLLoader* loader, const WebURLResponse& response)
+{
+ m_client = client;
+ m_loader = loader;
+ m_response = response;
+ m_isReady = true;
+}
+
+void MockRequest::didFail(const WebURLError& error)
+{
+ m_error = error;
+}
+
+void MockRequest::start()
+{
+ MockNetwork::current().servePendingRequests();
+ ASSERT(m_isReady);
+ m_client->didReceiveResponse(m_loader, m_response);
+}
+
+void MockRequest::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 MockRequest::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);
+ }
+ MockNetwork::current().removeMockRequest(*this);
+ reset();
+}
+
+void MockRequest::reset()
+{
+ m_isReady = false;
+ m_client = nullptr;
+ m_loader = nullptr;
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698