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

Unified Diff: content/public/test/browser_test_utils.cc

Issue 2686683004: ABANDONED CL: WaitForChildFrameSurfaceReady to avoid flaky test hangs. (Closed)
Patch Set: Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/test/browser_test_utils.cc
diff --git a/content/public/test/browser_test_utils.cc b/content/public/test/browser_test_utils.cc
index bdf2af36a38e5a329f77cf746c2c8549577d4f3b..4e912ec18f4b44e90c4bf4428f84d80a6bbe2e76 100644
--- a/content/public/test/browser_test_utils.cc
+++ b/content/public/test/browser_test_utils.cc
@@ -1161,21 +1161,56 @@ void SendRoutedGestureTapSequence(content::WebContents* web_contents,
rwhva->OnGestureEvent(&gesture_tap);
}
-// TODO(wjmaclean): The next two functions are a modified version of
-// SurfaceHitTestReadyNotifier that (1) works for BrowserPlugin-based guests,
-// and (2) links outside of content-browsertests. At some point in time we
-// should probably merge these.
namespace {
-bool ContainsSurfaceId(cc::SurfaceId container_surface_id,
- RenderWidgetHostViewChildFrame* target_view) {
+class SurfaceHitTestReadyNotifier {
+ public:
+ SurfaceHitTestReadyNotifier(RenderWidgetHostViewBase* target_view);
+ ~SurfaceHitTestReadyNotifier() {}
+
+ void WaitForSurfaceReady(RenderWidgetHostViewBase* root_container);
+
+ private:
+ bool ContainsSurfaceId(cc::SurfaceId container_surface_id);
+
+ cc::SurfaceManager* surface_manager_;
+ cc::SurfaceId root_surface_id_;
+ RenderWidgetHostViewBase* target_view_;
+
+ DISALLOW_COPY_AND_ASSIGN(SurfaceHitTestReadyNotifier);
+};
+
+SurfaceHitTestReadyNotifier::SurfaceHitTestReadyNotifier(
+ RenderWidgetHostViewBase* target_view)
+ : target_view_(target_view) {
+ surface_manager_ = GetSurfaceManager();
+}
+
+void SurfaceHitTestReadyNotifier::WaitForSurfaceReady(
+ RenderWidgetHostViewBase* root_view) {
+ LOG(ERROR) << "WaitForSurfaceReady...";
+ cc::SurfaceId root_surface_id = root_view->SurfaceIdForTesting();
+ while (!ContainsSurfaceId(root_surface_id)) {
+ // TODO(kenrb): Need a better way to do this. If
+ // RenderWidgetHostViewBase lifetime observer lands (see
+ // https://codereview.chromium.org/1711103002/), we can add a callback
+ // from OnSwapCompositorFrame and avoid this busy waiting, which is very
+ // frequent in tests in this file.
+ base::RunLoop run_loop;
+ base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
+ FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout());
+ run_loop.Run();
+ }
+}
+
+bool SurfaceHitTestReadyNotifier::ContainsSurfaceId(
+ cc::SurfaceId container_surface_id) {
if (!container_surface_id.is_valid())
return false;
for (cc::SurfaceId id :
- GetSurfaceManager()->GetSurfaceForId(container_surface_id)
+ surface_manager_->GetSurfaceForId(container_surface_id)
->referenced_surfaces()) {
- if (id == target_view->SurfaceIdForTesting() ||
- ContainsSurfaceId(id, target_view))
+ if (id == target_view_->SurfaceIdForTesting() || ContainsSurfaceId(id))
return true;
}
return false;
@@ -1188,20 +1223,32 @@ void WaitForGuestSurfaceReady(content::WebContents* guest_web_contents) {
static_cast<RenderWidgetHostViewChildFrame*>(
guest_web_contents->GetRenderWidgetHostView());
- cc::SurfaceId root_surface_id =
- static_cast<RenderWidgetHostViewAura*>(
- static_cast<content::WebContentsImpl*>(guest_web_contents)
- ->GetOuterWebContents()
- ->GetRenderWidgetHostView())
- ->SurfaceIdForTesting();
+ RenderWidgetHostViewBase* root_view = static_cast<RenderWidgetHostViewBase*>(
+ static_cast<content::WebContentsImpl*>(guest_web_contents)
+ ->GetOuterWebContents()
+ ->GetRenderWidgetHostView());
- while (!ContainsSurfaceId(root_surface_id, child_view)) {
- base::RunLoop run_loop;
- base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
- FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout());
- run_loop.Run();
- }
+ SurfaceHitTestReadyNotifier notifier(child_view);
+ notifier.WaitForSurfaceReady(root_view);
}
+
+void WaitForChildFrameSurfaceReady(content::RenderFrameHost* child_frame) {
+ RenderWidgetHostViewBase* child_view =
+ static_cast<RenderFrameHostImpl*>(child_frame)
+ ->GetRenderWidgetHost()
+ ->GetView();
+ if (!child_view->IsRenderWidgetHostViewChildFrame())
+ return;
+
+ RenderWidgetHostViewBase* root_view =
+ static_cast<RenderWidgetHostViewChildFrame*>(child_view)
+ ->FrameConnectorForTesting()
+ ->GetRootRenderWidgetHostViewForTesting();
+
+ SurfaceHitTestReadyNotifier notifier(child_view);
+ notifier.WaitForSurfaceReady(root_view);
+}
+
#endif
TitleWatcher::TitleWatcher(WebContents* web_contents,
« 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