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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016 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 "gpu/ipc/service/gpu_vsync_provider.h"
6
7 #include <memory>
8
9 #include "base/bind.h"
10 #include "base/synchronization/lock.h"
11 #include "base/synchronization/waitable_event.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/base/win/hidden_window.h"
14
15 namespace gpu {
16
17 class GpuVSyncProviderTest : public testing::Test {
18 public:
19 GpuVSyncProviderTest()
20 : vsync_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
21 base::WaitableEvent::InitialState::NOT_SIGNALED) {}
22 ~GpuVSyncProviderTest() override {}
23
24 void SetUp() override {}
25
26 void TearDown() override {}
27
28 void OnVSync(base::TimeTicks timestamp) {
29 // This is called on VSync worker thread.
30 base::AutoLock lock(lock_);
31 if (++vsync_count_ == 3)
32 vsync_event_.Signal();
33 }
34
35 int vsync_count() {
36 base::AutoLock lock(lock_);
37 return vsync_count_;
38 }
39
40 void reset_vsync_count() {
41 base::AutoLock lock(lock_);
42 vsync_count_ = 0;
43 }
44
45 protected:
46 base::WaitableEvent vsync_event_;
47
48 private:
49 base::Lock lock_;
50 int vsync_count_ = 0;
51 };
52
53 TEST_F(GpuVSyncProviderTest, VSyncSignalTest) {
54 SurfaceHandle window = ui::GetHiddenWindow();
55
56 std::unique_ptr<GpuVSyncProvider> provider = GpuVSyncProvider::Create(
57 base::Bind(&GpuVSyncProviderTest::OnVSync, base::Unretained(this)),
58 window);
59
60 constexpr base::TimeDelta wait_timeout =
61 base::TimeDelta::FromMilliseconds(300);
62
63 // Verify that there are no VSync signals before provider is enabled
64 bool wait_result = vsync_event_.TimedWait(wait_timeout);
65 EXPECT_FALSE(wait_result);
66 EXPECT_EQ(0, vsync_count());
67
68 provider->EnableVSync(true);
69
70 vsync_event_.Wait();
71
72 provider->EnableVSync(false);
73
74 // Verify that VSync callbacks stop coming after disabling.
75 // Please note that it might still be possible for one
76 // callback to be in flight on VSync worker thread, so |vsync_count_|
77 // could still be incremented once, but not enough times to trigger
78 // |vsync_event_|.
79 reset_vsync_count();
80 wait_result = vsync_event_.TimedWait(wait_timeout);
81 EXPECT_FALSE(wait_result);
82 }
83
84 } // namespace gpu
OLDNEW
« 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