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

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

Issue 15041004: Replace PruneAllButActive with PruneAllButVisible. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Draft for prerender test. Created 7 years, 7 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
« no previous file with comments | « no previous file | chrome/browser/prerender/prerender_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/prerender/prerender_browsertest.cc
diff --git a/chrome/browser/prerender/prerender_browsertest.cc b/chrome/browser/prerender/prerender_browsertest.cc
index 80199b50107ce2c2abdd60a37d4125ab72b3adec..97702afecec0047e6a20cc84753c7151cf784dd6 100644
--- a/chrome/browser/prerender/prerender_browsertest.cc
+++ b/chrome/browser/prerender/prerender_browsertest.cc
@@ -701,13 +701,14 @@ class PrerenderBrowserTest : virtual public InProcessBrowserTest {
}
void NavigateToDestURL() const {
- NavigateToDestURLWithDisposition(CURRENT_TAB);
+ NavigateToDestURLWithDisposition(CURRENT_TAB, true);
}
// Opens the url in a new tab, with no opener.
void NavigateToDestURLWithDisposition(
- WindowOpenDisposition disposition) const {
- NavigateToURLImpl(dest_url_, disposition);
+ WindowOpenDisposition disposition,
+ bool expect_swap_to_succeed) const {
+ NavigateToURLImpl(dest_url_, disposition, expect_swap_to_succeed);
}
void OpenDestURLViaClick() const {
@@ -818,7 +819,7 @@ class PrerenderBrowserTest : virtual public InProcessBrowserTest {
void NavigateToURL(const std::string& dest_html_file) const {
GURL dest_url = test_server()->GetURL(dest_html_file);
- NavigateToURLImpl(dest_url, CURRENT_TAB);
+ NavigateToURLImpl(dest_url, CURRENT_TAB, true);
}
bool UrlIsInPrerenderManager(const std::string& html_file) const {
@@ -1085,7 +1086,8 @@ class PrerenderBrowserTest : virtual public InProcessBrowserTest {
}
void NavigateToURLImpl(const GURL& dest_url,
- WindowOpenDisposition disposition) const {
+ WindowOpenDisposition disposition,
+ bool expect_swap_to_succeed) const {
ASSERT_NE(static_cast<PrerenderManager*>(NULL), GetPrerenderManager());
// Make sure in navigating we have a URL to use in the PrerenderManager.
ASSERT_NE(static_cast<PrerenderContents*>(NULL), GetPrerenderContents());
@@ -1118,10 +1120,11 @@ class PrerenderBrowserTest : virtual public InProcessBrowserTest {
current_browser(), dest_url, disposition,
ui_test_utils::BROWSER_TEST_NONE);
- // Make sure the PrerenderContents found earlier was used or removed.
- EXPECT_EQ(static_cast<PrerenderContents*>(NULL), GetPrerenderContents());
+ // Make sure the PrerenderContents found earlier was used or removed,
+ // unless we expect the swap in to fail.
+ EXPECT_EQ(expect_swap_to_succeed, !GetPrerenderContents());
- if (call_javascript_ && web_contents) {
+ if (call_javascript_ && web_contents && expect_swap_to_succeed) {
if (page_load_observer.get())
page_load_observer->Wait();
@@ -1365,12 +1368,27 @@ 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 prerendering of a page is canceled correctly if we try to
+// swap it in before it commits.
+IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNoCommitNoSwap) {
+ // Navigate to a page that triggers a prerender for a URL that never commits.
+ // TODO(creis): Use a mock HTTP job for a URL that never commits.
+ const GURL no_commit_url = test_server()->GetURL("/slow?5");
Charlie Reis 2013/05/29 22:30:52 This needs to be replaced with a request that does
+ PrerenderTestURL(no_commit_url,
+ FINAL_STATUS_CANCELLED,
+ 0);
+
+ // Navigate to the URL, but assume the contents won't be swapped in.
+ NavigateToDestURLWithDisposition(CURRENT_TAB, false);
+
+ // Confirm that the prerendered version of the URL is not swapped in,
+ // since it never committed.
+ EXPECT_TRUE(UrlIsInPrerenderManager(no_commit_url));
+
+ // Post a task to cancel all the prerenders, so that we don't wait further.
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&CancelAllPrerenders, GetPrerenderManager()));
+ content::RunMessageLoop();
}
// Checks that the prerendering of a page is canceled correctly when a
« no previous file with comments | « no previous file | chrome/browser/prerender/prerender_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698