Popular sites on the NTP: Try to keep the ordering constant
[chromium-blink-merge.git] / ash / screen_util_unittest.cc
blobf8d7f33eee44b4bb635e78df67d545b86979f136
1 // Copyright 2014 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.
5 #include "ash/screen_util.h"
7 #include "ash/display/display_manager.h"
8 #include "ash/root_window_controller.h"
9 #include "ash/shelf/shelf_layout_manager.h"
10 #include "ash/shelf/shelf_widget.h"
11 #include "ash/shell.h"
12 #include "ash/test/ash_test_base.h"
13 #include "ash/test/display_manager_test_api.h"
14 #include "ash/wm/window_util.h"
15 #include "ui/aura/env.h"
16 #include "ui/aura/window.h"
17 #include "ui/aura/window_event_dispatcher.h"
18 #include "ui/views/widget/widget.h"
19 #include "ui/views/widget/widget_delegate.h"
21 namespace ash {
22 namespace test {
24 typedef test::AshTestBase ScreenUtilTest;
26 TEST_F(ScreenUtilTest, Bounds) {
27 if (!SupportsMultipleDisplays())
28 return;
30 UpdateDisplay("600x600,500x500");
31 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()->
32 SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
34 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds(
35 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
36 primary->Show();
37 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds(
38 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100));
39 secondary->Show();
41 // Maximized bounds
42 EXPECT_EQ("0,0 600x597",
43 ScreenUtil::GetMaximizedWindowBoundsInParent(
44 primary->GetNativeView()).ToString());
45 EXPECT_EQ("0,0 500x453",
46 ScreenUtil::GetMaximizedWindowBoundsInParent(
47 secondary->GetNativeView()).ToString());
49 // Display bounds
50 EXPECT_EQ("0,0 600x600",
51 ScreenUtil::GetDisplayBoundsInParent(
52 primary->GetNativeView()).ToString());
53 EXPECT_EQ("0,0 500x500",
54 ScreenUtil::GetDisplayBoundsInParent(
55 secondary->GetNativeView()).ToString());
57 // Work area bounds
58 EXPECT_EQ("0,0 600x597",
59 ScreenUtil::GetDisplayWorkAreaBoundsInParent(
60 primary->GetNativeView()).ToString());
61 EXPECT_EQ("0,0 500x453",
62 ScreenUtil::GetDisplayWorkAreaBoundsInParent(
63 secondary->GetNativeView()).ToString());
66 // Test verifies a stable handling of secondary screen widget changes
67 // (crbug.com/226132).
68 TEST_F(ScreenUtilTest, StabilityTest) {
69 if (!SupportsMultipleDisplays())
70 return;
72 UpdateDisplay("600x600,500x500");
73 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds(
74 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100));
75 EXPECT_EQ(Shell::GetAllRootWindows()[1],
76 secondary->GetNativeView()->GetRootWindow());
77 secondary->Show();
78 secondary->Maximize();
79 secondary->Show();
80 secondary->SetFullscreen(true);
81 secondary->Hide();
82 secondary->Close();
85 TEST_F(ScreenUtilTest, ConvertRect) {
86 if (!SupportsMultipleDisplays())
87 return;
89 UpdateDisplay("600x600,500x500");
91 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds(
92 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
93 primary->Show();
94 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds(
95 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100));
96 secondary->Show();
98 EXPECT_EQ(
99 "0,0 100x100",
100 ScreenUtil::ConvertRectFromScreen(
101 primary->GetNativeView(), gfx::Rect(10, 10, 100, 100)).ToString());
102 EXPECT_EQ(
103 "10,10 100x100",
104 ScreenUtil::ConvertRectFromScreen(
105 secondary->GetNativeView(), gfx::Rect(620, 20, 100, 100)).ToString());
107 EXPECT_EQ(
108 "40,40 100x100",
109 ScreenUtil::ConvertRectToScreen(
110 primary->GetNativeView(), gfx::Rect(30, 30, 100, 100)).ToString());
111 EXPECT_EQ(
112 "650,50 100x100",
113 ScreenUtil::ConvertRectToScreen(
114 secondary->GetNativeView(), gfx::Rect(40, 40, 100, 100)).ToString());
117 TEST_F(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktop) {
118 if (!SupportsMultipleDisplays())
119 return;
120 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
122 display_manager->SetUnifiedDesktopEnabled(true);
124 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
125 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
127 UpdateDisplay("500x400");
128 EXPECT_EQ("0,0 500x400", ScreenUtil::GetShelfDisplayBoundsInScreen(
129 widget->GetNativeWindow()).ToString());
131 UpdateDisplay("500x400,600x400");
132 EXPECT_EQ("0,0 500x400", ScreenUtil::GetShelfDisplayBoundsInScreen(
133 widget->GetNativeWindow()).ToString());
135 // Move to the 2nd physical display. Shelf's display still should be
136 // the first.
137 widget->SetBounds(gfx::Rect(800, 0, 100, 100));
138 ASSERT_EQ("800,0 100x100", widget->GetWindowBoundsInScreen().ToString());
140 EXPECT_EQ("0,0 500x400", ScreenUtil::GetShelfDisplayBoundsInScreen(
141 widget->GetNativeWindow()).ToString());
143 UpdateDisplay("600x500");
144 EXPECT_EQ("0,0 600x500", ScreenUtil::GetShelfDisplayBoundsInScreen(
145 widget->GetNativeWindow()).ToString());
148 } // namespace test
149 } // namespace ash