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

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

Issue 2786223002: Fix flakiness in DragAndDropBrowserTests (Closed)
Patch Set: Review comments addressed Created 3 years, 8 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 <stddef.h> 7 #include <stddef.h>
8 #include <tuple> 8 #include <tuple>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1162 rwhva->OnGestureEvent(&gesture_tap_down); 1162 rwhva->OnGestureEvent(&gesture_tap_down);
1163 ui::GestureEventDetails gesture_tap_details(ui::ET_GESTURE_TAP); 1163 ui::GestureEventDetails gesture_tap_details(ui::ET_GESTURE_TAP);
1164 gesture_tap_details.set_device_type( 1164 gesture_tap_details.set_device_type(
1165 ui::GestureDeviceType::DEVICE_TOUCHSCREEN); 1165 ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
1166 gesture_tap_details.set_tap_count(1); 1166 gesture_tap_details.set_tap_count(1);
1167 ui::GestureEvent gesture_tap(point.x(), point.y(), 0, base::TimeTicks::Now(), 1167 ui::GestureEvent gesture_tap(point.x(), point.y(), 0, base::TimeTicks::Now(),
1168 gesture_tap_details); 1168 gesture_tap_details);
1169 rwhva->OnGestureEvent(&gesture_tap); 1169 rwhva->OnGestureEvent(&gesture_tap);
1170 } 1170 }
1171 1171
1172 // TODO(wjmaclean): The next two functions are a modified version of 1172 #endif
1173 // SurfaceHitTestReadyNotifier that (1) works for BrowserPlugin-based guests, 1173
1174 // and (2) links outside of content-browsertests. At some point in time we
1175 // should probably merge these.
1176 namespace { 1174 namespace {
1177 1175
1178 bool ContainsSurfaceId(const cc::SurfaceId& container_surface_id, 1176 class SurfaceHitTestReadyNotifier {
1179 RenderWidgetHostViewChildFrame* target_view) { 1177 public:
1178 SurfaceHitTestReadyNotifier(RenderWidgetHostViewBase* target_view);
1179 ~SurfaceHitTestReadyNotifier() {}
1180
1181 void WaitForSurfaceReady(RenderWidgetHostViewBase* root_container);
1182
1183 private:
1184 bool ContainsSurfaceId(const cc::SurfaceId& container_surface_id);
1185
1186 cc::SurfaceManager* surface_manager_;
1187 RenderWidgetHostViewBase* target_view_;
1188
1189 DISALLOW_COPY_AND_ASSIGN(SurfaceHitTestReadyNotifier);
1190 };
1191
1192 SurfaceHitTestReadyNotifier::SurfaceHitTestReadyNotifier(
1193 RenderWidgetHostViewBase* target_view)
1194 : target_view_(target_view) {
1195 surface_manager_ = GetSurfaceManager();
1196 }
1197
1198 void SurfaceHitTestReadyNotifier::WaitForSurfaceReady(
1199 RenderWidgetHostViewBase* root_view) {
1200 cc::SurfaceId root_surface_id = root_view->SurfaceIdForTesting();
1201 while (!ContainsSurfaceId(root_surface_id)) {
1202 // TODO(kenrb): Need a better way to do this. Needs investigation on
1203 // whether we can add a callback through RenderWidgetHostViewBaseObserver
1204 // from OnSwapCompositorFrame and avoid this busy waiting. A callback on
1205 // every compositor frame might be generally undesirable for performance,
1206 // however.
1207 base::RunLoop run_loop;
1208 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
1209 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout());
1210 run_loop.Run();
1211 }
1212 }
1213
1214 bool SurfaceHitTestReadyNotifier::ContainsSurfaceId(
1215 const cc::SurfaceId& container_surface_id) {
1180 if (!container_surface_id.is_valid()) 1216 if (!container_surface_id.is_valid())
1181 return false; 1217 return false;
1182 1218
1183 cc::Surface* container_surface = 1219 cc::Surface* container_surface =
1184 GetSurfaceManager()->GetSurfaceForId(container_surface_id); 1220 surface_manager_->GetSurfaceForId(container_surface_id);
1185 if (!container_surface || !container_surface->active_referenced_surfaces()) 1221 if (!container_surface || !container_surface->active_referenced_surfaces())
1186 return false; 1222 return false;
1187 1223
1188 for (const cc::SurfaceId& id : 1224 for (const cc::SurfaceId& id :
1189 *container_surface->active_referenced_surfaces()) { 1225 *container_surface->active_referenced_surfaces()) {
1190 if (id == target_view->SurfaceIdForTesting() || 1226 if (id == target_view_->SurfaceIdForTesting() || ContainsSurfaceId(id))
1191 ContainsSurfaceId(id, target_view))
1192 return true; 1227 return true;
1193 } 1228 }
1194 return false; 1229 return false;
1195 } 1230 }
1196 1231
1197 } // namespace 1232 } // namespace
1198 1233
1234 #if defined(USE_AURA)
1199 void WaitForGuestSurfaceReady(content::WebContents* guest_web_contents) { 1235 void WaitForGuestSurfaceReady(content::WebContents* guest_web_contents) {
1200 RenderWidgetHostViewChildFrame* child_view = 1236 RenderWidgetHostViewChildFrame* child_view =
1201 static_cast<RenderWidgetHostViewChildFrame*>( 1237 static_cast<RenderWidgetHostViewChildFrame*>(
1202 guest_web_contents->GetRenderWidgetHostView()); 1238 guest_web_contents->GetRenderWidgetHostView());
1203 1239
1204 cc::SurfaceId root_surface_id = 1240 RenderWidgetHostViewBase* root_view = static_cast<RenderWidgetHostViewBase*>(
1205 static_cast<RenderWidgetHostViewAura*>( 1241 static_cast<content::WebContentsImpl*>(guest_web_contents)
1206 static_cast<content::WebContentsImpl*>(guest_web_contents) 1242 ->GetOuterWebContents()
1207 ->GetOuterWebContents() 1243 ->GetRenderWidgetHostView());
1208 ->GetRenderWidgetHostView())
1209 ->SurfaceIdForTesting();
1210 1244
1211 while (!ContainsSurfaceId(root_surface_id, child_view)) { 1245 SurfaceHitTestReadyNotifier notifier(child_view);
1212 base::RunLoop run_loop; 1246 notifier.WaitForSurfaceReady(root_view);
1213 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
1214 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout());
1215 run_loop.Run();
1216 }
1217 } 1247 }
1248
1218 #endif 1249 #endif
1219 1250
1251 void WaitForChildFrameSurfaceReady(content::RenderFrameHost* child_frame) {
1252 RenderWidgetHostViewBase* child_view =
1253 static_cast<RenderFrameHostImpl*>(child_frame)
1254 ->GetRenderWidgetHost()
1255 ->GetView();
1256 if (!child_view || !child_view->IsRenderWidgetHostViewChildFrame())
1257 return;
1258
1259 RenderWidgetHostViewBase* root_view =
1260 static_cast<RenderWidgetHostViewChildFrame*>(child_view)
1261 ->FrameConnectorForTesting()
1262 ->GetRootRenderWidgetHostViewForTesting();
1263
1264 SurfaceHitTestReadyNotifier notifier(child_view);
1265 notifier.WaitForSurfaceReady(root_view);
1266 }
1267
1220 TitleWatcher::TitleWatcher(WebContents* web_contents, 1268 TitleWatcher::TitleWatcher(WebContents* web_contents,
1221 const base::string16& expected_title) 1269 const base::string16& expected_title)
1222 : WebContentsObserver(web_contents) { 1270 : WebContentsObserver(web_contents) {
1223 expected_titles_.push_back(expected_title); 1271 expected_titles_.push_back(expected_title);
1224 } 1272 }
1225 1273
1226 void TitleWatcher::AlsoWaitForTitle(const base::string16& expected_title) { 1274 void TitleWatcher::AlsoWaitForTitle(const base::string16& expected_title) {
1227 expected_titles_.push_back(expected_title); 1275 expected_titles_.push_back(expected_title);
1228 } 1276 }
1229 1277
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
1874 bool user_gesture, 1922 bool user_gesture,
1875 bool last_unlocked_by_target, 1923 bool last_unlocked_by_target,
1876 bool privileged) { 1924 bool privileged) {
1877 IPC::IpcSecurityTestUtil::PwnMessageReceived( 1925 IPC::IpcSecurityTestUtil::PwnMessageReceived(
1878 process->GetChannel(), 1926 process->GetChannel(),
1879 ViewHostMsg_LockMouse(routing_id, user_gesture, last_unlocked_by_target, 1927 ViewHostMsg_LockMouse(routing_id, user_gesture, last_unlocked_by_target,
1880 privileged)); 1928 privileged));
1881 } 1929 }
1882 1930
1883 } // namespace content 1931 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/browser_test_utils.h ('k') | content/test/content_browser_test_utils_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698