[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 5 | #include "ash/screen_util.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 6 | |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 7 | #include "ash/root_window_controller.h" |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 8 | #include "ash/shelf/shelf_layout_manager.h" |
| 9 | #include "ash/shelf/shelf_widget.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 10 | #include "ash/shell.h" |
| 11 | #include "ash/test/ash_test_base.h" |
| 12 | #include "ash/wm/window_util.h" |
| 13 | #include "ui/aura/env.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 14 | #include "ui/aura/window.h" |
[email protected] | fcc51c95 | 2014-02-21 21:31:26 | [diff] [blame] | 15 | #include "ui/aura/window_event_dispatcher.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 16 | #include "ui/views/widget/widget.h" |
| 17 | #include "ui/views/widget/widget_delegate.h" |
| 18 | |
| 19 | namespace ash { |
| 20 | namespace test { |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 21 | |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 22 | typedef test::AshTestBase ScreenUtilTest; |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 23 | |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 24 | TEST_F(ScreenUtilTest, Bounds) { |
[email protected] | e75642a | 2013-06-12 17:21:18 | [diff] [blame] | 25 | if (!SupportsMultipleDisplays()) |
| 26 | return; |
| 27 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 28 | UpdateDisplay("600x600,500x500"); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 29 | Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()-> |
| 30 | SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 31 | |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 32 | views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( |
| 33 | NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 34 | primary->Show(); |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 35 | views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( |
| 36 | NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 37 | secondary->Show(); |
| 38 | |
| 39 | // Maximized bounds |
[email protected] | 7b675df61 | 2012-09-16 18:33:20 | [diff] [blame] | 40 | EXPECT_EQ("0,0 600x597", |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 41 | ScreenUtil::GetMaximizedWindowBoundsInParent( |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 42 | primary->GetNativeView()).ToString()); |
[email protected] | f54effe | 2013-09-05 01:09:02 | [diff] [blame] | 43 | EXPECT_EQ("0,0 500x453", |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 44 | ScreenUtil::GetMaximizedWindowBoundsInParent( |
[email protected] | 8c0ec43 | 2013-05-10 04:33:39 | [diff] [blame] | 45 | secondary->GetNativeView()).ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 46 | |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 47 | // Display bounds |
| 48 | EXPECT_EQ("0,0 600x600", |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 49 | ScreenUtil::GetDisplayBoundsInParent( |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 50 | primary->GetNativeView()).ToString()); |
| 51 | EXPECT_EQ("0,0 500x500", |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 52 | ScreenUtil::GetDisplayBoundsInParent( |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 53 | secondary->GetNativeView()).ToString()); |
| 54 | |
| 55 | // Work area bounds |
[email protected] | eefd51b2 | 2012-09-25 20:26:24 | [diff] [blame] | 56 | EXPECT_EQ("0,0 600x597", |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 57 | ScreenUtil::GetDisplayWorkAreaBoundsInParent( |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 58 | primary->GetNativeView()).ToString()); |
[email protected] | f54effe | 2013-09-05 01:09:02 | [diff] [blame] | 59 | EXPECT_EQ("0,0 500x453", |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 60 | ScreenUtil::GetDisplayWorkAreaBoundsInParent( |
[email protected] | 8c0ec43 | 2013-05-10 04:33:39 | [diff] [blame] | 61 | secondary->GetNativeView()).ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 62 | } |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 63 | |
[email protected] | 805155f | 2013-04-10 02:11:20 | [diff] [blame] | 64 | // Test verifies a stable handling of secondary screen widget changes |
| 65 | // (crbug.com/226132). |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 66 | TEST_F(ScreenUtilTest, StabilityTest) { |
[email protected] | e75642a | 2013-06-12 17:21:18 | [diff] [blame] | 67 | if (!SupportsMultipleDisplays()) |
| 68 | return; |
| 69 | |
[email protected] | 805155f | 2013-04-10 02:11:20 | [diff] [blame] | 70 | UpdateDisplay("600x600,500x500"); |
| 71 | views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( |
| 72 | NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); |
| 73 | EXPECT_EQ(Shell::GetAllRootWindows()[1], |
| 74 | secondary->GetNativeView()->GetRootWindow()); |
| 75 | secondary->Show(); |
| 76 | secondary->Maximize(); |
| 77 | secondary->Show(); |
| 78 | secondary->SetFullscreen(true); |
| 79 | secondary->Hide(); |
| 80 | secondary->Close(); |
| 81 | } |
| 82 | |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 83 | TEST_F(ScreenUtilTest, ConvertRect) { |
[email protected] | e75642a | 2013-06-12 17:21:18 | [diff] [blame] | 84 | if (!SupportsMultipleDisplays()) |
| 85 | return; |
| 86 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 87 | UpdateDisplay("600x600,500x500"); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 88 | |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 89 | views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( |
| 90 | NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 91 | primary->Show(); |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 92 | views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( |
| 93 | NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 94 | secondary->Show(); |
| 95 | |
| 96 | EXPECT_EQ( |
| 97 | "0,0 100x100", |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 98 | ScreenUtil::ConvertRectFromScreen( |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 99 | primary->GetNativeView(), gfx::Rect(10, 10, 100, 100)).ToString()); |
| 100 | EXPECT_EQ( |
| 101 | "10,10 100x100", |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 102 | ScreenUtil::ConvertRectFromScreen( |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 103 | secondary->GetNativeView(), gfx::Rect(620, 20, 100, 100)).ToString()); |
| 104 | |
| 105 | EXPECT_EQ( |
| 106 | "40,40 100x100", |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 107 | ScreenUtil::ConvertRectToScreen( |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 108 | primary->GetNativeView(), gfx::Rect(30, 30, 100, 100)).ToString()); |
| 109 | EXPECT_EQ( |
| 110 | "650,50 100x100", |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 111 | ScreenUtil::ConvertRectToScreen( |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 112 | secondary->GetNativeView(), gfx::Rect(40, 40, 100, 100)).ToString()); |
| 113 | } |
| 114 | |
| 115 | } // namespace test |
| 116 | } // namespace ash |