| 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/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/message_loop/message_loop.h" | |
| 12 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "chrome/browser/net/url_request_mock_util.h" | 13 #include "chrome/browser/net/url_request_mock_util.h" |
| 15 #include "chrome/browser/prerender/prerender_contents.h" | 14 #include "chrome/browser/prerender/prerender_contents.h" |
| 16 #include "chrome/browser/prerender/prerender_manager.h" | 15 #include "chrome/browser/prerender/prerender_manager.h" |
| 17 #include "chrome/browser/prerender/prerender_resource_throttle.h" | 16 #include "chrome/browser/prerender/prerender_resource_throttle.h" |
| 18 #include "chrome/test/base/testing_browser_process.h" | 17 #include "chrome/test/base/testing_browser_process.h" |
| 19 #include "content/public/browser/resource_request_info.h" | 18 #include "content/public/browser/resource_request_info.h" |
| 20 #include "content/public/browser/resource_throttle.h" | 19 #include "content/public/browser/resource_throttle.h" |
| 21 #include "content/public/common/previews_state.h" | 20 #include "content/public/common/previews_state.h" |
| 22 #include "content/public/test/test_browser_thread.h" | 21 #include "content/public/test/test_browser_thread.h" |
| 22 #include "content/public/test/test_browser_thread_bundle.h" |
| 23 #include "ipc/ipc_message.h" | 23 #include "ipc/ipc_message.h" |
| 24 #include "net/base/request_priority.h" | 24 #include "net/base/request_priority.h" |
| 25 #include "net/test/url_request/url_request_mock_http_job.h" | 25 #include "net/test/url_request/url_request_mock_http_job.h" |
| 26 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" | 26 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| 27 #include "net/url_request/redirect_info.h" | 27 #include "net/url_request/redirect_info.h" |
| 28 #include "net/url_request/url_request.h" | 28 #include "net/url_request/url_request.h" |
| 29 #include "net/url_request/url_request_test_util.h" | 29 #include "net/url_request/url_request_test_util.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 31 |
| 32 using content::BrowserThread; | 32 using content::BrowserThread; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 DISALLOW_COPY_AND_ASSIGN(DeferredRedirectDelegate); | 159 DISALLOW_COPY_AND_ASSIGN(DeferredRedirectDelegate); |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 } // namespace | 162 } // namespace |
| 163 | 163 |
| 164 class PrerenderResourceThrottleTest : public testing::Test { | 164 class PrerenderResourceThrottleTest : public testing::Test { |
| 165 public: | 165 public: |
| 166 static const int kDefaultChildId = 0; | 166 static const int kDefaultChildId = 0; |
| 167 static const int kDefaultRouteId = 100; | 167 static const int kDefaultRouteId = 100; |
| 168 | 168 |
| 169 PrerenderResourceThrottleTest() : | 169 PrerenderResourceThrottleTest() |
| 170 ui_thread_(BrowserThread::UI, &message_loop_), | 170 : test_browser_thread_bundle_( |
| 171 io_thread_(BrowserThread::IO, &message_loop_), | 171 content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 172 test_contents_(&prerender_manager_, kDefaultChildId, kDefaultRouteId) { | 172 test_contents_(&prerender_manager_, kDefaultChildId, kDefaultRouteId) { |
| 173 chrome_browser_net::SetUrlRequestMocksEnabled(true); | 173 chrome_browser_net::SetUrlRequestMocksEnabled(true); |
| 174 } | 174 } |
| 175 | 175 |
| 176 ~PrerenderResourceThrottleTest() override { | 176 ~PrerenderResourceThrottleTest() override { |
| 177 chrome_browser_net::SetUrlRequestMocksEnabled(false); | 177 chrome_browser_net::SetUrlRequestMocksEnabled(false); |
| 178 | 178 |
| 179 // Cleanup work so the file IO tasks from URLRequestMockHTTPJob | 179 // Cleanup work so the file IO tasks from URLRequestMockHTTPJob |
| 180 // are gone. | 180 // are gone. |
| 181 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 181 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 182 RunEvents(); | 182 RunEvents(); |
| 183 } | 183 } |
| 184 | 184 |
| 185 TestPrerenderManager* prerender_manager() { | 185 TestPrerenderManager* prerender_manager() { |
| 186 return &prerender_manager_; | 186 return &prerender_manager_; |
| 187 } | 187 } |
| 188 | 188 |
| 189 TestPrerenderContents* test_contents() { | 189 TestPrerenderContents* test_contents() { |
| 190 return &test_contents_; | 190 return &test_contents_; |
| 191 } | 191 } |
| 192 | 192 |
| 193 // Runs any tasks queued on either thread. | 193 // Runs any tasks queued on either thread. |
| 194 void RunEvents() { base::RunLoop().RunUntilIdle(); } | 194 void RunEvents() { base::RunLoop().RunUntilIdle(); } |
| 195 | 195 |
| 196 private: | 196 private: |
| 197 base::MessageLoopForIO message_loop_; | 197 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
| 198 content::TestBrowserThread ui_thread_; | |
| 199 content::TestBrowserThread io_thread_; | |
| 200 | 198 |
| 201 TestPrerenderManager prerender_manager_; | 199 TestPrerenderManager prerender_manager_; |
| 202 TestPrerenderContents test_contents_; | 200 TestPrerenderContents test_contents_; |
| 203 }; | 201 }; |
| 204 | 202 |
| 205 // Checks that deferred redirects are throttled and resumed correctly. | 203 // Checks that deferred redirects are throttled and resumed correctly. |
| 206 TEST_F(PrerenderResourceThrottleTest, RedirectResume) { | 204 TEST_F(PrerenderResourceThrottleTest, RedirectResume) { |
| 207 test_contents()->Start(); | 205 test_contents()->Start(); |
| 208 RunEvents(); | 206 RunEvents(); |
| 209 | 207 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 // We should have cancelled the prerender. | 306 // We should have cancelled the prerender. |
| 309 EXPECT_EQ(FINAL_STATUS_BAD_DEFERRED_REDIRECT, | 307 EXPECT_EQ(FINAL_STATUS_BAD_DEFERRED_REDIRECT, |
| 310 test_contents()->final_status()); | 308 test_contents()->final_status()); |
| 311 | 309 |
| 312 // Cleanup work so the prerender is gone. | 310 // Cleanup work so the prerender is gone. |
| 313 test_contents()->Cancel(); | 311 test_contents()->Cancel(); |
| 314 RunEvents(); | 312 RunEvents(); |
| 315 } | 313 } |
| 316 | 314 |
| 317 } // namespace prerender | 315 } // namespace prerender |
| OLD | NEW |