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

Side by Side Diff: ui/views/widget/widget_unittest.cc

Issue 1268643002: [Views] Fix WidgetTest.GetRestoredBounds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 4 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <algorithm> 5 #include <algorithm>
6 #include <set> 6 #include <set>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 23 matching lines...) Expand all
34 #if defined(OS_WIN) 34 #if defined(OS_WIN)
35 #include "ui/aura/window.h" 35 #include "ui/aura/window.h"
36 #include "ui/aura/window_tree_host.h" 36 #include "ui/aura/window_tree_host.h"
37 #include "ui/base/view_prop.h" 37 #include "ui/base/view_prop.h"
38 #include "ui/base/win/window_event_target.h" 38 #include "ui/base/win/window_event_target.h"
39 #include "ui/views/win/hwnd_util.h" 39 #include "ui/views/win/hwnd_util.h"
40 #endif 40 #endif
41 41
42 #if defined(OS_MACOSX) 42 #if defined(OS_MACOSX)
43 #include "base/mac/mac_util.h" 43 #include "base/mac/mac_util.h"
44 #include "ui/base/test/scoped_fake_nswindow_fullscreen.h"
44 #endif 45 #endif
45 46
46 namespace views { 47 namespace views {
47 namespace test { 48 namespace test {
48 49
49 namespace { 50 namespace {
50 51
51 // TODO(tdanderson): This utility function is used in different unittest 52 // TODO(tdanderson): This utility function is used in different unittest
52 // files. Move to a common location to avoid 53 // files. Move to a common location to avoid
53 // repeated code. 54 // repeated code.
(...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 widget->GetClientAreaBoundsInScreen().ToString()); 1275 widget->GetClientAreaBoundsInScreen().ToString());
1275 1276
1276 // Verify origin is stable for a frameless window as well. 1277 // Verify origin is stable for a frameless window as well.
1277 widget->SetSize(kTestSize); 1278 widget->SetSize(kTestSize);
1278 EXPECT_EQ(kTestBounds.origin().ToString(), 1279 EXPECT_EQ(kTestBounds.origin().ToString(),
1279 widget->GetWindowBoundsInScreen().origin().ToString()); 1280 widget->GetWindowBoundsInScreen().origin().ToString());
1280 1281
1281 widget->CloseNow(); 1282 widget->CloseNow();
1282 } 1283 }
1283 1284
1284 // Before being enabled on Mac, this was #ifdef(false). 1285 // Non-Desktop widgets need the shell to maximize/fullscreen window.
1285 // TODO(tapted): Fix this for DesktopNativeWidgets on other platforms. 1286 // Disable on Linux because windows restore to the wrong bounds.
1287 // See http://crbug.com/515369.
1288 #if defined(OS_CHROMEOS) || defined(OS_LINUX)
1289 #define MAYBE_GetRestoredBounds DISABLED_GetRestoredBounds
1290 #else
1291 #define MAYBE_GetRestoredBounds GetRestoredBounds
1292 #endif
1293
1294 // Test that GetRestoredBounds() returns the original bounds of the window.
1295 TEST_F(WidgetTest, MAYBE_GetRestoredBounds) {
1286 #if defined(OS_MACOSX) 1296 #if defined(OS_MACOSX)
1287 // Aura needs shell to maximize/fullscreen window. 1297 // Fullscreen on Mac requires an interactive UI test, fake them here.
1288 // NativeWidgetGtk doesn't implement GetRestoredBounds. 1298 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen;
1289 TEST_F(WidgetTest, GetRestoredBounds) { 1299 #endif
1290 Widget* toplevel = CreateTopLevelPlatformWidget(); 1300
1291 EXPECT_EQ(toplevel->GetWindowBoundsInScreen().ToString(), 1301 Widget* toplevel = CreateNativeDesktopWidget();
1292 toplevel->GetRestoredBounds().ToString());
1293 toplevel->Show(); 1302 toplevel->Show();
1303 // Initial restored bounds have non-zero size.
1304 EXPECT_FALSE(toplevel->GetRestoredBounds().IsEmpty());
1305
1306 const gfx::Rect bounds(100, 100, 200, 200);
1307 toplevel->SetBounds(bounds);
1308 EXPECT_EQ(bounds, toplevel->GetWindowBoundsInScreen());
1309 EXPECT_EQ(bounds, toplevel->GetRestoredBounds());
1310
1294 toplevel->Maximize(); 1311 toplevel->Maximize();
1295 RunPendingMessages(); 1312 RunPendingMessages();
1296 #if defined(OS_MACOSX) 1313 #if defined(OS_MACOSX)
1297 // Current expectation on Mac is to do nothing on Maximize. 1314 // Current expectation on Mac is to do nothing on Maximize.
1298 EXPECT_EQ(toplevel->GetWindowBoundsInScreen().ToString(), 1315 EXPECT_EQ(toplevel->GetWindowBoundsInScreen(), toplevel->GetRestoredBounds());
1299 toplevel->GetRestoredBounds().ToString());
1300 #else 1316 #else
1301 EXPECT_NE(toplevel->GetWindowBoundsInScreen().ToString(), 1317 EXPECT_NE(toplevel->GetWindowBoundsInScreen(), toplevel->GetRestoredBounds());
1302 toplevel->GetRestoredBounds().ToString());
1303 #endif 1318 #endif
1304 EXPECT_GT(toplevel->GetRestoredBounds().width(), 0); 1319 EXPECT_EQ(bounds, toplevel->GetRestoredBounds());
1305 EXPECT_GT(toplevel->GetRestoredBounds().height(), 0);
1306 1320
1307 toplevel->Restore(); 1321 toplevel->Restore();
1308 RunPendingMessages(); 1322 RunPendingMessages();
1309 EXPECT_EQ(toplevel->GetWindowBoundsInScreen().ToString(), 1323 EXPECT_EQ(bounds, toplevel->GetWindowBoundsInScreen());
1310 toplevel->GetRestoredBounds().ToString()); 1324 EXPECT_EQ(bounds, toplevel->GetRestoredBounds());
1311 1325
1312 toplevel->SetFullscreen(true); 1326 toplevel->SetFullscreen(true);
1313 RunPendingMessages(); 1327 RunPendingMessages();
1314 1328
1315 if (IsTestingSnowLeopard()) { 1329 if (IsTestingSnowLeopard()) {
1316 // Fullscreen not implemented for Snow Leopard. 1330 // Fullscreen not implemented for Snow Leopard.
1317 EXPECT_EQ(toplevel->GetWindowBoundsInScreen().ToString(), 1331 EXPECT_EQ(toplevel->GetWindowBoundsInScreen(),
1318 toplevel->GetRestoredBounds().ToString()); 1332 toplevel->GetRestoredBounds());
1319 } else { 1333 } else {
1320 EXPECT_NE(toplevel->GetWindowBoundsInScreen().ToString(), 1334 EXPECT_NE(toplevel->GetWindowBoundsInScreen(),
1321 toplevel->GetRestoredBounds().ToString()); 1335 toplevel->GetRestoredBounds());
1322 } 1336 }
1323 EXPECT_GT(toplevel->GetRestoredBounds().width(), 0); 1337 EXPECT_EQ(bounds, toplevel->GetRestoredBounds());
1324 EXPECT_GT(toplevel->GetRestoredBounds().height(), 0); 1338
1339 toplevel->SetFullscreen(false);
1340 RunPendingMessages();
1341 EXPECT_EQ(bounds, toplevel->GetWindowBoundsInScreen());
1342 EXPECT_EQ(bounds, toplevel->GetRestoredBounds());
1343
1344 toplevel->CloseNow();
1325 } 1345 }
1326 #endif
1327 1346
1328 // The key-event propagation from Widget happens differently on aura and 1347 // The key-event propagation from Widget happens differently on aura and
1329 // non-aura systems because of the difference in IME. So this test works only on 1348 // non-aura systems because of the difference in IME. So this test works only on
1330 // aura. 1349 // aura.
1331 TEST_F(WidgetTest, KeyboardInputEvent) { 1350 TEST_F(WidgetTest, KeyboardInputEvent) {
1332 Widget* toplevel = CreateTopLevelPlatformWidget(); 1351 Widget* toplevel = CreateTopLevelPlatformWidget();
1333 View* container = toplevel->client_view(); 1352 View* container = toplevel->client_view();
1334 1353
1335 Textfield* textfield = new Textfield(); 1354 Textfield* textfield = new Textfield();
1336 textfield->SetText(base::ASCIIToUTF16("some text")); 1355 textfield->SetText(base::ASCIIToUTF16("some text"));
(...skipping 2101 matching lines...) Expand 10 before | Expand all | Expand 10 after
3438 EXPECT_FALSE(widget->IsAlwaysOnTop()); 3457 EXPECT_FALSE(widget->IsAlwaysOnTop());
3439 widget->SetAlwaysOnTop(true); 3458 widget->SetAlwaysOnTop(true);
3440 EXPECT_TRUE(widget->IsAlwaysOnTop()); 3459 EXPECT_TRUE(widget->IsAlwaysOnTop());
3441 widget->SetAlwaysOnTop(false); 3460 widget->SetAlwaysOnTop(false);
3442 EXPECT_FALSE(widget->IsAlwaysOnTop()); 3461 EXPECT_FALSE(widget->IsAlwaysOnTop());
3443 widget->CloseNow(); 3462 widget->CloseNow();
3444 } 3463 }
3445 3464
3446 } // namespace test 3465 } // namespace test
3447 } // namespace views 3466 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698