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 4b1c2e3a237cae4e8406f0cb8997286d4a116971..55091d8e5b3153e1a5dcbcdf11b3b2e9a46a1338 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/debug/test_web_graphics_context_3d.h" |
#include "cc/layers/content_layer.h" |
@@ -5202,4 +5203,137 @@ class LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface |
SINGLE_AND_MULTI_THREAD_TEST_F( |
LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface); |
+ |
+class LayerTreeHostTestAbortedCommitBreakSwapPromise |
+ : public LayerTreeHostTest { |
+ protected: |
+ LayerTreeHostTestAbortedCommitBreakSwapPromise() |
+ : commit_count_(0), commit_complete_count_(0), finish_promise_count_(0), |
+ break_promise_count_(0) {} |
+ |
+ virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
+ settings->begin_impl_frame_scheduling_enabled = true; |
+ } |
+ |
+ void FinishPromise() { |
+ finish_promise_count_++; |
+ } |
+ |
+ void BreakPromise(const std::string& msg) { |
+ break_promise_count_++; |
+ } |
+ |
+ virtual void WillBeginMainFrame() OVERRIDE { |
+ SwapPromise swap_promise( |
+ base::Bind( |
+ &LayerTreeHostTestAbortedCommitBreakSwapPromise::FinishPromise, |
+ base::Unretained(this)), |
+ base::Bind( |
+ &LayerTreeHostTestAbortedCommitBreakSwapPromise::BreakPromise, |
+ base::Unretained(this))); |
+ layer_tree_host()->QueueSwapPromise(swap_promise); |
+ } |
+ |
+ virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
+ |
+ virtual void DidCommit() OVERRIDE { |
+ commit_count_++; |
+ 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. |
+ host_impl->SetNeedsCommit(); |
+ } else { |
+ EndTest(); |
+ } |
+ } |
+ |
+ virtual void AfterTest() OVERRIDE { |
+ // 3 commits are scheduled. 2 completes. 1 is aborted. |
+ // The first completed commit casues swap buffer wihch finishes the promise. |
+ // The last completed commit does not reach swap buffer cause the |
+ // test is already ended. |
+ EXPECT_EQ(commit_count_, 3); |
+ EXPECT_EQ(commit_complete_count_, 2); |
+ EXPECT_EQ(finish_promise_count_, 1); |
+ EXPECT_EQ(break_promise_count_, 1); |
+ } |
+ |
+ int commit_count_; |
+ int commit_complete_count_; |
+ int finish_promise_count_; |
+ int break_promise_count_; |
+}; |
+ |
+MULTI_THREAD_TEST_F(LayerTreeHostTestAbortedCommitBreakSwapPromise); |
+ |
+ |
+class LayerTreeHostTestNoSwapBreakSwapPromise |
+ : public LayerTreeHostTest { |
+ protected: |
+ LayerTreeHostTestNoSwapBreakSwapPromise() |
+ : commit_count_(0), commit_complete_count_(0), finish_promise_count_(0), |
+ break_promise_count_(0) {} |
+ |
+ virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
+ settings->begin_impl_frame_scheduling_enabled = true; |
+ } |
+ |
+ void FinishPromise() { |
+ finish_promise_count_++; |
+ } |
+ |
+ void BreakPromise(const std::string& msg) { |
+ break_promise_count_++; |
+ } |
+ |
+ virtual void WillBeginMainFrame() OVERRIDE { |
+ SwapPromise swap_promise( |
+ base::Bind(&LayerTreeHostTestNoSwapBreakSwapPromise::FinishPromise, |
+ base::Unretained(this)), |
+ base::Bind(&LayerTreeHostTestNoSwapBreakSwapPromise::BreakPromise, |
+ base::Unretained(this))); |
+ layer_tree_host()->QueueSwapPromise(swap_promise); |
+ } |
+ |
+ virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
+ |
+ virtual void DidCommit() OVERRIDE { |
+ commit_count_++; |
+ // Schedule a new commit. |
+ layer_tree_host()->SetNeedsCommit(); |
+ } |
+ |
+ virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
+ commit_complete_count_++; |
+ if (commit_complete_count_ == 3) |
+ EndTest(); |
+ } |
+ |
+ virtual void AfterTest() OVERRIDE { |
+ // 3 commits are scheduled. 3 completes. |
+ // 2 completed commits reach swap buffer. the first swap buffer finishes |
+ // the promise. For the second swap buffer, no damage for the frame, so it |
+ // breaks the swap promise. The third commit does not reach the swap buffer |
+ // cause the test is ended. |
+ EXPECT_EQ(commit_count_, 3); |
+ EXPECT_EQ(commit_complete_count_, 3); |
+ EXPECT_EQ(finish_promise_count_, 1); |
+ EXPECT_EQ(break_promise_count_, 1); |
+ } |
+ |
+ int commit_count_; |
+ int commit_complete_count_; |
+ int finish_promise_count_; |
+ int break_promise_count_; |
+}; |
+ |
+MULTI_THREAD_TEST_F(LayerTreeHostTestNoSwapBreakSwapPromise); |
+ |
} // namespace cc |