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

Side by Side Diff: content/browser/renderer_host/compositor_resize_lock_unittest.cc

Issue 2773433003: Fix CompositorResizeLock to do something. (Closed)
Patch Set: resizelock: . Created 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 "content/browser/renderer_host/compositor_resize_lock.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/compositor/test/fake_compositor_lock.h"
10
11 namespace content {
12 namespace {
13
14 class FakeCompositorResizeLockClient
15 : public CompositorResizeLockClient,
16 public NON_EXPORTED_BASE(ui::CompositorLockDelegate) {
17 public:
18 FakeCompositorResizeLockClient() {}
19
20 std::unique_ptr<ui::CompositorLock> GetCompositorLock(
21 ui::CompositorLockClient* client) override {
22 created_ = true;
23 compositor_lock_ = new ui::FakeCompositorLock(client, this);
24 return base::WrapUnique(compositor_lock_);
25 }
26
27 // CompositorResizeLockClient implementation.
28 void CompositorResizeLockEnded() override {
29 // This informs when the CompositorResizeLock ends for the client to
30 // release anything else it is holding.
31 ended_ = true;
32 }
33
34 // CompositorLockDelegate implementation.
35 void RemoveCompositorLock(ui::CompositorLock* lock) override {
36 // This is where the ui::Compositor would be physically unlocked.
37 unlocked_ = true;
38 }
39
40 void CauseTimeout() { compositor_lock_->TimeoutLock(); }
41
42 bool created() const { return created_; }
43 bool unlocked() const { return unlocked_; }
44 bool ended() const { return ended_; }
45
46 private:
47 bool created_ = false;
48 bool unlocked_ = false;
49 bool ended_ = false;
50 ui::FakeCompositorLock* compositor_lock_ = nullptr;
51 };
52
53 TEST(CompositorResizeLockTest, EndWithoutLock) {
54 FakeCompositorResizeLockClient resize_client;
55 gfx::Size resize_to(10, 11);
56
57 {
58 CompositorResizeLock resize_lock(&resize_client, resize_to);
59 EXPECT_FALSE(resize_client.created());
60 EXPECT_FALSE(resize_client.unlocked());
61 EXPECT_FALSE(resize_client.ended());
62 }
63 // The compositor was never locked.
64 EXPECT_FALSE(resize_client.unlocked());
65 // The resize lock tells the client when it is destroyed.
66 EXPECT_TRUE(resize_client.ended());
67 }
68
69 TEST(CompositorResizeLockTest, EndAfterLock) {
70 FakeCompositorResizeLockClient resize_client;
71 gfx::Size resize_to(10, 11);
72
73 {
74 CompositorResizeLock resize_lock(&resize_client, resize_to);
75 EXPECT_FALSE(resize_client.created());
76 EXPECT_FALSE(resize_client.ended());
77
78 resize_lock.Lock();
79 EXPECT_TRUE(resize_client.created());
80 EXPECT_FALSE(resize_client.ended());
81 }
82 // The resize lock unlocks the compositor when it ends.
83 EXPECT_TRUE(resize_client.unlocked());
84 // The resize lock tells the client when it ends.
85 EXPECT_TRUE(resize_client.ended());
86 }
87
88 TEST(CompositorResizeLockTest, EndAfterUnlock) {
89 FakeCompositorResizeLockClient resize_client;
90 gfx::Size resize_to(10, 11);
91
92 {
93 CompositorResizeLock resize_lock(&resize_client, resize_to);
94 EXPECT_FALSE(resize_client.created());
95 EXPECT_FALSE(resize_client.ended());
96
97 resize_lock.Lock();
98 EXPECT_TRUE(resize_client.created());
99 EXPECT_FALSE(resize_client.ended());
100
101 // Unlocking the compositor but keeping the resize lock.
102 resize_lock.UnlockCompositor();
103 EXPECT_TRUE(resize_client.unlocked());
104 EXPECT_FALSE(resize_client.ended());
105 }
106 // The resize lock tells the client when it ends.
107 EXPECT_TRUE(resize_client.ended());
108 }
109
110 TEST(CompositorResizeLockTest, EndAfterTimeout) {
111 FakeCompositorResizeLockClient resize_client;
112 gfx::Size resize_to(10, 11);
113
114 {
115 CompositorResizeLock resize_lock(&resize_client, resize_to);
116 EXPECT_FALSE(resize_client.created());
117 EXPECT_FALSE(resize_client.ended());
118
119 resize_lock.Lock();
120 EXPECT_TRUE(resize_client.created());
121 EXPECT_FALSE(resize_client.ended());
122
123 // A timeout tells the client that the lock ended.
124 resize_client.CauseTimeout();
125 EXPECT_TRUE(resize_client.unlocked());
126 EXPECT_TRUE(resize_client.ended());
127 }
128 }
129
130 } // namespace
131 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698