Add vector icon gallery to views_examples_exe
[chromium-blink-merge.git] / ash / screen_util_unittest.cc
blob7fc9ae6314684c67d7ed641a89db17f41ae6d05d
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 test::DisplayManagerTestApi::EnableUnifiedDesktopForTest();
122 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
123 display_manager->SetDefaultMultiDisplayMode(DisplayManager::UNIFIED);
124 display_manager->SetMultiDisplayMode(DisplayManager::UNIFIED);
126 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
127 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
129 UpdateDisplay("500x400");
130 EXPECT_EQ("0,0 500x400", ScreenUtil::GetShelfDisplayBoundsInScreen(
131 widget->GetNativeWindow()).ToString());
133 UpdateDisplay("500x400,600x400");
134 EXPECT_EQ("0,0 500x400", ScreenUtil::GetShelfDisplayBoundsInScreen(
135 widget->GetNativeWindow()).ToString());
137 // Move to the 2nd physical display. Shelf's display still should be
138 // the first.
139 widget->SetBounds(gfx::Rect(800, 0, 100, 100));
140 ASSERT_EQ("800,0 100x100", widget->GetWindowBoundsInScreen().ToString());
142 EXPECT_EQ("0,0 500x400", ScreenUtil::GetShelfDisplayBoundsInScreen(
143 widget->GetNativeWindow()).ToString());
145 UpdateDisplay("600x500");
146 EXPECT_EQ("0,0 600x500", ScreenUtil::GetShelfDisplayBoundsInScreen(
147 widget->GetNativeWindow()).ToString());
150 } // namespace test
151 } // namespace ash