Chromium Code Reviews| 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..6c79d5dc66a62a440b49c218f648fba7d8897394 100644 |
| --- a/cc/trees/layer_tree_impl_unittest.cc |
| +++ b/cc/trees/layer_tree_impl_unittest.cc |
| @@ -2220,5 +2220,109 @@ 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 {} |
| + void DidSwap(CompositorFrameMetadata* metadata) override {} |
| + |
| + 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::DEFAULT_ACTION; |
| + } |
| + |
| + 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) { |
| + EXPECT_TRUE(persistent_promises[i]) << "While checking case #" << i; |
|
danakj
2016/08/10 01:04:15
Instead of checking the destructor didn't run (wha
svartmetal
2016/08/10 17:38:22
Reasonable. Made EXPECT_CALL for DidSwap.
|
| + } |
| +} |
| + |
| +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 |