Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(653)

Unified Diff: cc/trees/layer_tree_host_unittest.cc

Issue 2769213006: cc: If SetDeferCommits(true) happens inside the main frame, abort it. (Closed)
Patch Set: defer-inside-mainframe: comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | cc/trees/proxy_main.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 176f7baec707f3f1955cef2cf3849956102a253f..7a35dea31f7fc83540f5e4dc0b781176594cfcfb 100644
--- a/cc/trees/layer_tree_host_unittest.cc
+++ b/cc/trees/layer_tree_host_unittest.cc
@@ -2694,17 +2694,20 @@ SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousInvalidate);
class LayerTreeHostTestDeferCommits : public LayerTreeHostTest {
public:
- LayerTreeHostTestDeferCommits()
- : num_will_begin_impl_frame_(0), num_send_begin_main_frame_(0) {}
+ LayerTreeHostTestDeferCommits() = default;
- void BeginTest() override { PostSetNeedsCommitToMainThread(); }
+ void BeginTest() override {
+ // Start with commits deferred.
+ PostSetDeferCommitsToMainThread(true);
+ PostSetNeedsCommitToMainThread();
+ }
void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl,
const BeginFrameArgs& args) override {
+ // Impl frames happen while commits are deferred.
num_will_begin_impl_frame_++;
switch (num_will_begin_impl_frame_) {
case 1:
- break;
case 2:
case 3:
case 4:
@@ -2714,7 +2717,12 @@ class LayerTreeHostTestDeferCommits : public LayerTreeHostTest {
PostSetNeedsRedrawToMainThread();
break;
case 5:
- PostSetDeferCommitsToMainThread(false);
+ MainThreadTaskRunner()->PostTask(
+ FROM_HERE,
+ // Unretained because the test should not end before allowing
+ // commits via this running.
+ base::Bind(&LayerTreeHostTestDeferCommits::AllowCommits,
+ base::Unretained(this)));
break;
default:
// Sometimes |num_will_begin_impl_frame_| will be greater than 5 if the
@@ -2724,32 +2732,128 @@ class LayerTreeHostTestDeferCommits : public LayerTreeHostTest {
}
void WillBeginMainFrame() override {
+ EXPECT_TRUE(allow_commits_);
num_send_begin_main_frame_++;
- switch (num_send_begin_main_frame_) {
- case 1:
- layer_tree_host()->SetDeferCommits(true);
- break;
- case 2:
- EndTest();
- break;
- default:
- NOTREACHED();
- break;
- }
+ EndTest();
+ }
+
+ void AllowCommits() {
+ allow_commits_ = true;
+ layer_tree_host()->SetDeferCommits(false);
}
void AfterTest() override {
EXPECT_GE(num_will_begin_impl_frame_, 5);
- EXPECT_EQ(2, num_send_begin_main_frame_);
+ EXPECT_EQ(1, num_send_begin_main_frame_);
}
private:
- int num_will_begin_impl_frame_;
- int num_send_begin_main_frame_;
+ bool allow_commits_ = false;
+ int num_will_begin_impl_frame_ = 0;
+ int num_send_begin_main_frame_ = 0;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits);
+// This verifies that we can abort a commit inside the main frame, and
+// we don't leave any weird states around if we never allow the commit
enne (OOO) 2017/03/26 23:50:06 Thanks for testing both of these states. :D
+// to happen.
+class LayerTreeHostTestDeferCommitsInsideBeginMainFrame
+ : public LayerTreeHostTest {
+ public:
+ LayerTreeHostTestDeferCommitsInsideBeginMainFrame() = default;
+
+ void BeginTest() override { PostSetNeedsCommitToMainThread(); }
+
+ void WillBeginMainFrame() override {
+ ++begin_main_frame_count_;
+ if (allow_commits_)
+ return;
+
+ // This should prevent the commit from happening.
+ layer_tree_host()->SetDeferCommits(true);
+ // Wait to see if the commit happens. It's possible the deferred
enne (OOO) 2017/03/26 23:50:06 I looked at TestHooks and LayerTreeTest, but it do
+ // commit happens when it shouldn't but takes long enough that
+ // this passes. But it won't fail when it shouldn't.
+ MainThreadTaskRunner()->PostDelayedTask(
+ FROM_HERE,
+ // Unretained because the test doesn't end before this runs.
+ base::Bind(&LayerTreeTest::EndTest, base::Unretained(this)),
+ base::TimeDelta::FromMilliseconds(100));
+ }
+
+ void DidCommit() override { ++commit_count_; }
+
+ void AfterTest() override {
+ EXPECT_EQ(0, commit_count_);
+ EXPECT_EQ(1, begin_main_frame_count_);
+ }
+
+ private:
+ bool allow_commits_ = false;
+ int commit_count_ = 0;
+ int begin_main_frame_count_ = 0;
+};
+
+SINGLE_AND_MULTI_THREAD_TEST_F(
+ LayerTreeHostTestDeferCommitsInsideBeginMainFrame);
+
+// This verifies that we can abort a commit inside the main frame, and
+// we will finish the commit once it is allowed.
+class LayerTreeHostTestDeferCommitsInsideBeginMainFrameWithCommitAfter
+ : public LayerTreeHostTest {
+ public:
+ LayerTreeHostTestDeferCommitsInsideBeginMainFrameWithCommitAfter() = default;
+
+ void BeginTest() override { PostSetNeedsCommitToMainThread(); }
+
+ void WillBeginMainFrame() override {
+ ++begin_main_frame_count_;
+ if (allow_commits_)
+ return;
+
+ // This should prevent the commit from happening.
+ layer_tree_host()->SetDeferCommits(true);
+ // Wait to see if the commit happens. It's possible the deferred
+ // commit happens when it shouldn't but takes long enough that
+ // this passes. But it won't fail when it shouldn't.
+ MainThreadTaskRunner()->PostDelayedTask(
+ FROM_HERE,
+ // Unretained because the test doesn't end before this runs.
+ base::Bind(
+ &LayerTreeHostTestDeferCommitsInsideBeginMainFrameWithCommitAfter::
+ AllowCommits,
+ base::Unretained(this)),
+ base::TimeDelta::FromMilliseconds(100));
+ }
+
+ void AllowCommits() {
+ // Once we've waited and seen that commit did not happen, we
+ // allow commits and should see this one go through.
+ allow_commits_ = true;
+ layer_tree_host()->SetDeferCommits(false);
+ }
+
+ void DidCommit() override {
+ ++commit_count_;
+ EXPECT_TRUE(allow_commits_);
+ EndTest();
+ }
+
+ void AfterTest() override {
+ EXPECT_EQ(1, commit_count_);
+ EXPECT_EQ(2, begin_main_frame_count_);
+ }
+
+ private:
+ bool allow_commits_ = false;
+ int commit_count_ = 0;
+ int begin_main_frame_count_ = 0;
+};
+
+SINGLE_AND_MULTI_THREAD_TEST_F(
+ LayerTreeHostTestDeferCommitsInsideBeginMainFrameWithCommitAfter);
+
class LayerTreeHostTestCompositeImmediatelyStateTransitions
: public LayerTreeHostTest {
public:
« no previous file with comments | « no previous file | cc/trees/proxy_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698