summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-19 17:30:08 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-19 17:30:08 +0000
commit7f6af02238e5059ad42ae44dc2d01be378fd0847 (patch)
treead335ad935fe474b2015dab90178097385d902b3
parentb376a8b6f9104283e7f954b549040479664b2af1 (diff)
downloadchromium_src-7f6af02238e5059ad42ae44dc2d01be378fd0847.zip
chromium_src-7f6af02238e5059ad42ae44dc2d01be378fd0847.tar.gz
chromium_src-7f6af02238e5059ad42ae44dc2d01be378fd0847.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) Review URL: https://codereview.chromium.org/11414048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168547 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--build/filename_rules.gypi1
-rw-r--r--content/browser/web_contents/web_contents_view_aura_browsertest.cc157
-rw-r--r--content/content_tests.gypi1
-rw-r--r--content/test/data/overscroll_navigation.html64
4 files changed, 223 insertions, 0 deletions
diff --git a/build/filename_rules.gypi b/build/filename_rules.gypi
index f20a472..515adc1 100644
--- a/build/filename_rules.gypi
+++ b/build/filename_rules.gypi
@@ -78,6 +78,7 @@
}],
['<(use_aura)==0 or >(nacl_untrusted_build)==1', {
'sources/': [ ['exclude', '_aura(_unittest)?\\.(h|cc)$'],
+ ['exclude', '_aura(_browsertest)?\\.(h|cc)$'],
['exclude', '(^|/)aura/'],
]
}],
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..ed42158
--- /dev/null
+++ b/content/browser/web_contents/web_contents_view_aura_browsertest.cc
@@ -0,0 +1,157 @@
+// 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);
+};
+
+IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
+ OverscrollNavigation) {
+ TestOverscrollNavigation(false);
+}
+
+IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
+ 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>