summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_contents/test_tab_contents.cc
diff options
context:
space:
mode:
authorjcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-01 23:01:51 +0000
committerjcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-01 23:01:51 +0000
commit6dfdc020fa65c8ad5840ccb6c78021a578be8843 (patch)
treea1121f6713ec1be2b57f28527c41f436967905b9 /chrome/browser/tab_contents/test_tab_contents.cc
parenta9dc9130e3612bb613575c4ae210148d1fbb5157 (diff)
downloadchromium_src-6dfdc020fa65c8ad5840ccb6c78021a578be8843.zip
chromium_src-6dfdc020fa65c8ad5840ccb6c78021a578be8843.tar.gz
chromium_src-6dfdc020fa65c8ad5840ccb6c78021a578be8843.tar.bz2
Don't create pending entries when a navigation is initiated by the page.
If the page reloads while such a navigation happens, we could end up with the wrong pending entry. Also make sure TestTabContents::NavigateAndCommit() does commit on the right RVH. BUG=51680 TEST=See bug for steps. Review URL: http://codereview.chromium.org/3257002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58261 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents/test_tab_contents.cc')
-rw-r--r--chrome/browser/tab_contents/test_tab_contents.cc35
1 files changed, 31 insertions, 4 deletions
diff --git a/chrome/browser/tab_contents/test_tab_contents.cc b/chrome/browser/tab_contents/test_tab_contents.cc
index 54a6873..2c1ba39 100644
--- a/chrome/browser/tab_contents/test_tab_contents.cc
+++ b/chrome/browser/tab_contents/test_tab_contents.cc
@@ -45,7 +45,7 @@ void TestTabContents::Observe(NotificationType type,
}
}
-TestRenderViewHost* TestTabContents::pending_rvh() {
+TestRenderViewHost* TestTabContents::pending_rvh() const {
return static_cast<TestRenderViewHost*>(
render_manager_.pending_render_view_host_);
}
@@ -70,7 +70,34 @@ void TestTabContents::NavigateAndCommit(const GURL& url) {
bool reverse_on_redirect = false;
BrowserURLHandler::RewriteURLIfNecessary(
&loaded_url, profile(), &reverse_on_redirect);
- static_cast<TestRenderViewHost*>(render_view_host())->SendNavigate(
- static_cast<MockRenderProcessHost*>(render_view_host()->process())->
- max_page_id() + 1, loaded_url);
+
+ // LoadURL created a navigation entry, now simulate the RenderView sending
+ // a notification that it actually navigated.
+ CommitPendingNavigation();
+}
+
+void TestTabContents::CommitPendingNavigation() {
+ // If we are doing a cross-site navigation, this simulates the current RVH
+ // notifying that it has unloaded so the pending RVH is resumed and can
+ // navigate.
+ ProceedWithCrossSiteNavigation();
+ TestRenderViewHost* rvh = pending_rvh();
+ if (!rvh)
+ rvh = static_cast<TestRenderViewHost*>(render_manager_.current_host());
+
+ const NavigationEntry* entry = controller().pending_entry();
+ DCHECK(entry);
+ int page_id = entry->page_id();
+ if (page_id == -1) {
+ // It's a new navigation, assign a never-seen page id to it.
+ page_id =
+ static_cast<MockRenderProcessHost*>(rvh->process())->max_page_id() + 1;
+ }
+ rvh->SendNavigate(page_id, entry->url());
+}
+
+void TestTabContents::ProceedWithCrossSiteNavigation() {
+ if (!pending_rvh())
+ return;
+ render_manager_.ShouldClosePage(true, true);
}