Commit fa75cdc3 authored by Lukasz Anforowicz's avatar Lukasz Anforowicz Committed by Commit Bot

Move NavigateToURLFromRenderer to .../public/test/browser_test_utils.h

A comment in //content/public/test/content_browser_test_utils.h says: if
a function here also works with browser_tests, it should be in
content/public/test/browser_test_utils.h.  The NavigateToURLFromRenderer
functions only depend on //contnet/public types and therefore this CL
moves them to browser_test_utils.h.

Bug: 1148049
Change-Id: I5746e85e1478ffd8cbb6ed35111dbec74230ee86
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2533198
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Auto-Submit: Łukasz Anforowicz <lukasza@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827113}
parent 199523d4
...@@ -81,6 +81,7 @@ ...@@ -81,6 +81,7 @@
#include "content/public/test/no_renderer_crashes_assertion.h" #include "content/public/test/no_renderer_crashes_assertion.h"
#include "content/public/test/simple_url_loader_test_helper.h" #include "content/public/test/simple_url_loader_test_helper.h"
#include "content/public/test/test_fileapi_operation_waiter.h" #include "content/public/test/test_fileapi_operation_waiter.h"
#include "content/public/test/test_frame_navigation_observer.h"
#include "content/public/test/test_launcher.h" #include "content/public/test/test_launcher.h"
#include "content/public/test/test_navigation_observer.h" #include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
...@@ -587,6 +588,36 @@ bool NavigateToURL(WebContents* web_contents, ...@@ -587,6 +588,36 @@ bool NavigateToURL(WebContents* web_contents,
return is_same_url; return is_same_url;
} }
bool NavigateToURLFromRenderer(const ToRenderFrameHost& adapter,
const GURL& url) {
return NavigateToURLFromRenderer(adapter, url, url);
}
bool NavigateToURLFromRenderer(const ToRenderFrameHost& adapter,
const GURL& url,
const GURL& expected_commit_url) {
RenderFrameHost* rfh = adapter.render_frame_host();
TestFrameNavigationObserver nav_observer(rfh);
if (!ExecJs(rfh, JsReplace("location = $1", url)))
return false;
nav_observer.Wait();
return nav_observer.last_committed_url() == expected_commit_url &&
nav_observer.last_navigation_succeeded();
}
bool NavigateToURLFromRendererWithoutUserGesture(
const ToRenderFrameHost& adapter,
const GURL& url) {
RenderFrameHost* rfh = adapter.render_frame_host();
TestFrameNavigationObserver nav_observer(rfh);
if (!ExecJs(rfh, JsReplace("location = $1", url),
EXECUTE_SCRIPT_NO_USER_GESTURE)) {
return false;
}
nav_observer.Wait();
return nav_observer.last_committed_url() == url;
}
bool NavigateIframeToURL(WebContents* web_contents, bool NavigateIframeToURL(WebContents* web_contents,
const std::string& iframe_id, const std::string& iframe_id,
const GURL& url) { const GURL& url) {
......
...@@ -114,6 +114,7 @@ class RenderFrameProxyHost; ...@@ -114,6 +114,7 @@ class RenderFrameProxyHost;
class RenderWidgetHost; class RenderWidgetHost;
class RenderWidgetHostView; class RenderWidgetHostView;
class ScopedAllowRendererCrashes; class ScopedAllowRendererCrashes;
class ToRenderFrameHost;
class WebContents; class WebContents;
// Navigates |web_contents| to |url|, blocking until the navigation finishes. // Navigates |web_contents| to |url|, blocking until the navigation finishes.
...@@ -138,6 +139,24 @@ void NavigateToURLBlockUntilNavigationsComplete(WebContents* web_contents, ...@@ -138,6 +139,24 @@ void NavigateToURLBlockUntilNavigationsComplete(WebContents* web_contents,
const GURL& url, const GURL& url,
int number_of_navigations); int number_of_navigations);
// Perform a renderer-initiated navigation of |window| to |url|, blocking
// until the navigation finishes. The navigation is done by assigning
// location.href in the frame |adapter|. Returns true if the page was loaded
// successfully and the last committed URL matches |url|.
WARN_UNUSED_RESULT bool NavigateToURLFromRenderer(
const ToRenderFrameHost& adapter,
const GURL& url);
// Similar to above but takes in an additional URL, |expected_commit_url|, to
// which the navigation should eventually commit. (See the browser-initiated
// counterpart for more details).
WARN_UNUSED_RESULT bool NavigateToURLFromRenderer(
const ToRenderFrameHost& adapter,
const GURL& url,
const GURL& expected_commit_url);
WARN_UNUSED_RESULT bool NavigateToURLFromRendererWithoutUserGesture(
const ToRenderFrameHost& adapter,
const GURL& url);
// Navigate a frame with ID |iframe_id| to |url|, blocking until the navigation // Navigate a frame with ID |iframe_id| to |url|, blocking until the navigation
// finishes. Uses a renderer-initiated navigation from script code in the // finishes. Uses a renderer-initiated navigation from script code in the
// main frame. // main frame.
......
...@@ -92,36 +92,6 @@ bool NavigateToURL(Shell* window, ...@@ -92,36 +92,6 @@ bool NavigateToURL(Shell* window,
return NavigateToURL(window->web_contents(), url, expected_commit_url); return NavigateToURL(window->web_contents(), url, expected_commit_url);
} }
bool NavigateToURLFromRenderer(const ToRenderFrameHost& adapter,
const GURL& url) {
return NavigateToURLFromRenderer(adapter, url, url);
}
bool NavigateToURLFromRenderer(const ToRenderFrameHost& adapter,
const GURL& url,
const GURL& expected_commit_url) {
RenderFrameHost* rfh = adapter.render_frame_host();
TestFrameNavigationObserver nav_observer(rfh);
if (!ExecJs(rfh, JsReplace("location = $1", url)))
return false;
nav_observer.Wait();
return nav_observer.last_committed_url() == expected_commit_url &&
nav_observer.last_navigation_succeeded();
}
bool NavigateToURLFromRendererWithoutUserGesture(
const ToRenderFrameHost& adapter,
const GURL& url) {
RenderFrameHost* rfh = adapter.render_frame_host();
TestFrameNavigationObserver nav_observer(rfh);
if (!ExecJs(rfh, JsReplace("location = $1", url),
EXECUTE_SCRIPT_NO_USER_GESTURE)) {
return false;
}
nav_observer.Wait();
return nav_observer.last_committed_url() == url;
}
bool NavigateToURLAndExpectNoCommit(Shell* window, const GURL& url) { bool NavigateToURLAndExpectNoCommit(Shell* window, const GURL& url) {
NavigationEntry* old_entry = NavigationEntry* old_entry =
window->web_contents()->GetController().GetLastCommittedEntry(); window->web_contents()->GetController().GetLastCommittedEntry();
......
...@@ -86,24 +86,6 @@ WARN_UNUSED_RESULT bool NavigateToURL(Shell* window, ...@@ -86,24 +86,6 @@ WARN_UNUSED_RESULT bool NavigateToURL(Shell* window,
const GURL& url, const GURL& url,
const GURL& expected_commit_url); const GURL& expected_commit_url);
// Perform a renderer-initiated navigation of |window| to |url|, blocking
// until the navigation finishes. The navigation is done by assigning
// location.href in the frame |adapter|. Returns true if the page was loaded
// successfully and the last committed URL matches |url|.
WARN_UNUSED_RESULT bool NavigateToURLFromRenderer(
const ToRenderFrameHost& adapter,
const GURL& url);
// Similar to above but takes in an additional URL, |expected_commit_url|, to
// which the navigation should eventually commit. (See the browser-initiated
// counterpart for more details).
WARN_UNUSED_RESULT bool NavigateToURLFromRenderer(
const ToRenderFrameHost& adapter,
const GURL& url,
const GURL& expected_commit_url);
WARN_UNUSED_RESULT bool NavigateToURLFromRendererWithoutUserGesture(
const ToRenderFrameHost& adapter,
const GURL& url);
// Navigates |window| to |url|, blocking until the given number of navigations // Navigates |window| to |url|, blocking until the given number of navigations
// finishes. // finishes.
void NavigateToURLBlockUntilNavigationsComplete(Shell* window, void NavigateToURLBlockUntilNavigationsComplete(Shell* window,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment