OLD | NEW |
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 17 matching lines...) Expand all Loading... |
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/base/resource/resource_bundle.h" | 37 #include "ui/base/resource/resource_bundle.h" |
| 38 #include "ui/compositor/test/draw_waiter_for_test.h" |
38 #include "ui/events/gestures/gesture_configuration.h" | 39 #include "ui/events/gestures/gesture_configuration.h" |
39 #include "ui/events/keycodes/dom4/keycode_converter.h" | 40 #include "ui/events/keycodes/dom4/keycode_converter.h" |
40 | 41 |
| 42 #if defined(USE_AURA) |
| 43 #include "ui/aura/test/window_event_dispatcher_test_api.h" |
| 44 #include "ui/aura/window.h" |
| 45 #include "ui/aura/window_event_dispatcher.h" |
| 46 #include "ui/aura/window_tree_host.h" |
| 47 #endif // USE_AURA |
| 48 |
41 namespace content { | 49 namespace content { |
42 namespace { | 50 namespace { |
43 | 51 |
44 class DOMOperationObserver : public NotificationObserver, | 52 class DOMOperationObserver : public NotificationObserver, |
45 public WebContentsObserver { | 53 public WebContentsObserver { |
46 public: | 54 public: |
47 explicit DOMOperationObserver(RenderViewHost* rvh) | 55 explicit DOMOperationObserver(RenderViewHost* rvh) |
48 : WebContentsObserver(WebContents::FromRenderViewHost(rvh)), | 56 : WebContentsObserver(WebContents::FromRenderViewHost(rvh)), |
49 did_respond_(false) { | 57 did_respond_(false) { |
50 registrar_.Add(this, NOTIFICATION_DOM_OPERATION_RESPONSE, | 58 registrar_.Add(this, NOTIFICATION_DOM_OPERATION_RESPONSE, |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 GURL url = net::FilePathToFileURL(path); | 204 GURL url = net::FilePathToFileURL(path); |
197 if (!query_string.empty()) { | 205 if (!query_string.empty()) { |
198 GURL::Replacements replacements; | 206 GURL::Replacements replacements; |
199 replacements.SetQueryStr(query_string); | 207 replacements.SetQueryStr(query_string); |
200 return url.ReplaceComponents(replacements); | 208 return url.ReplaceComponents(replacements); |
201 } | 209 } |
202 return url; | 210 return url; |
203 } | 211 } |
204 | 212 |
205 void WaitForLoadStop(WebContents* web_contents) { | 213 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 | 214 // In many cases, the load may have finished before we get here. Only wait if |
210 // the tab still has a pending navigation. | 215 // the tab still has a pending navigation. |
211 if (!web_contents->IsLoading()) | 216 if (web_contents->IsLoading()) { |
212 return; | 217 WindowedNotificationObserver load_stop_observer( |
213 load_stop_observer.Wait(); | 218 NOTIFICATION_LOAD_STOP, |
| 219 Source<NavigationController>(&web_contents->GetController())); |
| 220 load_stop_observer.Wait(); |
| 221 } |
214 } | 222 } |
215 | 223 |
216 void CrashTab(WebContents* web_contents) { | 224 void CrashTab(WebContents* web_contents) { |
217 RenderProcessHost* rph = web_contents->GetRenderProcessHost(); | 225 RenderProcessHost* rph = web_contents->GetRenderProcessHost(); |
218 RenderProcessHostWatcher watcher( | 226 RenderProcessHostWatcher watcher( |
219 rph, RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | 227 rph, RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
220 base::KillProcess(rph->GetHandle(), 0, false); | 228 base::KillProcess(rph->GetHandle(), 0, false); |
221 watcher.Wait(); | 229 watcher.Wait(); |
222 } | 230 } |
223 | 231 |
| 232 #if defined(USE_AURA) |
| 233 bool IsResizeComplete(aura::test::WindowEventDispatcherTestApi* dispatcher_test, |
| 234 RenderWidgetHostImpl* widget_host) { |
| 235 return !dispatcher_test->HoldingPointerMoves() && |
| 236 !widget_host->resize_ack_pending_for_testing(); |
| 237 } |
| 238 |
| 239 void WaitForResizeComplete(WebContents* web_contents) { |
| 240 aura::Window* content = web_contents->GetContentNativeView(); |
| 241 if (!content) |
| 242 return; |
| 243 |
| 244 aura::WindowTreeHost* window_host = content->GetHost(); |
| 245 aura::WindowEventDispatcher* dispatcher = window_host->dispatcher(); |
| 246 aura::test::WindowEventDispatcherTestApi dispatcher_test(dispatcher); |
| 247 RenderWidgetHostImpl* widget_host = |
| 248 RenderWidgetHostImpl::From(web_contents->GetRenderViewHost()); |
| 249 if (!IsResizeComplete(&dispatcher_test, widget_host)) { |
| 250 WindowedNotificationObserver resize_observer( |
| 251 NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, |
| 252 base::Bind(IsResizeComplete, &dispatcher_test, widget_host)); |
| 253 resize_observer.Wait(); |
| 254 } |
| 255 } |
| 256 #endif // USE_AURA |
| 257 |
224 void SimulateMouseClick(WebContents* web_contents, | 258 void SimulateMouseClick(WebContents* web_contents, |
225 int modifiers, | 259 int modifiers, |
226 blink::WebMouseEvent::Button button) { | 260 blink::WebMouseEvent::Button button) { |
227 int x = web_contents->GetContainerBounds().width() / 2; | 261 int x = web_contents->GetContainerBounds().width() / 2; |
228 int y = web_contents->GetContainerBounds().height() / 2; | 262 int y = web_contents->GetContainerBounds().height() / 2; |
229 SimulateMouseClickAt(web_contents, modifiers, button, gfx::Point(x, y)); | 263 SimulateMouseClickAt(web_contents, modifiers, button, gfx::Point(x, y)); |
230 } | 264 } |
231 | 265 |
232 void SimulateMouseClickAt(WebContents* web_contents, | 266 void SimulateMouseClickAt(WebContents* web_contents, |
233 int modifiers, | 267 int modifiers, |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 } | 727 } |
694 // The queue should not be empty, unless we were quit because of a timeout. | 728 // The queue should not be empty, unless we were quit because of a timeout. |
695 if (message_queue_.empty()) | 729 if (message_queue_.empty()) |
696 return false; | 730 return false; |
697 *message = message_queue_.front(); | 731 *message = message_queue_.front(); |
698 message_queue_.pop(); | 732 message_queue_.pop(); |
699 return true; | 733 return true; |
700 } | 734 } |
701 | 735 |
702 } // namespace content | 736 } // namespace content |
OLD | NEW |