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

Side by Side Diff: cc/trees/layer_tree_host_unittest_proxy.cc

Issue 2000493002: cc: Fix overwriting of commit completion event in MFBA mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: better tests Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « cc/test/proxy_impl_for_test.cc ('k') | cc/trees/proxy_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/compiler_specific.h" 5 #include "base/compiler_specific.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "cc/test/fake_content_layer_client.h" 7 #include "cc/test/fake_content_layer_client.h"
8 #include "cc/test/fake_picture_layer.h" 8 #include "cc/test/fake_picture_layer.h"
9 #include "cc/test/layer_tree_test.h" 9 #include "cc/test/layer_tree_test.h"
10 #include "cc/trees/proxy_impl.h" 10 #include "cc/trees/proxy_impl.h"
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 } 273 }
274 274
275 private: 275 private:
276 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedSetNeedsCommitWhileAnimating); 276 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedSetNeedsCommitWhileAnimating);
277 }; 277 };
278 278
279 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedSetNeedsCommitWhileAnimating); 279 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedSetNeedsCommitWhileAnimating);
280 280
281 class ProxyMainThreadedCommitWaitsForActivation : public ProxyMainThreaded { 281 class ProxyMainThreadedCommitWaitsForActivation : public ProxyMainThreaded {
282 protected: 282 protected:
283 ProxyMainThreadedCommitWaitsForActivation() : commits_completed_(0) {} 283 ProxyMainThreadedCommitWaitsForActivation() : num_commits_(0) {}
284 ~ProxyMainThreadedCommitWaitsForActivation() override {} 284 ~ProxyMainThreadedCommitWaitsForActivation() override {}
285 285
286 void BeginTest() override { proxy()->SetNeedsCommit(); } 286 void BeginTest() override { proxy()->SetNeedsCommit(); }
287 287
288 void ScheduledActionCommit() override { 288 void ScheduledActionCommit() override {
289 switch (commits_completed_) { 289 switch (num_commits_) {
290 case 0: 290 case 0:
291 // The first commit does not wait for activation. Verify that the
292 // completion event is cleared.
293 EXPECT_FALSE(GetProxyImplForTest()->HasCommitCompletionEvent());
294 EXPECT_FALSE(GetProxyImplForTest()->GetNextCommitWaitsForActivation());
295
296 // Set next commit waits for activation and start another commit. 291 // Set next commit waits for activation and start another commit.
297 commits_completed_++;
298 PostNextCommitWaitsForActivationToMainThread(); 292 PostNextCommitWaitsForActivationToMainThread();
299 PostSetNeedsCommitToMainThread(); 293 PostSetNeedsCommitToMainThread();
300 break; 294 break;
301 case 1: 295 case 1:
302 // The second commit should be held until activation.
303 EXPECT_TRUE(GetProxyImplForTest()->HasCommitCompletionEvent());
304 EXPECT_TRUE(GetProxyImplForTest()->GetNextCommitWaitsForActivation());
305
306 // Start another commit to verify that this is not held until
307 // activation.
308 commits_completed_++;
309 PostSetNeedsCommitToMainThread(); 296 PostSetNeedsCommitToMainThread();
310 break; 297 break;
298 }
299 num_commits_++;
300 }
301
302 void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
303 CompletionEvent* activation_completion_event =
304 GetProxyImplForTest()->ActivationCompletionEventForTesting();
305 switch (num_commits_) {
306 case 1:
307 EXPECT_FALSE(activation_completion_event);
308 break;
311 case 2: 309 case 2:
312 // The third commit should not wait for activation. 310 EXPECT_TRUE(activation_completion_event);
313 EXPECT_FALSE(GetProxyImplForTest()->HasCommitCompletionEvent()); 311 EXPECT_FALSE(activation_completion_event->IsSignaled());
314 EXPECT_FALSE(GetProxyImplForTest()->GetNextCommitWaitsForActivation()); 312 break;
315 313 case 3:
316 commits_completed_++; 314 EXPECT_FALSE(activation_completion_event);
315 EndTest();
316 break;
317 } 317 }
318 } 318 }
319 319
320 void DidActivateSyncTree() override {
321 // The next_commit_waits_for_activation should have been cleared after the
322 // sync tree is activated.
323 EXPECT_FALSE(GetProxyImplForTest()->GetNextCommitWaitsForActivation());
324 if (commits_completed_ == 3)
325 EndTest();
326 }
327
328 void AfterTest() override { 320 void AfterTest() override {
329 // It is safe to read commits_completed_ on the main thread now since 321 // It is safe to read num_commits_ on the main thread now since AfterTest()
330 // AfterTest() runs after the LayerTreeHost is destroyed and the impl thread 322 // runs after the LayerTreeHost is destroyed and the impl thread tear down
331 // tear down is finished. 323 // is finished.
332 EXPECT_EQ(3, commits_completed_); 324 EXPECT_EQ(3, num_commits_);
333 } 325 }
334 326
335 private: 327 private:
336 int commits_completed_; 328 int num_commits_;
337 329
338 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedCommitWaitsForActivation); 330 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedCommitWaitsForActivation);
339 }; 331 };
340 332
341 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedCommitWaitsForActivation); 333 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedCommitWaitsForActivation);
342 334
335 // Test for a corner case of main frame before activation (MFBA) and commit
336 // waits for activation. If a commit (with wait for activation flag set)
337 // is ready before the activation for a previous commit then the activation
338 // should not signal the completion event of the second commit.
339 class ProxyMainThreadedCommitWaitsForActivationMFBA : public ProxyMainThreaded {
340 protected:
341 ProxyMainThreadedCommitWaitsForActivationMFBA() : num_commits_(0) {}
342 ~ProxyMainThreadedCommitWaitsForActivationMFBA() override {}
343
344 void InitializeSettings(LayerTreeSettings* settings) override {
345 settings->main_frame_before_activation_enabled = true;
346 ProxyMainThreaded::InitializeSettings(settings);
347 }
348
349 void BeginTest() override { proxy()->SetNeedsCommit(); }
350
351 // This is called right before NotifyReadyToCommit.
352 void StartCommitOnImpl() override {
353 switch (num_commits_) {
354 case 0:
355 // Block activation until next commit is ready.
356 GetProxyImplForTest()->BlockNotifyReadyToActivateForTesting(true);
357 break;
358 case 1:
359 // Unblock activation of first commit after second commit is ready.
360 ImplThreadTaskRunner()->PostTask(
361 FROM_HERE,
362 base::Bind(&ProxyImplForTest::BlockNotifyReadyToActivateForTesting,
363 base::Unretained(GetProxyImplForTest()), false));
364 break;
365 }
366 }
367
368 void ScheduledActionCommit() override {
369 switch (num_commits_) {
370 case 0:
371 // Set next commit waits for activation and start another commit.
372 PostNextCommitWaitsForActivationToMainThread();
373 PostSetNeedsCommitToMainThread();
374 break;
375 case 1:
376 PostSetNeedsCommitToMainThread();
377 break;
378 }
379 num_commits_++;
380 }
381
382 void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
383 CompletionEvent* activation_completion_event =
384 GetProxyImplForTest()->ActivationCompletionEventForTesting();
385 switch (num_commits_) {
386 case 1:
387 EXPECT_FALSE(activation_completion_event);
388 break;
389 case 2:
390 EXPECT_TRUE(activation_completion_event);
391 EXPECT_FALSE(activation_completion_event->IsSignaled());
392 break;
393 case 3:
394 EXPECT_FALSE(activation_completion_event);
395 EndTest();
396 break;
397 }
398 }
399
400 void AfterTest() override {
401 // It is safe to read num_commits_ on the main thread now since AfterTest()
402 // runs after the LayerTreeHost is destroyed and the impl thread tear down
403 // is finished.
404 EXPECT_EQ(3, num_commits_);
405 }
406
407 private:
408 int num_commits_;
409
410 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedCommitWaitsForActivationMFBA);
411 };
412
413 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedCommitWaitsForActivationMFBA);
414
343 } // namespace cc 415 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/proxy_impl_for_test.cc ('k') | cc/trees/proxy_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698