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

Unified Diff: net/test/url_request/url_request_mock_data_job.h

Issue 812543002: Update from https://crrev.com/308331 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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: net/test/url_request/url_request_mock_data_job.h
diff --git a/net/test/url_request/url_request_mock_data_job.h b/net/test/url_request/url_request_mock_data_job.h
new file mode 100644
index 0000000000000000000000000000000000000000..5bdfa23cf8efee56d4a411772dff973b6379287f
--- /dev/null
+++ b/net/test/url_request/url_request_mock_data_job.h
@@ -0,0 +1,60 @@
+// Copyright 2014 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.
+
+#ifndef NET_URL_REQUEST_URL_REQUEST_MOCK_DATA_JOB_H_
+#define NET_URL_REQUEST_URL_REQUEST_MOCK_DATA_JOB_H_
+
+#include <string>
+
+#include "base/memory/weak_ptr.h"
+#include "net/base/net_export.h"
+#include "net/url_request/url_request_job.h"
+
+namespace net {
+
+class URLRequest;
+
+// Mock data job, which synchronously returns data repeated multiple times.
+class URLRequestMockDataJob : public URLRequestJob {
+ public:
+ URLRequestMockDataJob(URLRequest* request,
+ NetworkDelegate* network_delegate,
+ const std::string& data,
+ int data_repeat_count);
+
+ void Start() override;
+ bool ReadRawData(IOBuffer* buf, int buf_size, int* bytes_read) override;
+
+ // Adds the testing URLs to the URLRequestFilter.
+ static void AddUrlHandler();
+ static void AddUrlHandlerForHostname(const std::string& hostname);
+
+ // Given data and repeat cound, constructs a mock URL that will return that
+ // data repeated |repeat_count| times when started. |data| must be safe for
+ // URL.
+ static GURL GetMockHttpUrl(const std::string& data, int repeat_count);
+ static GURL GetMockHttpsUrl(const std::string& data, int repeat_count);
+
+ // URLRequestFailedJob must be added as a handler for |hostname| for
+ // the returned URL to return |net_error|.
+ static GURL GetMockHttpUrlForHostname(const std::string& hostname,
+ const std::string& data,
+ int repeat_count);
+ static GURL GetMockHttpsUrlForHostname(const std::string& hostname,
+ const std::string& data,
+ int repeat_count);
+
+ private:
+ ~URLRequestMockDataJob() override;
+
+ void StartAsync();
+
+ std::string data_;
+ size_t data_offset_;
+ base::WeakPtrFactory<URLRequestMockDataJob> weak_factory_;
+};
+
+} // namespace net
+
+#endif // NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_
« no previous file with comments | « net/test/spawned_test_server/local_test_server_win.cc ('k') | net/test/url_request/url_request_mock_data_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698