summaryrefslogtreecommitdiffstats
path: root/chrome/browser/prerender
diff options
context:
space:
mode:
authordominich@google.com <dominich@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-30 20:51:22 +0000
committerdominich@google.com <dominich@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-30 20:51:22 +0000
commit7e86f18b3badca852dde6afa38f846d18f65018c (patch)
tree8a1f5b1be6518a18161eb0896f9083d1dd73d373 /chrome/browser/prerender
parent131dd2fa320ed1188a636eea648a015c8c24f94a (diff)
downloadchromium_src-7e86f18b3badca852dde6afa38f846d18f65018c.zip
chromium_src-7e86f18b3badca852dde6afa38f846d18f65018c.tar.gz
chromium_src-7e86f18b3badca852dde6afa38f846d18f65018c.tar.bz2
Use a queue for expected final status to remove link tag order-dependent behavior. The original code linked a status to a URL however we seem to get the URLs in non-deterministic order when there are multiple <link rel="prefetch"..> tags in a page. This uses a queue to assign the final statuses as we get the URLs and should remove the flakiness.
BUG=77323 TEST=PrerenderBrowserTest.(FLAKY_)PrerenderInfiniteLoopMultiple Review URL: http://codereview.chromium.org/6768005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79890 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/prerender')
-rw-r--r--chrome/browser/prerender/prerender_browsertest.cc63
-rw-r--r--chrome/browser/prerender/prerender_manager.cc4
2 files changed, 27 insertions, 40 deletions
diff --git a/chrome/browser/prerender/prerender_browsertest.cc b/chrome/browser/prerender/prerender_browsertest.cc
index af8b22a..e8a5699 100644
--- a/chrome/browser/prerender/prerender_browsertest.cc
+++ b/chrome/browser/prerender/prerender_browsertest.cc
@@ -21,6 +21,8 @@
#include "net/url_request/url_request_context.h"
#include "ui/base/l10n/l10n_util.h"
+#include <queue>
+
// Prerender tests work as follows:
//
// A page with a prefetch link to the test page is loaded. Once prerendered,
@@ -87,39 +89,29 @@ class TestPrerenderContents : public PrerenderContents {
class WaitForLoadPrerenderContentsFactory : public PrerenderContents::Factory {
public:
explicit WaitForLoadPrerenderContentsFactory(
- FinalStatus expected_final_status)
- : expected_final_status_(expected_final_status) {
- }
-
- void set_expected_final_status(FinalStatus expected_final_status) {
- expected_final_status_ = expected_final_status;
+ FinalStatus expected_final_status) {
+ PushExpectedFinalStatus(expected_final_status);
}
- void set_expected_final_status_for_url(const GURL& url,
- FinalStatus expected_final_status) {
- DCHECK(expected_final_status_map_.find(url) ==
- expected_final_status_map_.end());
- expected_final_status_map_[url] = expected_final_status;
+ void PushExpectedFinalStatus(FinalStatus expected_final_status) {
+ expected_final_status_queue_.push(expected_final_status);
}
virtual PrerenderContents* CreatePrerenderContents(
PrerenderManager* prerender_manager, Profile* profile, const GURL& url,
const std::vector<GURL>& alias_urls, const GURL& referrer) {
- FinalStatus expected_final_status = expected_final_status_;
- std::map<GURL, FinalStatus>::iterator it =
- expected_final_status_map_.find(url);
- if (it != expected_final_status_map_.end()) {
- expected_final_status = it->second;
- expected_final_status_map_.erase(it);
- }
+ CHECK(!expected_final_status_queue_.empty()) <<
+ "Creating prerender contents for " << url.path() <<
+ "with no expected final status";
+ FinalStatus expected_final_status = expected_final_status_queue_.front();
+ expected_final_status_queue_.pop();
return new TestPrerenderContents(prerender_manager, profile, url,
alias_urls, referrer,
expected_final_status);
}
private:
- FinalStatus expected_final_status_;
- std::map<GURL, FinalStatus> expected_final_status_map_;
+ std::queue<FinalStatus> expected_final_status_queue_;
};
} // namespace
@@ -265,18 +257,10 @@ class PrerenderBrowserTest : public InProcessBrowserTest {
use_https_src_server_ = use_https_src_server;
}
- void SetExpectedFinalStatus(FinalStatus expected_final_status) {
+ void PushExpectedFinalStatus(FinalStatus expected_final_status) {
DCHECK(prerender_manager()->prerender_contents_factory_.get() ==
prc_factory_);
- prc_factory_->set_expected_final_status(expected_final_status);
- }
-
- void SetExpectedFinalStatusForUrl(const std::string& html_file,
- FinalStatus expected_final_status) {
- GURL url = UrlForHtmlFile(html_file);
- DCHECK(prerender_manager()->prerender_contents_factory_.get() ==
- prc_factory_);
- prc_factory_->set_expected_final_status_for_url(url, expected_final_status);
+ prc_factory_->PushExpectedFinalStatus(expected_final_status);
}
TaskManagerModel* model() const {
@@ -439,7 +423,7 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderInfiniteLoop) {
// We are not going to navigate back to kHtmlFileA but we will start the
// preload so we need to set the final status to expect here before
// navigating.
- SetExpectedFinalStatus(FINAL_STATUS_APP_TERMINATING);
+ PushExpectedFinalStatus(FINAL_STATUS_APP_TERMINATING);
NavigateToDestURL();
@@ -467,17 +451,20 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, FLAKY_PrerenderInfiniteLoopMultiple
// We are not going to navigate back to kHtmlFileA but we will start the
// preload so we need to set the final status to expect here before
- // navigating.
- SetExpectedFinalStatusForUrl(kHtmlFileB, FINAL_STATUS_EVICTED);
- SetExpectedFinalStatusForUrl(kHtmlFileC, FINAL_STATUS_APP_TERMINATING);
+ // navigating. We set them on a queue so whichever we see first is expected to
+ // be evicted, and the second should stick around until we exit.
+ PushExpectedFinalStatus(FINAL_STATUS_EVICTED);
+ PushExpectedFinalStatus(FINAL_STATUS_APP_TERMINATING);
NavigateToDestURL();
// Make sure the PrerenderContents for the next urls are now in the manager
- // and not pending. url_c was the last seen so should be the active
- // entry.
- EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileB));
- EXPECT_TRUE(UrlIsInPrerenderManager(kHtmlFileC));
+ // and not pending. One and only one of the URLs (the last seen) should be the
+ // active entry.
+ bool url_b_is_active_prerender = UrlIsInPrerenderManager(kHtmlFileB);
+ bool url_c_is_active_prerender = UrlIsInPrerenderManager(kHtmlFileC);
+ EXPECT_TRUE((url_b_is_active_prerender || url_c_is_active_prerender) &&
+ !(url_b_is_active_prerender && url_c_is_active_prerender));
EXPECT_FALSE(UrlIsPendingInPrerenderManager(kHtmlFileB));
EXPECT_FALSE(UrlIsPendingInPrerenderManager(kHtmlFileC));
}
diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc
index 7f89e13..aa2eb01 100644
--- a/chrome/browser/prerender/prerender_manager.cc
+++ b/chrome/browser/prerender/prerender_manager.cc
@@ -9,7 +9,6 @@
#include "base/metrics/histogram.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
-#include "chrome/browser/favicon_helper.h"
#include "chrome/browser/prerender/prerender_contents.h"
#include "chrome/browser/prerender/prerender_final_status.h"
#include "chrome/browser/profiles/profile.h"
@@ -17,8 +16,9 @@
#include "content/browser/browser_thread.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/renderer_host/render_process_host.h"
-#include "content/browser/tab_contents/tab_contents.h"
+#include "content/browser/renderer_host/resource_dispatcher_host.h"
#include "content/browser/tab_contents/render_view_host_manager.h"
+#include "content/browser/tab_contents/tab_contents.h"
#include "content/common/notification_service.h"
namespace prerender {