| OLD | NEW |
| 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/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 route_id_(route_id) { | 45 route_id_(route_id) { |
| 46 PrerenderResourceThrottle::OverridePrerenderContentsForTesting(this); | 46 PrerenderResourceThrottle::OverridePrerenderContentsForTesting(this); |
| 47 } | 47 } |
| 48 | 48 |
| 49 virtual ~TestPrerenderContents() { | 49 virtual ~TestPrerenderContents() { |
| 50 if (final_status() == FINAL_STATUS_MAX) | 50 if (final_status() == FINAL_STATUS_MAX) |
| 51 SetFinalStatus(FINAL_STATUS_USED); | 51 SetFinalStatus(FINAL_STATUS_USED); |
| 52 PrerenderResourceThrottle::OverridePrerenderContentsForTesting(NULL); | 52 PrerenderResourceThrottle::OverridePrerenderContentsForTesting(NULL); |
| 53 } | 53 } |
| 54 | 54 |
| 55 virtual bool GetChildId(int* child_id) const OVERRIDE { | 55 virtual bool GetChildId(int* child_id) const override { |
| 56 *child_id = child_id_; | 56 *child_id = child_id_; |
| 57 return true; | 57 return true; |
| 58 } | 58 } |
| 59 | 59 |
| 60 virtual bool GetRouteId(int* route_id) const OVERRIDE { | 60 virtual bool GetRouteId(int* route_id) const override { |
| 61 *route_id = route_id_; | 61 *route_id = route_id_; |
| 62 return true; | 62 return true; |
| 63 } | 63 } |
| 64 | 64 |
| 65 void Start() { | 65 void Start() { |
| 66 prerendering_has_started_ = true; | 66 prerendering_has_started_ = true; |
| 67 NotifyPrerenderStart(); | 67 NotifyPrerenderStart(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void Cancel() { | 70 void Cancel() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 83 class TestPrerenderManager : public PrerenderManager { | 83 class TestPrerenderManager : public PrerenderManager { |
| 84 public: | 84 public: |
| 85 explicit TestPrerenderManager(PrerenderTracker* prerender_tracker) : | 85 explicit TestPrerenderManager(PrerenderTracker* prerender_tracker) : |
| 86 PrerenderManager(NULL, prerender_tracker) { | 86 PrerenderManager(NULL, prerender_tracker) { |
| 87 mutable_config().rate_limit_enabled = false; | 87 mutable_config().rate_limit_enabled = false; |
| 88 } | 88 } |
| 89 | 89 |
| 90 // We never allocate our PrerenderContents in PrerenderManager, so we don't | 90 // We never allocate our PrerenderContents in PrerenderManager, so we don't |
| 91 // ever want the default pending delete behaviour. | 91 // ever want the default pending delete behaviour. |
| 92 virtual void MoveEntryToPendingDelete(PrerenderContents* entry, | 92 virtual void MoveEntryToPendingDelete(PrerenderContents* entry, |
| 93 FinalStatus final_status) OVERRIDE { | 93 FinalStatus final_status) override { |
| 94 } | 94 } |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 class DeferredRedirectDelegate : public net::URLRequest::Delegate, | 97 class DeferredRedirectDelegate : public net::URLRequest::Delegate, |
| 98 public content::ResourceController { | 98 public content::ResourceController { |
| 99 public: | 99 public: |
| 100 DeferredRedirectDelegate() | 100 DeferredRedirectDelegate() |
| 101 : throttle_(NULL), | 101 : throttle_(NULL), |
| 102 was_deferred_(false), | 102 was_deferred_(false), |
| 103 cancel_called_(false), | 103 cancel_called_(false), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 114 run_loop_->Run(); | 114 run_loop_->Run(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 bool was_deferred() const { return was_deferred_; } | 117 bool was_deferred() const { return was_deferred_; } |
| 118 bool cancel_called() const { return cancel_called_; } | 118 bool cancel_called() const { return cancel_called_; } |
| 119 bool resume_called() const { return resume_called_; } | 119 bool resume_called() const { return resume_called_; } |
| 120 | 120 |
| 121 // net::URLRequest::Delegate implementation: | 121 // net::URLRequest::Delegate implementation: |
| 122 virtual void OnReceivedRedirect(net::URLRequest* request, | 122 virtual void OnReceivedRedirect(net::URLRequest* request, |
| 123 const net::RedirectInfo& redirect_info, | 123 const net::RedirectInfo& redirect_info, |
| 124 bool* defer_redirect) OVERRIDE { | 124 bool* defer_redirect) override { |
| 125 // Defer the redirect either way. | 125 // Defer the redirect either way. |
| 126 *defer_redirect = true; | 126 *defer_redirect = true; |
| 127 | 127 |
| 128 // Find out what the throttle would have done. | 128 // Find out what the throttle would have done. |
| 129 throttle_->WillRedirectRequest(redirect_info.new_url, &was_deferred_); | 129 throttle_->WillRedirectRequest(redirect_info.new_url, &was_deferred_); |
| 130 run_loop_->Quit(); | 130 run_loop_->Quit(); |
| 131 } | 131 } |
| 132 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE { } | 132 virtual void OnResponseStarted(net::URLRequest* request) override { } |
| 133 virtual void OnReadCompleted(net::URLRequest* request, | 133 virtual void OnReadCompleted(net::URLRequest* request, |
| 134 int bytes_read) OVERRIDE { | 134 int bytes_read) override { |
| 135 } | 135 } |
| 136 | 136 |
| 137 // content::ResourceController implementation: | 137 // content::ResourceController implementation: |
| 138 virtual void Cancel() OVERRIDE { | 138 virtual void Cancel() override { |
| 139 EXPECT_FALSE(cancel_called_); | 139 EXPECT_FALSE(cancel_called_); |
| 140 EXPECT_FALSE(resume_called_); | 140 EXPECT_FALSE(resume_called_); |
| 141 | 141 |
| 142 cancel_called_ = true; | 142 cancel_called_ = true; |
| 143 run_loop_->Quit(); | 143 run_loop_->Quit(); |
| 144 } | 144 } |
| 145 virtual void CancelAndIgnore() OVERRIDE { Cancel(); } | 145 virtual void CancelAndIgnore() override { Cancel(); } |
| 146 virtual void CancelWithError(int error_code) OVERRIDE { Cancel(); } | 146 virtual void CancelWithError(int error_code) override { Cancel(); } |
| 147 virtual void Resume() OVERRIDE { | 147 virtual void Resume() override { |
| 148 EXPECT_TRUE(was_deferred_); | 148 EXPECT_TRUE(was_deferred_); |
| 149 EXPECT_FALSE(cancel_called_); | 149 EXPECT_FALSE(cancel_called_); |
| 150 EXPECT_FALSE(resume_called_); | 150 EXPECT_FALSE(resume_called_); |
| 151 | 151 |
| 152 resume_called_ = true; | 152 resume_called_ = true; |
| 153 run_loop_->Quit(); | 153 run_loop_->Quit(); |
| 154 } | 154 } |
| 155 | 155 |
| 156 private: | 156 private: |
| 157 scoped_ptr<base::RunLoop> run_loop_; | 157 scoped_ptr<base::RunLoop> run_loop_; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 // We should have cancelled the prerender. | 335 // We should have cancelled the prerender. |
| 336 EXPECT_EQ(FINAL_STATUS_BAD_DEFERRED_REDIRECT, | 336 EXPECT_EQ(FINAL_STATUS_BAD_DEFERRED_REDIRECT, |
| 337 test_contents()->final_status()); | 337 test_contents()->final_status()); |
| 338 | 338 |
| 339 // Cleanup work so the prerender is gone. | 339 // Cleanup work so the prerender is gone. |
| 340 test_contents()->Cancel(); | 340 test_contents()->Cancel(); |
| 341 RunEvents(); | 341 RunEvents(); |
| 342 } | 342 } |
| 343 | 343 |
| 344 } // namespace prerender | 344 } // namespace prerender |
| OLD | NEW |