Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Unified Diff: chrome/browser/prerender/prerender_browsertest.cc

Issue 7046053: Add PrerenderUnload browser test (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add browser test Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..70528621ddd672f905a6a1b4e2cdac1cd0bce824 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"
@@ -315,7 +317,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 +468,10 @@ class PrerenderBrowserTest : public InProcessBrowserTest {
return safe_browsing_factory_->most_recent_service();
}
+ void set_loader_path(const std::string& path) {
+ loader_path_ = path;
+ }
+
private:
void PrerenderTestURLImpl(
const GURL& url,
@@ -477,7 +484,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 +578,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 +1348,61 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderLocalStorageWrite) {
NavigateToDestURL();
}
+class TitleWatcher : public NotificationObserver {
dominich 2011/06/08 22:19:19 Can you put this up with the other classes at the
mmenke 2011/06/08 22:29:05 nit: Should stick this in an anonymous namespace,
cbentzel 2011/06/09 00:49:49 Done.
cbentzel 2011/06/09 00:49:49 Done.
+ public:
+ TitleWatcher(TabContents* tab_contents, const string16& expected_title)
+ : expected_title_(expected_title),
+ title_observed_(false),
+ quit_loop_on_observation_(false) {
+ 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;
+
+ TitleUpdatedDetails* title_details =
+ Details<TitleUpdatedDetails>(details).ptr();
+ if (!title_details || title_details->entry()->title() != expected_title_)
+ return;
+
+ title_observed_ = true;
+ if (quit_loop_on_observation_)
+ MessageLoopForUI::current()->Quit();
dominich 2011/06/08 22:19:19 Please make sure you run this on the release trybo
+ }
+
+ bool WaitForTitleChange() {
+ if (title_observed_)
+ return true;
+ quit_loop_on_observation_ = true;
+ ui_test_utils::RunMessageLoop();
+ return title_observed_;
+ }
+
+ private:
+ string16 expected_title_;
+ NotificationRegistrar notification_registrar_;
+ bool title_observed_;
+ bool quit_loop_on_observation_;
+};
+
+// 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();
+ string16 expected_title = ASCIIToUTF16("Unloaded");
dominich 2011/06/08 22:19:19 nit: No need for this to be a local variable.
cbentzel 2011/06/09 00:49:49 Done.
+ TitleWatcher title_watcher(tab_contents, expected_title);
+ NavigateToDestURL();
+ EXPECT_TRUE(title_watcher.WaitForTitleChange());
+}
+
} // namespace prerender
« no previous file with comments | « no previous file | chrome/browser/prerender/prerender_manager.cc » ('j') | chrome/browser/prerender/prerender_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698