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

Unified Diff: components/web_view/web_view_apptest.cc

Issue 1326443006: mandoline: Add back/forward support and UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits and such. Created 5 years, 3 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
« no previous file with comments | « components/web_view/url_request_cloneable.cc ('k') | components/web_view/web_view_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/web_view/web_view_apptest.cc
diff --git a/components/web_view/web_view_apptest.cc b/components/web_view/web_view_apptest.cc
index 228653979cf81e7c8876d42ff08c409a24a2807f..0fffd4cc310f97be5508b1f85fdde7707ab844b3 100644
--- a/components/web_view/web_view_apptest.cc
+++ b/components/web_view/web_view_apptest.cc
@@ -19,6 +19,15 @@
namespace web_view {
+namespace {
+const char kTestOneFile[] = "test_one.html";
+const char kTestOneTitle[] = "Test Title One";
+const char kTestTwoFile[] = "test_two.html";
+const char kTestTwoTitle[] = "Test Title Two";
+const char kTestThreeFile[] = "test_three.html";
+const char kTestThreeTitle[] = "Test Title Three";
+}
+
class WebViewTest : public mojo::ViewManagerTestBase,
public mojom::WebViewClient {
public:
@@ -28,12 +37,30 @@ class WebViewTest : public mojo::ViewManagerTestBase,
mojom::WebView* web_view() { return web_view_.web_view(); }
const std::string& last_title() { return last_title_; }
+ mojom::ButtonState last_back_button_state() {
+ return last_back_button_state_;
+ }
+ mojom::ButtonState last_forward_button_state() {
+ return last_forward_button_state_;
+ }
void StartNestedRunLoopUntilLoadingDone() {
run_loop_.reset(new base::RunLoop);
run_loop_->Run();
}
+ void NavigateTo(const std::string& file) {
+ base::FilePath data_file;
+ ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &data_file));
+ data_file = data_file.AppendASCII("components/test/data/web_view")
+ .AppendASCII(file).NormalizePathSeparators();
+ ASSERT_TRUE(base::PathExists(data_file));
+ mojo::URLRequestPtr request(mojo::URLRequest::New());
+ request->url = mojo::util::FilePathToFileURL(data_file).spec();
+ web_view()->LoadRequest(request.Pass());
+ StartNestedRunLoopUntilLoadingDone();
+ }
+
private:
void QuitNestedRunLoop() {
if (run_loop_) {
@@ -70,6 +97,11 @@ class WebViewTest : public mojo::ViewManagerTestBase,
QuitNestedRunLoop();
}
void ProgressChanged(double progress) override {}
+ void BackForwardChanged(mojom::ButtonState back_button,
+ mojom::ButtonState forward_button) override {
+ last_back_button_state_ = back_button;
+ last_forward_button_state_ = forward_button;
+ }
void TitleChanged(const mojo::String& title) override {
last_title_ = title.get();
}
@@ -83,29 +115,76 @@ class WebViewTest : public mojo::ViewManagerTestBase,
scoped_ptr<base::RunLoop> run_loop_;
std::string last_title_;
+ mojom::ButtonState last_back_button_state_;
+ mojom::ButtonState last_forward_button_state_;
DISALLOW_COPY_AND_ASSIGN(WebViewTest);
};
TEST_F(WebViewTest, TestTitleChanged) {
- base::FilePath data_file;
- ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &data_file));
- data_file = data_file.AppendASCII("components").
- AppendASCII("test").
- AppendASCII("data").
- AppendASCII("web_view").
- AppendASCII("test_title_changed.html");
- ASSERT_TRUE(base::PathExists(data_file));
-
- mojo::URLRequestPtr request(mojo::URLRequest::New());
- request->url = mojo::util::FilePathToFileURL(data_file).spec();
- web_view()->LoadRequest(request.Pass());
-
- // Build a nested run loop.
+ ASSERT_NO_FATAL_FAILURE(NavigateTo(kTestOneFile));
+
+ // Our title should have been set on the navigation.
+ EXPECT_EQ(kTestOneTitle, last_title());
+}
+
+TEST_F(WebViewTest, CanGoBackAndForward) {
+ ASSERT_NO_FATAL_FAILURE(NavigateTo(kTestOneFile));
+
+ // We can't go back on first navigation since there's nothing previously on
+ // the stack.
+ EXPECT_EQ(kTestOneTitle, last_title());
+ EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED,
+ last_back_button_state());
+ EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED,
+ last_forward_button_state());
+
+ ASSERT_NO_FATAL_FAILURE(NavigateTo(kTestTwoFile));
+
+ EXPECT_EQ(kTestTwoTitle, last_title());
+ EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_ENABLED, last_back_button_state());
+ EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED,
+ last_forward_button_state());
+
+ web_view()->GoBack();
+ StartNestedRunLoopUntilLoadingDone();
+
+ EXPECT_EQ(kTestOneTitle, last_title());
+ EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED,
+ last_back_button_state());
+ EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_ENABLED,
+ last_forward_button_state());
+
+ web_view()->GoForward();
StartNestedRunLoopUntilLoadingDone();
+ EXPECT_EQ(kTestTwoTitle, last_title());
+ EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_ENABLED, last_back_button_state());
+ EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED,
+ last_forward_button_state());
+}
+
+TEST_F(WebViewTest, NavigationClearsForward) {
+ // First navigate somewhere, navigate somewhere else, and go back so we have
+ // one item in the forward stack.
+ ASSERT_NO_FATAL_FAILURE(NavigateTo(kTestOneFile));
+ ASSERT_NO_FATAL_FAILURE(NavigateTo(kTestTwoFile));
+
+ web_view()->GoBack();
+ StartNestedRunLoopUntilLoadingDone();
+
+ EXPECT_EQ(kTestOneTitle, last_title());
+ EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED,
+ last_back_button_state());
+ EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_ENABLED,
+ last_forward_button_state());
+
+ // Now navigate to a third file. This should clear the forward stack.
+ ASSERT_NO_FATAL_FAILURE(NavigateTo(kTestThreeFile));
- // Our title should have been set on the final.
- EXPECT_EQ("Test Title Changed", last_title());
+ EXPECT_EQ(kTestThreeTitle, last_title());
+ EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_ENABLED, last_back_button_state());
+ EXPECT_EQ(mojom::ButtonState::BUTTON_STATE_DISABLED,
+ last_forward_button_state());
}
} // namespace web_view
« no previous file with comments | « components/web_view/url_request_cloneable.cc ('k') | components/web_view/web_view_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698