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

Unified Diff: gpu/ipc/service/gpu_vsync_provider_unittest_win.cc

Issue 2596123002: GpuVSyncProvider with unit test (Closed)
Patch Set: Added comment for GpuVSyncWorker destructor Created 3 years, 11 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 | « gpu/ipc/service/gpu_vsync_provider_posix.cc ('k') | gpu/ipc/service/gpu_vsync_provider_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/ipc/service/gpu_vsync_provider_unittest_win.cc
diff --git a/gpu/ipc/service/gpu_vsync_provider_unittest_win.cc b/gpu/ipc/service/gpu_vsync_provider_unittest_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2b96b4a493c80cd660f54c29283f334efc06b8cf
--- /dev/null
+++ b/gpu/ipc/service/gpu_vsync_provider_unittest_win.cc
@@ -0,0 +1,84 @@
+// Copyright (c) 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 "gpu/ipc/service/gpu_vsync_provider.h"
+
+#include <memory>
+
+#include "base/bind.h"
+#include "base/synchronization/lock.h"
+#include "base/synchronization/waitable_event.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/base/win/hidden_window.h"
+
+namespace gpu {
+
+class GpuVSyncProviderTest : public testing::Test {
+ public:
+ GpuVSyncProviderTest()
+ : vsync_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
+ base::WaitableEvent::InitialState::NOT_SIGNALED) {}
+ ~GpuVSyncProviderTest() override {}
+
+ void SetUp() override {}
+
+ void TearDown() override {}
+
+ void OnVSync(base::TimeTicks timestamp) {
+ // This is called on VSync worker thread.
+ base::AutoLock lock(lock_);
+ if (++vsync_count_ == 3)
+ vsync_event_.Signal();
+ }
+
+ int vsync_count() {
+ base::AutoLock lock(lock_);
+ return vsync_count_;
+ }
+
+ void reset_vsync_count() {
+ base::AutoLock lock(lock_);
+ vsync_count_ = 0;
+ }
+
+ protected:
+ base::WaitableEvent vsync_event_;
+
+ private:
+ base::Lock lock_;
+ int vsync_count_ = 0;
+};
+
+TEST_F(GpuVSyncProviderTest, VSyncSignalTest) {
+ SurfaceHandle window = ui::GetHiddenWindow();
+
+ std::unique_ptr<GpuVSyncProvider> provider = GpuVSyncProvider::Create(
+ base::Bind(&GpuVSyncProviderTest::OnVSync, base::Unretained(this)),
+ window);
+
+ constexpr base::TimeDelta wait_timeout =
+ base::TimeDelta::FromMilliseconds(300);
+
+ // Verify that there are no VSync signals before provider is enabled
+ bool wait_result = vsync_event_.TimedWait(wait_timeout);
+ EXPECT_FALSE(wait_result);
+ EXPECT_EQ(0, vsync_count());
+
+ provider->EnableVSync(true);
+
+ vsync_event_.Wait();
+
+ provider->EnableVSync(false);
+
+ // Verify that VSync callbacks stop coming after disabling.
+ // Please note that it might still be possible for one
+ // callback to be in flight on VSync worker thread, so |vsync_count_|
+ // could still be incremented once, but not enough times to trigger
+ // |vsync_event_|.
+ reset_vsync_count();
+ wait_result = vsync_event_.TimedWait(wait_timeout);
+ EXPECT_FALSE(wait_result);
+}
+
+} // namespace gpu
« no previous file with comments | « gpu/ipc/service/gpu_vsync_provider_posix.cc ('k') | gpu/ipc/service/gpu_vsync_provider_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698