Skip to content

Commit

Permalink
Convert TestNavigationObserver to use the new navigation callbacks.
Browse files Browse the repository at this point in the history
BUG=682002

Review-Url: https://codereview.chromium.org/2650033008
Cr-Commit-Position: refs/heads/master@{#446353}
  • Loading branch information
jam authored and Commit bot committed Jan 26, 2017
1 parent 23eb09c commit 5c162d7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 59 deletions.
5 changes: 2 additions & 3 deletions content/browser/site_per_process_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2275,13 +2275,12 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, ProcessTransferAfterError) {
GURL url_a = child->current_url();

// Disable host resolution in the test server and try to navigate the subframe
// cross-site, which will lead to a committed net error (which looks like
// success to the TestNavigationObserver).
// cross-site, which will lead to a committed net error.
GURL url_b = embedded_test_server()->GetURL("b.com", "/title3.html");
host_resolver()->ClearRules();
TestNavigationObserver observer(shell()->web_contents());
NavigateIframeToURL(shell()->web_contents(), "child-0", url_b);
EXPECT_TRUE(observer.last_navigation_succeeded());
EXPECT_FALSE(observer.last_navigation_succeeded());
EXPECT_EQ(url_b, observer.last_navigation_url());
EXPECT_EQ(2, shell()->web_contents()->GetController().GetEntryCount());

Expand Down
57 changes: 15 additions & 42 deletions content/public/test/test_navigation_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
#include "content/public/test/test_navigation_observer.h"

#include "base/bind.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/web_contents_observer.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace content {

Expand Down Expand Up @@ -47,29 +44,19 @@ class TestNavigationObserver::TestWebContentsObserver
parent_->OnDidStopLoading(web_contents());
}

void DidStartProvisionalLoadForFrame(RenderFrameHost* render_frame_host,
const GURL& validated_url,
bool is_error_page) override {
parent_->OnDidStartProvisionalLoad(render_frame_host, validated_url,
is_error_page);
}
void DidStartNavigation(NavigationHandle* navigation_handle) override {
if (navigation_handle->IsSamePage())
return;

void DidFailProvisionalLoad(
RenderFrameHost* render_frame_host,
const GURL& validated_url,
int error_code,
const base::string16& error_description,
bool was_ignored_by_handler) override {
parent_->OnDidFailProvisionalLoad(render_frame_host, validated_url,
error_code, error_description);
parent_->OnDidStartNavigation();
}

void DidCommitProvisionalLoadForFrame(
RenderFrameHost* render_frame_host,
const GURL& url,
ui::PageTransition transition_type) override {
parent_->OnDidCommitProvisionalLoadForFrame(
render_frame_host, url, transition_type);
void DidFinishNavigation(NavigationHandle* navigation_handle) override {
if (!navigation_handle->HasCommitted())
return;

parent_->OnDidFinishNavigation(navigation_handle->IsErrorPage(),
navigation_handle->GetURL());
}

TestNavigationObserver* parent_;
Expand Down Expand Up @@ -163,28 +150,14 @@ void TestNavigationObserver::OnDidStopLoading(WebContents* web_contents) {
}
}

void TestNavigationObserver::OnDidStartProvisionalLoad(
RenderFrameHost* render_frame_host,
const GURL& validated_url,
bool is_error_page) {
last_navigation_succeeded_ = false;
}

void TestNavigationObserver::OnDidFailProvisionalLoad(
RenderFrameHost* render_frame_host,
const GURL& validated_url,
int error_code,
const base::string16& error_description) {
last_navigation_url_ = validated_url;
void TestNavigationObserver::OnDidStartNavigation() {
last_navigation_succeeded_ = false;
}

void TestNavigationObserver::OnDidCommitProvisionalLoadForFrame(
RenderFrameHost* render_frame_host,
const GURL& url,
ui::PageTransition transition_type) {
void TestNavigationObserver::OnDidFinishNavigation(bool is_error_page,
const GURL& url) {
last_navigation_url_ = url;
last_navigation_succeeded_ = true;
last_navigation_succeeded_ = !is_error_page;
}

} // namespace content
16 changes: 2 additions & 14 deletions content/public/test/test_navigation_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@
#include <set>

#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "content/public/test/test_utils.h"
#include "ui/base/page_transition_types.h"
#include "url/gurl.h"

namespace content {
class RenderFrameHost;
class WebContents;
struct LoadCommittedDetails;

// For browser_tests, which run on the UI thread, run a second
// MessageLoop and quit when the navigation completes loading.
Expand Down Expand Up @@ -67,16 +63,8 @@ class TestNavigationObserver {
void OnDidAttachInterstitialPage(WebContents* web_contents);
void OnDidStartLoading(WebContents* web_contents);
void OnDidStopLoading(WebContents* web_contents);
void OnDidStartProvisionalLoad(RenderFrameHost* render_frame_host,
const GURL& validated_url,
bool is_error_page);
void OnDidFailProvisionalLoad(RenderFrameHost* render_frame_host,
const GURL& validated_url,
int error_code,
const base::string16& error_description);
void OnDidCommitProvisionalLoadForFrame(RenderFrameHost* render_frame_host,
const GURL& url,
ui::PageTransition transition_type);
void OnDidStartNavigation();
void OnDidFinishNavigation(bool is_error_page, const GURL& url);

// If true the navigation has started.
bool navigation_started_;
Expand Down

0 comments on commit 5c162d7

Please sign in to comment.