Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "apps/ui/native_app_window.h" | 5 #include "apps/ui/native_app_window.h" |
| 6 #include "chrome/browser/apps/app_browsertest_util.h" | 6 #include "chrome/browser/apps/app_browsertest_util.h" |
| 7 #include "chrome/browser/extensions/extension_test_message_listener.h" | 7 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 8 #include "chrome/test/base/interactive_test_utils.h" | 8 #include "chrome/test/base/interactive_test_utils.h" |
| 9 | 9 |
| 10 #if defined(OS_MACOSX) && !defined(OS_IOS) | 10 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 11 #include "base/mac/mac_util.h" | 11 #include "base/mac/mac_util.h" |
| 12 #endif | 12 #endif |
| 13 | 13 |
| 14 #if defined(OS_WIN) | |
| 15 #include <windows.h> | |
| 16 #include "ui/aura/window.h" | |
| 17 #include "ui/aura/window_tree_host.h" | |
| 18 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h" | |
| 19 #include "ui/views/win/hwnd_message_handler_delegate.h" | |
| 20 #include "ui/views/win/hwnd_util.h" | |
| 21 #endif | |
| 22 | |
| 14 using apps::NativeAppWindow; | 23 using apps::NativeAppWindow; |
| 15 | 24 |
| 16 // Helper class that has to be created in the stack to check if the fullscreen | 25 // Helper class that has to be created in the stack to check if the fullscreen |
| 17 // setting of a NativeWindow has changed since the creation of the object. | 26 // setting of a NativeWindow has changed since the creation of the object. |
| 18 class FullscreenChangeWaiter { | 27 class FullscreenChangeWaiter { |
| 19 public: | 28 public: |
| 20 explicit FullscreenChangeWaiter(NativeAppWindow* window) | 29 explicit FullscreenChangeWaiter(NativeAppWindow* window) |
| 21 : window_(window), | 30 : window_(window), |
| 22 initial_fullscreen_state_(window_->IsFullscreen()) {} | 31 initial_fullscreen_state_(window_->IsFullscreen()) {} |
| 23 | 32 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 | 320 |
| 312 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); | 321 ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); |
| 313 | 322 |
| 314 // We assume that at that point, if we had to leave fullscreen, we should be. | 323 // We assume that at that point, if we had to leave fullscreen, we should be. |
| 315 // However, by nature, we can not guarantee that and given that we do test | 324 // However, by nature, we can not guarantee that and given that we do test |
| 316 // that nothing happens, we might end up with random-success when the feature | 325 // that nothing happens, we might end up with random-success when the feature |
| 317 // is broken. | 326 // is broken. |
| 318 EXPECT_TRUE(GetFirstAppWindow()->GetBaseWindow()->IsFullscreen()); | 327 EXPECT_TRUE(GetFirstAppWindow()->GetBaseWindow()->IsFullscreen()); |
| 319 } | 328 } |
| 320 | 329 |
| 330 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, TestInnerBounds) { | |
| 331 ASSERT_TRUE(RunAppWindowInteractiveTest("testInnerBounds")) << message_; | |
| 332 } | |
| 333 | |
| 334 // TODO(jackhou): Make this test work for other OSes. | |
| 335 #if !defined(OS_WIN) | |
| 336 #define MAYBE_TestOuterBounds DISABLED_TestOuterBounds | |
| 337 #else | |
| 338 #define MAYBE_TestOuterBounds TestOuterBounds | |
| 339 #endif | |
| 340 | |
| 341 // Test that the outer bounds match that of the native window. | |
| 342 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestOuterBounds) { | |
| 343 ExtensionTestMessageListener launched_listener("Launched", true); | |
|
benwells
2014/08/12 03:51:40
Nit: You don't need this listener. Just call LoadA
jackhou1
2014/08/12 06:12:07
Done.
| |
| 344 const extensions::Extension* app = | |
| 345 LoadAndLaunchPlatformApp("outer_bounds", &launched_listener); | |
| 346 | |
| 347 apps::AppWindow* window = GetFirstAppWindowForApp(app->id()); | |
| 348 gfx::Rect window_bounds; | |
| 349 gfx::Size min_size, max_size; | |
| 350 | |
| 351 #if defined(OS_WIN) | |
| 352 // Get the bounds from the HWND. | |
| 353 HWND hwnd = views::HWNDForNativeWindow(window->GetNativeWindow()); | |
| 354 RECT rect; | |
| 355 ::GetWindowRect(hwnd, &rect); | |
| 356 window_bounds = gfx::Rect( | |
| 357 rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); | |
| 358 | |
| 359 // HWNDMessageHandler calls this when responding to WM_GETMINMAXSIZE, so it's | |
| 360 // the closest to what the window will see. | |
| 361 views::HWNDMessageHandlerDelegate* host = | |
| 362 static_cast<views::HWNDMessageHandlerDelegate*>( | |
| 363 static_cast<views::DesktopWindowTreeHostWin*>( | |
| 364 aura::WindowTreeHost::GetForAcceleratedWidget(hwnd))); | |
| 365 host->GetMinMaxSize(&min_size, &max_size); | |
| 366 // Note that this does not include the the client area insets so we need to | |
| 367 // add them. | |
| 368 gfx::Insets insets; | |
| 369 host->GetClientAreaInsets(&insets); | |
| 370 min_size = gfx::Size(min_size.width() + insets.left() + insets.right(), | |
| 371 min_size.height() + insets.top() + insets.bottom()); | |
| 372 max_size = gfx::Size( | |
| 373 max_size.width() ? max_size.width() + insets.left() + insets.right() : 0, | |
| 374 max_size.height() ? max_size.height() + insets.top() + insets.bottom() | |
| 375 : 0); | |
| 376 #endif // defined(OS_WIN) | |
| 377 | |
| 378 // These match the values in the outer_bounds/test.js | |
| 379 EXPECT_EQ(gfx::Rect(10, 11, 300, 301), window_bounds); | |
| 380 EXPECT_EQ(window->GetBaseWindow()->GetBounds(), window_bounds); | |
| 381 EXPECT_EQ(200, min_size.width()); | |
| 382 EXPECT_EQ(201, min_size.height()); | |
| 383 EXPECT_EQ(400, max_size.width()); | |
| 384 EXPECT_EQ(401, max_size.height()); | |
| 385 } | |
| 386 | |
| 321 // This test does not work on Linux Aura because ShowInactive() is not | 387 // This test does not work on Linux Aura because ShowInactive() is not |
| 322 // implemented. See http://crbug.com/325142 | 388 // implemented. See http://crbug.com/325142 |
| 323 // It also does not work on Windows because of the document being focused even | 389 // It also does not work on Windows because of the document being focused even |
| 324 // though the window is not activated. See http://crbug.com/326986 | 390 // though the window is not activated. See http://crbug.com/326986 |
| 325 // It also does not work on MacOS because ::ShowInactive() ends up behaving like | 391 // It also does not work on MacOS because ::ShowInactive() ends up behaving like |
| 326 // ::Show() because of Cocoa conventions. See http://crbug.com/326987 | 392 // ::Show() because of Cocoa conventions. See http://crbug.com/326987 |
| 327 // Those tests should be disabled on Linux GTK when they are enabled on the | 393 // Those tests should be disabled on Linux GTK when they are enabled on the |
| 328 // other platforms, see http://crbug.com/328829 | 394 // other platforms, see http://crbug.com/328829 |
| 329 #if (defined(OS_LINUX) && defined(USE_AURA)) || \ | 395 #if (defined(OS_LINUX) && defined(USE_AURA)) || \ |
| 330 defined(OS_WIN) || defined(OS_MACOSX) | 396 defined(OS_WIN) || defined(OS_MACOSX) |
| 331 #define MAYBE_TestCreate DISABLED_TestCreate | 397 #define MAYBE_TestCreate DISABLED_TestCreate |
| 332 #define MAYBE_TestShow DISABLED_TestShow | 398 #define MAYBE_TestShow DISABLED_TestShow |
| 333 #else | 399 #else |
| 334 #define MAYBE_TestCreate TestCreate | 400 #define MAYBE_TestCreate TestCreate |
| 335 #define MAYBE_TestShow TestShow | 401 #define MAYBE_TestShow TestShow |
| 336 #endif | 402 #endif |
| 337 | 403 |
| 338 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestCreate) { | 404 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestCreate) { |
| 339 ASSERT_TRUE(RunAppWindowInteractiveTest("testCreate")) << message_; | 405 ASSERT_TRUE(RunAppWindowInteractiveTest("testCreate")) << message_; |
| 340 } | 406 } |
| 341 | 407 |
| 342 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestShow) { | 408 IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, MAYBE_TestShow) { |
| 343 ASSERT_TRUE(RunAppWindowInteractiveTest("testShow")) << message_; | 409 ASSERT_TRUE(RunAppWindowInteractiveTest("testShow")) << message_; |
| 344 } | 410 } |
| OLD | NEW |