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

Unified Diff: content/browser/compositor/delegated_frame_host_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 side-by-side diff with in-line comments
Download patch
Index: content/browser/compositor/delegated_frame_host_unittest.cc
diff --git a/content/browser/compositor/delegated_frame_host_unittest.cc b/content/browser/compositor/delegated_frame_host_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..389ba5462b76a7fb4459365ae0144cb28f59c456
--- /dev/null
+++ b/content/browser/compositor/delegated_frame_host_unittest.cc
@@ -0,0 +1,126 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/memory/scoped_ptr.h"
+#include "cc/output/begin_frame_args.h"
+#include "cc/test/begin_frame_args_test.h"
+#include "content/browser/compositor/delegated_frame_host.h"
+#include "content/browser/compositor/resize_lock.h"
+#include "content/browser/compositor/test/no_transport_image_transport_factory.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/compositor/compositor.h"
+#include "ui/compositor/test/context_factories_for_test.h"
+
+namespace content {
+namespace {
+
+class FakeTaskRunner : public base::SingleThreadTaskRunner {
mithro-old 2015/03/11 03:42:58 There is a TestSimpleTaskRunner in base/test/test_
simonhong 2015/03/11 16:27:47 Removed. TestSimpleTaskRunner works well.
+ public:
+ FakeTaskRunner() {}
+
+ bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
+ const base::Closure& task,
+ base::TimeDelta delay) override {
+ return true;
+ }
+ bool PostDelayedTask(const tracked_objects::Location& from_here,
+ const base::Closure& task,
+ base::TimeDelta delay) override {
+ return true;
+ }
+ bool RunsTasksOnCurrentThread() const override { return true; }
+
+ protected:
+ ~FakeTaskRunner() override {}
+};
+
+class TestDelegatedFrameHostClient : public DelegatedFrameHostClient {
+ public:
+ TestDelegatedFrameHostClient() : begin_frame_sent_(false) {}
+ ~TestDelegatedFrameHostClient() {}
+
+ // DelegatedFrameHostClient:
+ ui::Layer* DelegatedFrameHostGetLayer() const override { return nullptr; }
+ bool DelegatedFrameHostIsVisible() const override { return true; }
+ gfx::Size DelegatedFrameHostDesiredSizeInDIP() const override {
+ return gfx::Size();
+ }
+ bool DelegatedFrameCanCreateResizeLock() const override { return true; }
+ scoped_ptr<ResizeLock> DelegatedFrameHostCreateResizeLock(
+ bool defer_compositor_lock) override { return nullptr; }
+ void DelegatedFrameHostResizeLockWasReleased() override {}
+ void DelegatedFrameHostSendCompositorSwapAck(
+ int output_surface_id,
+ const cc::CompositorFrameAck& ack) override {}
+ void DelegatedFrameHostSendReclaimCompositorResources(
+ int output_surface_id,
+ const cc::CompositorFrameAck& ack) override {}
+ void DelegatedFrameHostOnLostCompositorResources() override {}
+ void DelegatedFrameHostUpdateVSyncParameters(
+ const base::TimeTicks& timebase,
+ const base::TimeDelta& interval) override {}
+ void DelegatedFrameHostSendBeginFrame(
+ const cc::BeginFrameArgs& args) override {
+ begin_frame_sent_ = true;
+ }
+
+ bool begin_frame_sent() { return begin_frame_sent_; }
+
+ private:
+ bool begin_frame_sent_;
+};
+
+class DelegatedFrameHostTest : public testing::Test {
+ public:
+ DelegatedFrameHostTest() {}
+ ~DelegatedFrameHostTest() override {}
+
+ void SetUp() override {
+ bool enable_pixel_output = false;
+ ui::ContextFactory* context_factory =
+ ui::InitializeContextFactoryForTests(enable_pixel_output);
+ ImageTransportFactory::InitializeForUnitTests(
+ scoped_ptr<ImageTransportFactory>(
+ new NoTransportImageTransportFactory));
+ compositor_task_runner_ = new FakeTaskRunner();
+ compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget,
+ context_factory,
+ compositor_task_runner_.get()));
+ }
+
+ void TearDown() override {
+ compositor_.reset();
+ ui::TerminateContextFactoryForTests();
+ }
+
+ ui::Compositor* compositor() { return compositor_.get(); }
+
+ private:
+ scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
+ scoped_ptr<ui::Compositor> compositor_;
+ scoped_ptr<DelegatedFrameHost> delegated_frame_host_;
+};
+
+TEST_F(DelegatedFrameHostTest, BeginFrameScheduling) {
+ bool begin_frame_scheduling_enabled = true;
+ TestDelegatedFrameHostClient client;
+ DelegatedFrameHost delegated_frame_host(&client,
+ begin_frame_scheduling_enabled);
+ delegated_frame_host.SetCompositor(compositor());
+ delegated_frame_host.OnSetNeedsBeginFrames(true);
+ EXPECT_FALSE(client.begin_frame_sent());
+
+ cc::BeginFrameArgs args =
+ cc::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE,
+ base::TimeTicks::FromInternalValue(33));
+ compositor()->SendBeginFramesToChildren(args);
+ EXPECT_TRUE(client.begin_frame_sent());
mithro-old 2015/03/11 03:42:58 Can you check the right value is received somewher
simonhong 2015/03/11 16:27:47 frame_time check is added.
+
+ delegated_frame_host.ResetCompositor();
+}
+
+} // namespace
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698