1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- // Copyright (c) 2012 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #include "ui/compositor/test/test_utils.h"
- #include "base/cancelable_callback.h"
- #include "base/run_loop.h"
- #include "base/test/bind.h"
- #include "base/timer/timer.h"
- #include "testing/gtest/include/gtest/gtest.h"
- #include "ui/compositor/compositor.h"
- #include "ui/gfx/geometry/rect.h"
- #include "ui/gfx/geometry/rounded_corners_f.h"
- #include "ui/gfx/geometry/transform.h"
- namespace ui {
- // TODO(avallee): Use macros in ui/gfx/geometry/test/geometry_util.h.
- void CheckApproximatelyEqual(const gfx::Transform& lhs,
- const gfx::Transform& rhs) {
- unsigned int errors = 0;
- for (int i = 0; i < 4; ++i) {
- for (int j = 0; j < 4; ++j) {
- EXPECT_FLOAT_EQ(lhs.matrix().rc(i, j), rhs.matrix().rc(i, j))
- << "(i, j) = (" << i << ", " << j << "), error count: " << ++errors;
- }
- }
- if (errors) {
- ADD_FAILURE() << "Expected matrix:\n"
- << lhs.ToString() << "\n"
- << "Actual matrix:\n"
- << rhs.ToString();
- }
- }
- void CheckApproximatelyEqual(const gfx::Rect& lhs, const gfx::Rect& rhs) {
- EXPECT_FLOAT_EQ(lhs.x(), rhs.x());
- EXPECT_FLOAT_EQ(lhs.y(), rhs.y());
- EXPECT_FLOAT_EQ(lhs.width(), rhs.width());
- EXPECT_FLOAT_EQ(lhs.height(), rhs.height());
- }
- void CheckApproximatelyEqual(const gfx::RoundedCornersF& lhs,
- const gfx::RoundedCornersF& rhs) {
- EXPECT_FLOAT_EQ(lhs.upper_left(), rhs.upper_left());
- EXPECT_FLOAT_EQ(lhs.upper_right(), rhs.upper_right());
- EXPECT_FLOAT_EQ(lhs.lower_left(), rhs.lower_left());
- EXPECT_FLOAT_EQ(lhs.lower_right(), rhs.lower_right());
- }
- bool WaitForNextFrameToBePresented(ui::Compositor* compositor,
- absl::optional<base::TimeDelta> timeout) {
- bool frames_presented = false;
- base::RunLoop runloop;
- base::CancelableOnceCallback<void(const gfx::PresentationFeedback&)>
- cancelable_callback(base::BindLambdaForTesting(
- [&](const gfx::PresentationFeedback& feedback) {
- frames_presented = true;
- runloop.Quit();
- }));
- compositor->RequestPresentationTimeForNextFrame(
- cancelable_callback.callback());
- absl::optional<base::OneShotTimer> timer;
- if (timeout.has_value()) {
- timer.emplace();
- timer->Start(FROM_HERE, timeout.value(), runloop.QuitClosure());
- }
- runloop.Run();
- return frames_presented;
- }
- } // namespace ui
|