| 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 |
| (...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 rwhva->OnGestureEvent(&gesture_tap_down); | 1154 rwhva->OnGestureEvent(&gesture_tap_down); |
| 1155 ui::GestureEventDetails gesture_tap_details(ui::ET_GESTURE_TAP); | 1155 ui::GestureEventDetails gesture_tap_details(ui::ET_GESTURE_TAP); |
| 1156 gesture_tap_details.set_device_type( | 1156 gesture_tap_details.set_device_type( |
| 1157 ui::GestureDeviceType::DEVICE_TOUCHSCREEN); | 1157 ui::GestureDeviceType::DEVICE_TOUCHSCREEN); |
| 1158 gesture_tap_details.set_tap_count(1); | 1158 gesture_tap_details.set_tap_count(1); |
| 1159 ui::GestureEvent gesture_tap(point.x(), point.y(), 0, base::TimeTicks::Now(), | 1159 ui::GestureEvent gesture_tap(point.x(), point.y(), 0, base::TimeTicks::Now(), |
| 1160 gesture_tap_details); | 1160 gesture_tap_details); |
| 1161 rwhva->OnGestureEvent(&gesture_tap); | 1161 rwhva->OnGestureEvent(&gesture_tap); |
| 1162 } | 1162 } |
| 1163 | 1163 |
| 1164 // TODO(wjmaclean): The next two functions are a modified version of | |
| 1165 // SurfaceHitTestReadyNotifier that (1) works for BrowserPlugin-based guests, | |
| 1166 // and (2) links outside of content-browsertests. At some point in time we | |
| 1167 // should probably merge these. | |
| 1168 namespace { | 1164 namespace { |
| 1169 | 1165 |
| 1170 bool ContainsSurfaceId(cc::SurfaceId container_surface_id, | 1166 class SurfaceHitTestReadyNotifier { |
| 1171 RenderWidgetHostViewChildFrame* target_view) { | 1167 public: |
| 1168 SurfaceHitTestReadyNotifier(RenderWidgetHostViewBase* target_view); |
| 1169 ~SurfaceHitTestReadyNotifier() {} |
| 1170 |
| 1171 void WaitForSurfaceReady(RenderWidgetHostViewBase* root_container); |
| 1172 |
| 1173 private: |
| 1174 bool ContainsSurfaceId(cc::SurfaceId container_surface_id); |
| 1175 |
| 1176 cc::SurfaceManager* surface_manager_; |
| 1177 cc::SurfaceId root_surface_id_; |
| 1178 RenderWidgetHostViewBase* target_view_; |
| 1179 |
| 1180 DISALLOW_COPY_AND_ASSIGN(SurfaceHitTestReadyNotifier); |
| 1181 }; |
| 1182 |
| 1183 SurfaceHitTestReadyNotifier::SurfaceHitTestReadyNotifier( |
| 1184 RenderWidgetHostViewBase* target_view) |
| 1185 : target_view_(target_view) { |
| 1186 surface_manager_ = GetSurfaceManager(); |
| 1187 } |
| 1188 |
| 1189 void SurfaceHitTestReadyNotifier::WaitForSurfaceReady( |
| 1190 RenderWidgetHostViewBase* root_view) { |
| 1191 LOG(ERROR) << "WaitForSurfaceReady..."; |
| 1192 cc::SurfaceId root_surface_id = root_view->SurfaceIdForTesting(); |
| 1193 while (!ContainsSurfaceId(root_surface_id)) { |
| 1194 // TODO(kenrb): Need a better way to do this. If |
| 1195 // RenderWidgetHostViewBase lifetime observer lands (see |
| 1196 // https://codereview.chromium.org/1711103002/), we can add a callback |
| 1197 // from OnSwapCompositorFrame and avoid this busy waiting, which is very |
| 1198 // frequent in tests in this file. |
| 1199 base::RunLoop run_loop; |
| 1200 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1201 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout()); |
| 1202 run_loop.Run(); |
| 1203 } |
| 1204 } |
| 1205 |
| 1206 bool SurfaceHitTestReadyNotifier::ContainsSurfaceId( |
| 1207 cc::SurfaceId container_surface_id) { |
| 1172 if (!container_surface_id.is_valid()) | 1208 if (!container_surface_id.is_valid()) |
| 1173 return false; | 1209 return false; |
| 1174 for (cc::SurfaceId id : | 1210 for (cc::SurfaceId id : |
| 1175 GetSurfaceManager()->GetSurfaceForId(container_surface_id) | 1211 surface_manager_->GetSurfaceForId(container_surface_id) |
| 1176 ->referenced_surfaces()) { | 1212 ->referenced_surfaces()) { |
| 1177 if (id == target_view->SurfaceIdForTesting() || | 1213 if (id == target_view_->SurfaceIdForTesting() || ContainsSurfaceId(id)) |
| 1178 ContainsSurfaceId(id, target_view)) | |
| 1179 return true; | 1214 return true; |
| 1180 } | 1215 } |
| 1181 return false; | 1216 return false; |
| 1182 } | 1217 } |
| 1183 | 1218 |
| 1184 } // namespace | 1219 } // namespace |
| 1185 | 1220 |
| 1186 void WaitForGuestSurfaceReady(content::WebContents* guest_web_contents) { | 1221 void WaitForGuestSurfaceReady(content::WebContents* guest_web_contents) { |
| 1187 RenderWidgetHostViewChildFrame* child_view = | 1222 RenderWidgetHostViewChildFrame* child_view = |
| 1188 static_cast<RenderWidgetHostViewChildFrame*>( | 1223 static_cast<RenderWidgetHostViewChildFrame*>( |
| 1189 guest_web_contents->GetRenderWidgetHostView()); | 1224 guest_web_contents->GetRenderWidgetHostView()); |
| 1190 | 1225 |
| 1191 cc::SurfaceId root_surface_id = | 1226 RenderWidgetHostViewBase* root_view = static_cast<RenderWidgetHostViewBase*>( |
| 1192 static_cast<RenderWidgetHostViewAura*>( | 1227 static_cast<content::WebContentsImpl*>(guest_web_contents) |
| 1193 static_cast<content::WebContentsImpl*>(guest_web_contents) | 1228 ->GetOuterWebContents() |
| 1194 ->GetOuterWebContents() | 1229 ->GetRenderWidgetHostView()); |
| 1195 ->GetRenderWidgetHostView()) | |
| 1196 ->SurfaceIdForTesting(); | |
| 1197 | 1230 |
| 1198 while (!ContainsSurfaceId(root_surface_id, child_view)) { | 1231 SurfaceHitTestReadyNotifier notifier(child_view); |
| 1199 base::RunLoop run_loop; | 1232 notifier.WaitForSurfaceReady(root_view); |
| 1200 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 1201 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout()); | |
| 1202 run_loop.Run(); | |
| 1203 } | |
| 1204 } | 1233 } |
| 1234 |
| 1235 void WaitForChildFrameSurfaceReady(content::RenderFrameHost* child_frame) { |
| 1236 RenderWidgetHostViewBase* child_view = |
| 1237 static_cast<RenderFrameHostImpl*>(child_frame) |
| 1238 ->GetRenderWidgetHost() |
| 1239 ->GetView(); |
| 1240 if (!child_view->IsRenderWidgetHostViewChildFrame()) |
| 1241 return; |
| 1242 |
| 1243 RenderWidgetHostViewBase* root_view = |
| 1244 static_cast<RenderWidgetHostViewChildFrame*>(child_view) |
| 1245 ->FrameConnectorForTesting() |
| 1246 ->GetRootRenderWidgetHostViewForTesting(); |
| 1247 |
| 1248 SurfaceHitTestReadyNotifier notifier(child_view); |
| 1249 notifier.WaitForSurfaceReady(root_view); |
| 1250 } |
| 1251 |
| 1205 #endif | 1252 #endif |
| 1206 | 1253 |
| 1207 TitleWatcher::TitleWatcher(WebContents* web_contents, | 1254 TitleWatcher::TitleWatcher(WebContents* web_contents, |
| 1208 const base::string16& expected_title) | 1255 const base::string16& expected_title) |
| 1209 : WebContentsObserver(web_contents) { | 1256 : WebContentsObserver(web_contents) { |
| 1210 expected_titles_.push_back(expected_title); | 1257 expected_titles_.push_back(expected_title); |
| 1211 } | 1258 } |
| 1212 | 1259 |
| 1213 void TitleWatcher::AlsoWaitForTitle(const base::string16& expected_title) { | 1260 void TitleWatcher::AlsoWaitForTitle(const base::string16& expected_title) { |
| 1214 expected_titles_.push_back(expected_title); | 1261 expected_titles_.push_back(expected_title); |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1850 IPC::IpcSecurityTestUtil::PwnMessageReceived( | 1897 IPC::IpcSecurityTestUtil::PwnMessageReceived( |
| 1851 process->GetChannel(), | 1898 process->GetChannel(), |
| 1852 FileSystemHostMsg_Write(request_id, file_path, blob_uuid, position)); | 1899 FileSystemHostMsg_Write(request_id, file_path, blob_uuid, position)); |
| 1853 | 1900 |
| 1854 // If this started an async operation, wait for it to complete. | 1901 // If this started an async operation, wait for it to complete. |
| 1855 if (waiter.did_start_update()) | 1902 if (waiter.did_start_update()) |
| 1856 waiter.WaitForEndUpdate(); | 1903 waiter.WaitForEndUpdate(); |
| 1857 } | 1904 } |
| 1858 | 1905 |
| 1859 } // namespace content | 1906 } // namespace content |
| OLD | NEW |