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

Unified Diff: cc/trees/swap_promise_manager_unittest.cc

Issue 2323423002: cc: Add SwapPromiseManager and SurfaceSequenceGenerator. (Closed)
Patch Set: tests Created 4 years, 3 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
« no previous file with comments | « cc/trees/swap_promise_manager.cc ('k') | cc/trees/swap_promise_monitor.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/trees/swap_promise_manager_unittest.cc
diff --git a/cc/trees/swap_promise_manager_unittest.cc b/cc/trees/swap_promise_manager_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9ae203702215b5aee857d8fa3045b050dce01eec
--- /dev/null
+++ b/cc/trees/swap_promise_manager_unittest.cc
@@ -0,0 +1,72 @@
+// Copyright 2016 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 "cc/trees/swap_promise_manager.h"
+
+#include "base/memory/ptr_util.h"
+#include "cc/trees/swap_promise_monitor.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::StrictMock;
+
+namespace cc {
+namespace {
+
+class MockSwapPromiseMonitor : public SwapPromiseMonitor {
+ public:
+ explicit MockSwapPromiseMonitor(SwapPromiseManager* manager)
+ : SwapPromiseMonitor(manager, nullptr) {}
+ ~MockSwapPromiseMonitor() override {}
+
+ MOCK_METHOD0(OnSetNeedsCommitOnMain, void());
+ void OnSetNeedsRedrawOnImpl() override {}
+ void OnForwardScrollUpdateToMainThreadOnImpl() override {}
+};
+
+class MockSwapPromise : public SwapPromise {
+ public:
+ MockSwapPromise() {}
+ ~MockSwapPromise() override {}
+
+ void DidActivate() override {}
+ void DidSwap(CompositorFrameMetadata* metadata) override {}
+ DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override {
+ return DidNotSwapAction::BREAK_PROMISE;
+ }
+ MOCK_METHOD0(OnCommit, void());
+ int64_t TraceId() const override { return 0; }
+};
+
+TEST(SwapPromiseManagerTest, SwapPromiseMonitors) {
+ SwapPromiseManager manager;
+ StrictMock<MockSwapPromiseMonitor> monitor(&manager);
+
+ EXPECT_CALL(monitor, OnSetNeedsCommitOnMain()).Times(2);
+
+ manager.NotifySwapPromiseMonitorsOfSetNeedsCommit();
+ manager.NotifySwapPromiseMonitorsOfSetNeedsCommit();
+}
+
+TEST(SwapPromiseManagerTest, SwapPromises) {
+ SwapPromiseManager manager;
+ std::unique_ptr<StrictMock<MockSwapPromise>> swap_promise =
+ base::MakeUnique<StrictMock<MockSwapPromise>>();
+ MockSwapPromise* mock_promise = swap_promise.get();
+
+ manager.QueueSwapPromise(std::move(swap_promise));
+
+ EXPECT_CALL(*mock_promise, OnCommit()).Times(1);
+ manager.WillCommit();
+
+ std::vector<std::unique_ptr<SwapPromise>> swap_promise_list =
+ manager.TakeSwapPromises();
+ // Now that we've taken the promises, this shouldn't trigger a call.
+ manager.WillCommit();
+
+ EXPECT_EQ(1, static_cast<int>(swap_promise_list.size()));
+}
+
+} // namespace
+} // namespace cc
« no previous file with comments | « cc/trees/swap_promise_manager.cc ('k') | cc/trees/swap_promise_monitor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698