Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 <algorithm> | |
| 6 #include <list> | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/compiler_specific.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/test/test_simple_task_runner.h" | |
| 12 #include "cc/output/begin_frame_args.h" | |
| 13 #include "cc/test/begin_frame_args_test.h" | |
| 14 #include "content/browser/renderer_host/compositor_begin_frame_observer_impl.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | |
| 16 #include "ui/compositor/compositor.h" | |
| 17 #include "ui/compositor/test/context_factories_for_test.h" | |
| 18 | |
| 19 namespace content { | |
| 20 namespace { | |
| 21 | |
| 22 class TestCompositorBeginFrameObserverImplClient | |
| 23 : public CompositorBeginFrameObserverImplClient { | |
| 24 public: | |
| 25 TestCompositorBeginFrameObserverImplClient() : begin_frame_sent_(false) {} | |
| 26 ~TestCompositorBeginFrameObserverImplClient() {} | |
| 27 | |
| 28 // CompositorBeginFrameObserverImplClient: | |
| 29 void SendBeginFrame(const cc::BeginFrameArgs& args) override { | |
| 30 last_begin_frame_args_ = args; | |
| 31 begin_frame_sent_ = true; | |
| 32 } | |
| 33 | |
| 34 bool begin_frame_sent() { return begin_frame_sent_; } | |
| 35 cc::BeginFrameArgs last_begin_frame_args() { return last_begin_frame_args_; } | |
| 36 | |
| 37 private: | |
| 38 bool begin_frame_sent_; | |
| 39 cc::BeginFrameArgs last_begin_frame_args_; | |
| 40 }; | |
| 41 | |
| 42 class CompositorBeginFrameObserverImplTest : public testing::Test { | |
| 43 public: | |
| 44 CompositorBeginFrameObserverImplTest() {} | |
| 45 ~CompositorBeginFrameObserverImplTest() override {} | |
| 46 | |
| 47 void SetUp() override { | |
| 48 bool enable_pixel_output = false; | |
| 49 ui::ContextFactory* context_factory = | |
| 50 ui::InitializeContextFactoryForTests(enable_pixel_output); | |
| 51 compositor_task_runner_ = new base::TestSimpleTaskRunner(); | |
| 52 compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget, | |
| 53 context_factory, | |
| 54 compositor_task_runner_)); | |
| 55 } | |
| 56 | |
| 57 void TearDown() override { | |
| 58 compositor_.reset(); | |
| 59 ui::TerminateContextFactoryForTests(); | |
| 60 } | |
| 61 | |
| 62 ui::Compositor* compositor() { return compositor_.get(); } | |
| 63 | |
| 64 private: | |
| 65 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | |
| 66 scoped_ptr<ui::Compositor> compositor_; | |
| 67 }; | |
| 68 | |
| 69 } // namespace | |
| 70 | |
| 71 TEST_F(CompositorBeginFrameObserverImplTest, BeginFrameScheduling) { | |
| 72 TestCompositorBeginFrameObserverImplClient client; | |
| 73 CompositorBeginFrameObserverImpl begin_frame_observer(&client); | |
| 74 begin_frame_observer.SetCompositor(compositor()); | |
| 75 begin_frame_observer.SetNeedsBeginFrames(true); | |
| 76 EXPECT_FALSE(client.begin_frame_sent()); | |
| 77 | |
| 78 cc::BeginFrameArgs args = | |
| 79 cc::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, | |
| 80 base::TimeTicks::FromInternalValue(33)); | |
| 81 compositor()->SendBeginFramesToChildren(args); | |
| 82 EXPECT_TRUE(client.begin_frame_sent()); | |
| 83 EXPECT_EQ(args.frame_time, client.last_begin_frame_args().frame_time); | |
| 84 | |
| 85 begin_frame_observer.ResetCompositor(); | |
| 86 } | |
| 87 | |
| 88 TEST_F(CompositorBeginFrameObserverImplTest, AddAndRemoveFromCompositor) { | |
| 89 TestCompositorBeginFrameObserverImplClient client; | |
| 90 CompositorBeginFrameObserverImpl begin_frame_observer(&client); | |
| 91 | |
| 92 std::list<ui::CompositorBeginFrameObserver*>& list = | |
| 93 compositor()->BeginFrameObserverListForTesting(); | |
| 94 EXPECT_TRUE(list.empty()); | |
| 95 | |
| 96 begin_frame_observer.SetNeedsBeginFrames(true); | |
| 97 begin_frame_observer.SetCompositor(compositor()); | |
| 98 std::list<ui::CompositorBeginFrameObserver*>::iterator it = | |
| 99 std::find(list.begin(), list.end(), &begin_frame_observer); | |
| 100 EXPECT_TRUE(list.end() != it); | |
| 101 | |
| 102 begin_frame_observer.ResetCompositor(); | |
| 103 EXPECT_TRUE(compositor()->BeginFrameObserverListForTesting().empty()); | |
|
danakj
2015/03/19 22:36:40
you could do this without exposing compositor impl
simonhong
2015/03/20 16:07:36
Yep, that way can verify.
I added that in the abov
| |
| 104 } | |
| 105 | |
| 106 } // namespace content | |
| OLD | NEW |