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

Side by Side Diff: ui/compositor/compositor_unittest.cc

Issue 1000503002: Add BeginFrameObserverProxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add BeginFrameManager Created 5 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 unified diff | Download patch
« ui/compositor/compositor.cc ('K') | « ui/compositor/compositor.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/test/test_simple_task_runner.h" 5 #include "base/test/test_simple_task_runner.h"
6 #include "cc/output/begin_frame_args.h"
7 #include "cc/test/begin_frame_args_test.h"
8 #include "testing/gmock/include/gmock/gmock.h"
6 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/compositor/compositor.h" 10 #include "ui/compositor/compositor.h"
8 #include "ui/compositor/test/context_factories_for_test.h" 11 #include "ui/compositor/test/context_factories_for_test.h"
9 12
13 using testing::Mock;
14 using testing::_;
15
10 namespace ui { 16 namespace ui {
11 namespace { 17 namespace {
12 18
19 class MockCompositorBeginFrameObserver : public CompositorBeginFrameObserver {
20 public:
21 MOCK_METHOD1(OnSendBeginFrame, void(const cc::BeginFrameArgs&));
22 };
23
13 // Test fixture for tests that require a ui::Compositor with a real task 24 // Test fixture for tests that require a ui::Compositor with a real task
14 // runner. 25 // runner.
15 class CompositorTest : public testing::Test { 26 class CompositorTest : public testing::Test {
16 public: 27 public:
17 CompositorTest() {} 28 CompositorTest() {}
18 ~CompositorTest() override {} 29 ~CompositorTest() override {}
19 30
20 void SetUp() override { 31 void SetUp() override {
21 task_runner_ = new base::TestSimpleTaskRunner; 32 task_runner_ = new base::TestSimpleTaskRunner;
22 33
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 EXPECT_FALSE(compositor()->IsLocked()); 65 EXPECT_FALSE(compositor()->IsLocked());
55 66
56 // Ensure that the lock does not time out when set. 67 // Ensure that the lock does not time out when set.
57 compositor()->SetLocksWillTimeOut(false); 68 compositor()->SetLocksWillTimeOut(false);
58 lock = compositor()->GetCompositorLock(); 69 lock = compositor()->GetCompositorLock();
59 EXPECT_TRUE(compositor()->IsLocked()); 70 EXPECT_TRUE(compositor()->IsLocked());
60 task_runner()->RunUntilIdle(); 71 task_runner()->RunUntilIdle();
61 EXPECT_TRUE(compositor()->IsLocked()); 72 EXPECT_TRUE(compositor()->IsLocked());
62 } 73 }
63 74
75 // Tests whether |missed_begin_frame_args_| is used immediately or not when new
76 // observer is added.
77 TEST_F(CompositorTest, AddBeginFrameObserver) {
78 cc::BeginFrameArgs last_args =
79 cc::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE,
80 base::TimeTicks::FromInternalValue(33));
81 cc::BeginFrameArgs new_args =
82 cc::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE,
83 base::TimeTicks::FromInternalValue(55));
84
85 // Simulate to trigger new BeginFrame by using |new_args|.
86 compositor()->SendBeginFramesToChildren(new_args);
87 // |new_args| is stored in |missed_begin_frame_args_| in Compositor for using
88 // later added observers.
89 EXPECT_EQ(new_args.frame_time,
90 compositor()->MissedBeginFrameArgsForTesting().frame_time);
danakj 2015/03/17 18:56:45 I don't think you need this check (or the ForTesti
simonhong 2015/03/19 15:48:46 Removed.
91
92 // When |missed_begin_frame_args_| is sent, its type is set to MISSED.
93 cc::BeginFrameArgs expected_args(new_args);
94 expected_args.type = cc::BeginFrameArgs::MISSED;
95
96 MockCompositorBeginFrameObserver test_observer;
97 EXPECT_CALL(test_observer, OnSendBeginFrame(expected_args));
danakj 2015/03/17 18:56:45 This is the right level of testing here.
98 // When new observer is added, Compositor immediately sends BeginFrame with
99 // |missed_begin_frame_args_| when new observer didn't used it.
100 compositor()->AddBeginFrameObserver(&test_observer, last_args);
101 compositor()->RemoveBeginFrameObserver(&test_observer);
102 Mock::VerifyAndClearExpectations(&test_observer);
103
104 EXPECT_CALL(test_observer, OnSendBeginFrame(_)).Times(0);
105 //test_observer.Reset();
106 // BeginFrame is not sended immediately because new observer already used
107 // |missed_begin_frame_args_|.
108 compositor()->AddBeginFrameObserver(&test_observer, new_args);
109 compositor()->RemoveBeginFrameObserver(&test_observer);
110 }
111
64 } // namespace ui 112 } // namespace ui
OLDNEW
« ui/compositor/compositor.cc ('K') | « ui/compositor/compositor.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698