Make USB permissions work in the new permission message system
[chromium-blink-merge.git] / content / browser / renderer_host / begin_frame_observer_proxy_unittest.cc
blobb54eadd7caef640b5766c5ac23116d6b58d52766
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.
5 #include <algorithm>
6 #include <list>
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/begin_frame_observer_proxy.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "ui/compositor/compositor.h"
18 #include "ui/compositor/test/context_factories_for_test.h"
20 using testing::Mock;
21 using testing::_;
23 namespace content {
24 namespace {
26 class MockBeginFrameObserverProxyClient : public BeginFrameObserverProxyClient {
27 public:
28 MOCK_METHOD1(SendBeginFrame, void(const cc::BeginFrameArgs&));
31 class BeginFrameObserverProxyTest : public testing::Test {
32 public:
33 BeginFrameObserverProxyTest() {}
34 ~BeginFrameObserverProxyTest() override {}
36 void SetUp() override {
37 bool enable_pixel_output = false;
38 ui::ContextFactory* context_factory =
39 ui::InitializeContextFactoryForTests(enable_pixel_output);
40 compositor_task_runner_ = new base::TestSimpleTaskRunner();
41 compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget,
42 context_factory,
43 compositor_task_runner_));
46 void TearDown() override {
47 compositor_.reset();
48 ui::TerminateContextFactoryForTests();
51 ui::Compositor* compositor() { return compositor_.get(); }
53 private:
54 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
55 scoped_ptr<ui::Compositor> compositor_;
58 } // namespace
60 TEST_F(BeginFrameObserverProxyTest, BeginFrameScheduling) {
61 MockBeginFrameObserverProxyClient client;
62 BeginFrameObserverProxy begin_frame_observer(&client);
63 begin_frame_observer.SetCompositor(compositor());
64 begin_frame_observer.SetNeedsBeginFrames(true);
66 // SendBeginFrame is called when new |args| is delivered.
67 cc::BeginFrameArgs args =
68 cc::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE,
69 base::TimeTicks::FromInternalValue(33));
70 EXPECT_CALL(client, SendBeginFrame(args));
71 compositor()->SendBeginFramesToChildren(args);
72 Mock::VerifyAndClearExpectations(&client);
74 // SendBeginFrame is called when new |args2| is delivered.
75 cc::BeginFrameArgs args2 =
76 cc::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE,
77 base::TimeTicks::FromInternalValue(66));
78 EXPECT_CALL(client, SendBeginFrame(args2));
79 compositor()->SendBeginFramesToChildren(args2);
80 Mock::VerifyAndClearExpectations(&client);
82 // SendBeginFrame is not called when used |args2| is delivered.
83 EXPECT_CALL(client, SendBeginFrame(_)).Times(0);
84 compositor()->SendBeginFramesToChildren(args2);
85 Mock::VerifyAndClearExpectations(&client);
87 // SendBeginFrame is not called when compositor is reset.
88 begin_frame_observer.ResetCompositor();
89 cc::BeginFrameArgs args3 =
90 cc::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE,
91 base::TimeTicks::FromInternalValue(99));
92 EXPECT_CALL(client, SendBeginFrame(_)).Times(0);
93 compositor()->SendBeginFramesToChildren(args3);
94 Mock::VerifyAndClearExpectations(&client);
97 } // namespace content