Commit 8277b65c authored by Xiyuan Xia's avatar Xiyuan Xia Committed by Commit Bot

ash: Fix WorkspaceWindowResizerTest.ResizeHistogram

- WorkspaceWindowResizer::CompleteDrag() does not necessarily
  trigger a new compositor frame. As a result, the wait for the
  next frame could time out. This CL fixes the issue by explicitly
  marking a damaged rect to ensure a new frame is produced;
- Fix ui::WaitForNextFrameToBePresented use-after-free by using
  a CancelableCallback as the frame presented callback so that
  local var |runloop| is not accessed when it times out;

Bug: 1047657
Change-Id: I6e7ac27f14d92adf3c9d1535fec62e32e3964f2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2036369Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738176}
parent 0a4bcb24
......@@ -1905,7 +1905,7 @@ TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_BOTTOM) {
touch_resize_window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, DISABLED_ResizeHistogram) {
TEST_F(WorkspaceWindowResizerTest, ResizeHistogram) {
base::HistogramTester histograms;
window_->SetBounds(gfx::Rect(20, 30, 400, 60));
std::unique_ptr<WindowResizer> resizer(
......@@ -1920,6 +1920,12 @@ TEST_F(WorkspaceWindowResizerTest, DISABLED_ResizeHistogram) {
// Completing the drag should not generate another histogram.
resizer->CompleteDrag();
// Ensures a compositor frame will be generated. Otherwise,
// ui::WaitForNextFrameToBePresented below could time out.
// See https://crbug.com/1047657.
window_->GetHost()->compositor()->ScheduleRedrawRect(gfx::Rect(0, 0, 1, 1));
ui::WaitForNextFrameToBePresented(window_->GetHost()->compositor());
histograms.ExpectTotalCount("Ash.InteractiveWindowResize.TimeToPresent", 1);
}
......
......@@ -4,6 +4,7 @@
#include "ui/compositor/test/test_utils.h"
#include "base/cancelable_callback.h"
#include "base/run_loop.h"
#include "base/test/bind_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -50,10 +51,13 @@ void CheckApproximatelyEqual(const gfx::RoundedCornersF& lhs,
void WaitForNextFrameToBePresented(ui::Compositor* compositor) {
base::RunLoop runloop;
compositor->RequestPresentationTimeForNextFrame(base::BindLambdaForTesting(
[&runloop](const gfx::PresentationFeedback& feedback) {
runloop.Quit();
}));
base::CancelableOnceCallback<void(const gfx::PresentationFeedback&)>
cancelable_callback(base::BindLambdaForTesting(
[&runloop](const gfx::PresentationFeedback& feedback) {
runloop.Quit();
}));
compositor->RequestPresentationTimeForNextFrame(
cancelable_callback.callback());
runloop.Run();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment