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

Side by Side Diff: chrome/browser/prerender/prerender_resource_throttle_unittest.cc

Issue 2535723005: Stop using ResourceController in ResourceThrottle (Closed)
Patch Set: Addressed #62 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <set> 5 #include <set>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/threading/sequenced_worker_pool.h" 13 #include "base/threading/sequenced_worker_pool.h"
14 #include "chrome/browser/net/url_request_mock_util.h" 14 #include "chrome/browser/net/url_request_mock_util.h"
15 #include "chrome/browser/prerender/prerender_contents.h" 15 #include "chrome/browser/prerender/prerender_contents.h"
16 #include "chrome/browser/prerender/prerender_manager.h" 16 #include "chrome/browser/prerender/prerender_manager.h"
17 #include "chrome/browser/prerender/prerender_resource_throttle.h" 17 #include "chrome/browser/prerender/prerender_resource_throttle.h"
18 #include "chrome/test/base/testing_browser_process.h" 18 #include "chrome/test/base/testing_browser_process.h"
19 #include "content/public/browser/resource_controller.h"
20 #include "content/public/browser/resource_request_info.h" 19 #include "content/public/browser/resource_request_info.h"
20 #include "content/public/browser/resource_throttle.h"
21 #include "content/public/test/test_browser_thread.h" 21 #include "content/public/test/test_browser_thread.h"
22 #include "ipc/ipc_message.h" 22 #include "ipc/ipc_message.h"
23 #include "net/base/request_priority.h" 23 #include "net/base/request_priority.h"
24 #include "net/test/url_request/url_request_mock_http_job.h" 24 #include "net/test/url_request/url_request_mock_http_job.h"
25 #include "net/url_request/redirect_info.h" 25 #include "net/url_request/redirect_info.h"
26 #include "net/url_request/url_request.h" 26 #include "net/url_request/url_request.h"
27 #include "net/url_request/url_request_test_util.h" 27 #include "net/url_request/url_request_test_util.h"
28 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
29 29
30 using content::BrowserThread; 30 using content::BrowserThread;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 mutable_config().rate_limit_enabled = false; 84 mutable_config().rate_limit_enabled = false;
85 } 85 }
86 86
87 // We never allocate our PrerenderContents in PrerenderManager, so we don't 87 // We never allocate our PrerenderContents in PrerenderManager, so we don't
88 // ever want the default pending delete behaviour. 88 // ever want the default pending delete behaviour.
89 void MoveEntryToPendingDelete(PrerenderContents* entry, 89 void MoveEntryToPendingDelete(PrerenderContents* entry,
90 FinalStatus final_status) override {} 90 FinalStatus final_status) override {}
91 }; 91 };
92 92
93 class DeferredRedirectDelegate : public net::URLRequest::Delegate, 93 class DeferredRedirectDelegate : public net::URLRequest::Delegate,
94 public content::ResourceController { 94 public content::ResourceThrottle::Delegate {
95 public: 95 public:
96 DeferredRedirectDelegate() 96 DeferredRedirectDelegate()
97 : throttle_(NULL), 97 : throttle_(NULL),
98 was_deferred_(false), 98 was_deferred_(false),
99 cancel_called_(false), 99 cancel_called_(false),
100 resume_called_(false) { 100 resume_called_(false) {
101 } 101 }
102 102
103 void SetThrottle(PrerenderResourceThrottle* throttle) { 103 void SetThrottle(PrerenderResourceThrottle* throttle) {
104 throttle_ = throttle; 104 throttle_ = throttle;
105 throttle_->set_controller_for_testing(this); 105 throttle_->set_delegate_for_testing(this);
106 } 106 }
107 107
108 void Run() { 108 void Run() {
109 run_loop_.reset(new base::RunLoop()); 109 run_loop_.reset(new base::RunLoop());
110 run_loop_->Run(); 110 run_loop_->Run();
111 } 111 }
112 112
113 bool was_deferred() const { return was_deferred_; } 113 bool was_deferred() const { return was_deferred_; }
114 bool cancel_called() const { return cancel_called_; } 114 bool cancel_called() const { return cancel_called_; }
115 bool resume_called() const { return resume_called_; } 115 bool resume_called() const { return resume_called_; }
116 116
117 // net::URLRequest::Delegate implementation: 117 // net::URLRequest::Delegate implementation:
118 void OnReceivedRedirect(net::URLRequest* request, 118 void OnReceivedRedirect(net::URLRequest* request,
119 const net::RedirectInfo& redirect_info, 119 const net::RedirectInfo& redirect_info,
120 bool* defer_redirect) override { 120 bool* defer_redirect) override {
121 // Defer the redirect either way. 121 // Defer the redirect either way.
122 *defer_redirect = true; 122 *defer_redirect = true;
123 123
124 // Find out what the throttle would have done. 124 // Find out what the throttle would have done.
125 throttle_->WillRedirectRequest(redirect_info, &was_deferred_); 125 throttle_->WillRedirectRequest(redirect_info, &was_deferred_);
126 run_loop_->Quit(); 126 run_loop_->Quit();
127 } 127 }
128 void OnResponseStarted(net::URLRequest* request, int net_error) override {} 128 void OnResponseStarted(net::URLRequest* request, int net_error) override {}
129 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {} 129 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {}
130 130
131 // content::ResourceController implementation: 131 // content::ResourceThrottle::Delegate implementation:
132 void Cancel() override { 132 void Cancel() override {
133 EXPECT_FALSE(cancel_called_); 133 EXPECT_FALSE(cancel_called_);
134 EXPECT_FALSE(resume_called_); 134 EXPECT_FALSE(resume_called_);
135 135
136 cancel_called_ = true; 136 cancel_called_ = true;
137 run_loop_->Quit(); 137 run_loop_->Quit();
138 } 138 }
139 void CancelAndIgnore() override { Cancel(); } 139 void CancelAndIgnore() override { Cancel(); }
140 void CancelWithError(int error_code) override { Cancel(); } 140 void CancelWithError(int error_code) override { Cancel(); }
141 void Resume() override { 141 void Resume() override {
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 // We should have cancelled the prerender. 321 // We should have cancelled the prerender.
322 EXPECT_EQ(FINAL_STATUS_BAD_DEFERRED_REDIRECT, 322 EXPECT_EQ(FINAL_STATUS_BAD_DEFERRED_REDIRECT,
323 test_contents()->final_status()); 323 test_contents()->final_status());
324 324
325 // Cleanup work so the prerender is gone. 325 // Cleanup work so the prerender is gone.
326 test_contents()->Cancel(); 326 test_contents()->Cancel();
327 RunEvents(); 327 RunEvents();
328 } 328 }
329 329
330 } // namespace prerender 330 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698