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

Side by Side Diff: content/browser/web_contents/web_contents_view_aura_browsertest.cc

Issue 11414048: overscroll: Add a browser-test for the aura implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: disable-test-on-win-aura Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/filename_rules.gypi ('k') | content/content_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/web_contents/web_contents_view_aura.h"
6
7 #include "base/command_line.h"
8 #include "base/run_loop.h"
9 #include "base/test/test_timeouts.h"
10 #include "base/utf_string_conversions.h"
11 #include "content/browser/renderer_host/render_view_host_impl.h"
12 #include "content/browser/web_contents/web_contents_impl.h"
13 #include "content/public/common/content_switches.h"
14 #include "content/public/test/browser_test_utils.h"
15 #include "content/public/test/test_utils.h"
16 #include "content/shell/shell.h"
17 #include "content/test/content_browser_test.h"
18 #include "content/test/content_browser_test_utils.h"
19 #include "ui/aura/root_window.h"
20 #include "ui/aura/test/event_generator.h"
21 #include "ui/aura/window.h"
22
23 namespace content {
24
25 class WebContentsViewAuraTest : public ContentBrowserTest {
26 public:
27 WebContentsViewAuraTest() {}
28
29 virtual void SetUpCommandLine(CommandLine* command_line) {
30 command_line->AppendSwitch(switches::kEnableOverscrollHistoryNavigation);
31 }
32
33 // Executes the javascript synchronously and makes sure the returned value is
34 // freed properly.
35 void ExecuteSyncJSFunction(RenderViewHost* rvh, const std::string& jscript) {
36 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(
37 string16(), ASCIIToUTF16(jscript)));
38 }
39
40 // Starts the test server and navigates to the given url. Sets a large enough
41 // size to the root window. Returns after the navigation to the url is
42 // complete.
43 void StartTestWithPage(const std::string& url) {
44 ASSERT_TRUE(test_server()->Start());
45 GURL test_url(test_server()->GetURL(url));
46 NavigateToURL(shell(), test_url);
47 aura::Window* content = shell()->web_contents()->GetContentNativeView();
48 content->GetRootWindow()->SetHostSize(gfx::Size(800, 600));
49 }
50
51 void TestOverscrollNavigation(bool touch_handler) {
52 ASSERT_NO_FATAL_FAILURE(
53 StartTestWithPage("files/overscroll_navigation.html"));
54 WebContentsImpl* web_contents =
55 static_cast<WebContentsImpl*>(shell()->web_contents());
56 NavigationController& controller = web_contents->GetController();
57 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>(
58 web_contents->GetRenderViewHost());
59
60 EXPECT_FALSE(controller.CanGoBack());
61 EXPECT_FALSE(controller.CanGoForward());
62 int index = -1;
63 scoped_ptr<base::Value> value;
64 value.reset(view_host->ExecuteJavascriptAndGetValue(string16(),
65 ASCIIToUTF16("get_current()")));
66 ASSERT_TRUE(value->GetAsInteger(&index));
67 EXPECT_EQ(0, index);
68
69 if (touch_handler)
70 ExecuteSyncJSFunction(view_host, "install_touch_handler()");
71
72 ExecuteSyncJSFunction(view_host, "navigate_next()");
73 ExecuteSyncJSFunction(view_host, "navigate_next()");
74 value.reset(view_host->ExecuteJavascriptAndGetValue(string16(),
75 ASCIIToUTF16("get_current()")));
76 ASSERT_TRUE(value->GetAsInteger(&index));
77 EXPECT_EQ(2, index);
78 EXPECT_TRUE(controller.CanGoBack());
79 EXPECT_FALSE(controller.CanGoForward());
80
81 aura::Window* content = web_contents->GetContentNativeView();
82 gfx::Rect bounds = content->GetBoundsInRootWindow();
83 aura::test::EventGenerator generator(content->GetRootWindow(), content);
84
85 {
86 // Do a swipe-right now. That should navigate backwards.
87 string16 expected_title = ASCIIToUTF16("Title: #1");
88 content::TitleWatcher title_watcher(web_contents, expected_title);
89 generator.GestureScrollSequence(
90 gfx::Point(bounds.x() + 2, bounds.y() + 10),
91 gfx::Point(bounds.right() - 10, bounds.y() + 10),
92 base::TimeDelta::FromMilliseconds(20),
93 1);
94 string16 actual_title = title_watcher.WaitAndGetTitle();
95 EXPECT_EQ(expected_title, actual_title);
96 value.reset(view_host->ExecuteJavascriptAndGetValue(string16(),
97 ASCIIToUTF16("get_current()")));
98 ASSERT_TRUE(value->GetAsInteger(&index));
99 EXPECT_EQ(1, index);
100 EXPECT_TRUE(controller.CanGoBack());
101 EXPECT_TRUE(controller.CanGoForward());
102 }
103
104 {
105 // Do a fling-right now. That should navigate backwards.
106 string16 expected_title = ASCIIToUTF16("Title:");
107 content::TitleWatcher title_watcher(web_contents, expected_title);
108 generator.GestureScrollSequence(
109 gfx::Point(bounds.x() + 2, bounds.y() + 10),
110 gfx::Point(bounds.right() - 10, bounds.y() + 10),
111 base::TimeDelta::FromMilliseconds(20),
112 10);
113 string16 actual_title = title_watcher.WaitAndGetTitle();
114 EXPECT_EQ(expected_title, actual_title);
115 value.reset(view_host->ExecuteJavascriptAndGetValue(string16(),
116 ASCIIToUTF16("get_current()")));
117 ASSERT_TRUE(value->GetAsInteger(&index));
118 EXPECT_EQ(0, index);
119 EXPECT_FALSE(controller.CanGoBack());
120 EXPECT_TRUE(controller.CanGoForward());
121 }
122
123 {
124 // Do a swipe-left now. That should navigate forward.
125 string16 expected_title = ASCIIToUTF16("Title: #1");
126 content::TitleWatcher title_watcher(web_contents, expected_title);
127 generator.GestureScrollSequence(
128 gfx::Point(bounds.right() - 10, bounds.y() + 10),
129 gfx::Point(bounds.x() + 2, bounds.y() + 10),
130 base::TimeDelta::FromMilliseconds(20),
131 10);
132 string16 actual_title = title_watcher.WaitAndGetTitle();
133 EXPECT_EQ(expected_title, actual_title);
134 value.reset(view_host->ExecuteJavascriptAndGetValue(string16(),
135 ASCIIToUTF16("get_current()")));
136 ASSERT_TRUE(value->GetAsInteger(&index));
137 EXPECT_EQ(1, index);
138 EXPECT_TRUE(controller.CanGoBack());
139 EXPECT_TRUE(controller.CanGoForward());
140 }
141 }
142
143 private:
144 DISALLOW_COPY_AND_ASSIGN(WebContentsViewAuraTest);
145 };
146
147 // The tests are disabled on windows since the gesture support in win-aura isn't
148 // complete yet. See http://crbug.com/157268
149 #if defined(OS_WIN)
150 #define MAYBE_OverscrollNavigation DISABLED_OverscrollNavigation
151 #else
152 #define MAYBE_OverscrollNavigation OverscrollNavigation
153 #endif
154 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
155 MAYBE_OverscrollNavigation) {
156 TestOverscrollNavigation(false);
157 }
158
159 // The tests are disabled on windows since the gesture support in win-aura isn't
160 // complete yet. See http://crbug.com/157268
161 #if defined(OS_WIN)
162 #define MAYBE_OverscrollNavigationWithTouchHandler \
163 DISABLED_OverscrollNavigationWithTouchHandler
164 #else
165 #define MAYBE_OverscrollNavigationWithTouchHandler \
166 OverscrollNavigationWithTouchHandler
167 #endif
168 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
169 MAYBE_OverscrollNavigationWithTouchHandler) {
170 TestOverscrollNavigation(true);
171 }
172
173 } // namespace content
OLDNEW
« no previous file with comments | « build/filename_rules.gypi ('k') | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698