diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-27 04:35:13 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-27 04:35:13 +0000 |
commit | 208ce7e5e178bca7c7845b5c5129505ee85064ae (patch) | |
tree | 5ed7ff8cff680377430d0b26d951de46732fbff5 /chrome/browser/prerender | |
parent | 9639b940f0c7701c63ef21036f979ae6a76ccc17 (diff) | |
download | chromium_src-208ce7e5e178bca7c7845b5c5129505ee85064ae.zip chromium_src-208ce7e5e178bca7c7845b5c5129505ee85064ae.tar.gz chromium_src-208ce7e5e178bca7c7845b5c5129505ee85064ae.tar.bz2 |
Revert 98539
Test fails consistently on Linux Views bots:
PrerenderBrowserTest.PrerenderVisibilityBackgroundTab:
[6686:6686:0826/200949:368667468:WARNING:zygote_host_linux.cc(148)] Running without the SUID sandbox! See http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment for more information on developing with the sandbox on.
[6686:6686:0826/200949:368753313:WARNING:proxy_config_service_impl.cc(654)] Error retrieving proxy setting from device
[6686:6686:0826/200949:368754972:WARNING:wm_ipc.cc(311)] Missing _CHROME_LAYOUT_MODE property on root window
[6686:6691:0826/200949:368757012:INFO:gl_implementation.cc(94)] Using desktop GL implementation.
[6686:6691:0826/200949:368762612:ERROR:gl_surface_glx.cc(64)] GLX 1.3 or later is required.
[6686:6691:0826/200949:368762779:ERROR:gl_surface_linux.cc(73)] GLSurfaceGLX::InitializeOneOff failed.
[6686:6691:0826/200949:368762962:ERROR:gpu_info_collector_linux.cc(216)] gfx::GLContext::InitializeOneOff() failed
[6686:6686:0826/200949:368808876:ERROR:timezone_settings.cc(61)] GetTimezoneID: Cannot read timezone symlink /var/lib/timezone/localtime
[6686:6686:0826/200949:368808913:ERROR:timezone_settings.cc(141)] Got an empty string for timezone, default to America/Los_Angeles
[6686:6686:0826/200949:368816216:WARNING:input_method_manager.cc(146)] No active input methods found.
[6686:6686:0826/200949:368818013:WARNING:input_method_manager.cc(146)] No active input methods found.
[6686:6686:0826/200949:368818259:WARNING:input_method_manager.cc(146)] No active input methods found.
[6686:6686:0826/200950:369084812:WARNING:native_widget_gtk.cc(418)] compositing not supported; allowing anyway
chrome/browser/prerender/prerender_browsertest.cc:680: Failure
Value of: display_test_result
Actual: false
Expected: true
- Deflake PrerenderExcessiveMemory, fixing a race in setting
the visibility state of prerendered RenderViews in the
process.
Also add some more visibility API tests that would have
reliably failed when losing the fixed race.
BUG=93081
TEST=PrerenderBrowserTest.PrerenderExcessiveMemory. PrerenderBrowserTest.PrerenderInfiniteLoop
Review URL: http://codereview.chromium.org/7693029
TBR=mmenke@chromium.org
Review URL: http://codereview.chromium.org/7736003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98545 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/prerender')
-rw-r--r-- | chrome/browser/prerender/prerender_browsertest.cc | 79 | ||||
-rw-r--r-- | chrome/browser/prerender/prerender_contents.cc | 33 | ||||
-rw-r--r-- | chrome/browser/prerender/prerender_contents.h | 6 |
3 files changed, 52 insertions, 66 deletions
diff --git a/chrome/browser/prerender/prerender_browsertest.cc b/chrome/browser/prerender/prerender_browsertest.cc index b91abe2..eab87f9 100644 --- a/chrome/browser/prerender/prerender_browsertest.cc +++ b/chrome/browser/prerender/prerender_browsertest.cc @@ -102,21 +102,19 @@ class TestPrerenderContents : public PrerenderContents { Profile* profile, const GURL& url, const GURL& referrer, - int expected_number_of_loads, + int number_of_loads, FinalStatus expected_final_status) : PrerenderContents(prerender_manager, prerender_tracker, profile, url, referrer, ORIGIN_LINK_REL_PRERENDER, PrerenderManager::kNoExperiment), number_of_loads_(0), - expected_number_of_loads_(expected_number_of_loads), + expected_number_of_loads_(number_of_loads), expected_final_status_(expected_final_status), new_render_view_host_(NULL), was_hidden_(false), was_shown_(false), should_be_shown_(expected_final_status == FINAL_STATUS_USED), quit_message_loop_on_destruction_(true) { - if (expected_number_of_loads == 0) - MessageLoopForUI::current()->Quit(); } virtual ~TestPrerenderContents() { @@ -128,8 +126,9 @@ class TestPrerenderContents : public PrerenderContents { // navigation, so this should be happen for every PrerenderContents for // which a RenderViewHost is created, regardless of whether or not it's // used. - if (new_render_view_host_) + if (new_render_view_host_) { EXPECT_TRUE(was_hidden_); + } // A used PrerenderContents will only be destroyed when we swap out // TabContents, at the end of a navigation caused by a call to @@ -186,8 +185,6 @@ class TestPrerenderContents : public PrerenderContents { quit_message_loop_on_destruction_ = value; } - int number_of_loads() { return number_of_loads_; } - private: virtual void OnRenderViewHostCreated( RenderViewHost* new_render_view_host) OVERRIDE { @@ -248,8 +245,11 @@ class WaitForLoadPrerenderContentsFactory : public PrerenderContents::Factory { WaitForLoadPrerenderContentsFactory( int number_of_loads, const std::deque<FinalStatus>& expected_final_status_queue) - : number_of_loads_(number_of_loads), - expected_final_status_queue_(expected_final_status_queue) { + : number_of_loads_(number_of_loads) { + expected_final_status_queue_.resize(expected_final_status_queue.size()); + std::copy(expected_final_status_queue.begin(), + expected_final_status_queue.end(), + expected_final_status_queue_.begin()); VLOG(1) << "Factory created with queue length " << expected_final_status_queue_.size(); } @@ -615,7 +615,7 @@ class PrerenderBrowserTest : public InProcessBrowserTest { ASSERT_TRUE(prerender_contents != NULL); EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status()); - if (call_javascript_ && total_navigations > 0) { + if (call_javascript_) { // Check if page behaves as expected while in prerendered state. bool prerender_test_result = false; ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( @@ -625,7 +625,7 @@ class PrerenderBrowserTest : public InProcessBrowserTest { EXPECT_TRUE(prerender_test_result); } } else { - // In the failure case, we should have removed |dest_url_| from the + // In the failure case, we should have removed dest_url_ from the // prerender_manager. EXPECT_TRUE(prerender_contents == NULL); } @@ -641,18 +641,6 @@ class PrerenderBrowserTest : public InProcessBrowserTest { if (disposition == NEW_BACKGROUND_TAB) GetPrerenderContents()->set_should_be_shown(false); - // In the case of zero loads, need to wait for the page load to complete - // before running any Javascript. - scoped_ptr<ui_test_utils::WindowedNotificationObserver> page_load_observer; - TabContents* tab_contents = - GetPrerenderContents()->prerender_contents()->tab_contents(); - if (GetPrerenderContents()->number_of_loads() == 0) { - page_load_observer.reset( - new ui_test_utils::WindowedNotificationObserver( - content::NOTIFICATION_LOAD_STOP, - Source<NavigationController>(&tab_contents->controller()))); - } - // ui_test_utils::NavigateToURL waits until DidStopLoading is called on // the current tab. As that tab is going to end up deleted, and may never // finish loading before that happens, exit the message loop on the deletion @@ -669,8 +657,23 @@ class PrerenderBrowserTest : public InProcessBrowserTest { EXPECT_TRUE(GetPrerenderContents() == NULL); if (call_javascript_) { - if (page_load_observer.get()) - page_load_observer->Wait(); + // Check if page behaved as expected when actually displayed. + + // Locate the navigated TabContents. + TabContents* tab_contents = NULL; + switch (disposition) { + case CURRENT_TAB: + case NEW_FOREGROUND_TAB: + tab_contents = browser()->GetSelectedTabContents(); + break; + case NEW_BACKGROUND_TAB: + tab_contents = + browser()->GetTabContentsAt(browser()->active_index() + 1); + break; + default: + ASSERT_TRUE(false) << "Unsupported creation disposition"; + } + ASSERT_TRUE(tab_contents); bool display_test_result = false; ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( @@ -707,14 +710,6 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderVisibility) { NavigateToDestURL(); } -// Checks that the visibility API works when the prerender is quickly opened -// in a new tab before it stops loading. -IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderVisibilityQuickSwitch) { - PrerenderTestURL("files/prerender/prerender_visibility_quick.html", - FINAL_STATUS_USED, 0); - NavigateToDestURL(); -} - // Checks that the visibility API works when opening a page in a new hidden // tab. IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderVisibilityBackgroundTab) { @@ -724,15 +719,6 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderVisibilityBackgroundTab) { NavigateToDestURLWithDisposition(NEW_BACKGROUND_TAB); } -// Checks that the visibility API works when opening a page in a new hidden -// tab, which is switched to before it stops loading. -IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, - PrerenderVisibilityBackgroundTabQuickSwitch) { - PrerenderTestURL("files/prerender/prerender_visibility_hidden_quick.html", - FINAL_STATUS_USED, 0); - NavigateToDestURLWithDisposition(NEW_BACKGROUND_TAB); -} - // Checks that the visibility API works when opening a page in a new foreground // tab. IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderVisibilityForegroundTab) { @@ -742,15 +728,6 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderVisibilityForegroundTab) { NavigateToDestURLWithDisposition(NEW_FOREGROUND_TAB); } -// Checks that the visibility API works when the prerender is quickly opened -// in a new tab foreground before it stops loading. -IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, - PrerenderVisibilityForegroundTabQuickSwitch) { - PrerenderTestURL("files/prerender/prerender_visibility_quick.html", - FINAL_STATUS_USED, 0); - NavigateToDestURL(); -} - // Checks that the prerendering of a page is canceled correctly when a // Javascript alert is called. IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderAlertBeforeOnload) { diff --git a/chrome/browser/prerender/prerender_contents.cc b/chrome/browser/prerender/prerender_contents.cc index cdc975d..f983347 100644 --- a/chrome/browser/prerender/prerender_contents.cc +++ b/chrome/browser/prerender/prerender_contents.cc @@ -172,6 +172,7 @@ void PrerenderContents::StartPrerendering( prerender_contents_.reset(new TabContentsWrapper(new_contents)); TabContentsObserver::Observe(new_contents); + gfx::Rect tab_bounds; if (source_render_view_host) { DCHECK(source_render_view_host->view() != NULL); TabContents* source_tc = @@ -182,7 +183,7 @@ void PrerenderContents::StartPrerendering( starting_page_id_ = source_tc->GetMaxPageID(); // Set the size of the new TC to that of the old TC. - source_tc->view()->GetContainerBounds(&tab_bounds_); + source_tc->view()->GetContainerBounds(&tab_bounds); } } else { int max_page_id = -1; @@ -208,7 +209,7 @@ void PrerenderContents::StartPrerendering( if (active_browser) { TabContents* active_tab_contents = active_browser->GetTabContentsAt( active_browser->active_index()); - active_tab_contents->view()->GetContainerBounds(&tab_bounds_); + active_tab_contents->view()->GetContainerBounds(&tab_bounds); } } @@ -222,6 +223,9 @@ void PrerenderContents::StartPrerendering( tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); new_contents->set_delegate(tab_contents_delegate_.get()); + // Set the size of the prerender TabContents. + prerender_contents_->view()->SizeContents(tab_bounds.size()); + // Register as an observer of the RenderViewHost so we get messages. render_view_host_observer_.reset( new PrerenderRenderViewHostObserver(this, render_view_host_mutable())); @@ -254,6 +258,12 @@ void PrerenderContents::StartPrerendering( this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, Source<TabContents>(new_contents)); + // Register to be told when the RenderView is ready, so we can hide it. + // It will automatically be set to visible when we resize it, otherwise. + notification_registrar_.Add(this, + content::NOTIFICATION_TAB_CONTENTS_CONNECTED, + Source<TabContents>(new_contents)); + // Register for redirect notifications sourced from |this|. notification_registrar_.Add( this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, @@ -371,17 +381,20 @@ void PrerenderContents::Observe(int type, new ChromeViewMsg_SetIsPrerendering( new_render_view_host->routing_id(), true)); + } + break; + } - // Set the size of the prerender TabContents. This must be done after - // the RenderView has been created so that the RenderView will be - // informated promptly of the size change. - prerender_contents_->view()->SizeContents(tab_bounds_.size()); - - // Hide the tab contents. Must be done after setting the size, as - // resizing currently forces the RenderView to set itself as visible. + case content::NOTIFICATION_TAB_CONTENTS_CONNECTED: { + if (prerender_contents_.get()) { + DCHECK_EQ(Source<TabContents>(source).ptr(), + prerender_contents_->tab_contents()); + // Set the new TabContents and its RenderViewHost as hidden, to reduce + // resource usage. This can only be done after the size has been sent + // to the RenderView, which is why it's done here. prerender_contents_->tab_contents()->HideContents(); } - break; + return; } case content::NOTIFICATION_CREATING_NEW_WINDOW_CANCELLED: { diff --git a/chrome/browser/prerender/prerender_contents.h b/chrome/browser/prerender/prerender_contents.h index d9077ca..9a6d4df 100644 --- a/chrome/browser/prerender/prerender_contents.h +++ b/chrome/browser/prerender/prerender_contents.h @@ -16,7 +16,6 @@ #include "content/browser/tab_contents/tab_contents_observer.h" #include "content/browser/renderer_host/render_view_host_delegate.h" #include "content/common/notification_registrar.h" -#include "ui/gfx/rect.h" class Profile; class RenderViewHost; @@ -280,12 +279,9 @@ class PrerenderContents : public NotificationObserver, // Experiment during which this prerender is performed. uint8 experiment_id_; - // Offset by which to offset prerendered pages. + // Offset by which to offset prerendered pages static const int32 kPrerenderPageIdOffset = 10; - // Bounds to use for the prerendered TabContents. - gfx::Rect tab_bounds_; - DISALLOW_COPY_AND_ASSIGN(PrerenderContents); }; |