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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_WRAPPER_H_
6 #define CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_WRAPPER_H_
7
8 #include <memory>
9 #include <string>
10
11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/run_loop.h"
14 #include "net/base/net_errors.h"
15
16 class GURL;
17
18 namespace net {
19 struct RedirectInfo;
20 class URLRequestStatus;
21 }
22
23 namespace content {
24 class ResourceHandler;
25 struct ResourceResponse;
26
27 class TestResourceHandlerWrapper {
28 public:
29 explicit TestResourceHandlerWrapper(ResourceHandler* resource_handler);
30 ~TestResourceHandlerWrapper();
31
32 enum class Result { NONE, CALLBACK_PENDING, RESUME, CANCEL };
33
34 // These all run the corresponding methods on ResourceHandler, with a new
35 // ResourceController. They include checks that the previous callback was run,
36 // and all previous ResourceControllers were destroyed.
37 Result OnRequestRedirected(const net::RedirectInfo& redirect_info,
38 ResourceResponse* response);
39 Result OnResponseStarted(ResourceResponse* response);
40 Result OnWillStart(const GURL& url);
41 Result OnReadCompleted(int bytes_read);
42 Result OnResponseCompleted(const net::URLRequestStatus& status);
43
44 // Same as OnResponseCompleted, except it can be called while waiting on a
45 // callback from a previous ResourceController. When that happens, has checks
46 // that the oustanding ResourceController is not used.
47 Result OnResponseCompletedForOutOfBandCancel(
48 const net::URLRequestStatus& status);
49
50 void OnResume();
51
52 void OnCancelWithError(int net_error);
53
54 void RunUntilCanceled();
55
56 Result last_result() const { return last_result_; }
57 int net_error() const { return net_error_; }
58
59 private:
60 class TestResourceController;
61
62 ResourceHandler* const resource_handler_;
63
64 Result last_result_ = Result::NONE;
65 int net_error_ = net::OK;
66
67 base::RunLoop cancel_run_loop_;
68
69 base::WeakPtrFactory<TestResourceHandlerWrapper> weak_factory_;
70
71 DISALLOW_COPY_AND_ASSIGN(TestResourceHandlerWrapper);
72 };
73
74 } // namespace content
75
76 #endif // CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_WRAPPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698