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

Side by Side Diff: content/public/test/browser_test_utils.cc

Issue 330113002: Fixing flaky overscroll and touch exploration mode browser tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup Created 6 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/public/test/browser_test_utils.h" 5 #include "content/public/test/browser_test_utils.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/process/kill.h" 10 #include "base/process/kill.h"
(...skipping 16 matching lines...) Expand all
27 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
28 #include "content/public/browser/web_contents_observer.h" 28 #include "content/public/browser/web_contents_observer.h"
29 #include "content/public/test/test_utils.h" 29 #include "content/public/test/test_utils.h"
30 #include "grit/webui_resources.h" 30 #include "grit/webui_resources.h"
31 #include "net/base/filename_util.h" 31 #include "net/base/filename_util.h"
32 #include "net/cookies/cookie_store.h" 32 #include "net/cookies/cookie_store.h"
33 #include "net/test/python_utils.h" 33 #include "net/test/python_utils.h"
34 #include "net/url_request/url_request_context.h" 34 #include "net/url_request/url_request_context.h"
35 #include "net/url_request/url_request_context_getter.h" 35 #include "net/url_request/url_request_context_getter.h"
36 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
37 #include "ui/aura/window.h"
37 #include "ui/base/resource/resource_bundle.h" 38 #include "ui/base/resource/resource_bundle.h"
39 #include "ui/compositor/test/draw_waiter_for_test.h"
38 #include "ui/events/gestures/gesture_configuration.h" 40 #include "ui/events/gestures/gesture_configuration.h"
39 #include "ui/events/keycodes/dom4/keycode_converter.h" 41 #include "ui/events/keycodes/dom4/keycode_converter.h"
40 42
41 namespace content { 43 namespace content {
42 namespace { 44 namespace {
43 45
44 class DOMOperationObserver : public NotificationObserver, 46 class DOMOperationObserver : public NotificationObserver,
45 public WebContentsObserver { 47 public WebContentsObserver {
46 public: 48 public:
47 explicit DOMOperationObserver(RenderViewHost* rvh) 49 explicit DOMOperationObserver(RenderViewHost* rvh)
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 GURL url = net::FilePathToFileURL(path); 198 GURL url = net::FilePathToFileURL(path);
197 if (!query_string.empty()) { 199 if (!query_string.empty()) {
198 GURL::Replacements replacements; 200 GURL::Replacements replacements;
199 replacements.SetQueryStr(query_string); 201 replacements.SetQueryStr(query_string);
200 return url.ReplaceComponents(replacements); 202 return url.ReplaceComponents(replacements);
201 } 203 }
202 return url; 204 return url;
203 } 205 }
204 206
205 void WaitForLoadStop(WebContents* web_contents) { 207 void WaitForLoadStop(WebContents* web_contents) {
206 WindowedNotificationObserver load_stop_observer(
207 NOTIFICATION_LOAD_STOP,
208 Source<NavigationController>(&web_contents->GetController()));
209 // In many cases, the load may have finished before we get here. Only wait if 208 // In many cases, the load may have finished before we get here. Only wait if
210 // the tab still has a pending navigation. 209 // the tab still has a pending navigation.
211 if (!web_contents->IsLoading()) 210 if (web_contents->IsLoading()) {
212 return; 211 WindowedNotificationObserver load_stop_observer(
213 load_stop_observer.Wait(); 212 NOTIFICATION_LOAD_STOP,
213 Source<NavigationController>(&web_contents->GetController()));
214 load_stop_observer.Wait();
215 }
216 // If this is the very first navigation, the RenderView for WebContents
217 // will be created as a result. The creation involves sending a resize
218 // message to the renderer process. Here we wait for the resize ack to be
219 // received, since tests may not expect to end up in a "waiting for resize"
220 // state after the first navigation.
221 // E.g. currently WindowEventDispatcher has code to hold touch and mouse
222 // move events until resize is complete (crbug.com/384342)
223 WaitForResizeComplete(web_contents);
mfomitchev 2014/06/13 15:56:21 I wonder if we should make it so that this is done
214 } 224 }
215 225
216 void CrashTab(WebContents* web_contents) { 226 void CrashTab(WebContents* web_contents) {
217 RenderProcessHost* rph = web_contents->GetRenderProcessHost(); 227 RenderProcessHost* rph = web_contents->GetRenderProcessHost();
218 RenderProcessHostWatcher watcher( 228 RenderProcessHostWatcher watcher(
219 rph, RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); 229 rph, RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
220 base::KillProcess(rph->GetHandle(), 0, false); 230 base::KillProcess(rph->GetHandle(), 0, false);
221 watcher.Wait(); 231 watcher.Wait();
222 } 232 }
223 233
234 bool IsResizeComplete(RenderWidgetHostImpl* widget_host) {
235 return !widget_host->IsResizeAckPendingForTesting();
236 }
237
238 void WaitForResizeComplete(WebContents* web_contents) {
239 aura::Window* content = web_contents->GetContentNativeView();
240 if (content) {
241 RenderWidgetHostImpl* widget_host =
242 RenderWidgetHostImpl::From(web_contents->GetRenderViewHost());
243 if (!IsResizeComplete(widget_host)) {
244 WindowedNotificationObserver resize_observer(
245 NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE,
246 base::Bind(IsResizeComplete, widget_host));
247 resize_observer.Wait();
248 }
249 }
250 }
251
224 void SimulateMouseClick(WebContents* web_contents, 252 void SimulateMouseClick(WebContents* web_contents,
225 int modifiers, 253 int modifiers,
226 blink::WebMouseEvent::Button button) { 254 blink::WebMouseEvent::Button button) {
227 int x = web_contents->GetContainerBounds().width() / 2; 255 int x = web_contents->GetContainerBounds().width() / 2;
228 int y = web_contents->GetContainerBounds().height() / 2; 256 int y = web_contents->GetContainerBounds().height() / 2;
229 SimulateMouseClickAt(web_contents, modifiers, button, gfx::Point(x, y)); 257 SimulateMouseClickAt(web_contents, modifiers, button, gfx::Point(x, y));
230 } 258 }
231 259
232 void SimulateMouseClickAt(WebContents* web_contents, 260 void SimulateMouseClickAt(WebContents* web_contents,
233 int modifiers, 261 int modifiers,
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 } 721 }
694 // The queue should not be empty, unless we were quit because of a timeout. 722 // The queue should not be empty, unless we were quit because of a timeout.
695 if (message_queue_.empty()) 723 if (message_queue_.empty())
696 return false; 724 return false;
697 *message = message_queue_.front(); 725 *message = message_queue_.front();
698 message_queue_.pop(); 726 message_queue_.pop();
699 return true; 727 return true;
700 } 728 }
701 729
702 } // namespace content 730 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698