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 <stddef.h> | 7 #include <stddef.h> |
8 #include <tuple> | 8 #include <tuple> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/process/kill.h" | 16 #include "base/process/kill.h" |
17 #include "base/rand_util.h" | 17 #include "base/rand_util.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "base/synchronization/waitable_event.h" | 21 #include "base/synchronization/waitable_event.h" |
22 #include "base/test/test_timeouts.h" | 22 #include "base/test/test_timeouts.h" |
23 #include "base/values.h" | 23 #include "base/values.h" |
24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 25 #include "cc/surfaces/surface.h" |
| 26 #include "cc/surfaces/surface_manager.h" |
25 #include "content/browser/accessibility/accessibility_mode_helper.h" | 27 #include "content/browser/accessibility/accessibility_mode_helper.h" |
26 #include "content/browser/accessibility/browser_accessibility.h" | 28 #include "content/browser/accessibility/browser_accessibility.h" |
27 #include "content/browser/accessibility/browser_accessibility_manager.h" | 29 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 30 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 31 #include "content/browser/compositor/surface_utils.h" |
| 32 #include "content/browser/frame_host/cross_process_frame_connector.h" |
28 #include "content/browser/frame_host/frame_tree_node.h" | 33 #include "content/browser/frame_host/frame_tree_node.h" |
29 #include "content/browser/frame_host/render_frame_host_impl.h" | 34 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 35 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
30 #include "content/browser/renderer_host/render_widget_host_impl.h" | 36 #include "content/browser/renderer_host/render_widget_host_impl.h" |
31 #include "content/browser/web_contents/web_contents_impl.h" | 37 #include "content/browser/web_contents/web_contents_impl.h" |
32 #include "content/browser/web_contents/web_contents_view.h" | 38 #include "content/browser/web_contents/web_contents_view.h" |
33 #include "content/common/input/synthetic_web_input_event_builders.h" | 39 #include "content/common/input/synthetic_web_input_event_builders.h" |
34 #include "content/common/input_messages.h" | 40 #include "content/common/input_messages.h" |
35 #include "content/common/view_messages.h" | 41 #include "content/common/view_messages.h" |
36 #include "content/public/browser/browser_context.h" | 42 #include "content/public/browser/browser_context.h" |
37 #include "content/public/browser/histogram_fetcher.h" | 43 #include "content/public/browser/histogram_fetcher.h" |
38 #include "content/public/browser/navigation_entry.h" | 44 #include "content/public/browser/navigation_entry.h" |
39 #include "content/public/browser/notification_service.h" | 45 #include "content/public/browser/notification_service.h" |
(...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 ui::AXTreeUpdate GetAccessibilityTreeSnapshot(WebContents* web_contents) { | 1002 ui::AXTreeUpdate GetAccessibilityTreeSnapshot(WebContents* web_contents) { |
997 WebContentsImpl* web_contents_impl = | 1003 WebContentsImpl* web_contents_impl = |
998 static_cast<WebContentsImpl*>(web_contents); | 1004 static_cast<WebContentsImpl*>(web_contents); |
999 BrowserAccessibilityManager* manager = | 1005 BrowserAccessibilityManager* manager = |
1000 web_contents_impl->GetRootBrowserAccessibilityManager(); | 1006 web_contents_impl->GetRootBrowserAccessibilityManager(); |
1001 if (!manager) | 1007 if (!manager) |
1002 return ui::AXTreeUpdate(); | 1008 return ui::AXTreeUpdate(); |
1003 return manager->SnapshotAXTreeForTesting(); | 1009 return manager->SnapshotAXTreeForTesting(); |
1004 } | 1010 } |
1005 | 1011 |
| 1012 bool IsWebContentsBrowserPluginFocused(content::WebContents* web_contents) { |
| 1013 WebContentsImpl* web_contents_impl = |
| 1014 static_cast<WebContentsImpl*>(web_contents); |
| 1015 BrowserPluginGuest* browser_plugin_guest = |
| 1016 web_contents_impl->GetBrowserPluginGuest(); |
| 1017 return browser_plugin_guest ? browser_plugin_guest->focused() : false; |
| 1018 } |
| 1019 |
| 1020 #if defined(USE_AURA) |
| 1021 void SendRoutedTouchTapSequence(content::WebContents* web_contents, |
| 1022 gfx::Point point) { |
| 1023 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( |
| 1024 web_contents->GetRenderWidgetHostView()); |
| 1025 ui::TouchEvent touch_start(ui::ET_TOUCH_PRESSED, point, 0, |
| 1026 base::TimeTicks::Now()); |
| 1027 rwhva->OnTouchEvent(&touch_start); |
| 1028 ui::TouchEvent touch_end(ui::ET_TOUCH_RELEASED, point, 0, |
| 1029 base::TimeTicks::Now()); |
| 1030 rwhva->OnTouchEvent(&touch_end); |
| 1031 } |
| 1032 |
| 1033 void SendRoutedGestureTapSequence(content::WebContents* web_contents, |
| 1034 gfx::Point point) { |
| 1035 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( |
| 1036 web_contents->GetRenderWidgetHostView()); |
| 1037 ui::GestureEventDetails gesture_tap_down_details(ui::ET_GESTURE_TAP_DOWN); |
| 1038 gesture_tap_down_details.set_device_type( |
| 1039 ui::GestureDeviceType::DEVICE_TOUCHSCREEN); |
| 1040 ui::GestureEvent gesture_tap_down(point.x(), point.y(), 0, |
| 1041 base::TimeTicks::Now(), |
| 1042 gesture_tap_down_details); |
| 1043 rwhva->OnGestureEvent(&gesture_tap_down); |
| 1044 ui::GestureEventDetails gesture_tap_details(ui::ET_GESTURE_TAP); |
| 1045 gesture_tap_details.set_device_type( |
| 1046 ui::GestureDeviceType::DEVICE_TOUCHSCREEN); |
| 1047 gesture_tap_details.set_tap_count(1); |
| 1048 ui::GestureEvent gesture_tap(point.x(), point.y(), 0, base::TimeTicks::Now(), |
| 1049 gesture_tap_details); |
| 1050 rwhva->OnGestureEvent(&gesture_tap); |
| 1051 } |
| 1052 |
| 1053 // TODO(wjmaclean): The next two functions are a modified version of |
| 1054 // SurfaceHitTestReadyNotifier that (1) works for BrowserPlugin-based guests, |
| 1055 // and (2) links outside of content-browsertests. At some point in time we |
| 1056 // should probably merge these. |
| 1057 namespace { |
| 1058 |
| 1059 bool ContainsSurfaceId(cc::SurfaceId container_surface_id, |
| 1060 RenderWidgetHostViewChildFrame* target_view) { |
| 1061 if (container_surface_id.is_null()) |
| 1062 return false; |
| 1063 for (cc::SurfaceId id : |
| 1064 GetSurfaceManager()->GetSurfaceForId(container_surface_id) |
| 1065 ->referenced_surfaces()) { |
| 1066 if (id == target_view->SurfaceIdForTesting() || |
| 1067 ContainsSurfaceId(id, target_view)) |
| 1068 return true; |
| 1069 } |
| 1070 return false; |
| 1071 } |
| 1072 |
| 1073 } // namespace |
| 1074 |
| 1075 void WaitForGuestSurfaceReady(content::WebContents* guest_web_contents) { |
| 1076 RenderWidgetHostViewChildFrame* child_view = |
| 1077 static_cast<RenderWidgetHostViewChildFrame*>( |
| 1078 guest_web_contents->GetRenderWidgetHostView()); |
| 1079 |
| 1080 cc::SurfaceId root_surface_id = |
| 1081 static_cast<RenderWidgetHostViewAura*>( |
| 1082 static_cast<content::WebContentsImpl*>(guest_web_contents) |
| 1083 ->GetOuterWebContents() |
| 1084 ->GetRenderWidgetHostView()) |
| 1085 ->SurfaceIdForTesting(); |
| 1086 |
| 1087 while (!ContainsSurfaceId(root_surface_id, child_view)) { |
| 1088 base::RunLoop run_loop; |
| 1089 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1090 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout()); |
| 1091 run_loop.Run(); |
| 1092 } |
| 1093 } |
| 1094 #endif |
| 1095 |
1006 TitleWatcher::TitleWatcher(WebContents* web_contents, | 1096 TitleWatcher::TitleWatcher(WebContents* web_contents, |
1007 const base::string16& expected_title) | 1097 const base::string16& expected_title) |
1008 : WebContentsObserver(web_contents), | 1098 : WebContentsObserver(web_contents), |
1009 message_loop_runner_(new MessageLoopRunner) { | 1099 message_loop_runner_(new MessageLoopRunner) { |
1010 EXPECT_TRUE(web_contents != NULL); | 1100 EXPECT_TRUE(web_contents != NULL); |
1011 expected_titles_.push_back(expected_title); | 1101 expected_titles_.push_back(expected_title); |
1012 } | 1102 } |
1013 | 1103 |
1014 void TitleWatcher::AlsoWaitForTitle(const base::string16& expected_title) { | 1104 void TitleWatcher::AlsoWaitForTitle(const base::string16& expected_title) { |
1015 expected_titles_.push_back(expected_title); | 1105 expected_titles_.push_back(expected_title); |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1407 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1318 if (ack_result_ != INPUT_EVENT_ACK_STATE_UNKNOWN) | 1408 if (ack_result_ != INPUT_EVENT_ACK_STATE_UNKNOWN) |
1319 return ack_result_; | 1409 return ack_result_; |
1320 base::RunLoop run_loop; | 1410 base::RunLoop run_loop; |
1321 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); | 1411 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); |
1322 run_loop.Run(); | 1412 run_loop.Run(); |
1323 return ack_result_; | 1413 return ack_result_; |
1324 } | 1414 } |
1325 | 1415 |
1326 } // namespace content | 1416 } // namespace content |
OLD | NEW |