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

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

Issue 775143003: cc: Implement unified BeginFrame on aura (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add unittest 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "cc/output/begin_frame_args.h"
9 #include "cc/test/begin_frame_args_test.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/compositor/compositor.h"
12 #include "ui/compositor/test/compositor_test_api.h"
13 #include "ui/compositor/test/context_factories_for_test.h"
14 #include "ui/compositor/test/test_compositor_host.h"
15 #include "ui/gfx/geometry/rect.h"
16
17 namespace ui {
18
19 namespace {
20
21 class TestCompositorBeginFrameObserver : public CompositorBeginFrameObserver {
22 public:
23 TestCompositorBeginFrameObserver() : send_begin_frame_called_(false) {}
24 ~TestCompositorBeginFrameObserver() override {}
25
26 void OnSendBeginFrame(const cc::BeginFrameArgs& args) override {
27 send_begin_frame_called_ = true;
28 }
29
30 void Reset() {
31 send_begin_frame_called_ = false;
32 }
33
34 bool send_begin_frame_called() { return send_begin_frame_called_; }
35
36 private:
37 bool send_begin_frame_called_;
38 };
39
40 class BeginFrameWithCompositorTest : public testing::Test {
41 public:
42 BeginFrameWithCompositorTest() {}
43 ~BeginFrameWithCompositorTest() override {}
44
45 // Overridden from testing::Test:
46 void SetUp() override {
47 bool enable_pixel_output = false;
48 ui::ContextFactory* context_factory =
49 InitializeContextFactoryForTests(enable_pixel_output);
50
51 const gfx::Rect host_bounds(10, 10, 500, 500);
danakj 2015/03/10 00:40:44 kHostBounds for compile time constants
52 compositor_host_.reset(
53 TestCompositorHost::Create(host_bounds, context_factory));
brianderson 2015/03/06 20:37:00 It looks like TestCompositorHost is used to test p
danakj 2015/03/10 00:40:44 I think brian is right here. If you don't need pix
54 compositor_host_->Show();
55
56 compositor_test_api_.reset(new CompositorTestAPI(GetCompositor()));
57 }
58
59 void TearDown() override {
60 compositor_host_.reset();
61 TerminateContextFactoryForTests();
62 }
63
64 Compositor* GetCompositor() { return compositor_host_->GetCompositor(); }
65
66 cc::BeginFrameArgs missed_begin_frame_args() {
67 return compositor_test_api_->missed_begin_frame_args();
68 }
69
70 private:
71 scoped_ptr<TestCompositorHost> compositor_host_;
72 scoped_ptr<CompositorTestAPI> compositor_test_api_;
73
74 DISALLOW_COPY_AND_ASSIGN(BeginFrameWithCompositorTest);
75 };
76
77 } // namespace
78
79 TEST_F(BeginFrameWithCompositorTest, AddBeginFrameObserver) {
brianderson 2015/03/06 20:36:59 The test looks good, but please add comments expla
80 cc::BeginFrameArgs last_args =
81 cc::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE,
82 base::TimeTicks::FromInternalValue(33));
83 cc::BeginFrameArgs new_args =
84 cc::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE,
85 base::TimeTicks::FromInternalValue(55));
86 TestCompositorBeginFrameObserver test_observer;
87
88 GetCompositor()->SendBeginFramesToChildren(new_args);
89 EXPECT_EQ(new_args.frame_time,
90 missed_begin_frame_args().frame_time);
91
92 GetCompositor()->AddBeginFrameObserver(&test_observer, last_args);
93 EXPECT_TRUE(test_observer.send_begin_frame_called());
94 GetCompositor()->RemoveBeginFrameObserver(&test_observer);
95
96 test_observer.Reset();
97 GetCompositor()->AddBeginFrameObserver(&test_observer, new_args);
98 EXPECT_FALSE(test_observer.send_begin_frame_called());
99 GetCompositor()->RemoveBeginFrameObserver(&test_observer);
100 }
101
102 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698