| 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 <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 "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #include "chrome/common/pref_names.h" | 41 #include "chrome/common/pref_names.h" |
| 42 #include "chrome/test/base/in_process_browser_test.h" | 42 #include "chrome/test/base/in_process_browser_test.h" |
| 43 #include "chrome/test/base/ui_test_utils.h" | 43 #include "chrome/test/base/ui_test_utils.h" |
| 44 #include "content/public/browser/devtools_agent_host_registry.h" | 44 #include "content/public/browser/devtools_agent_host_registry.h" |
| 45 #include "content/public/browser/devtools_client_host.h" | 45 #include "content/public/browser/devtools_client_host.h" |
| 46 #include "content/public/browser/devtools_manager.h" | 46 #include "content/public/browser/devtools_manager.h" |
| 47 #include "content/public/browser/notification_service.h" | 47 #include "content/public/browser/notification_service.h" |
| 48 #include "content/public/browser/render_view_host.h" | 48 #include "content/public/browser/render_view_host.h" |
| 49 #include "content/public/browser/web_contents.h" | 49 #include "content/public/browser/web_contents.h" |
| 50 #include "content/public/common/url_constants.h" | 50 #include "content/public/common/url_constants.h" |
| 51 #include "content/public/test/browser_test_utils.h" |
| 51 #include "content/public/test/test_navigation_observer.h" | 52 #include "content/public/test/test_navigation_observer.h" |
| 52 #include "content/public/test/test_utils.h" | 53 #include "content/public/test/test_utils.h" |
| 53 #include "grit/generated_resources.h" | 54 #include "grit/generated_resources.h" |
| 54 #include "net/base/mock_host_resolver.h" | 55 #include "net/base/mock_host_resolver.h" |
| 55 #include "net/url_request/url_request_context.h" | 56 #include "net/url_request/url_request_context.h" |
| 56 #include "net/url_request/url_request_context_getter.h" | 57 #include "net/url_request/url_request_context_getter.h" |
| 57 #include "ui/base/l10n/l10n_util.h" | 58 #include "ui/base/l10n/l10n_util.h" |
| 58 | 59 |
| 59 using content::BrowserThread; | 60 using content::BrowserThread; |
| 60 using content::DevToolsAgentHost; | 61 using content::DevToolsAgentHost; |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 MessageLoop::current()->Quit(); | 244 MessageLoop::current()->Quit(); |
| 244 } | 245 } |
| 245 } | 246 } |
| 246 | 247 |
| 247 virtual WebContents* CreateWebContents( | 248 virtual WebContents* CreateWebContents( |
| 248 content::SessionStorageNamespace* session_storage_namespace) OVERRIDE { | 249 content::SessionStorageNamespace* session_storage_namespace) OVERRIDE { |
| 249 WebContents* web_contents = PrerenderContents::CreateWebContents( | 250 WebContents* web_contents = PrerenderContents::CreateWebContents( |
| 250 session_storage_namespace); | 251 session_storage_namespace); |
| 251 string16 ready_title = ASCIIToUTF16(kReadyTitle); | 252 string16 ready_title = ASCIIToUTF16(kReadyTitle); |
| 252 if (prerender_should_wait_for_ready_title_) | 253 if (prerender_should_wait_for_ready_title_) |
| 253 ready_title_watcher_.reset(new ui_test_utils::TitleWatcher( | 254 ready_title_watcher_.reset(new content::TitleWatcher( |
| 254 web_contents, ready_title)); | 255 web_contents, ready_title)); |
| 255 return web_contents; | 256 return web_contents; |
| 256 } | 257 } |
| 257 | 258 |
| 258 void WaitForPrerenderToHaveReadyTitleIfRequired() { | 259 void WaitForPrerenderToHaveReadyTitleIfRequired() { |
| 259 if (ready_title_watcher_.get()) { | 260 if (ready_title_watcher_.get()) { |
| 260 string16 ready_title = ASCIIToUTF16(kReadyTitle); | 261 string16 ready_title = ASCIIToUTF16(kReadyTitle); |
| 261 ASSERT_EQ(ready_title, ready_title_watcher_->WaitAndGetTitle()); | 262 ASSERT_EQ(ready_title, ready_title_watcher_->WaitAndGetTitle()); |
| 262 } | 263 } |
| 263 } | 264 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 // If true, quits message loop on destruction of |this|. | 358 // If true, quits message loop on destruction of |this|. |
| 358 bool quit_message_loop_on_destruction_; | 359 bool quit_message_loop_on_destruction_; |
| 359 | 360 |
| 360 // Total number of pending prerenders we're currently waiting for. Zero | 361 // Total number of pending prerenders we're currently waiting for. Zero |
| 361 // indicates we currently aren't waiting for any. | 362 // indicates we currently aren't waiting for any. |
| 362 size_t expected_pending_prerenders_; | 363 size_t expected_pending_prerenders_; |
| 363 | 364 |
| 364 // If true, before calling DidPrerenderPass, will wait for the title of the | 365 // If true, before calling DidPrerenderPass, will wait for the title of the |
| 365 // prerendered page to turn to "READY". | 366 // prerendered page to turn to "READY". |
| 366 bool prerender_should_wait_for_ready_title_; | 367 bool prerender_should_wait_for_ready_title_; |
| 367 scoped_ptr<ui_test_utils::TitleWatcher> ready_title_watcher_; | 368 scoped_ptr<content::TitleWatcher> ready_title_watcher_; |
| 368 }; | 369 }; |
| 369 | 370 |
| 370 // PrerenderManager that uses TestPrerenderContents. | 371 // PrerenderManager that uses TestPrerenderContents. |
| 371 class WaitForLoadPrerenderContentsFactory : public PrerenderContents::Factory { | 372 class WaitForLoadPrerenderContentsFactory : public PrerenderContents::Factory { |
| 372 public: | 373 public: |
| 373 WaitForLoadPrerenderContentsFactory( | 374 WaitForLoadPrerenderContentsFactory( |
| 374 int expected_number_of_loads, | 375 int expected_number_of_loads, |
| 375 const std::deque<FinalStatus>& expected_final_status_queue, | 376 const std::deque<FinalStatus>& expected_final_status_queue, |
| 376 bool prerender_should_wait_for_ready_title) | 377 bool prerender_should_wait_for_ready_title) |
| 377 : expected_number_of_loads_(expected_number_of_loads), | 378 : expected_number_of_loads_(expected_number_of_loads), |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 } | 683 } |
| 683 | 684 |
| 684 void NavigateToNextPageAfterPrerender() const { | 685 void NavigateToNextPageAfterPrerender() const { |
| 685 ui_test_utils::NavigateToURL( | 686 ui_test_utils::NavigateToURL( |
| 686 current_browser(), | 687 current_browser(), |
| 687 test_server()->GetURL("files/prerender/prerender_page.html")); | 688 test_server()->GetURL("files/prerender/prerender_page.html")); |
| 688 } | 689 } |
| 689 | 690 |
| 690 void NavigateToDestUrlAndWaitForPassTitle() { | 691 void NavigateToDestUrlAndWaitForPassTitle() { |
| 691 string16 expected_title = ASCIIToUTF16(kPassTitle); | 692 string16 expected_title = ASCIIToUTF16(kPassTitle); |
| 692 ui_test_utils::TitleWatcher title_watcher( | 693 content::TitleWatcher title_watcher( |
| 693 GetPrerenderContents()->prerender_contents()->web_contents(), | 694 GetPrerenderContents()->prerender_contents()->web_contents(), |
| 694 expected_title); | 695 expected_title); |
| 695 NavigateToDestURL(); | 696 NavigateToDestURL(); |
| 696 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 697 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 697 } | 698 } |
| 698 | 699 |
| 699 // Called after the prerendered page has been navigated to and then away from. | 700 // Called after the prerendered page has been navigated to and then away from. |
| 700 // Navigates back through the history to the prerendered page. | 701 // Navigates back through the history to the prerendered page. |
| 701 void GoBackToPrerender() { | 702 void GoBackToPrerender() { |
| 702 content::WindowedNotificationObserver back_nav_observer( | 703 content::WindowedNotificationObserver back_nav_observer( |
| (...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2107 // unload handlers on the referring page are executed. | 2108 // unload handlers on the referring page are executed. |
| 2108 #if defined(OS_WIN) | 2109 #if defined(OS_WIN) |
| 2109 #define MAYBE_PrerenderUnload FLAKY_PrerenderUnload | 2110 #define MAYBE_PrerenderUnload FLAKY_PrerenderUnload |
| 2110 #else | 2111 #else |
| 2111 #define MAYBE_PrerenderUnload PrerenderUnload | 2112 #define MAYBE_PrerenderUnload PrerenderUnload |
| 2112 #endif | 2113 #endif |
| 2113 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, MAYBE_PrerenderUnload) { | 2114 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, MAYBE_PrerenderUnload) { |
| 2114 set_loader_path("files/prerender/prerender_loader_with_unload.html"); | 2115 set_loader_path("files/prerender/prerender_loader_with_unload.html"); |
| 2115 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | 2116 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
| 2116 string16 expected_title = ASCIIToUTF16("Unloaded"); | 2117 string16 expected_title = ASCIIToUTF16("Unloaded"); |
| 2117 ui_test_utils::TitleWatcher title_watcher( | 2118 content::TitleWatcher title_watcher( |
| 2118 chrome::GetActiveWebContents(current_browser()), expected_title); | 2119 chrome::GetActiveWebContents(current_browser()), expected_title); |
| 2119 NavigateToDestURL(); | 2120 NavigateToDestURL(); |
| 2120 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 2121 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 2121 } | 2122 } |
| 2122 | 2123 |
| 2123 // Checks that when the history is cleared, prerendering is cancelled and | 2124 // Checks that when the history is cleared, prerendering is cancelled and |
| 2124 // prerendering history is cleared. | 2125 // prerendering history is cleared. |
| 2125 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClearHistory) { | 2126 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClearHistory) { |
| 2126 PrerenderTestURL("files/prerender/prerender_page.html", | 2127 PrerenderTestURL("files/prerender/prerender_page.html", |
| 2127 FINAL_STATUS_CACHE_OR_HISTORY_CLEARED, | 2128 FINAL_STATUS_CACHE_OR_HISTORY_CLEARED, |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2382 ResultCatcher catcher; | 2383 ResultCatcher catcher; |
| 2383 | 2384 |
| 2384 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | 2385 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
| 2385 NavigateToDestURL(); | 2386 NavigateToDestURL(); |
| 2386 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); | 2387 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); |
| 2387 | 2388 |
| 2388 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 2389 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 2389 } | 2390 } |
| 2390 | 2391 |
| 2391 } // namespace prerender | 2392 } // namespace prerender |
| OLD | NEW |