Don't consider a Bluetooth adapter present until it has an address.
[chromium-blink-merge.git] / ash / root_window_controller_unittest.cc
blob12b27e82b419d272393630c50dc5d7b4eb02bb0c
1 // Copyright (c) 2012 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/display/display_controller.h"
6 #include "ash/display/multi_display_manager.h"
7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h"
9 #include "ash/test/ash_test_base.h"
10 #include "ash/wm/window_util.h"
11 #include "ui/aura/env.h"
12 #include "ui/aura/root_window.h"
13 #include "ui/aura/test/event_generator.h"
14 #include "ui/aura/window.h"
15 #include "ui/views/controls/menu/menu_controller.h"
16 #include "ui/views/widget/widget.h"
17 #include "ui/views/widget/widget_delegate.h"
19 namespace ash {
20 namespace {
22 class TestDelegate : public views::WidgetDelegateView {
23 public:
24 explicit TestDelegate(bool system_modal) : system_modal_(system_modal) {}
25 virtual ~TestDelegate() {}
27 // Overridden from views::WidgetDelegate:
28 virtual views::View* GetContentsView() OVERRIDE {
29 return this;
32 virtual ui::ModalType GetModalType() const OVERRIDE {
33 return system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE;
36 private:
37 bool system_modal_;
38 DISALLOW_COPY_AND_ASSIGN(TestDelegate);
41 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
42 views::Widget* widget =
43 views::Widget::CreateWindowWithBounds(NULL, bounds);
44 widget->Show();
45 return widget;
48 views::Widget* CreateModalWidget(const gfx::Rect& bounds) {
49 views::Widget* widget =
50 views::Widget::CreateWindowWithBounds(new TestDelegate(true), bounds);
51 widget->Show();
52 return widget;
55 aura::Window* GetModalContainer(aura::RootWindow* root_window) {
56 return Shell::GetContainer(
57 root_window,
58 ash::internal::kShellWindowId_SystemModalContainer);
61 } // namespace
63 namespace test {
65 typedef test::AshTestBase RootWindowControllerTest;
67 TEST_F(RootWindowControllerTest, MoveWindows_Basic) {
68 UpdateDisplay("600x600,500x500");
69 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
71 views::Widget* normal = CreateTestWidget(gfx::Rect(650, 10, 100, 100));
72 EXPECT_EQ(root_windows[1], normal->GetNativeView()->GetRootWindow());
73 EXPECT_EQ("650,10 100x100", normal->GetWindowBoundsInScreen().ToString());
74 EXPECT_EQ("50,10 100x100",
75 normal->GetNativeView()->GetBoundsInRootWindow().ToString());
77 views::Widget* maximized = CreateTestWidget(gfx::Rect(700, 10, 100, 100));
78 maximized->Maximize();
79 EXPECT_EQ(root_windows[1], maximized->GetNativeView()->GetRootWindow());
80 #if !defined(OS_WIN)
81 // TODO(oshima): Window reports smaller screen size. Investigate why.
82 EXPECT_EQ("600,0 500x500", maximized->GetWindowBoundsInScreen().ToString());
83 EXPECT_EQ("0,0 500x500",
84 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
85 #endif
87 views::Widget* minimized = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
88 minimized->Minimize();
89 EXPECT_EQ(root_windows[1], minimized->GetNativeView()->GetRootWindow());
90 EXPECT_EQ("800,10 100x100",
91 minimized->GetWindowBoundsInScreen().ToString());
93 views::Widget* fullscreen = CreateTestWidget(gfx::Rect(900, 10, 100, 100));
94 fullscreen->SetFullscreen(true);
95 EXPECT_EQ(root_windows[1], fullscreen->GetNativeView()->GetRootWindow());
96 #if !defined(OS_WIN)
97 // TODO(oshima): Window reports smaller screen size. Investigate why.
98 EXPECT_EQ("600,0 500x500",
99 fullscreen->GetWindowBoundsInScreen().ToString());
100 EXPECT_EQ("0,0 500x500",
101 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
102 #endif
104 UpdateDisplay("600x600");
106 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
107 EXPECT_EQ("50,10 100x100", normal->GetWindowBoundsInScreen().ToString());
108 EXPECT_EQ("50,10 100x100",
109 normal->GetNativeView()->GetBoundsInRootWindow().ToString());
111 // Maximized area on primary display has 2px (given as
112 // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom.
113 EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow());
114 EXPECT_EQ("0,0 600x598",
115 maximized->GetWindowBoundsInScreen().ToString());
116 EXPECT_EQ("0,0 600x598",
117 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
119 EXPECT_EQ(root_windows[0], minimized->GetNativeView()->GetRootWindow());
120 EXPECT_EQ("200,10 100x100",
121 minimized->GetWindowBoundsInScreen().ToString());
123 EXPECT_EQ(root_windows[0], fullscreen->GetNativeView()->GetRootWindow());
124 EXPECT_TRUE(fullscreen->IsFullscreen());
125 EXPECT_EQ("0,0 600x600",
126 fullscreen->GetWindowBoundsInScreen().ToString());
127 EXPECT_EQ("0,0 600x600",
128 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
130 // Test if the restore bounds are correctly updated.
131 wm::RestoreWindow(maximized->GetNativeView());
132 EXPECT_EQ("100,10 100x100", maximized->GetWindowBoundsInScreen().ToString());
133 EXPECT_EQ("100,10 100x100",
134 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
136 fullscreen->SetFullscreen(false);
137 EXPECT_EQ("300,10 100x100",
138 fullscreen->GetWindowBoundsInScreen().ToString());
139 EXPECT_EQ("300,10 100x100",
140 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
143 TEST_F(RootWindowControllerTest, MoveWindows_Modal) {
144 UpdateDisplay("500x500,500x500");
146 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
147 // Emulate virtual screen coordinate system.
148 root_windows[0]->SetBounds(gfx::Rect(0, 0, 500, 500));
149 root_windows[1]->SetBounds(gfx::Rect(500, 0, 500, 500));
151 views::Widget* normal = CreateTestWidget(gfx::Rect(300, 10, 100, 100));
152 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
153 EXPECT_TRUE(wm::IsActiveWindow(normal->GetNativeView()));
155 views::Widget* modal = CreateModalWidget(gfx::Rect(650, 10, 100, 100));
156 EXPECT_EQ(root_windows[1], modal->GetNativeView()->GetRootWindow());
157 EXPECT_TRUE(GetModalContainer(root_windows[1])->Contains(
158 modal->GetNativeView()));
159 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
161 aura::test::EventGenerator generator_1st(root_windows[0]);
162 generator_1st.ClickLeftButton();
163 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
165 UpdateDisplay("500x500");
166 EXPECT_EQ(root_windows[0], modal->GetNativeView()->GetRootWindow());
167 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
168 generator_1st.ClickLeftButton();
169 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
172 } // namespace test
173 } // namespace ash