net: Fix proxy_start times to include full resolution time.
[chromium-blink-merge.git] / ash / screen_util_unittest.cc
blob6e74390703d48e94194b46aeedaaf4a35baab5cc
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/wm/window_util.h"
14 #include "ui/aura/env.h"
15 #include "ui/aura/window.h"
16 #include "ui/aura/window_event_dispatcher.h"
17 #include "ui/views/widget/widget.h"
18 #include "ui/views/widget/widget_delegate.h"
20 namespace ash {
21 namespace test {
23 typedef test::AshTestBase ScreenUtilTest;
25 TEST_F(ScreenUtilTest, Bounds) {
26 if (!SupportsMultipleDisplays())
27 return;
29 UpdateDisplay("600x600,500x500");
30 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()->
31 SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
33 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds(
34 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
35 primary->Show();
36 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds(
37 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100));
38 secondary->Show();
40 // Maximized bounds
41 EXPECT_EQ("0,0 600x597",
42 ScreenUtil::GetMaximizedWindowBoundsInParent(
43 primary->GetNativeView()).ToString());
44 EXPECT_EQ("0,0 500x453",
45 ScreenUtil::GetMaximizedWindowBoundsInParent(
46 secondary->GetNativeView()).ToString());
48 // Display bounds
49 EXPECT_EQ("0,0 600x600",
50 ScreenUtil::GetDisplayBoundsInParent(
51 primary->GetNativeView()).ToString());
52 EXPECT_EQ("0,0 500x500",
53 ScreenUtil::GetDisplayBoundsInParent(
54 secondary->GetNativeView()).ToString());
56 // Work area bounds
57 EXPECT_EQ("0,0 600x597",
58 ScreenUtil::GetDisplayWorkAreaBoundsInParent(
59 primary->GetNativeView()).ToString());
60 EXPECT_EQ("0,0 500x453",
61 ScreenUtil::GetDisplayWorkAreaBoundsInParent(
62 secondary->GetNativeView()).ToString());
65 // Test verifies a stable handling of secondary screen widget changes
66 // (crbug.com/226132).
67 TEST_F(ScreenUtilTest, StabilityTest) {
68 if (!SupportsMultipleDisplays())
69 return;
71 UpdateDisplay("600x600,500x500");
72 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds(
73 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100));
74 EXPECT_EQ(Shell::GetAllRootWindows()[1],
75 secondary->GetNativeView()->GetRootWindow());
76 secondary->Show();
77 secondary->Maximize();
78 secondary->Show();
79 secondary->SetFullscreen(true);
80 secondary->Hide();
81 secondary->Close();
84 TEST_F(ScreenUtilTest, ConvertRect) {
85 if (!SupportsMultipleDisplays())
86 return;
88 UpdateDisplay("600x600,500x500");
90 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds(
91 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
92 primary->Show();
93 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds(
94 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100));
95 secondary->Show();
97 EXPECT_EQ(
98 "0,0 100x100",
99 ScreenUtil::ConvertRectFromScreen(
100 primary->GetNativeView(), gfx::Rect(10, 10, 100, 100)).ToString());
101 EXPECT_EQ(
102 "10,10 100x100",
103 ScreenUtil::ConvertRectFromScreen(
104 secondary->GetNativeView(), gfx::Rect(620, 20, 100, 100)).ToString());
106 EXPECT_EQ(
107 "40,40 100x100",
108 ScreenUtil::ConvertRectToScreen(
109 primary->GetNativeView(), gfx::Rect(30, 30, 100, 100)).ToString());
110 EXPECT_EQ(
111 "650,50 100x100",
112 ScreenUtil::ConvertRectToScreen(
113 secondary->GetNativeView(), gfx::Rect(40, 40, 100, 100)).ToString());
116 TEST_F(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktop) {
117 if (!SupportsMultipleDisplays())
118 return;
119 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
120 display_manager->SetDefaultMultiDisplayMode(DisplayManager::UNIFIED);
121 display_manager->SetMultiDisplayMode(DisplayManager::UNIFIED);
123 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
124 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
126 UpdateDisplay("500x400");
127 EXPECT_EQ("0,0 500x400", ScreenUtil::GetShelfDisplayBoundsInScreen(
128 widget->GetNativeWindow()).ToString());
130 UpdateDisplay("500x400,600x400");
131 EXPECT_EQ("0,0 500x400", ScreenUtil::GetShelfDisplayBoundsInScreen(
132 widget->GetNativeWindow()).ToString());
134 // Move to the 2nd physical display. Shelf's display still should be
135 // the first.
136 widget->SetBounds(gfx::Rect(800, 0, 100, 100));
137 ASSERT_EQ("800,0 100x100", widget->GetWindowBoundsInScreen().ToString());
139 EXPECT_EQ("0,0 500x400", ScreenUtil::GetShelfDisplayBoundsInScreen(
140 widget->GetNativeWindow()).ToString());
142 UpdateDisplay("600x500");
143 EXPECT_EQ("0,0 600x500", ScreenUtil::GetShelfDisplayBoundsInScreen(
144 widget->GetNativeWindow()).ToString());
147 } // namespace test
148 } // namespace ash