diff options
author | shishir@chromium.org <shishir@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-06 23:01:07 +0000 |
---|---|---|
committer | shishir@chromium.org <shishir@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-06 23:01:07 +0000 |
commit | de1fcdd5944c7095ffac2bff41e55baa6779ebfb (patch) | |
tree | e7975c610b3ed781d8c2eb3bde597d5c43eb4172 | |
parent | 45d83a197a7aa201a0cbe72cbf08b79f72649eba (diff) | |
download | chromium_src-de1fcdd5944c7095ffac2bff41e55baa6779ebfb.zip chromium_src-de1fcdd5944c7095ffac2bff41e55baa6779ebfb.tar.gz chromium_src-de1fcdd5944c7095ffac2bff41e55baa6779ebfb.tar.bz2 |
Fixing PrerenderBrowserTest.PrerenderHTML5VideoNetwork test to test for stalled event.
BUG=None
TEST=PrerenderBrowserTest.PrerenderHTML5VideoNetwork
Review URL: http://codereview.chromium.org/9972001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131204 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/prerender/prerender_browsertest.cc | 96 | ||||
-rw-r--r-- | chrome/browser/prerender/prerender_contents.cc | 9 | ||||
-rw-r--r-- | chrome/browser/prerender/prerender_contents.h | 4 | ||||
-rw-r--r-- | chrome/test/data/prerender/prerender_html5_common.js | 15 |
4 files changed, 103 insertions, 21 deletions
diff --git a/chrome/browser/prerender/prerender_browsertest.cc b/chrome/browser/prerender/prerender_browsertest.cc index 1c0b922..3a06eaf 100644 --- a/chrome/browser/prerender/prerender_browsertest.cc +++ b/chrome/browser/prerender/prerender_browsertest.cc @@ -71,6 +71,10 @@ namespace prerender { namespace { +// Constants used in the test HTML files. +static const char* kReadyTitle = "READY"; +static const char* kPassTitle = "PASS"; + std::string CreateClientRedirect(const std::string& dest_url) { const char* const kClientRedirectBase = "client-redirect?"; return kClientRedirectBase + dest_url; @@ -125,7 +129,8 @@ class TestPrerenderContents : public PrerenderContents { const GURL& url, const content::Referrer& referrer, int expected_number_of_loads, - FinalStatus expected_final_status) + FinalStatus expected_final_status, + bool prerender_should_wait_for_ready_title) : PrerenderContents(prerender_manager, prerender_tracker, profile, url, referrer, ORIGIN_LINK_REL_PRERENDER, PrerenderManager::kNoExperiment), @@ -140,7 +145,9 @@ class TestPrerenderContents : public PrerenderContents { expected_final_status != FINAL_STATUS_EVICTED && expected_final_status != FINAL_STATUS_APP_TERMINATING && expected_final_status != FINAL_STATUS_MAX), - expected_pending_prerenders_(0) { + expected_pending_prerenders_(0), + prerender_should_wait_for_ready_title_( + prerender_should_wait_for_ready_title) { if (expected_number_of_loads == 0) MessageLoopForUI::current()->Quit(); } @@ -225,6 +232,24 @@ class TestPrerenderContents : public PrerenderContents { } } + virtual WebContents* CreateWebContents( + content::SessionStorageNamespace* session_storage_namespace) OVERRIDE { + WebContents* web_contents = PrerenderContents::CreateWebContents( + session_storage_namespace); + string16 ready_title = ASCIIToUTF16(kReadyTitle); + if (prerender_should_wait_for_ready_title_) + ready_title_watcher_.reset(new ui_test_utils::TitleWatcher( + web_contents, ready_title)); + return web_contents; + } + + void WaitForPrerenderToHaveReadyTitleIfRequired() { + if (ready_title_watcher_.get()) { + string16 ready_title = ASCIIToUTF16(kReadyTitle); + ASSERT_EQ(ready_title, ready_title_watcher_->WaitAndGetTitle()); + } + } + // Waits until the prerender has |expected_pending_prerenders| pending // prerenders. void WaitForPendingPrerenders(size_t expected_pending_prerenders) { @@ -302,6 +327,11 @@ class TestPrerenderContents : public PrerenderContents { // Total number of pending prerenders we're currently waiting for. Zero // indicates we currently aren't waiting for any. size_t expected_pending_prerenders_; + + // If true, before calling DidPrerenderPass, will wait for the title of the + // prerendered page to turn to "READY". + bool prerender_should_wait_for_ready_title_; + scoped_ptr<ui_test_utils::TitleWatcher> ready_title_watcher_; }; // PrerenderManager that uses TestPrerenderContents. @@ -309,9 +339,12 @@ class WaitForLoadPrerenderContentsFactory : public PrerenderContents::Factory { public: WaitForLoadPrerenderContentsFactory( int expected_number_of_loads, - const std::deque<FinalStatus>& expected_final_status_queue) + const std::deque<FinalStatus>& expected_final_status_queue, + bool prerender_should_wait_for_ready_title) : expected_number_of_loads_(expected_number_of_loads), - expected_final_status_queue_(expected_final_status_queue) { + expected_final_status_queue_(expected_final_status_queue), + prerender_should_wait_for_ready_title_( + prerender_should_wait_for_ready_title) { VLOG(1) << "Factory created with queue length " << expected_final_status_queue_.size(); } @@ -335,12 +368,14 @@ class WaitForLoadPrerenderContentsFactory : public PrerenderContents::Factory { return new TestPrerenderContents(prerender_manager, prerender_tracker, profile, url, referrer, expected_number_of_loads_, - expected_final_status); + expected_final_status, + prerender_should_wait_for_ready_title_); } private: int expected_number_of_loads_; std::deque<FinalStatus> expected_final_status_queue_; + bool prerender_should_wait_for_ready_title_; }; #if defined(ENABLE_SAFE_BROWSING) @@ -481,21 +516,42 @@ class PrerenderBrowserTest : public InProcessBrowserTest { void PrerenderTestURL(const std::string& html_file, FinalStatus expected_final_status, int expected_number_of_loads) { + PrerenderTestURL(html_file, + expected_final_status, + expected_number_of_loads, + false); + } + + void PrerenderTestURL(const std::string& html_file, + FinalStatus expected_final_status, + int expected_number_of_loads, + bool prerender_should_wait_for_ready_title) { std::deque<FinalStatus> expected_final_status_queue(1, expected_final_status); PrerenderTestURL(html_file, expected_final_status_queue, - expected_number_of_loads); + expected_number_of_loads, + prerender_should_wait_for_ready_title); } void PrerenderTestURL( const std::string& html_file, const std::deque<FinalStatus>& expected_final_status_queue, - int expected_number_of_loads) { + int expected_number_of_loads, + bool prerender_should_wait_for_ready_title) { GURL url = test_server()->GetURL(html_file); PrerenderTestURLImpl(url, url, expected_final_status_queue, - expected_number_of_loads); + expected_number_of_loads, + prerender_should_wait_for_ready_title); + } + + void PrerenderTestURL( + const std::string& html_file, + const std::deque<FinalStatus>& expected_final_status_queue, + int expected_number_of_loads) { + PrerenderTestURL(html_file, expected_final_status_queue, + expected_number_of_loads, false); } void PrerenderTestURL( @@ -506,7 +562,8 @@ class PrerenderBrowserTest : public InProcessBrowserTest { expected_final_status); PrerenderTestURLImpl(url, url, expected_final_status_queue, - expected_number_of_loads); + expected_number_of_loads, + false); } void PrerenderTestURL( @@ -518,7 +575,8 @@ class PrerenderBrowserTest : public InProcessBrowserTest { expected_final_status); PrerenderTestURLImpl(prerender_url, destination_url, expected_final_status_queue, - expected_number_of_loads); + expected_number_of_loads, + false); } void NavigateToDestURL() const { @@ -585,7 +643,7 @@ class PrerenderBrowserTest : public InProcessBrowserTest { } void NavigateToDestUrlAndWaitForPassTitle() { - string16 expected_title = ASCIIToUTF16("PASS"); + string16 expected_title = ASCIIToUTF16(kPassTitle); ui_test_utils::TitleWatcher title_watcher( GetPrerenderContents()->prerender_contents()->web_contents(), expected_title); @@ -731,7 +789,8 @@ class PrerenderBrowserTest : public InProcessBrowserTest { const GURL& prerender_url, const GURL& destination_url, const std::deque<FinalStatus>& expected_final_status_queue, - int expected_number_of_loads) { + int expected_number_of_loads, + bool prerender_should_wait_for_ready_title) { dest_url_ = destination_url; std::vector<net::TestServer::StringPair> replacement_text; @@ -762,8 +821,10 @@ class PrerenderBrowserTest : public InProcessBrowserTest { prerender_manager()->mutable_config().https_allowed = true; ASSERT_TRUE(prerender_contents_factory_ == NULL); prerender_contents_factory_ = - new WaitForLoadPrerenderContentsFactory(expected_number_of_loads, - expected_final_status_queue); + new WaitForLoadPrerenderContentsFactory( + expected_number_of_loads, + expected_final_status_queue, + prerender_should_wait_for_ready_title); prerender_manager()->SetPrerenderContentsFactory( prerender_contents_factory_); FinalStatus expected_final_status = expected_final_status_queue.front(); @@ -785,6 +846,10 @@ class PrerenderBrowserTest : public InProcessBrowserTest { EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status()); if (call_javascript_ && expected_number_of_loads > 0) { + // Wait for the prerendered page to change title to signal it is ready + // if required. + prerender_contents->WaitForPrerenderToHaveReadyTitleIfRequired(); + // Check if page behaves as expected while in prerendered state. bool prerender_test_result = false; ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( @@ -1451,7 +1516,8 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHTML5VideoJs) { IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHTML5VideoNetwork) { PrerenderTestURL("files/prerender/prerender_html5_video_network.html", FINAL_STATUS_USED, - 1); + 1, + true); NavigateToDestUrlAndWaitForPassTitle(); } diff --git a/chrome/browser/prerender/prerender_contents.cc b/chrome/browser/prerender/prerender_contents.cc index 113a652..d1b7a06a 100644 --- a/chrome/browser/prerender/prerender_contents.cc +++ b/chrome/browser/prerender/prerender_contents.cc @@ -281,8 +281,7 @@ void PrerenderContents::StartPrerendering( InformRenderProcessAboutPrerender(prerender_url_, true, creator_child_id_); - WebContents* new_contents = WebContents::Create( - profile_, NULL, MSG_ROUTING_NONE, NULL, session_storage_namespace); + WebContents* new_contents = CreateWebContents(session_storage_namespace); prerender_contents_.reset(new TabContentsWrapper(new_contents)); content::WebContentsObserver::Observe(new_contents); @@ -490,6 +489,12 @@ void PrerenderContents::OnRenderViewHostCreated( RenderViewHost* new_render_view_host) { } +WebContents* PrerenderContents::CreateWebContents( + content::SessionStorageNamespace* session_storage_namespace) { + return WebContents::Create(profile_, NULL, MSG_ROUTING_NONE, NULL, + session_storage_namespace); +} + void PrerenderContents::OnUpdateFaviconURL( int32 page_id, const std::vector<FaviconURL>& urls) { diff --git a/chrome/browser/prerender/prerender_contents.h b/chrome/browser/prerender/prerender_contents.h index 85aa433..2463ed9 100644 --- a/chrome/browser/prerender/prerender_contents.h +++ b/chrome/browser/prerender/prerender_contents.h @@ -31,6 +31,7 @@ namespace content { class RenderViewHost; class RenderViewHostDelegate; class SessionStorageNamespace; +class WebContents; } namespace prerender { @@ -242,6 +243,9 @@ class PrerenderContents : public content::NotificationObserver, return &pending_prerender_list_; } + virtual content::WebContents* CreateWebContents( + content::SessionStorageNamespace* session_storage_namespace); + private: class TabContentsDelegateImpl; diff --git a/chrome/test/data/prerender/prerender_html5_common.js b/chrome/test/data/prerender/prerender_html5_common.js index 2a4c0a4..0e2af7d 100644 --- a/chrome/test/data/prerender/prerender_html5_common.js +++ b/chrome/test/data/prerender/prerender_html5_common.js @@ -11,6 +11,9 @@ // very early, to test for it reliably, the source of the media tag // should be added after this script is included or add // 'onLoadStart=mediEventHandler' as an attribute to the media element. +// Also to reliably test the stalled event, the the test should wait for the +// prerendered page's title to change to "READY" before calling +// DidPrerenderPass. function assert(bool) { if (!bool) @@ -21,6 +24,7 @@ var canPlaySeen = false; var playingSeen = false; var canPlayThroughSeen = false; var loadStartSeen = false; +var stalledSeen = false; var hasError = false; assert(typeof(willPlay) != 'undefined'); @@ -48,9 +52,11 @@ function mediaEventHandler(e) { loadStartSeen = true; break; case 'stalled': - // We should never see a stalled event during the display portion of the - // test. - assert(false); + assert(loadStartSeen); + stalledSeen = true; + if (testNetworkEvents) { + document.title = 'READY'; + } break; } @@ -75,7 +81,8 @@ function DidPrerenderPass() { // The media should not have started at this point. return !canPlaySeen && !playingSeen && !hasError && mediaEl.currentTime == 0 && - mediaEl.readyState == mediaEl.HAVE_NOTHING; + mediaEl.readyState == mediaEl.HAVE_NOTHING && + (!testNetworkEvents || stalledSeen); } function DidDisplayPass() { |