Index: cc/trees/layer_tree_host_unittest.cc |
diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc |
index 82134e3df0420690b88dd7ad4fa00925417becc4..dd450b41979e7db468e867381ad04e7916986612 100644 |
--- a/cc/trees/layer_tree_host_unittest.cc |
+++ b/cc/trees/layer_tree_host_unittest.cc |
@@ -9,6 +9,7 @@ |
#include "base/auto_reset.h" |
#include "base/synchronization/lock.h" |
#include "cc/animation/timing_function.h" |
+#include "cc/base/swap_promise.h" |
#include "cc/debug/frame_rate_counter.h" |
#include "cc/layers/content_layer.h" |
#include "cc/layers/content_layer_client.h" |
@@ -5215,4 +5216,109 @@ class LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface |
SINGLE_AND_MULTI_THREAD_TEST_F( |
LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface); |
+struct SwapPromiseResult { |
+ bool did_swap_called; |
+ bool did_not_swap_called; |
+ bool dtor_called; |
+ SwapPromise::DidNotSwapReason reason; |
+}; |
+ |
+class TestSwapPromise : public SwapPromise { |
+ public: |
+ explicit TestSwapPromise(SwapPromiseResult* result) |
+ : SwapPromise(SWAP_PROMISE_UNKNOWN), |
+ result_(result) { |
+ } |
+ |
+ virtual ~TestSwapPromise() { |
+ result_->dtor_called = true; |
+ } |
+ |
+ virtual void DidSwap() OVERRIDE { |
+ EXPECT_FALSE(result_->did_swap_called); |
+ EXPECT_FALSE(result_->did_not_swap_called); |
+ result_->did_swap_called = true; |
+ } |
+ |
+ virtual void DidNotSwap(DidNotSwapReason reason) { |
+ EXPECT_FALSE(result_->did_swap_called); |
+ EXPECT_FALSE(result_->did_not_swap_called); |
+ result_->did_not_swap_called = true; |
+ result_->reason = reason; |
+ } |
+ |
+ private: |
+ // Not owned. |
+ SwapPromiseResult* result_; |
+}; |
+ |
+class LayerTreeHostTestBreakSwapPromise |
+ : public LayerTreeHostTest { |
+ protected: |
+ LayerTreeHostTestBreakSwapPromise() |
+ : commit_count_(0), commit_complete_count_(0) { |
+ memset(&swap_promise_result_, 0, sizeof(swap_promise_result_)); |
danakj
2013/11/13 23:22:09
Make a constructor on SwapPromiseResult instead of
Yufeng Shen (Slow to review)
2013/11/14 22:09:55
Done.
|
+ } |
+ |
+ virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
+ settings->begin_impl_frame_scheduling_enabled = true; |
danakj
2013/11/13 23:22:09
Why is this needed?
Yufeng Shen (Slow to review)
2013/11/14 22:09:55
removed.
|
+ } |
+ |
+ virtual void WillBeginMainFrame() OVERRIDE { |
+ layer_tree_host()->QueueSwapPromise( |
+ new TestSwapPromise(&swap_promise_result_[commit_count_])); |
+ } |
+ |
+ virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
+ |
+ virtual void DidCommit() OVERRIDE { |
+ commit_count_++; |
danakj
2013/11/13 23:22:09
You can use layer_tree_host()->source_frame_number
Yufeng Shen (Slow to review)
2013/11/14 22:09:55
I think here what we want is that after we have tr
|
+ if (commit_count_ == 2) { |
+ // This commit will finish. |
+ layer_tree_host()->SetNeedsCommit(); |
+ } |
+ } |
+ |
+ virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
+ commit_complete_count_++; |
+ if (commit_complete_count_ == 1) { |
+ // This commit will be aborted. |
danakj
2013/11/13 23:22:09
I think that a better way to make an aborted commi
Yufeng Shen (Slow to review)
2013/11/14 22:09:55
Done.
|
+ host_impl->SetNeedsCommit(); |
+ } else { |
+ EndTest(); |
+ } |
+ } |
+ |
+ virtual void AfterTest() OVERRIDE { |
+ // 3 commits are scheduled. 2 completes. 1 is aborted. |
+ EXPECT_EQ(commit_count_, 3); |
+ EXPECT_EQ(commit_complete_count_, 2); |
+ |
+ // The first commit completes and causes swap buffer wihch finishes |
danakj
2013/11/13 23:22:09
which
Yufeng Shen (Slow to review)
2013/11/14 22:09:55
Done.
|
+ // the promise. |
+ EXPECT_TRUE(swap_promise_result_[0].did_swap_called); |
+ EXPECT_FALSE(swap_promise_result_[0].did_not_swap_called); |
+ EXPECT_TRUE(swap_promise_result_[0].dtor_called); |
+ |
+ // The second commit aborts. |
+ EXPECT_FALSE(swap_promise_result_[1].did_swap_called); |
+ EXPECT_TRUE(swap_promise_result_[1].did_not_swap_called); |
+ EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_[1].reason); |
+ EXPECT_TRUE(swap_promise_result_[1].dtor_called); |
+ |
+ // The last commit completes but it does not cause swap buffer because |
+ // there is no damage in the frame data. |
+ EXPECT_FALSE(swap_promise_result_[2].did_swap_called); |
+ EXPECT_TRUE(swap_promise_result_[2].did_not_swap_called); |
+ EXPECT_EQ(SwapPromise::SWAP_FAILS, swap_promise_result_[2].reason); |
+ EXPECT_TRUE(swap_promise_result_[2].dtor_called); |
+ } |
+ |
+ int commit_count_; |
+ int commit_complete_count_; |
+ SwapPromiseResult swap_promise_result_[3]; |
+}; |
+ |
+MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise); |
+ |
} // namespace cc |