[LCP] Test: mock swap-time request for text and image
TextPaintTimingDetector(LTP) and ImagePaintTimingDetector (LIP) both use ChromeClient to register callbacks in their implementation. However, ChromeClient is an external component, which needs to be decoupled in the test. The initial design bypasses the callback in test. Specifically, LIP bypasses it by having a control flag to direct the callback to a local callback queue, and LTP simply just ignores the callback logic. Either approach did not achieve a comprehensive coverage. The new design in this CL uses a mocking approach for decoupling. As ChromeClient was called to register callbacks, the new design inserts an interface between LTP&LIP and ChromeClient. When testing LTP&LIP, the interface is mocked with a local callback queue. So the external component can be removed from the unit test. Compared to an earlier attempt crrev.com/c/1701058 where two callbacks were combined, this approach allows for separate callback-queueing for Image/TextPaintTimingDetector, LargestContentfulPaintDetector and other paint timing components in unit test. This way, future change in LTP wouldn't affect the unit-test in LIP via ChromeClient and vice versa. In addition, LargestContentfulPaintCalculator can thus keep being capable of controlling the order of text callback and image callback. As ChromeClient is shared with other paint metrics (FP, FCP, FMP), the tests of LTP and LIP would couple with these metrics if ChromeClient is not well separated. As an extra benefit, this change will make it possible to combine two callbacks by implementing the callback-manager interface in a different way. The combination will then provide a hook to the time when "both LIP and LTP callbacks have been invoked". This hook would make it easy to solve crbug.com/982307. This CL doesn't change the unit-tests expectations. Bug: 982307, 987984 Change-Id: I8d58a9676b1b350c630f076c530b54f2d7c6ab04 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1722449Reviewed-by:Steve Kobes <skobes@chromium.org> Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org> Cr-Commit-Position: refs/heads/master@{#682923}
Showing
Please register or sign in to comment