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

Side by Side Diff: content/browser/renderer_host/begin_frame_manager_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
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 "base/test/test_simple_task_runner.h"
9 #include "cc/output/begin_frame_args.h"
10 #include "cc/test/begin_frame_args_test.h"
11 #include "content/browser/renderer_host/begin_frame_manager.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/compositor/compositor.h"
14 #include "ui/compositor/test/context_factories_for_test.h"
15
16 namespace content {
17 namespace {
18
19 class TestBeginFrameManagerClient : public BeginFrameManagerClient {
20 public:
21 TestBeginFrameManagerClient() : begin_frame_sent_(false) {}
22 ~TestBeginFrameManagerClient() {}
23
24 // BeginFrameManagerClient:
25 void SendBeginFrame(const cc::BeginFrameArgs& args) override {
26 last_begin_frame_args_ = args;
27 begin_frame_sent_ = true;
28 }
29
30 bool begin_frame_sent() { return begin_frame_sent_; }
31 cc::BeginFrameArgs last_begin_frame_args() { return last_begin_frame_args_; }
32
33 private:
34 bool begin_frame_sent_;
35 cc::BeginFrameArgs last_begin_frame_args_;
36 };
37
38 class BeginFrameManagerTest : public testing::Test {
39 public:
40 BeginFrameManagerTest() {}
41 ~BeginFrameManagerTest() override {}
42
43 void SetUp() override {
44 bool enable_pixel_output = false;
45 ui::ContextFactory* context_factory =
46 ui::InitializeContextFactoryForTests(enable_pixel_output);
47 compositor_task_runner_ = new base::TestSimpleTaskRunner();
48 compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget,
49 context_factory,
50 compositor_task_runner_));
51 }
52
53 void TearDown() override {
54 compositor_.reset();
55 ui::TerminateContextFactoryForTests();
56 }
57
58 ui::Compositor* compositor() { return compositor_.get(); }
59
60 private:
61 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
62 scoped_ptr<ui::Compositor> compositor_;
63 };
64
65 } // namespace
66
67 TEST_F(BeginFrameManagerTest, BeginFrameScheduling) {
68 TestBeginFrameManagerClient client;
69 BeginFrameManager begin_frame_manager(&client);
70 begin_frame_manager.SetCompositor(compositor());
danakj 2015/03/17 18:56:45 Shall we also test setting the compositor to null
brianderson 2015/03/17 22:29:32 +1
simonhong 2015/03/19 15:48:46 Done.
71 begin_frame_manager.OnSetNeedsBeginFrames(true);
72 EXPECT_FALSE(client.begin_frame_sent());
73
74 cc::BeginFrameArgs args =
75 cc::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE,
76 base::TimeTicks::FromInternalValue(33));
77 compositor()->SendBeginFramesToChildren(args);
78 EXPECT_TRUE(client.begin_frame_sent());
79 EXPECT_EQ(args.frame_time, client.last_begin_frame_args().frame_time);
80
81 begin_frame_manager.ResetCompositor();
82 }
83
84 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698