| Index: cc/trees/layer_tree_impl_unittest.cc
|
| diff --git a/cc/trees/layer_tree_impl_unittest.cc b/cc/trees/layer_tree_impl_unittest.cc
|
| index a365985a7415c82b12891d7fe574f49055c7c947..52c2da3906f89398622581ae1b180eb58a6b92a2 100644
|
| --- a/cc/trees/layer_tree_impl_unittest.cc
|
| +++ b/cc/trees/layer_tree_impl_unittest.cc
|
| @@ -13,6 +13,7 @@
|
| #include "cc/trees/draw_property_utils.h"
|
| #include "cc/trees/layer_tree_host_common.h"
|
| #include "cc/trees/layer_tree_host_impl.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace cc {
|
| @@ -2220,5 +2221,111 @@ TEST_F(LayerTreeImplTest, HitTestingCorrectLayerWheelListener) {
|
| EXPECT_EQ(2, result_layer->id());
|
| }
|
|
|
| +namespace {
|
| +
|
| +class CC_EXPORT PersistentSwapPromise
|
| + : public SwapPromise,
|
| + public base::SupportsWeakPtr<PersistentSwapPromise> {
|
| + public:
|
| + PersistentSwapPromise() = default;
|
| + ~PersistentSwapPromise() override = default;
|
| +
|
| + void DidActivate() override {}
|
| + MOCK_METHOD1(DidSwap, void(CompositorFrameMetadata* metadata));
|
| +
|
| + DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override {
|
| + return DidNotSwapAction::KEEP_ACTIVE;
|
| + }
|
| +
|
| + void OnCommit() override {}
|
| + int64_t TraceId() const override { return 0; }
|
| +};
|
| +
|
| +class CC_EXPORT NotPersistentSwapPromise
|
| + : public SwapPromise,
|
| + public base::SupportsWeakPtr<NotPersistentSwapPromise> {
|
| + public:
|
| + NotPersistentSwapPromise() = default;
|
| + ~NotPersistentSwapPromise() override = default;
|
| +
|
| + void DidActivate() override {}
|
| + void DidSwap(CompositorFrameMetadata* metadata) override {}
|
| +
|
| + DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override {
|
| + return DidNotSwapAction::BREAK_PROMISE;
|
| + }
|
| +
|
| + void OnCommit() override {}
|
| + int64_t TraceId() const override { return 0; }
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +TEST_F(LayerTreeImplTest, PersistentSwapPromisesAreKeptAlive) {
|
| + const size_t promises_count = 2;
|
| +
|
| + std::vector<base::WeakPtr<PersistentSwapPromise>> persistent_promises;
|
| + std::vector<std::unique_ptr<PersistentSwapPromise>>
|
| + persistent_promises_to_pass;
|
| + for (size_t i = 0; i < promises_count; ++i) {
|
| + persistent_promises_to_pass.push_back(
|
| + base::WrapUnique(new PersistentSwapPromise()));
|
| + }
|
| +
|
| + for (auto& promise : persistent_promises_to_pass) {
|
| + persistent_promises.push_back(promise->AsWeakPtr());
|
| + host_impl().active_tree()->QueueSwapPromise(std::move(promise));
|
| + }
|
| +
|
| + std::vector<std::unique_ptr<SwapPromise>> promises;
|
| + host_impl().active_tree()->PassSwapPromises(&promises);
|
| + host_impl().active_tree()->BreakSwapPromises(
|
| + SwapPromise::DidNotSwapReason::SWAP_FAILS);
|
| +
|
| + ASSERT_EQ(promises_count, persistent_promises.size());
|
| + for (size_t i = 0; i < persistent_promises.size(); ++i) {
|
| + SCOPED_TRACE(testing::Message() << "While checking case #" << i);
|
| + ASSERT_TRUE(persistent_promises[i]);
|
| + EXPECT_CALL(*persistent_promises[i], DidSwap(testing::_));
|
| + }
|
| + host_impl().active_tree()->FinishSwapPromises(nullptr);
|
| +}
|
| +
|
| +TEST_F(LayerTreeImplTest, NotPersistentSwapPromisesAreDroppedWhenSwapFails) {
|
| + const size_t promises_count = 2;
|
| +
|
| + std::vector<base::WeakPtr<NotPersistentSwapPromise>> not_persistent_promises;
|
| + std::vector<std::unique_ptr<NotPersistentSwapPromise>>
|
| + not_persistent_promises_to_pass;
|
| + for (size_t i = 0; i < promises_count; ++i) {
|
| + not_persistent_promises_to_pass.push_back(
|
| + base::WrapUnique(new NotPersistentSwapPromise()));
|
| + }
|
| +
|
| + for (auto& promise : not_persistent_promises_to_pass) {
|
| + not_persistent_promises.push_back(promise->AsWeakPtr());
|
| + host_impl().active_tree()->QueueSwapPromise(std::move(promise));
|
| + }
|
| + std::vector<std::unique_ptr<SwapPromise>> promises;
|
| + host_impl().active_tree()->PassSwapPromises(&promises);
|
| +
|
| + ASSERT_EQ(promises_count, not_persistent_promises.size());
|
| + for (size_t i = 0; i < not_persistent_promises.size(); ++i) {
|
| + EXPECT_FALSE(not_persistent_promises[i]) << "While checking case #" << i;
|
| + }
|
| +
|
| + // Finally, check that not persistent promise doesn't survive
|
| + // |LayerTreeImpl::BreakSwapPromises|.
|
| + {
|
| + std::unique_ptr<NotPersistentSwapPromise> promise(
|
| + new NotPersistentSwapPromise());
|
| + auto weak_promise = promise->AsWeakPtr();
|
| + host_impl().active_tree()->QueueSwapPromise(std::move(promise));
|
| + host_impl().active_tree()->BreakSwapPromises(
|
| + SwapPromise::DidNotSwapReason::SWAP_FAILS);
|
| + EXPECT_FALSE(weak_promise);
|
| + }
|
| +}
|
| +
|
| } // namespace
|
| } // namespace cc
|
|
|