| 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" | |
| 52 #include "content/public/test/test_navigation_observer.h" | 51 #include "content/public/test/test_navigation_observer.h" |
| 52 #include "content/public/test/test_utils.h" |
| 53 #include "grit/generated_resources.h" | 53 #include "grit/generated_resources.h" |
| 54 #include "net/base/mock_host_resolver.h" | 54 #include "net/base/mock_host_resolver.h" |
| 55 #include "net/url_request/url_request_context.h" | 55 #include "net/url_request/url_request_context.h" |
| 56 #include "net/url_request/url_request_context_getter.h" | 56 #include "net/url_request/url_request_context_getter.h" |
| 57 #include "ui/base/l10n/l10n_util.h" | 57 #include "ui/base/l10n/l10n_util.h" |
| 58 | 58 |
| 59 using content::BrowserThread; | 59 using content::BrowserThread; |
| 60 using content::DevToolsAgentHost; | 60 using content::DevToolsAgentHost; |
| 61 using content::DevToolsAgentHostRegistry; | 61 using content::DevToolsAgentHostRegistry; |
| 62 using content::DevToolsClientHost; | 62 using content::DevToolsClientHost; |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 | 663 |
| 664 void OpenDestURLViaWindowOpen() const { | 664 void OpenDestURLViaWindowOpen() const { |
| 665 OpenDestURLWithJSImpl("WindowOpen()"); | 665 OpenDestURLWithJSImpl("WindowOpen()"); |
| 666 } | 666 } |
| 667 | 667 |
| 668 void RemoveLinkElementsAndNavigate() const { | 668 void RemoveLinkElementsAndNavigate() const { |
| 669 OpenDestURLWithJSImpl("RemoveLinkElementsAndNavigate()"); | 669 OpenDestURLWithJSImpl("RemoveLinkElementsAndNavigate()"); |
| 670 } | 670 } |
| 671 | 671 |
| 672 void ClickToNextPageAfterPrerender() { | 672 void ClickToNextPageAfterPrerender() { |
| 673 ui_test_utils::WindowedNotificationObserver new_page_observer( | 673 content::WindowedNotificationObserver new_page_observer( |
| 674 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 674 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 675 content::NotificationService::AllSources()); | 675 content::NotificationService::AllSources()); |
| 676 RenderViewHost* render_view_host = | 676 RenderViewHost* render_view_host = |
| 677 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(); | 677 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(); |
| 678 render_view_host->ExecuteJavascriptInWebFrame( | 678 render_view_host->ExecuteJavascriptInWebFrame( |
| 679 string16(), | 679 string16(), |
| 680 ASCIIToUTF16("ClickOpenLink()")); | 680 ASCIIToUTF16("ClickOpenLink()")); |
| 681 new_page_observer.Wait(); | 681 new_page_observer.Wait(); |
| 682 } | 682 } |
| 683 | 683 |
| 684 void NavigateToNextPageAfterPrerender() const { | 684 void NavigateToNextPageAfterPrerender() const { |
| 685 ui_test_utils::NavigateToURL( | 685 ui_test_utils::NavigateToURL( |
| 686 current_browser(), | 686 current_browser(), |
| 687 test_server()->GetURL("files/prerender/prerender_page.html")); | 687 test_server()->GetURL("files/prerender/prerender_page.html")); |
| 688 } | 688 } |
| 689 | 689 |
| 690 void NavigateToDestUrlAndWaitForPassTitle() { | 690 void NavigateToDestUrlAndWaitForPassTitle() { |
| 691 string16 expected_title = ASCIIToUTF16(kPassTitle); | 691 string16 expected_title = ASCIIToUTF16(kPassTitle); |
| 692 ui_test_utils::TitleWatcher title_watcher( | 692 ui_test_utils::TitleWatcher title_watcher( |
| 693 GetPrerenderContents()->prerender_contents()->web_contents(), | 693 GetPrerenderContents()->prerender_contents()->web_contents(), |
| 694 expected_title); | 694 expected_title); |
| 695 NavigateToDestURL(); | 695 NavigateToDestURL(); |
| 696 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 696 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 697 } | 697 } |
| 698 | 698 |
| 699 // Called after the prerendered page has been navigated to and then away from. | 699 // Called after the prerendered page has been navigated to and then away from. |
| 700 // Navigates back through the history to the prerendered page. | 700 // Navigates back through the history to the prerendered page. |
| 701 void GoBackToPrerender() { | 701 void GoBackToPrerender() { |
| 702 ui_test_utils::WindowedNotificationObserver back_nav_observer( | 702 content::WindowedNotificationObserver back_nav_observer( |
| 703 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 703 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 704 content::NotificationService::AllSources()); | 704 content::NotificationService::AllSources()); |
| 705 chrome::GoBack(current_browser(), CURRENT_TAB); | 705 chrome::GoBack(current_browser(), CURRENT_TAB); |
| 706 back_nav_observer.Wait(); | 706 back_nav_observer.Wait(); |
| 707 bool original_prerender_page = false; | 707 bool original_prerender_page = false; |
| 708 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 708 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 709 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(), | 709 chrome::GetActiveWebContents(current_browser())->GetRenderViewHost(), |
| 710 L"", L"window.domAutomationController.send(IsOriginalPrerenderPage())", | 710 L"", L"window.domAutomationController.send(IsOriginalPrerenderPage())", |
| 711 &original_prerender_page)); | 711 &original_prerender_page)); |
| 712 EXPECT_TRUE(original_prerender_page); | 712 EXPECT_TRUE(original_prerender_page); |
| 713 } | 713 } |
| 714 | 714 |
| 715 // Goes back to the page that was active before the prerender was swapped | 715 // Goes back to the page that was active before the prerender was swapped |
| 716 // in. This must be called when the prerendered page is the current page | 716 // in. This must be called when the prerendered page is the current page |
| 717 // in the active tab. | 717 // in the active tab. |
| 718 void GoBackToPageBeforePrerender() { | 718 void GoBackToPageBeforePrerender() { |
| 719 WebContents* tab = chrome::GetActiveWebContents(current_browser()); | 719 WebContents* tab = chrome::GetActiveWebContents(current_browser()); |
| 720 ASSERT_TRUE(tab); | 720 ASSERT_TRUE(tab); |
| 721 EXPECT_FALSE(tab->IsLoading()); | 721 EXPECT_FALSE(tab->IsLoading()); |
| 722 ui_test_utils::WindowedNotificationObserver back_nav_observer( | 722 content::WindowedNotificationObserver back_nav_observer( |
| 723 content::NOTIFICATION_LOAD_STOP, | 723 content::NOTIFICATION_LOAD_STOP, |
| 724 content::Source<NavigationController>(&tab->GetController())); | 724 content::Source<NavigationController>(&tab->GetController())); |
| 725 chrome::GoBack(current_browser(), CURRENT_TAB); | 725 chrome::GoBack(current_browser(), CURRENT_TAB); |
| 726 back_nav_observer.Wait(); | 726 back_nav_observer.Wait(); |
| 727 bool js_result; | 727 bool js_result; |
| 728 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 728 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 729 tab->GetRenderViewHost(), L"", | 729 tab->GetRenderViewHost(), L"", |
| 730 L"window.domAutomationController.send(DidBackToOriginalPagePass())", | 730 L"window.domAutomationController.send(DidBackToOriginalPagePass())", |
| 731 &js_result)); | 731 &js_result)); |
| 732 EXPECT_TRUE(js_result); | 732 EXPECT_TRUE(js_result); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 expected_final_status_queue, | 889 expected_final_status_queue, |
| 890 prerender_should_wait_for_ready_title); | 890 prerender_should_wait_for_ready_title); |
| 891 prerender_manager->SetPrerenderContentsFactory( | 891 prerender_manager->SetPrerenderContentsFactory( |
| 892 prerender_contents_factory_); | 892 prerender_contents_factory_); |
| 893 FinalStatus expected_final_status = expected_final_status_queue.front(); | 893 FinalStatus expected_final_status = expected_final_status_queue.front(); |
| 894 | 894 |
| 895 // We construct launch_nav_observer so that we can be certain our loader | 895 // We construct launch_nav_observer so that we can be certain our loader |
| 896 // page has finished loading before continuing. This prevents ambiguous | 896 // page has finished loading before continuing. This prevents ambiguous |
| 897 // NOTIFICATION_LOAD_STOP events from making tests flaky. | 897 // NOTIFICATION_LOAD_STOP events from making tests flaky. |
| 898 WebContents* web_contents = chrome::GetActiveWebContents(current_browser()); | 898 WebContents* web_contents = chrome::GetActiveWebContents(current_browser()); |
| 899 ui_test_utils::WindowedNotificationObserver loader_nav_observer( | 899 content::WindowedNotificationObserver loader_nav_observer( |
| 900 content::NOTIFICATION_LOAD_STOP, | 900 content::NOTIFICATION_LOAD_STOP, |
| 901 content::Source<NavigationController>( | 901 content::Source<NavigationController>( |
| 902 &web_contents->GetController())); | 902 &web_contents->GetController())); |
| 903 | 903 |
| 904 // ui_test_utils::NavigateToURL uses its own observer and message loop. | 904 // ui_test_utils::NavigateToURL uses its own observer and message loop. |
| 905 // Since the test needs to wait until the prerendered page has stopped | 905 // Since the test needs to wait until the prerendered page has stopped |
| 906 // loading, rather than the page directly navigated to, need to | 906 // loading, rather than the page directly navigated to, need to |
| 907 // handle browser navigation directly. | 907 // handle browser navigation directly. |
| 908 current_browser()->OpenURL(OpenURLParams( | 908 current_browser()->OpenURL(OpenURLParams( |
| 909 loader_url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, | 909 loader_url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 WindowOpenDisposition disposition) const { | 947 WindowOpenDisposition disposition) const { |
| 948 ASSERT_TRUE(GetPrerenderManager() != NULL); | 948 ASSERT_TRUE(GetPrerenderManager() != NULL); |
| 949 // Make sure in navigating we have a URL to use in the PrerenderManager. | 949 // Make sure in navigating we have a URL to use in the PrerenderManager. |
| 950 ASSERT_TRUE(GetPrerenderContents() != NULL); | 950 ASSERT_TRUE(GetPrerenderContents() != NULL); |
| 951 | 951 |
| 952 // If opening the page in a background tab, it won't be shown when swapped | 952 // If opening the page in a background tab, it won't be shown when swapped |
| 953 // in. | 953 // in. |
| 954 if (disposition == NEW_BACKGROUND_TAB) | 954 if (disposition == NEW_BACKGROUND_TAB) |
| 955 GetPrerenderContents()->set_should_be_shown(false); | 955 GetPrerenderContents()->set_should_be_shown(false); |
| 956 | 956 |
| 957 scoped_ptr<ui_test_utils::WindowedNotificationObserver> page_load_observer; | 957 scoped_ptr<content::WindowedNotificationObserver> page_load_observer; |
| 958 WebContents* web_contents = NULL; | 958 WebContents* web_contents = NULL; |
| 959 | 959 |
| 960 if (GetPrerenderContents()->prerender_contents()) { | 960 if (GetPrerenderContents()->prerender_contents()) { |
| 961 // In the case of zero loads, need to wait for the page load to complete | 961 // In the case of zero loads, need to wait for the page load to complete |
| 962 // before running any Javascript. | 962 // before running any Javascript. |
| 963 web_contents = | 963 web_contents = |
| 964 GetPrerenderContents()->prerender_contents()->web_contents(); | 964 GetPrerenderContents()->prerender_contents()->web_contents(); |
| 965 if (GetPrerenderContents()->number_of_loads() == 0) { | 965 if (GetPrerenderContents()->number_of_loads() == 0) { |
| 966 page_load_observer.reset( | 966 page_load_observer.reset( |
| 967 new ui_test_utils::WindowedNotificationObserver( | 967 new content::WindowedNotificationObserver( |
| 968 content::NOTIFICATION_LOAD_STOP, | 968 content::NOTIFICATION_LOAD_STOP, |
| 969 content::Source<NavigationController>( | 969 content::Source<NavigationController>( |
| 970 &web_contents->GetController()))); | 970 &web_contents->GetController()))); |
| 971 } | 971 } |
| 972 } | 972 } |
| 973 | 973 |
| 974 // Navigate to the prerendered URL, but don't run the message loop. Browser | 974 // Navigate to the prerendered URL, but don't run the message loop. Browser |
| 975 // issued navigations to prerendered pages will synchronously swap in the | 975 // issued navigations to prerendered pages will synchronously swap in the |
| 976 // prerendered page. | 976 // prerendered page. |
| 977 ui_test_utils::NavigateToURLWithDisposition( | 977 ui_test_utils::NavigateToURLWithDisposition( |
| (...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2088 NavigateToDestURL(); | 2088 NavigateToDestURL(); |
| 2089 } | 2089 } |
| 2090 | 2090 |
| 2091 // Checks that the favicon is properly loaded on prerender. | 2091 // Checks that the favicon is properly loaded on prerender. |
| 2092 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderFavicon) { | 2092 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderFavicon) { |
| 2093 PrerenderTestURL("files/prerender/prerender_favicon.html", | 2093 PrerenderTestURL("files/prerender/prerender_favicon.html", |
| 2094 FINAL_STATUS_USED, | 2094 FINAL_STATUS_USED, |
| 2095 1); | 2095 1); |
| 2096 TestPrerenderContents* prerender_contents = GetPrerenderContents(); | 2096 TestPrerenderContents* prerender_contents = GetPrerenderContents(); |
| 2097 ASSERT_TRUE(prerender_contents != NULL); | 2097 ASSERT_TRUE(prerender_contents != NULL); |
| 2098 ui_test_utils::WindowedNotificationObserver favicon_update_watcher( | 2098 content::WindowedNotificationObserver favicon_update_watcher( |
| 2099 chrome::NOTIFICATION_FAVICON_UPDATED, | 2099 chrome::NOTIFICATION_FAVICON_UPDATED, |
| 2100 content::Source<WebContents>(prerender_contents->prerender_contents()-> | 2100 content::Source<WebContents>(prerender_contents->prerender_contents()-> |
| 2101 web_contents())); | 2101 web_contents())); |
| 2102 NavigateToDestURL(); | 2102 NavigateToDestURL(); |
| 2103 favicon_update_watcher.Wait(); | 2103 favicon_update_watcher.Wait(); |
| 2104 } | 2104 } |
| 2105 | 2105 |
| 2106 // Checks that when a prerendered page is swapped in to a referring page, the | 2106 // Checks that when a prerendered page is swapped in to a referring page, the |
| 2107 // unload handlers on the referring page are executed. | 2107 // unload handlers on the referring page are executed. |
| 2108 #if defined(OS_WIN) | 2108 #if defined(OS_WIN) |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2382 ResultCatcher catcher; | 2382 ResultCatcher catcher; |
| 2383 | 2383 |
| 2384 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | 2384 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
| 2385 NavigateToDestURL(); | 2385 NavigateToDestURL(); |
| 2386 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); | 2386 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); |
| 2387 | 2387 |
| 2388 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 2388 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 2389 } | 2389 } |
| 2390 | 2390 |
| 2391 } // namespace prerender | 2391 } // namespace prerender |
| OLD | NEW |