| 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 "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
| 13 #include "chrome/browser/browsing_data_remover.h" | 13 #include "chrome/browser/browsing_data_remover.h" |
| 14 #include "chrome/browser/content_settings/host_content_settings_map.h" | 14 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 15 #include "chrome/browser/favicon/favicon_tab_helper.h" | 15 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 16 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
| 17 #include "chrome/browser/prerender/prerender_contents.h" | 17 #include "chrome/browser/prerender/prerender_contents.h" |
| 18 #include "chrome/browser/prerender/prerender_manager.h" | 18 #include "chrome/browser/prerender/prerender_manager.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 20 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 21 #include "chrome/browser/task_manager/task_manager.h" | 21 #include "chrome/browser/task_manager/task_manager.h" |
| 22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
| 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 25 #include "chrome/common/chrome_notification_types.h" |
| 25 #include "chrome/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 28 #include "chrome/test/in_process_browser_test.h" | 29 #include "chrome/test/in_process_browser_test.h" |
| 29 #include "chrome/test/ui_test_utils.h" | 30 #include "chrome/test/ui_test_utils.h" |
| 30 #include "content/browser/renderer_host/render_view_host.h" | 31 #include "content/browser/renderer_host/render_view_host.h" |
| 31 #include "content/browser/tab_contents/tab_contents.h" | 32 #include "content/browser/tab_contents/tab_contents.h" |
| 32 #include "content/common/notification_service.h" | 33 #include "content/common/notification_service.h" |
| 33 #include "content/common/url_constants.h" | 34 #include "content/common/url_constants.h" |
| 34 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 quit_message_loop_on_destruction_ = value; | 179 quit_message_loop_on_destruction_ = value; |
| 179 } | 180 } |
| 180 | 181 |
| 181 private: | 182 private: |
| 182 virtual void OnRenderViewHostCreated( | 183 virtual void OnRenderViewHostCreated( |
| 183 RenderViewHost* new_render_view_host) OVERRIDE { | 184 RenderViewHost* new_render_view_host) OVERRIDE { |
| 184 // Used to make sure the RenderViewHost is hidden and, if used, | 185 // Used to make sure the RenderViewHost is hidden and, if used, |
| 185 // subsequently shown. | 186 // subsequently shown. |
| 186 notification_registrar().Add( | 187 notification_registrar().Add( |
| 187 this, | 188 this, |
| 188 NotificationType::RENDER_WIDGET_VISIBILITY_CHANGED, | 189 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
| 189 Source<RenderWidgetHost>(new_render_view_host)); | 190 Source<RenderWidgetHost>(new_render_view_host)); |
| 190 | 191 |
| 191 new_render_view_host_ = new_render_view_host; | 192 new_render_view_host_ = new_render_view_host; |
| 192 | 193 |
| 193 PrerenderContents::OnRenderViewHostCreated(new_render_view_host); | 194 PrerenderContents::OnRenderViewHostCreated(new_render_view_host); |
| 194 } | 195 } |
| 195 | 196 |
| 196 virtual void Observe(NotificationType type, | 197 virtual void Observe(int type, |
| 197 const NotificationSource& source, | 198 const NotificationSource& source, |
| 198 const NotificationDetails& details) OVERRIDE { | 199 const NotificationDetails& details) OVERRIDE { |
| 199 if (type.value == | 200 if (type == |
| 200 NotificationType::RENDER_WIDGET_VISIBILITY_CHANGED) { | 201 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED) { |
| 201 EXPECT_EQ(new_render_view_host_, Source<RenderWidgetHost>(source).ptr()); | 202 EXPECT_EQ(new_render_view_host_, Source<RenderWidgetHost>(source).ptr()); |
| 202 bool is_visible = *Details<bool>(details).ptr(); | 203 bool is_visible = *Details<bool>(details).ptr(); |
| 203 | 204 |
| 204 if (!is_visible) { | 205 if (!is_visible) { |
| 205 was_hidden_ = true; | 206 was_hidden_ = true; |
| 206 } else if (is_visible && was_hidden_) { | 207 } else if (is_visible && was_hidden_) { |
| 207 // Once hidden, a prerendered RenderViewHost should only be shown after | 208 // Once hidden, a prerendered RenderViewHost should only be shown after |
| 208 // being removed from the PrerenderContents for display. | 209 // being removed from the PrerenderContents for display. |
| 209 EXPECT_FALSE(render_view_host()); | 210 EXPECT_FALSE(render_view_host()); |
| 210 was_shown_ = true; | 211 was_shown_ = true; |
| (...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1453 } | 1454 } |
| 1454 | 1455 |
| 1455 // Checks that the favicon is properly loaded on prerender. | 1456 // Checks that the favicon is properly loaded on prerender. |
| 1456 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderFavicon) { | 1457 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderFavicon) { |
| 1457 PrerenderTestURL("files/prerender/prerender_favicon.html", | 1458 PrerenderTestURL("files/prerender/prerender_favicon.html", |
| 1458 FINAL_STATUS_USED, | 1459 FINAL_STATUS_USED, |
| 1459 1); | 1460 1); |
| 1460 TestPrerenderContents* prerender_contents = GetPrerenderContents(); | 1461 TestPrerenderContents* prerender_contents = GetPrerenderContents(); |
| 1461 ASSERT_TRUE(prerender_contents != NULL); | 1462 ASSERT_TRUE(prerender_contents != NULL); |
| 1462 ui_test_utils::WindowedNotificationObserver favicon_update_watcher( | 1463 ui_test_utils::WindowedNotificationObserver favicon_update_watcher( |
| 1463 NotificationType::FAVICON_UPDATED, | 1464 chrome::NOTIFICATION_FAVICON_UPDATED, |
| 1464 Source<TabContents>(prerender_contents->prerender_contents()-> | 1465 Source<TabContents>(prerender_contents->prerender_contents()-> |
| 1465 tab_contents())); | 1466 tab_contents())); |
| 1466 NavigateToDestURL(); | 1467 NavigateToDestURL(); |
| 1467 favicon_update_watcher.Wait(); | 1468 favicon_update_watcher.Wait(); |
| 1468 } | 1469 } |
| 1469 | 1470 |
| 1470 // Checks that when a prerendered page is swapped in to a referring page, the | 1471 // Checks that when a prerendered page is swapped in to a referring page, the |
| 1471 // unload handlers on the referring page are executed. | 1472 // unload handlers on the referring page are executed. |
| 1472 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderUnload) { | 1473 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderUnload) { |
| 1473 set_loader_path("files/prerender/prerender_loader_with_unload.html"); | 1474 set_loader_path("files/prerender/prerender_loader_with_unload.html"); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1510 NewRunnableFunction(ClearBrowsingData, browser(), | 1511 NewRunnableFunction(ClearBrowsingData, browser(), |
| 1511 BrowsingDataRemover::REMOVE_CACHE)); | 1512 BrowsingDataRemover::REMOVE_CACHE)); |
| 1512 ui_test_utils::RunMessageLoop(); | 1513 ui_test_utils::RunMessageLoop(); |
| 1513 | 1514 |
| 1514 // Make sure prerender history was not cleared. Not a vital behavior, but | 1515 // Make sure prerender history was not cleared. Not a vital behavior, but |
| 1515 // used to compare with PrerenderClearHistory test. | 1516 // used to compare with PrerenderClearHistory test. |
| 1516 EXPECT_EQ(1, GetHistoryLength()); | 1517 EXPECT_EQ(1, GetHistoryLength()); |
| 1517 } | 1518 } |
| 1518 | 1519 |
| 1519 } // namespace prerender | 1520 } // namespace prerender |
| OLD | NEW |