Chromium Code Reviews| Index: content/browser/web_contents/web_contents_view_aura_browsertest.cc |
| 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 0000000000000000000000000000000000000000..7936a131c2c22144bf6c5a6e3d0435efe5d599d4 |
| --- /dev/null |
| +++ b/content/browser/web_contents/web_contents_view_aura_browsertest.cc |
| @@ -0,0 +1,156 @@ |
| +// 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) { |
| + StartTestWithPage("files/overscroll_navigation.html"); |
|
sky
2012/11/19 17:14:35
Sine StartTestWithPage may assert you need to wrap
sadrul
2012/11/19 17:22:00
Nice! Didn't know about this. Thanks!
|
| + 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 |