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

Side by Side Diff: components/exo/shell_surface_unittest.cc

Issue 1580033004: exo: Improve Maximize and Fullscreen support for ShellSurfaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add TODO Created 4 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 | « components/exo/shell_surface.cc ('k') | components/exo/touch_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "components/exo/buffer.h" 7 #include "components/exo/buffer.h"
8 #include "components/exo/shell_surface.h" 8 #include "components/exo/shell_surface.h"
9 #include "components/exo/surface.h" 9 #include "components/exo/surface.h"
10 #include "components/exo/test/exo_test_base.h" 10 #include "components/exo/test/exo_test_base.h"
11 #include "components/exo/test/exo_test_helper.h" 11 #include "components/exo/test/exo_test_helper.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/khronos/GLES2/gl2.h" 13 #include "third_party/khronos/GLES2/gl2.h"
14 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
15 #include "ui/views/widget/widget.h" 15 #include "ui/views/widget/widget.h"
16 16
17 namespace exo { 17 namespace exo {
18 namespace { 18 namespace {
19 19
20 using ShellSurfaceTest = test::ExoTestBase; 20 using ShellSurfaceTest = test::ExoTestBase;
21 21
22 TEST_F(ShellSurfaceTest, SetTopLevel) { 22 TEST_F(ShellSurfaceTest, Init) {
23 gfx::Size small_buffer_size(64, 64); 23 gfx::Size small_buffer_size(64, 64);
24 scoped_ptr<Buffer> small_buffer( 24 scoped_ptr<Buffer> small_buffer(
25 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(small_buffer_size), 25 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(small_buffer_size),
26 GL_TEXTURE_2D)); 26 GL_TEXTURE_2D));
27 gfx::Size large_buffer_size(256, 256); 27 gfx::Size large_buffer_size(256, 256);
28 scoped_ptr<Buffer> large_buffer( 28 scoped_ptr<Buffer> large_buffer(
29 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(large_buffer_size), 29 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(large_buffer_size),
30 GL_TEXTURE_2D)); 30 GL_TEXTURE_2D));
31 scoped_ptr<Surface> surface(new Surface); 31 scoped_ptr<Surface> surface(new Surface);
32 scoped_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 32 scoped_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
33 33
34 shell_surface->SetToplevel(); 34 shell_surface->Init();
35 ASSERT_TRUE(shell_surface->GetWidget());
36
35 surface->Attach(small_buffer.get()); 37 surface->Attach(small_buffer.get());
36 surface->Commit(); 38 surface->Commit();
37 ASSERT_TRUE(shell_surface->GetWidget());
38 EXPECT_EQ( 39 EXPECT_EQ(
39 small_buffer_size.ToString(), 40 small_buffer_size.ToString(),
40 shell_surface->GetWidget()->GetWindowBoundsInScreen().size().ToString()); 41 shell_surface->GetWidget()->GetWindowBoundsInScreen().size().ToString());
41 42
42 surface->Attach(large_buffer.get()); 43 surface->Attach(large_buffer.get());
43 surface->Commit(); 44 surface->Commit();
44 EXPECT_EQ( 45 EXPECT_EQ(
45 large_buffer_size.ToString(), 46 large_buffer_size.ToString(),
46 shell_surface->GetWidget()->GetWindowBoundsInScreen().size().ToString()); 47 shell_surface->GetWidget()->GetWindowBoundsInScreen().size().ToString());
47 } 48 }
48 49
49 TEST_F(ShellSurfaceTest, SetMaximized) { 50 TEST_F(ShellSurfaceTest, Maximize) {
50 gfx::Size buffer_size(256, 256); 51 gfx::Size buffer_size(256, 256);
51 scoped_ptr<Buffer> buffer(new Buffer( 52 scoped_ptr<Buffer> buffer(new Buffer(
52 exo_test_helper()->CreateGpuMemoryBuffer(buffer_size), GL_TEXTURE_2D)); 53 exo_test_helper()->CreateGpuMemoryBuffer(buffer_size), GL_TEXTURE_2D));
53 scoped_ptr<Surface> surface(new Surface); 54 scoped_ptr<Surface> surface(new Surface);
54 scoped_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 55 scoped_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
55 56
56 shell_surface->SetMaximized(); 57 shell_surface->Init();
57 surface->Attach(buffer.get()); 58 surface->Attach(buffer.get());
59 shell_surface->Maximize();
58 surface->Commit(); 60 surface->Commit();
59 EXPECT_EQ(CurrentContext()->bounds().width(), 61 EXPECT_EQ(CurrentContext()->bounds().width(),
60 shell_surface->GetWidget()->GetWindowBoundsInScreen().width()); 62 shell_surface->GetWidget()->GetWindowBoundsInScreen().width());
61 surface->Commit();
62 } 63 }
63 64
64 TEST_F(ShellSurfaceTest, SetFullscreen) { 65 TEST_F(ShellSurfaceTest, SetFullscreen) {
65 gfx::Size buffer_size(256, 256); 66 gfx::Size buffer_size(256, 256);
66 scoped_ptr<Buffer> buffer(new Buffer( 67 scoped_ptr<Buffer> buffer(new Buffer(
67 exo_test_helper()->CreateGpuMemoryBuffer(buffer_size), GL_TEXTURE_2D)); 68 exo_test_helper()->CreateGpuMemoryBuffer(buffer_size), GL_TEXTURE_2D));
68 scoped_ptr<Surface> surface(new Surface); 69 scoped_ptr<Surface> surface(new Surface);
69 scoped_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 70 scoped_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
70 71
71 shell_surface->SetFullscreen(); 72 shell_surface->Init();
73 shell_surface->SetFullscreen(true);
72 surface->Attach(buffer.get()); 74 surface->Attach(buffer.get());
73 surface->Commit(); 75 surface->Commit();
74 EXPECT_EQ(CurrentContext()->bounds().ToString(), 76 EXPECT_EQ(CurrentContext()->bounds().ToString(),
75 shell_surface->GetWidget()->GetWindowBoundsInScreen().ToString()); 77 shell_surface->GetWidget()->GetWindowBoundsInScreen().ToString());
76 } 78 }
77 79
78 TEST_F(ShellSurfaceTest, SetTitle) { 80 TEST_F(ShellSurfaceTest, SetTitle) {
79 scoped_ptr<Surface> surface(new Surface); 81 scoped_ptr<Surface> surface(new Surface);
80 scoped_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 82 scoped_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
81 83
82 shell_surface->SetTitle(base::string16(base::ASCIIToUTF16("test"))); 84 shell_surface->SetTitle(base::string16(base::ASCIIToUTF16("test")));
83 surface->Commit(); 85 surface->Commit();
84 } 86 }
85 87
86 TEST_F(ShellSurfaceTest, SetApplicationId) { 88 TEST_F(ShellSurfaceTest, SetApplicationId) {
87 scoped_ptr<Surface> surface(new Surface); 89 scoped_ptr<Surface> surface(new Surface);
88 scoped_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 90 scoped_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
89 91
90 shell_surface->SetToplevel(); 92 shell_surface->Init();
91 surface->Commit(); 93 surface->Commit();
92 EXPECT_EQ("", ShellSurface::GetApplicationId( 94 EXPECT_EQ("", ShellSurface::GetApplicationId(
93 shell_surface->GetWidget()->GetNativeWindow())); 95 shell_surface->GetWidget()->GetNativeWindow()));
94 shell_surface->SetApplicationId("test"); 96 shell_surface->SetApplicationId("test");
95 EXPECT_EQ("test", ShellSurface::GetApplicationId( 97 EXPECT_EQ("test", ShellSurface::GetApplicationId(
96 shell_surface->GetWidget()->GetNativeWindow())); 98 shell_surface->GetWidget()->GetNativeWindow()));
97 } 99 }
98 100
99 void DestroyShellSurface(scoped_ptr<ShellSurface>* shell_surface) { 101 void DestroyShellSurface(scoped_ptr<ShellSurface>* shell_surface) {
100 shell_surface->reset(); 102 shell_surface->reset();
101 } 103 }
102 104
103 TEST_F(ShellSurfaceTest, Move) { 105 TEST_F(ShellSurfaceTest, Move) {
104 scoped_ptr<Surface> surface(new Surface); 106 scoped_ptr<Surface> surface(new Surface);
105 scoped_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 107 scoped_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
106 108
107 // Map shell surface. 109 // Map shell surface.
108 shell_surface->SetToplevel(); 110 shell_surface->Init();
109 surface->Commit(); 111 surface->Commit();
110 112
111 // Post a task that will destroy the shell surface and then start an 113 // Post a task that will destroy the shell surface and then start an
112 // interactive move. The interactive move should end when surface is 114 // interactive move. The interactive move should end when surface is
113 // destroyed. 115 // destroyed.
114 base::MessageLoopForUI::current()->PostTask( 116 base::MessageLoopForUI::current()->PostTask(
115 FROM_HERE, 117 FROM_HERE,
116 base::Bind(&DestroyShellSurface, base::Unretained(&shell_surface))); 118 base::Bind(&DestroyShellSurface, base::Unretained(&shell_surface)));
117 shell_surface->Move(); 119 shell_surface->Move();
118 } 120 }
119 121
120 TEST_F(ShellSurfaceTest, SetGeometry) { 122 TEST_F(ShellSurfaceTest, SetGeometry) {
121 gfx::Size buffer_size(64, 64); 123 gfx::Size buffer_size(64, 64);
122 scoped_ptr<Buffer> buffer(new Buffer( 124 scoped_ptr<Buffer> buffer(new Buffer(
123 exo_test_helper()->CreateGpuMemoryBuffer(buffer_size), GL_TEXTURE_2D)); 125 exo_test_helper()->CreateGpuMemoryBuffer(buffer_size), GL_TEXTURE_2D));
124 scoped_ptr<Surface> surface(new Surface); 126 scoped_ptr<Surface> surface(new Surface);
125 scoped_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 127 scoped_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
126 128
127 shell_surface->SetToplevel(); 129 shell_surface->Init();
128 gfx::Rect geometry(16, 16, 32, 32); 130 gfx::Rect geometry(16, 16, 32, 32);
129 shell_surface->SetGeometry(geometry); 131 shell_surface->SetGeometry(geometry);
130 surface->Attach(buffer.get()); 132 surface->Attach(buffer.get());
131 surface->Commit(); 133 surface->Commit();
132 EXPECT_EQ( 134 EXPECT_EQ(
133 geometry.size().ToString(), 135 geometry.size().ToString(),
134 shell_surface->GetWidget()->GetWindowBoundsInScreen().size().ToString()); 136 shell_surface->GetWidget()->GetWindowBoundsInScreen().size().ToString());
135 EXPECT_EQ(gfx::Rect(gfx::Point() - geometry.OffsetFromOrigin(), buffer_size) 137 EXPECT_EQ(gfx::Rect(gfx::Point() - geometry.OffsetFromOrigin(), buffer_size)
136 .ToString(), 138 .ToString(),
137 surface->bounds().ToString()); 139 surface->bounds().ToString());
138 } 140 }
139 141
140 void Close(int* close_call_count) { 142 void Close(int* close_call_count) {
141 (*close_call_count)++; 143 (*close_call_count)++;
142 } 144 }
143 145
144 TEST_F(ShellSurfaceTest, CloseCallback) { 146 TEST_F(ShellSurfaceTest, CloseCallback) {
145 scoped_ptr<Surface> surface(new Surface); 147 scoped_ptr<Surface> surface(new Surface);
146 scoped_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 148 scoped_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
147 149
148 int close_call_count = 0; 150 int close_call_count = 0;
149 shell_surface->set_close_callback( 151 shell_surface->set_close_callback(
150 base::Bind(&Close, base::Unretained(&close_call_count))); 152 base::Bind(&Close, base::Unretained(&close_call_count)));
151 153
152 shell_surface->SetToplevel(); 154 shell_surface->Init();
153 surface->Commit(); 155 surface->Commit();
154 156
155 EXPECT_EQ(0, close_call_count); 157 EXPECT_EQ(0, close_call_count);
156 shell_surface->GetWidget()->Close(); 158 shell_surface->GetWidget()->Close();
157 EXPECT_EQ(1, close_call_count); 159 EXPECT_EQ(1, close_call_count);
158 } 160 }
159 161
160 TEST_F(ShellSurfaceTest, SurfaceDestroyedCallback) { 162 TEST_F(ShellSurfaceTest, SurfaceDestroyedCallback) {
161 scoped_ptr<Surface> surface(new Surface); 163 scoped_ptr<Surface> surface(new Surface);
162 scoped_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 164 scoped_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
163 165
164 shell_surface->set_surface_destroyed_callback( 166 shell_surface->set_surface_destroyed_callback(
165 base::Bind(&DestroyShellSurface, base::Unretained(&shell_surface))); 167 base::Bind(&DestroyShellSurface, base::Unretained(&shell_surface)));
166 168
167 shell_surface->SetToplevel(); 169 shell_surface->Init();
168 surface->Commit(); 170 surface->Commit();
169 171
170 EXPECT_TRUE(shell_surface.get()); 172 EXPECT_TRUE(shell_surface.get());
171 surface.reset(); 173 surface.reset();
172 EXPECT_FALSE(shell_surface.get()); 174 EXPECT_FALSE(shell_surface.get());
173 } 175 }
174 176
177 void Configure(gfx::Size* suggested_size, const gfx::Size& size) {
178 *suggested_size = size;
179 }
180
181 TEST_F(ShellSurfaceTest, ConfigureCallback) {
182 scoped_ptr<Surface> surface(new Surface);
183 scoped_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
184
185 shell_surface->Init();
186
187 gfx::Size suggested_size;
188 shell_surface->set_configure_callback(
189 base::Bind(&Configure, base::Unretained(&suggested_size)));
190 shell_surface->Maximize();
191 EXPECT_EQ(CurrentContext()->bounds().width(), suggested_size.width());
192
193 shell_surface->SetFullscreen(true);
194 EXPECT_EQ(CurrentContext()->bounds().size().ToString(),
195 suggested_size.ToString());
196 }
197
175 } // namespace 198 } // namespace
176 } // namespace exo 199 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/shell_surface.cc ('k') | components/exo/touch_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698