Index: chrome/browser/prerender/prerender_browsertest.cc |
diff --git a/chrome/browser/prerender/prerender_browsertest.cc b/chrome/browser/prerender/prerender_browsertest.cc |
index e2e8c8418e752d98b9f9cf324c0d7fa234791b5c..44e362711a6f6d125ab2eecb2e170f0dc42a9a3d 100644 |
--- a/chrome/browser/prerender/prerender_browsertest.cc |
+++ b/chrome/browser/prerender/prerender_browsertest.cc |
@@ -7,6 +7,7 @@ |
#include "base/command_line.h" |
#include "base/path_service.h" |
#include "base/string_util.h" |
+#include "base/utf_string_conversions.h" |
#include "chrome/browser/content_settings/host_content_settings_map.h" |
#include "chrome/browser/prefs/pref_service.h" |
#include "chrome/browser/prerender/prerender_contents.h" |
@@ -24,6 +25,7 @@ |
#include "chrome/test/ui_test_utils.h" |
#include "content/browser/renderer_host/render_view_host.h" |
#include "content/browser/tab_contents/tab_contents.h" |
+#include "content/browser/tab_contents/title_updated_details.h" |
#include "content/common/notification_service.h" |
#include "grit/generated_resources.h" |
#include "net/url_request/url_request_context.h" |
@@ -240,6 +242,55 @@ class WaitForLoadPrerenderContentsFactory : public PrerenderContents::Factory { |
std::deque<FinalStatus> expected_final_status_queue_; |
}; |
+// Watches title changes on a tab, blocking until an expected change occurs. |
+class TitleWatcher : public NotificationObserver { |
Paweł Hajdan Jr.
2011/06/09 09:23:15
Could you move this to chrome/test/ui_test_utils?
cbentzel
2011/06/09 15:29:21
This seems like a pretty specific class, and doesn
Paweł Hajdan Jr.
2011/06/09 19:24:12
Yes please, for now it's not used by more tests bu
|
+ public: |
+ TitleWatcher(TabContents* tab_contents, const string16& expected_title) |
+ : expected_tab_(tab_contents), |
+ expected_title_(expected_title), |
+ title_observed_(false), |
+ quit_loop_on_observation_(false) { |
+ EXPECT_TRUE(tab_contents != NULL); |
+ notification_registrar_.Add(this, |
+ NotificationType::TAB_CONTENTS_TITLE_UPDATED, |
+ Source<TabContents>(tab_contents)); |
+ } |
+ |
+ ~TitleWatcher() { |
+ } |
+ |
+ virtual void Observe(NotificationType type, |
+ const NotificationSource& source, |
+ const NotificationDetails& details) OVERRIDE { |
+ if (type != NotificationType::TAB_CONTENTS_TITLE_UPDATED) |
+ return; |
+ |
+ TabContents* source_contents = Source<TabContents>(source).ptr(); |
+ ASSERT_EQ(expected_tab_, source_contents); |
+ if (source_contents->GetTitle() != expected_title_) |
+ return; |
+ |
+ title_observed_ = true; |
+ if (quit_loop_on_observation_) |
+ MessageLoopForUI::current()->Quit(); |
+ } |
+ |
+ bool WaitForTitleChange() { |
Paweł Hajdan Jr.
2011/06/09 09:23:15
nit: Add WARN_UNUSED_RESULT from base/compiler_spe
cbentzel
2011/06/09 15:29:21
Done.
|
+ if (title_observed_) |
+ return true; |
+ quit_loop_on_observation_ = true; |
+ ui_test_utils::RunMessageLoop(); |
+ return title_observed_; |
+ } |
+ |
+ private: |
+ TabContents* expected_tab_; |
+ string16 expected_title_; |
+ NotificationRegistrar notification_registrar_; |
+ bool title_observed_; |
+ bool quit_loop_on_observation_; |
Paweł Hajdan Jr.
2011/06/09 09:23:15
nit: DISALLOW_COPY_AND_ASSIGN.
cbentzel
2011/06/09 15:29:21
Done.
|
+}; |
+ |
} // namespace |
// A SafeBrowingService implementation that returns a fixed result for a given |
@@ -315,7 +366,8 @@ class PrerenderBrowserTest : public InProcessBrowserTest { |
: safe_browsing_factory_(new TestSafeBrowsingServiceFactory()), |
prerender_contents_factory_(NULL), |
use_https_src_server_(false), |
- call_javascript_(true) { |
+ call_javascript_(true), |
+ loader_path_("files/prerender/prerender_loader.html") { |
EnableDOMAutomation(); |
} |
@@ -465,6 +517,10 @@ class PrerenderBrowserTest : public InProcessBrowserTest { |
return safe_browsing_factory_->most_recent_service(); |
} |
+ void set_loader_path(const std::string& path) { |
dominich
2011/06/09 14:26:56
Did you consider adding another PrerenderTestURL v
cbentzel
2011/06/09 15:29:21
I did consider it, but it seemed like the combinat
|
+ loader_path_ = path; |
+ } |
+ |
private: |
void PrerenderTestURLImpl( |
const GURL& url, |
@@ -477,7 +533,7 @@ class PrerenderBrowserTest : public InProcessBrowserTest { |
make_pair("REPLACE_WITH_PRERENDER_URL", dest_url_.spec())); |
std::string replacement_path; |
ASSERT_TRUE(net::TestServer::GetFilePathWithReplacements( |
- "files/prerender/prerender_loader.html", |
+ loader_path_, |
replacement_text, |
&replacement_path)); |
@@ -571,6 +627,7 @@ class PrerenderBrowserTest : public InProcessBrowserTest { |
GURL dest_url_; |
bool use_https_src_server_; |
bool call_javascript_; |
+ std::string loader_path_; |
}; |
// Checks that a page is correctly prerendered in the case of a |
@@ -1340,4 +1397,15 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderLocalStorageWrite) { |
NavigateToDestURL(); |
} |
+// Checks that when a prerendered page is swapped in to a referring page, the |
+// unload handlers on the referring page are executed. |
+IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderUnload) { |
+ set_loader_path("files/prerender/prerender_loader_with_unload.html"); |
+ PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
+ TabContents* tab_contents = browser()->GetSelectedTabContents(); |
dominich
2011/06/09 14:26:56
nit: no need for this to be a local variable.
cbentzel
2011/06/09 15:29:21
Done.
|
+ TitleWatcher title_watcher(tab_contents, ASCIIToUTF16("Unloaded")); |
+ NavigateToDestURL(); |
+ EXPECT_TRUE(title_watcher.WaitForTitleChange()); |
+} |
+ |
} // namespace prerender |