| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <deque> | 5 #include <deque> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "chrome/browser/prerender/prerender_contents.h" | 10 #include "chrome/browser/prerender/prerender_contents.h" |
| 11 #include "chrome/browser/prerender/prerender_manager.h" | 11 #include "chrome/browser/prerender/prerender_manager.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/task_manager/task_manager.h" | 13 #include "chrome/browser/task_manager/task_manager.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
| 16 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
| 17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/test/in_process_browser_test.h" | 18 #include "chrome/test/in_process_browser_test.h" |
| 19 #include "chrome/test/ui_test_utils.h" | 19 #include "chrome/test/ui_test_utils.h" |
| 20 #include "content/browser/renderer_host/render_view_host.h" |
| 20 #include "content/browser/tab_contents/tab_contents.h" | 21 #include "content/browser/tab_contents/tab_contents.h" |
| 21 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
| 22 #include "net/url_request/url_request_context.h" | 23 #include "net/url_request/url_request_context.h" |
| 23 #include "net/url_request/url_request_context_getter.h" | 24 #include "net/url_request/url_request_context_getter.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 25 | 26 |
| 26 // Prerender tests work as follows: | 27 // Prerender tests work as follows: |
| 27 // | 28 // |
| 28 // A page with a prefetch link to the test page is loaded. Once prerendered, | 29 // A page with a prefetch link to the test page is loaded. Once prerendered, |
| 29 // its Javascript function DidPrerenderPass() is called, which returns true if | 30 // its Javascript function DidPrerenderPass() is called, which returns true if |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 // the UI message loop. | 71 // the UI message loop. |
| 71 MessageLoopForUI::current()->Quit(); | 72 MessageLoopForUI::current()->Quit(); |
| 72 } | 73 } |
| 73 | 74 |
| 74 virtual void DidStopLoading() { | 75 virtual void DidStopLoading() { |
| 75 PrerenderContents::DidStopLoading(); | 76 PrerenderContents::DidStopLoading(); |
| 76 ++number_of_loads_; | 77 ++number_of_loads_; |
| 77 if (expected_final_status_ == FINAL_STATUS_USED && | 78 if (expected_final_status_ == FINAL_STATUS_USED && |
| 78 number_of_loads_ >= expected_number_of_loads_) { | 79 number_of_loads_ >= expected_number_of_loads_) { |
| 79 MessageLoopForUI::current()->Quit(); | 80 MessageLoopForUI::current()->Quit(); |
| 81 } else if (expected_final_status_ == FINAL_STATUS_RENDERER_CRASHED) { |
| 82 // Crash the render process. |
| 83 render_view_host()->NavigateToURL(GURL("about:crash")); |
| 80 } | 84 } |
| 81 } | 85 } |
| 82 | 86 |
| 83 private: | 87 private: |
| 84 int number_of_loads_; | 88 int number_of_loads_; |
| 85 int expected_number_of_loads_; | 89 int expected_number_of_loads_; |
| 86 FinalStatus expected_final_status_; | 90 FinalStatus expected_final_status_; |
| 87 }; | 91 }; |
| 88 | 92 |
| 89 // PrerenderManager that uses TestPrerenderContents. | 93 // PrerenderManager that uses TestPrerenderContents. |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 } | 667 } |
| 664 | 668 |
| 665 // Checks that scripts can retrieve the correct window size while prerendering. | 669 // Checks that scripts can retrieve the correct window size while prerendering. |
| 666 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderWindowSize) { | 670 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderWindowSize) { |
| 667 PrerenderTestURL("files/prerender/prerender_size.html", | 671 PrerenderTestURL("files/prerender/prerender_size.html", |
| 668 FINAL_STATUS_USED, | 672 FINAL_STATUS_USED, |
| 669 1); | 673 1); |
| 670 NavigateToDestURL(); | 674 NavigateToDestURL(); |
| 671 } | 675 } |
| 672 | 676 |
| 677 // Checks that prerenderers will terminate when the RenderView crashes. |
| 678 // Note that the prerendering RenderView will be redirected to about:crash. |
| 679 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderRendererCrash) { |
| 680 PrerenderTestURL(CreateClientRedirect("files/prerender/prerender_page.html"), |
| 681 FINAL_STATUS_RENDERER_CRASHED, |
| 682 1); |
| 683 } |
| 684 |
| 673 } // namespace prerender | 685 } // namespace prerender |
| OLD | NEW |