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

Unified Diff: content/browser/loader/test_resource_handler_wrapper.h

Issue 2526983002: Refactor ResourceHandler API. (Closed)
Patch Set: Fix merge again (?) Created 4 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: content/browser/loader/test_resource_handler_wrapper.h
diff --git a/content/browser/loader/test_resource_handler_wrapper.h b/content/browser/loader/test_resource_handler_wrapper.h
new file mode 100644
index 0000000000000000000000000000000000000000..8b2d22ffb23e10a5fc07bccf0273c2aade800129
--- /dev/null
+++ b/content/browser/loader/test_resource_handler_wrapper.h
@@ -0,0 +1,76 @@
+// Copyright 2016 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 CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_WRAPPER_H_
+#define CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_WRAPPER_H_
+
+#include <memory>
+#include <string>
+
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "base/run_loop.h"
+#include "net/base/net_errors.h"
+
+class GURL;
+
+namespace net {
+struct RedirectInfo;
+class URLRequestStatus;
+}
+
+namespace content {
+class ResourceHandler;
+struct ResourceResponse;
+
+class TestResourceHandlerWrapper {
+ public:
+ explicit TestResourceHandlerWrapper(ResourceHandler* resource_handler);
+ ~TestResourceHandlerWrapper();
+
+ enum class Result { NONE, CALLBACK_PENDING, RESUME, CANCEL };
+
+ // These all run the corresponding methods on ResourceHandler, with a new
+ // ResourceController. They include checks that the previous callback was run,
+ // and all previous ResourceControllers were destroyed.
+ Result OnRequestRedirected(const net::RedirectInfo& redirect_info,
+ ResourceResponse* response);
+ Result OnResponseStarted(ResourceResponse* response);
+ Result OnWillStart(const GURL& url);
+ Result OnReadCompleted(int bytes_read);
+ Result OnResponseCompleted(const net::URLRequestStatus& status);
+
+ // Same as OnResponseCompleted, except it can be called while waiting on a
+ // callback from a previous ResourceController. When that happens, has checks
+ // that the oustanding ResourceController is not used.
+ Result OnResponseCompletedForOutOfBandCancel(
+ const net::URLRequestStatus& status);
+
+ void OnResume();
+
+ void OnCancelWithError(int net_error);
+
+ void RunUntilCanceled();
+
+ Result last_result() const { return last_result_; }
+ int net_error() const { return net_error_; }
+
+ private:
+ class TestResourceController;
+
+ ResourceHandler* const resource_handler_;
+
+ Result last_result_ = Result::NONE;
+ int net_error_ = net::OK;
+
+ base::RunLoop cancel_run_loop_;
+
+ base::WeakPtrFactory<TestResourceHandlerWrapper> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestResourceHandlerWrapper);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_WRAPPER_H_

Powered by Google App Engine
This is Rietveld 408576698