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

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: 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
88 // When |missed_begin_frame_args_| is sent, its type is set to MISSED.
89 cc::BeginFrameArgs expected_args(new_args);
90 expected_args.type = cc::BeginFrameArgs::MISSED;
91
92 MockCompositorBeginFrameObserver test_observer;
93 EXPECT_CALL(test_observer, OnSendBeginFrame(expected_args));
94 // When new observer is added, Compositor immediately sends BeginFrame with
95 // |missed_begin_frame_args_| when new observer didn't used it.
96 compositor()->AddBeginFrameObserver(&test_observer, last_args);
97 compositor()->RemoveBeginFrameObserver(&test_observer);
98 Mock::VerifyAndClearExpectations(&test_observer);
99
100 EXPECT_CALL(test_observer, OnSendBeginFrame(_)).Times(0);
101 //test_observer.Reset();
102 // BeginFrame is not sended immediately because new observer already used
103 // |missed_begin_frame_args_|.
104 compositor()->AddBeginFrameObserver(&test_observer, new_args);
105 compositor()->RemoveBeginFrameObserver(&test_observer);
106 }
107
64 } // namespace ui 108 } // 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