summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-19 20:51:37 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-19 20:51:37 +0000
commitd5184b491bb69be0fe56c0b8b519f15dc987baee (patch)
tree162f6453e3398b559e8d0e374e3c3f01582e5f9e /content
parent78ab1b6f10a49ba0cd9175eadb32fc909b771737 (diff)
downloadchromium_src-d5184b491bb69be0fe56c0b8b519f15dc987baee.zip
chromium_src-d5184b491bb69be0fe56c0b8b519f15dc987baee.tar.gz
chromium_src-d5184b491bb69be0fe56c0b8b519f15dc987baee.tar.bz2
overscroll: Add a browser-test for the aura implementation.
The test verifies that overscroll performs navigation correctly on pages with and without touch event handlers. BUG=160668 TBR=joi@chromium.org (for content_tests.gypi) Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=168547 Review URL: https://codereview.chromium.org/11414048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168600 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/web_contents/web_contents_view_aura_browsertest.cc173
-rw-r--r--content/content_tests.gypi1
-rw-r--r--content/test/data/overscroll_navigation.html64
3 files changed, 238 insertions, 0 deletions
diff --git a/content/browser/web_contents/web_contents_view_aura_browsertest.cc b/content/browser/web_contents/web_contents_view_aura_browsertest.cc
new file mode 100644
index 0000000..f38749b
--- /dev/null
+++ b/content/browser/web_contents/web_contents_view_aura_browsertest.cc
@@ -0,0 +1,173 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/web_contents/web_contents_view_aura.h"
+
+#include "base/command_line.h"
+#include "base/run_loop.h"
+#include "base/test/test_timeouts.h"
+#include "base/utf_string_conversions.h"
+#include "content/browser/renderer_host/render_view_host_impl.h"
+#include "content/browser/web_contents/web_contents_impl.h"
+#include "content/public/common/content_switches.h"
+#include "content/public/test/browser_test_utils.h"
+#include "content/public/test/test_utils.h"
+#include "content/shell/shell.h"
+#include "content/test/content_browser_test.h"
+#include "content/test/content_browser_test_utils.h"
+#include "ui/aura/root_window.h"
+#include "ui/aura/test/event_generator.h"
+#include "ui/aura/window.h"
+
+namespace content {
+
+class WebContentsViewAuraTest : public ContentBrowserTest {
+ public:
+ WebContentsViewAuraTest() {}
+
+ virtual void SetUpCommandLine(CommandLine* command_line) {
+ command_line->AppendSwitch(switches::kEnableOverscrollHistoryNavigation);
+ }
+
+ // Executes the javascript synchronously and makes sure the returned value is
+ // freed properly.
+ void ExecuteSyncJSFunction(RenderViewHost* rvh, const std::string& jscript) {
+ scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(
+ string16(), ASCIIToUTF16(jscript)));
+ }
+
+ // Starts the test server and navigates to the given url. Sets a large enough
+ // size to the root window. Returns after the navigation to the url is
+ // complete.
+ void StartTestWithPage(const std::string& url) {
+ ASSERT_TRUE(test_server()->Start());
+ GURL test_url(test_server()->GetURL(url));
+ NavigateToURL(shell(), test_url);
+ aura::Window* content = shell()->web_contents()->GetContentNativeView();
+ content->GetRootWindow()->SetHostSize(gfx::Size(800, 600));
+ }
+
+ void TestOverscrollNavigation(bool touch_handler) {
+ ASSERT_NO_FATAL_FAILURE(
+ StartTestWithPage("files/overscroll_navigation.html"));
+ WebContentsImpl* web_contents =
+ static_cast<WebContentsImpl*>(shell()->web_contents());
+ NavigationController& controller = web_contents->GetController();
+ RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>(
+ web_contents->GetRenderViewHost());
+
+ EXPECT_FALSE(controller.CanGoBack());
+ EXPECT_FALSE(controller.CanGoForward());
+ int index = -1;
+ scoped_ptr<base::Value> value;
+ value.reset(view_host->ExecuteJavascriptAndGetValue(string16(),
+ ASCIIToUTF16("get_current()")));
+ ASSERT_TRUE(value->GetAsInteger(&index));
+ EXPECT_EQ(0, index);
+
+ if (touch_handler)
+ ExecuteSyncJSFunction(view_host, "install_touch_handler()");
+
+ ExecuteSyncJSFunction(view_host, "navigate_next()");
+ ExecuteSyncJSFunction(view_host, "navigate_next()");
+ value.reset(view_host->ExecuteJavascriptAndGetValue(string16(),
+ ASCIIToUTF16("get_current()")));
+ ASSERT_TRUE(value->GetAsInteger(&index));
+ EXPECT_EQ(2, index);
+ EXPECT_TRUE(controller.CanGoBack());
+ EXPECT_FALSE(controller.CanGoForward());
+
+ aura::Window* content = web_contents->GetContentNativeView();
+ gfx::Rect bounds = content->GetBoundsInRootWindow();
+ aura::test::EventGenerator generator(content->GetRootWindow(), content);
+
+ {
+ // Do a swipe-right now. That should navigate backwards.
+ string16 expected_title = ASCIIToUTF16("Title: #1");
+ content::TitleWatcher title_watcher(web_contents, expected_title);
+ generator.GestureScrollSequence(
+ gfx::Point(bounds.x() + 2, bounds.y() + 10),
+ gfx::Point(bounds.right() - 10, bounds.y() + 10),
+ base::TimeDelta::FromMilliseconds(20),
+ 1);
+ string16 actual_title = title_watcher.WaitAndGetTitle();
+ EXPECT_EQ(expected_title, actual_title);
+ value.reset(view_host->ExecuteJavascriptAndGetValue(string16(),
+ ASCIIToUTF16("get_current()")));
+ ASSERT_TRUE(value->GetAsInteger(&index));
+ EXPECT_EQ(1, index);
+ EXPECT_TRUE(controller.CanGoBack());
+ EXPECT_TRUE(controller.CanGoForward());
+ }
+
+ {
+ // Do a fling-right now. That should navigate backwards.
+ string16 expected_title = ASCIIToUTF16("Title:");
+ content::TitleWatcher title_watcher(web_contents, expected_title);
+ generator.GestureScrollSequence(
+ gfx::Point(bounds.x() + 2, bounds.y() + 10),
+ gfx::Point(bounds.right() - 10, bounds.y() + 10),
+ base::TimeDelta::FromMilliseconds(20),
+ 10);
+ string16 actual_title = title_watcher.WaitAndGetTitle();
+ EXPECT_EQ(expected_title, actual_title);
+ value.reset(view_host->ExecuteJavascriptAndGetValue(string16(),
+ ASCIIToUTF16("get_current()")));
+ ASSERT_TRUE(value->GetAsInteger(&index));
+ EXPECT_EQ(0, index);
+ EXPECT_FALSE(controller.CanGoBack());
+ EXPECT_TRUE(controller.CanGoForward());
+ }
+
+ {
+ // Do a swipe-left now. That should navigate forward.
+ string16 expected_title = ASCIIToUTF16("Title: #1");
+ content::TitleWatcher title_watcher(web_contents, expected_title);
+ generator.GestureScrollSequence(
+ gfx::Point(bounds.right() - 10, bounds.y() + 10),
+ gfx::Point(bounds.x() + 2, bounds.y() + 10),
+ base::TimeDelta::FromMilliseconds(20),
+ 10);
+ string16 actual_title = title_watcher.WaitAndGetTitle();
+ EXPECT_EQ(expected_title, actual_title);
+ value.reset(view_host->ExecuteJavascriptAndGetValue(string16(),
+ ASCIIToUTF16("get_current()")));
+ ASSERT_TRUE(value->GetAsInteger(&index));
+ EXPECT_EQ(1, index);
+ EXPECT_TRUE(controller.CanGoBack());
+ EXPECT_TRUE(controller.CanGoForward());
+ }
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(WebContentsViewAuraTest);
+};
+
+// The tests are disabled on windows since the gesture support in win-aura isn't
+// complete yet. See http://crbug.com/157268
+#if defined(OS_WIN)
+#define MAYBE_OverscrollNavigation DISABLED_OverscrollNavigation
+#else
+#define MAYBE_OverscrollNavigation OverscrollNavigation
+#endif
+IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
+ MAYBE_OverscrollNavigation) {
+ TestOverscrollNavigation(false);
+}
+
+// The tests are disabled on windows since the gesture support in win-aura isn't
+// complete yet. See http://crbug.com/157268
+#if defined(OS_WIN)
+#define MAYBE_OverscrollNavigationWithTouchHandler \
+ DISABLED_OverscrollNavigationWithTouchHandler
+#else
+#define MAYBE_OverscrollNavigationWithTouchHandler \
+ OverscrollNavigationWithTouchHandler
+#endif
+IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
+ MAYBE_OverscrollNavigationWithTouchHandler) {
+ TestOverscrollNavigation(true);
+}
+
+} // namespace content
diff --git a/content/content_tests.gypi b/content/content_tests.gypi
index bab047e..97c3cd3 100644
--- a/content/content_tests.gypi
+++ b/content/content_tests.gypi
@@ -687,6 +687,7 @@
'browser/renderer_host/resource_dispatcher_host_browsertest.cc',
'browser/session_history_browsertest.cc',
'browser/speech/speech_recognition_browsertest.cc',
+ 'browser/web_contents/web_contents_view_aura_browsertest.cc',
'browser/webkit_browsertest.cc',
'browser/worker_host/test/worker_browsertest.cc',
'common/content_constants_internal.cc',
diff --git a/content/test/data/overscroll_navigation.html b/content/test/data/overscroll_navigation.html
new file mode 100644
index 0000000..7ea687b
--- /dev/null
+++ b/content/test/data/overscroll_navigation.html
@@ -0,0 +1,64 @@
+<html>
+<title>Title: 0</title>
+<style>
+
+.large {
+ width: 300px;
+ height: 100px;
+ background-color: red;
+ margin: 300px;
+}
+
+</style>
+
+<div name='0' class='large'></div>
+<div name='1' class='large'></div>
+<div name='2' class='large'></div>
+<div name='3' class='large'></div>
+<div name='4' class='large'></div>
+<div name='5' class='large'></div>
+<div name='6' class='large'></div>
+<div name='7' class='large'></div>
+<div name='8' class='large'></div>
+<div name='9' class='large'></div>
+
+<script>
+
+function get_current() {
+ if (location.hash.length == 0)
+ return 0;
+ return parseInt(location.hash.substr(1));
+}
+
+function navigate_next() {
+ var current = get_current();
+ current = (current + 1) % 10;
+ location.hash = "#" + current;
+}
+
+function navigate_prev() {
+ var current = get_current();
+ current = (current + 9) % 10;
+ location.hash = "#" + current;
+}
+
+function touch_start_handler() {
+}
+
+function install_touch_handler() {
+ document.addEventListener('touchstart', touch_start_handler);
+}
+
+function uninstall_touch_handler() {
+ document.removeEventListener('touchstart', touch_start_handler);
+}
+
+onload = function() {
+ window.onhashchange = function() {
+ document.title = "Title: " + location.hash;
+ }
+}
+
+</script>
+
+</html>