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

Unified Diff: content/public/test/test_renderer_host.cc

Issue 2296483002: Fix some unit_tests under PlzNavigate (Closed)
Patch Set: . Created 4 years, 4 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: content/public/test/test_renderer_host.cc
diff --git a/content/public/test/test_renderer_host.cc b/content/public/test/test_renderer_host.cc
index d385871bbf9ea30a84975834abc2050cec70f82a..73780a15e06fb86d521351f4f4fe0a99c7f25e0c 100644
--- a/content/public/test/test_renderer_host.cc
+++ b/content/public/test/test_renderer_host.cc
@@ -16,9 +16,9 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/browser_side_navigation_policy.h"
+#include "content/public/test/browser_side_navigation_test_utils.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_browser_context.h"
-#include "content/test/browser_side_navigation_test_utils.h"
#include "content/test/content_browser_sanity_checker.h"
#include "content/test/test_render_frame_host.h"
#include "content/test/test_render_frame_host_factory.h"
@@ -56,11 +56,51 @@ RenderFrameHostTester* RenderFrameHostTester::For(RenderFrameHost* host) {
}
// static
-RenderFrameHost* RenderFrameHostTester::GetPendingForController(
+void RenderFrameHostTester::CommitPendingLoad(
NavigationController* controller) {
- WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
- controller->GetWebContents());
- return web_contents->GetRenderManagerForTesting()->pending_frame_host();
+ // This function is currently used by BrowserWithTestWindowTest. It would be
+ // ideal to instead make the users of that class use TestWebContents (rather
+ // than WebContentsImpl directly) so that PrepareForCommitIfNecessary() could
+ // live in TestWebContents::CommitPendingNavigation() and could be used, so
+ // that only one place would handle this simulation. Unfortunately, it is not
+ // trivial to do so, so for now we have this extra simulation for
nasko 2016/08/31 19:45:24 nit: maybe drop one of the "so" in the "so, so" :
scottmg 2016/08/31 20:10:36 Replaced with "this, this". ;) (Rewrote it a bit
+ // non-TestWebContents.
+ RenderFrameHost* old_rfh = controller->GetWebContents()->GetMainFrame();
+ RenderFrameHostTester* old_rfh_tester = For(old_rfh);
+ old_rfh_tester->PrepareForCommitIfNecessary();
+
+ WebContentsImpl* web_contents =
+ static_cast<WebContentsImpl*>(controller->GetWebContents());
+ RenderFrameHost* pending_rfh =
+ IsBrowserSideNavigationEnabled()
+ ? web_contents->GetRenderManagerForTesting()
+ ->speculative_render_frame_host_.get()
+ : web_contents->GetRenderManagerForTesting()->pending_frame_host();
+
+ // Commit on the pending_rfh, if one exists.
+ RenderFrameHost* test_rfh = pending_rfh ? pending_rfh : old_rfh;
+ RenderFrameHostTester* test_rfh_tester = For(test_rfh);
+
+ // For new navigations, we need to send a larger page ID. For renavigations,
+ // we need to send the preexisting page ID. We can tell these apart because
+ // renavigations will have a pending_entry_index while new ones won't (they'll
+ // just have a standalong pending_entry that isn't in the list already).
+ if (controller->GetPendingEntryIndex() >= 0) {
+ test_rfh_tester->SendNavigateWithTransition(
+ controller->GetPendingEntry()->GetPageID(),
+ controller->GetPendingEntry()->GetUniqueID(),
+ false,
+ controller->GetPendingEntry()->GetURL(),
+ controller->GetPendingEntry()->GetTransitionType());
+ } else {
+ test_rfh_tester->SendNavigateWithTransition(
+ controller->GetWebContents()->GetMaxPageIDForSiteInstance(
+ test_rfh->GetSiteInstance()) + 1,
+ controller->GetPendingEntry()->GetUniqueID(),
+ true,
+ controller->GetPendingEntry()->GetURL(),
+ controller->GetPendingEntry()->GetTransitionType());
+ }
}
// RenderViewHostTester -------------------------------------------------------

Powered by Google App Engine
This is Rietveld 408576698