Commit be8b5afc authored by bgoldman's avatar bgoldman Committed by Commit bot

More Blimp browser tests for navigation

The Blimp browser tests now cover every action of NavigationFeature.

GoForward is an additional step in the existing GoBack test, rather than a new test, because you can't test GoForward without GoBack.

Also adds no-op behavior on the engine for when the client requests GoBack or GoForward but those operations aren't valid, and tests for those cases.

Tested log output for the invalid GoBack and GoForward cases with the following:
blimp_browsertests --single_process --gtest_filter=EngineBrowserTest.InvalidGoBack | grep Ignoring
blimp_browsertests --single_process --gtest_filter=EngineBrowserTest.InvalidGoForward | grep Ignoring

BUG=

Review-Url: https://codereview.chromium.org/2295543002
Cr-Commit-Position: refs/heads/master@{#415368}
parent 3c2c00cc
...@@ -28,6 +28,10 @@ namespace blimp { ...@@ -28,6 +28,10 @@ namespace blimp {
namespace { namespace {
const int kDummyTabId = 0; const int kDummyTabId = 0;
const char kPage1Path[] = "/page1.html";
const char kPage2Path[] = "/page2.html";
const char kPage1Title[] = "page1";
const char kPage2Title[] = "page2";
// Uses a headless client session to test a full engine. // Uses a headless client session to test a full engine.
class EngineBrowserTest : public BlimpBrowserTest { class EngineBrowserTest : public BlimpBrowserTest {
...@@ -110,26 +114,68 @@ class EngineBrowserTest : public BlimpBrowserTest { ...@@ -110,26 +114,68 @@ class EngineBrowserTest : public BlimpBrowserTest {
IN_PROC_BROWSER_TEST_F(EngineBrowserTest, LoadUrl) { IN_PROC_BROWSER_TEST_F(EngineBrowserTest, LoadUrl) {
EXPECT_CALL(client_rw_feature_delegate_, OnRenderWidgetCreated(1)); EXPECT_CALL(client_rw_feature_delegate_, OnRenderWidgetCreated(1));
ExpectPageLoad(); ExpectPageLoad();
NavigateToLocalUrl("/page1.html"); NavigateToLocalUrl(kPage1Path);
RunAndVerify(); RunAndVerify();
EXPECT_EQ("page1", last_page_title_); EXPECT_EQ(kPage1Title, last_page_title_);
} }
IN_PROC_BROWSER_TEST_F(EngineBrowserTest, GoBack) { IN_PROC_BROWSER_TEST_F(EngineBrowserTest, Reload) {
ExpectPageLoad(); ExpectPageLoad();
NavigateToLocalUrl("/page1.html"); NavigateToLocalUrl(kPage1Path);
RunAndVerify(); RunAndVerify();
EXPECT_EQ("page1", last_page_title_); EXPECT_EQ(kPage1Title, last_page_title_);
ExpectPageLoad(); ExpectPageLoad();
NavigateToLocalUrl("/page2.html"); client_session_->GetNavigationFeature()->Reload(kDummyTabId);
RunAndVerify(); RunAndVerify();
EXPECT_EQ("page2", last_page_title_); EXPECT_EQ(kPage1Title, last_page_title_);
}
IN_PROC_BROWSER_TEST_F(EngineBrowserTest, GoBackAndGoForward) {
ExpectPageLoad();
NavigateToLocalUrl(kPage1Path);
RunAndVerify();
EXPECT_EQ(kPage1Title, last_page_title_);
ExpectPageLoad();
NavigateToLocalUrl(kPage2Path);
RunAndVerify();
EXPECT_EQ(kPage2Title, last_page_title_);
ExpectPageLoad();
client_session_->GetNavigationFeature()->GoBack(kDummyTabId);
RunAndVerify();
EXPECT_EQ(kPage1Title, last_page_title_);
ExpectPageLoad();
client_session_->GetNavigationFeature()->GoForward(kDummyTabId);
RunAndVerify();
EXPECT_EQ(kPage2Title, last_page_title_);
}
IN_PROC_BROWSER_TEST_F(EngineBrowserTest, InvalidGoBack) {
// Try an invalid GoBack before loading a page, and assert that the page still
// loads correctly.
ExpectPageLoad(); ExpectPageLoad();
client_session_->GetNavigationFeature()->GoBack(kDummyTabId); client_session_->GetNavigationFeature()->GoBack(kDummyTabId);
NavigateToLocalUrl(kPage1Path);
RunAndVerify();
EXPECT_EQ(kPage1Title, last_page_title_);
}
IN_PROC_BROWSER_TEST_F(EngineBrowserTest, InvalidGoForward) {
ExpectPageLoad();
NavigateToLocalUrl(kPage1Path);
RunAndVerify();
EXPECT_EQ(kPage1Title, last_page_title_);
// Try an invalid GoForward before loading a different page, and
// assert that the page still loads correctly.
ExpectPageLoad();
client_session_->GetNavigationFeature()->GoForward(kDummyTabId);
NavigateToLocalUrl(kPage2Path);
RunAndVerify(); RunAndVerify();
EXPECT_EQ("page1", last_page_title_); EXPECT_EQ(kPage2Title, last_page_title_);
} }
} // namespace } // namespace
......
...@@ -75,11 +75,19 @@ void Tab::LoadUrl(const GURL& url) { ...@@ -75,11 +75,19 @@ void Tab::LoadUrl(const GURL& url) {
} }
void Tab::GoBack() { void Tab::GoBack() {
if (!web_contents_->GetController().CanGoBack()) {
DLOG(ERROR) << "Ignoring back in tab " << tab_id_;
return;
}
DVLOG(1) << "Back in tab " << tab_id_; DVLOG(1) << "Back in tab " << tab_id_;
web_contents_->GetController().GoBack(); web_contents_->GetController().GoBack();
} }
void Tab::GoForward() { void Tab::GoForward() {
if (!web_contents_->GetController().CanGoForward()) {
DLOG(ERROR) << "Ignoring forward in tab " << tab_id_;
return;
}
DVLOG(1) << "Forward in tab " << tab_id_; DVLOG(1) << "Forward in tab " << tab_id_;
web_contents_->GetController().GoForward(); web_contents_->GetController().GoForward();
} }
......
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