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

Side by Side Diff: cc/scheduler/scheduler_state_machine_unittest.cc

Issue 380763002: Add builders for tracing event's structural arguments (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed memory leak found by Linux ASAN Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/scheduler/scheduler_unittest.cc » ('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 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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 "cc/scheduler/scheduler_state_machine.h" 5 #include "cc/scheduler/scheduler_state_machine.h"
6 6
7 #include "base/debug/trace_event.h"
7 #include "cc/scheduler/scheduler.h" 8 #include "cc/scheduler/scheduler.h"
8 #include "cc/test/begin_frame_args_test.h" 9 #include "cc/test/begin_frame_args_test.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 #define EXPECT_ACTION_UPDATE_STATE(action) \ 12 #define EXPECT_ACTION_UPDATE_STATE(action) \
12 EXPECT_EQ(action, state.NextAction()) << *state.AsValue(); \ 13 EXPECT_EQ(action, state.NextAction()) << state.AsValue()->ToString(); \
13 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \ 14 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \
14 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \ 15 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \
15 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, \ 16 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, \
16 state.begin_impl_frame_state()) \ 17 state.begin_impl_frame_state()) \
17 << *state.AsValue(); \ 18 << state.AsValue()->ToString(); \
18 } \ 19 } \
19 state.UpdateState(action); \ 20 state.UpdateState(action); \
20 if (action == SchedulerStateMachine::ACTION_NONE) { \ 21 if (action == SchedulerStateMachine::ACTION_NONE) { \
21 if (state.begin_impl_frame_state() == \ 22 if (state.begin_impl_frame_state() == \
22 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) \ 23 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) \
23 state.OnBeginImplFrameDeadlinePending(); \ 24 state.OnBeginImplFrameDeadlinePending(); \
24 if (state.begin_impl_frame_state() == \ 25 if (state.begin_impl_frame_state() == \
25 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \ 26 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \
26 state.OnBeginImplFrameIdle(); \ 27 state.OnBeginImplFrameIdle(); \
27 } 28 }
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 state.SetVisible(visible); 684 state.SetVisible(visible);
684 685
685 // Case 1: needs_commit=false 686 // Case 1: needs_commit=false
686 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 687 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
687 state.NextAction()); 688 state.NextAction());
688 689
689 // Case 2: needs_commit=true 690 // Case 2: needs_commit=true
690 state.SetNeedsCommit(); 691 state.SetNeedsCommit();
691 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 692 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
692 state.NextAction()) 693 state.NextAction())
693 << *state.AsValue(); 694 << state.AsValue()->ToString();
694 } 695 }
695 } 696 }
696 697
697 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw 698 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw
698 // except if we're ready to commit, in which case we expect a commit first. 699 // except if we're ready to commit, in which case we expect a commit first.
699 for (size_t i = 0; i < num_commit_states; ++i) { 700 for (size_t i = 0; i < num_commit_states; ++i) {
700 StateMachine state(default_scheduler_settings); 701 StateMachine state(default_scheduler_settings);
701 state.SetCanStart(); 702 state.SetCanStart();
702 state.UpdateState(state.NextAction()); 703 state.UpdateState(state.NextAction());
703 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 704 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
704 state.SetCanDraw(true); 705 state.SetCanDraw(true);
705 state.SetCommitState(all_commit_states[i]); 706 state.SetCommitState(all_commit_states[i]);
706 state.SetBeginImplFrameState( 707 state.SetBeginImplFrameState(
707 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 708 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
708 709
709 state.SetNeedsRedraw(true); 710 state.SetNeedsRedraw(true);
710 state.SetVisible(true); 711 state.SetVisible(true);
711 712
712 SchedulerStateMachine::Action expected_action; 713 SchedulerStateMachine::Action expected_action;
713 if (all_commit_states[i] == 714 if (all_commit_states[i] ==
714 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { 715 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) {
715 expected_action = SchedulerStateMachine::ACTION_COMMIT; 716 expected_action = SchedulerStateMachine::ACTION_COMMIT;
716 } else { 717 } else {
717 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE; 718 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE;
718 EXPECT_EQ(state.NextAction(), SchedulerStateMachine::ACTION_ANIMATE) 719 EXPECT_EQ(state.NextAction(), SchedulerStateMachine::ACTION_ANIMATE)
719 << *state.AsValue(); 720 << state.AsValue()->ToString();
720 state.UpdateState(state.NextAction()); 721 state.UpdateState(state.NextAction());
721 } 722 }
722 723
723 // Case 1: needs_commit=false. 724 // Case 1: needs_commit=false.
724 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue(); 725 EXPECT_EQ(state.NextAction(), expected_action)
726 << state.AsValue()->ToString();
725 727
726 // Case 2: needs_commit=true. 728 // Case 2: needs_commit=true.
727 state.SetNeedsCommit(); 729 state.SetNeedsCommit();
728 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue(); 730 EXPECT_EQ(state.NextAction(), expected_action)
731 << state.AsValue()->ToString();
729 } 732 }
730 } 733 }
731 734
732 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { 735 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) {
733 SchedulerSettings default_scheduler_settings; 736 SchedulerSettings default_scheduler_settings;
734 737
735 size_t num_commit_states = 738 size_t num_commit_states =
736 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); 739 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState);
737 for (size_t i = 0; i < num_commit_states; ++i) { 740 for (size_t i = 0; i < num_commit_states; ++i) {
738 // There shouldn't be any drawing regardless of BeginImplFrame. 741 // There shouldn't be any drawing regardless of BeginImplFrame.
(...skipping 11 matching lines...) Expand all
750 } 753 }
751 754
752 // Case 1: needs_commit=false. 755 // Case 1: needs_commit=false.
753 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 756 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
754 state.NextAction()); 757 state.NextAction());
755 758
756 // Case 2: needs_commit=true. 759 // Case 2: needs_commit=true.
757 state.SetNeedsCommit(); 760 state.SetNeedsCommit();
758 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 761 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
759 state.NextAction()) 762 state.NextAction())
760 << *state.AsValue(); 763 << state.AsValue()->ToString();
761 } 764 }
762 } 765 }
763 } 766 }
764 767
765 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) { 768 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) {
766 SchedulerSettings default_scheduler_settings; 769 SchedulerSettings default_scheduler_settings;
767 770
768 size_t num_commit_states = 771 size_t num_commit_states =
769 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); 772 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState);
770 for (size_t i = 0; i < num_commit_states; ++i) { 773 for (size_t i = 0; i < num_commit_states; ++i) {
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 1651
1649 state.DidCreateAndInitializeOutputSurface(); 1652 state.DidCreateAndInitializeOutputSurface();
1650 EXPECT_EQ(state.output_surface_state(), 1653 EXPECT_EQ(state.output_surface_state(),
1651 SchedulerStateMachine::OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT); 1654 SchedulerStateMachine::OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT);
1652 1655
1653 // We should not send a BeginMainFrame when we are invisible, even if we've 1656 // We should not send a BeginMainFrame when we are invisible, even if we've
1654 // lost the output surface and are trying to get the first commit, since the 1657 // lost the output surface and are trying to get the first commit, since the
1655 // main thread will just abort anyway. 1658 // main thread will just abort anyway.
1656 state.SetVisible(false); 1659 state.SetVisible(false);
1657 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()) 1660 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction())
1658 << *state.AsValue(); 1661 << state.AsValue()->ToString();
1659 } 1662 }
1660 1663
1661 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) { 1664 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) {
1662 SchedulerSettings default_scheduler_settings; 1665 SchedulerSettings default_scheduler_settings;
1663 StateMachine state(default_scheduler_settings); 1666 StateMachine state(default_scheduler_settings);
1664 state.SetCanStart(); 1667 state.SetCanStart();
1665 state.UpdateState(state.NextAction()); 1668 state.UpdateState(state.NextAction());
1666 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1669 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1667 1670
1668 state.SetCanDraw(true); 1671 state.SetCanDraw(true);
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1899 state.SetNeedsAnimate(); 1902 state.SetNeedsAnimate();
1900 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1903 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1901 1904
1902 state.OnBeginImplFrameDeadline(); 1905 state.OnBeginImplFrameDeadline();
1903 EXPECT_ACTION_UPDATE_STATE( 1906 EXPECT_ACTION_UPDATE_STATE(
1904 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1907 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1905 } 1908 }
1906 1909
1907 } // namespace 1910 } // namespace
1908 } // namespace cc 1911 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/scheduler/scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698