From 4f866625ccd81a682589640b360065eb43ffdf85 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Thu, 29 Oct 2015 21:11:06 -0700 Subject: [PATCH] Attempt to fix webfont-related intermittent test failures. I'm not completely sure the race condition outlined in this patch is actually the race condition causing failures... but it seems reasonable. --- components/compositing/constellation.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/components/compositing/constellation.rs b/components/compositing/constellation.rs index d0c5003f908..d578fac7832 100644 --- a/components/compositing/constellation.rs +++ b/components/compositing/constellation.rs @@ -1203,6 +1203,21 @@ impl Constellation { for frame in self.current_frame_tree_iter(self.root_frame_id) { let pipeline = self.pipeline(frame.current); + // Check to see if there are any webfonts still loading. + // + // If GetWebFontLoadState returns false, either there are no + // webfonts loading, or there's a WebFontLoaded message waiting in + // script_chan's message queue. Therefore, we need to check this + // before we check whether the document is ready; otherwise, + // there's a race condition where a webfont has finished loading, + // but hasn't yet notified the document. + let (sender, receiver) = ipc::channel().unwrap(); + let msg = LayoutControlMsg::GetWebFontLoadState(sender); + pipeline.layout_chan.0.send(msg).unwrap(); + if receiver.recv().unwrap() { + return false; + } + // Synchronously query the script task for this pipeline // to see if it is idle. let (sender, receiver) = channel(); @@ -1213,13 +1228,6 @@ impl Constellation { return false; } - let (sender, receiver) = ipc::channel().unwrap(); - let msg = LayoutControlMsg::GetWebFontLoadState(sender); - pipeline.layout_chan.0.send(msg).unwrap(); - if receiver.recv().unwrap() { - return false; - } - // Check the visible rectangle for this pipeline. If the constellation has received a // size for the pipeline, then its painting should be up to date. If the constellation // *hasn't* received a size, it could be that the layer was hidden by script before the