OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/wm/panel_layout_manager.h" | 5 #include "ash/wm/panel_layout_manager.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/launcher/launcher.h" | 8 #include "ash/launcher/launcher.h" |
| 9 #include "ash/launcher/launcher_button.h" |
| 10 #include "ash/launcher/launcher_model.h" |
| 11 #include "ash/launcher/launcher_view.h" |
9 #include "ash/shell.h" | 12 #include "ash/shell.h" |
10 #include "ash/shell_window_ids.h" | 13 #include "ash/shell_window_ids.h" |
11 #include "ash/test/ash_test_base.h" | 14 #include "ash/test/ash_test_base.h" |
12 #include "ash/test/launcher_view_test_api.h" | 15 #include "ash/test/launcher_view_test_api.h" |
| 16 #include "ash/test/shell_test_api.h" |
13 #include "ash/test/test_launcher_delegate.h" | 17 #include "ash/test/test_launcher_delegate.h" |
14 #include "ash/wm/window_util.h" | 18 #include "ash/wm/window_util.h" |
15 #include "base/basictypes.h" | 19 #include "base/basictypes.h" |
16 #include "base/command_line.h" | 20 #include "base/command_line.h" |
17 #include "base/compiler_specific.h" | 21 #include "base/compiler_specific.h" |
18 #include "ui/aura/client/aura_constants.h" | 22 #include "ui/aura/client/aura_constants.h" |
| 23 #include "ui/aura/root_window.h" |
| 24 #include "ui/aura/test/event_generator.h" |
19 #include "ui/aura/test/test_windows.h" | 25 #include "ui/aura/test/test_windows.h" |
20 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
21 #include "ui/views/corewm/corewm_switches.h" | 27 #include "ui/views/corewm/corewm_switches.h" |
22 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
23 | 29 |
24 namespace ash { | 30 namespace ash { |
25 namespace internal { | 31 namespace internal { |
26 | 32 |
27 using aura::test::WindowIsAbove; | 33 using aura::test::WindowIsAbove; |
28 | 34 |
29 class PanelLayoutManagerTest : public ash::test::AshTestBase { | 35 class PanelLayoutManagerTest : public test::AshTestBase { |
30 public: | 36 public: |
31 PanelLayoutManagerTest() {} | 37 PanelLayoutManagerTest() {} |
32 virtual ~PanelLayoutManagerTest() {} | 38 virtual ~PanelLayoutManagerTest() {} |
33 | 39 |
34 virtual void SetUp() OVERRIDE { | 40 virtual void SetUp() OVERRIDE { |
35 ash::test::AshTestBase::SetUp(); | 41 test::AshTestBase::SetUp(); |
36 ASSERT_TRUE(ash::test::TestLauncherDelegate::instance()); | 42 ASSERT_TRUE(test::TestLauncherDelegate::instance()); |
37 | 43 |
38 launcher_view_test_.reset(new test::LauncherViewTestAPI( | 44 launcher_view_test_.reset(new test::LauncherViewTestAPI( |
39 Launcher::ForPrimaryDisplay()->GetLauncherViewForTest())); | 45 Launcher::ForPrimaryDisplay()->GetLauncherViewForTest())); |
40 launcher_view_test_->SetAnimationDuration(1); | 46 launcher_view_test_->SetAnimationDuration(1); |
41 } | 47 } |
42 | 48 |
43 aura::Window* CreateNormalWindow() { | 49 aura::Window* CreateNormalWindow() { |
44 return CreateTestWindowInShellWithBounds(gfx::Rect()); | 50 return CreateTestWindowInShellWithBounds(gfx::Rect()); |
45 } | 51 } |
46 | 52 |
47 aura::Window* CreatePanelWindow(const gfx::Rect& bounds) { | 53 aura::Window* CreatePanelWindow(const gfx::Rect& bounds) { |
48 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( | 54 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( |
49 NULL, | 55 NULL, |
50 aura::client::WINDOW_TYPE_PANEL, | 56 aura::client::WINDOW_TYPE_PANEL, |
51 0, | 57 0, |
52 bounds); | 58 bounds); |
53 ash::test::TestLauncherDelegate* launcher_delegate = | 59 test::TestLauncherDelegate* launcher_delegate = |
54 ash::test::TestLauncherDelegate::instance(); | 60 test::TestLauncherDelegate::instance(); |
55 launcher_delegate->AddLauncherItem(window); | 61 launcher_delegate->AddLauncherItem(window); |
56 PanelLayoutManager* manager = | 62 PanelLayoutManager* manager = |
57 static_cast<PanelLayoutManager*>(GetPanelContainer()->layout_manager()); | 63 static_cast<PanelLayoutManager*>(GetPanelContainer()->layout_manager()); |
58 manager->Relayout(); | 64 manager->Relayout(); |
59 return window; | 65 return window; |
60 } | 66 } |
61 | 67 |
62 aura::Window* GetPanelContainer() { | 68 aura::Window* GetPanelContainer() { |
63 return Shell::GetContainer( | 69 return Shell::GetContainer( |
64 Shell::GetPrimaryRootWindow(), | 70 Shell::GetPrimaryRootWindow(), |
65 ash::internal::kShellWindowId_PanelContainer); | 71 internal::kShellWindowId_PanelContainer); |
66 } | 72 } |
67 | 73 |
68 void GetCalloutWidget(views::Widget** widget) { | 74 void GetCalloutWidget(views::Widget** widget) { |
69 PanelLayoutManager* manager = | 75 PanelLayoutManager* manager = |
70 static_cast<PanelLayoutManager*>(GetPanelContainer()->layout_manager()); | 76 static_cast<PanelLayoutManager*>(GetPanelContainer()->layout_manager()); |
71 ASSERT_TRUE(manager); | 77 ASSERT_TRUE(manager); |
72 ASSERT_TRUE(manager->callout_widget()); | 78 ASSERT_TRUE(manager->callout_widget()); |
73 *widget = manager->callout_widget(); | 79 *widget = manager->callout_widget(); |
74 } | 80 } |
75 | 81 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 bool IsCalloutVisible() { | 129 bool IsCalloutVisible() { |
124 views::Widget* widget = NULL; | 130 views::Widget* widget = NULL; |
125 GetCalloutWidget(&widget); | 131 GetCalloutWidget(&widget); |
126 return widget->IsVisible(); | 132 return widget->IsVisible(); |
127 } | 133 } |
128 | 134 |
129 test::LauncherViewTestAPI* launcher_view_test() { | 135 test::LauncherViewTestAPI* launcher_view_test() { |
130 return launcher_view_test_.get(); | 136 return launcher_view_test_.get(); |
131 } | 137 } |
132 | 138 |
| 139 // Clicks the launcher items on |launcher_view| that is |
| 140 /// associated with given |window|. |
| 141 void ClickLauncherItemForWindow(LauncherView* launcher_view, |
| 142 aura::Window* window) { |
| 143 test::LauncherViewTestAPI test_api(launcher_view); |
| 144 test_api.SetAnimationDuration(1); |
| 145 |
| 146 LauncherModel* model = |
| 147 test::ShellTestApi(Shell::GetInstance()).launcher_model(); |
| 148 test::TestLauncherDelegate* launcher_delegate = |
| 149 test::TestLauncherDelegate::instance(); |
| 150 int index = model->ItemIndexByID(launcher_delegate->GetIDByWindow(window)); |
| 151 gfx::Rect bounds = test_api.GetButton(index)->GetBoundsInScreen(); |
| 152 |
| 153 aura::test::EventGenerator& event_generator = GetEventGenerator(); |
| 154 event_generator.MoveMouseTo(bounds.CenterPoint()); |
| 155 event_generator.ClickLeftButton(); |
| 156 |
| 157 test_api.RunMessageLoopUntilAnimationsDone(); |
| 158 } |
| 159 |
133 private: | 160 private: |
134 scoped_ptr<test::LauncherViewTestAPI> launcher_view_test_; | 161 scoped_ptr<test::LauncherViewTestAPI> launcher_view_test_; |
135 | 162 |
136 DISALLOW_COPY_AND_ASSIGN(PanelLayoutManagerTest); | 163 DISALLOW_COPY_AND_ASSIGN(PanelLayoutManagerTest); |
137 }; | 164 }; |
138 | 165 |
139 // Tests that a created panel window is successfully added to the panel | 166 // Tests that a created panel window is successfully added to the panel |
140 // layout manager. | 167 // layout manager. |
141 TEST_F(PanelLayoutManagerTest, AddOnePanel) { | 168 TEST_F(PanelLayoutManagerTest, AddOnePanel) { |
142 gfx::Rect bounds(0, 0, 201, 201); | 169 gfx::Rect bounds(0, 0, 201, 201); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 // should be hidden. | 344 // should be hidden. |
318 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 345 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
319 RunAllPendingInMessageLoop(); | 346 RunAllPendingInMessageLoop(); |
320 EXPECT_FALSE(IsCalloutVisible()); | 347 EXPECT_FALSE(IsCalloutVisible()); |
321 // Activate the window, ensure callout is visible. | 348 // Activate the window, ensure callout is visible. |
322 wm::ActivateWindow(window.get()); | 349 wm::ActivateWindow(window.get()); |
323 RunAllPendingInMessageLoop(); | 350 RunAllPendingInMessageLoop(); |
324 EXPECT_TRUE(IsCalloutVisible()); | 351 EXPECT_TRUE(IsCalloutVisible()); |
325 } | 352 } |
326 | 353 |
327 TEST_F(PanelLayoutManagerTest, PanelOnMultipleDisplays) { | 354 TEST_F(PanelLayoutManagerTest, PanelMoveBetweenMultipleDisplays) { |
328 UpdateDisplay("300x400,400x400"); | 355 // Keep the displays wide so that launchers have enough |
| 356 // spaces for launcher buttons. |
| 357 UpdateDisplay("500x400,500x400"); |
329 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 358 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
330 | 359 |
331 scoped_ptr<aura::Window> p1_d1(CreatePanelWindow(gfx::Rect(0, 0, 50, 50))); | 360 scoped_ptr<aura::Window> p1_d1(CreatePanelWindow(gfx::Rect(0, 0, 50, 50))); |
332 scoped_ptr<aura::Window> p2_d1(CreatePanelWindow(gfx::Rect(0, 0, 50, 50))); | 361 scoped_ptr<aura::Window> p2_d1(CreatePanelWindow(gfx::Rect(0, 0, 50, 50))); |
333 scoped_ptr<aura::Window> p1_d2(CreatePanelWindow(gfx::Rect(400, 0, 50, 50))); | 362 scoped_ptr<aura::Window> p1_d2(CreatePanelWindow(gfx::Rect(500, 0, 50, 50))); |
334 scoped_ptr<aura::Window> p2_d2(CreatePanelWindow(gfx::Rect(400, 0, 50, 50))); | 363 scoped_ptr<aura::Window> p2_d2(CreatePanelWindow(gfx::Rect(500, 0, 50, 50))); |
| 364 |
| 365 LauncherView* launcher_view_1st = |
| 366 Launcher::ForPrimaryDisplay()->GetLauncherViewForTest(); |
| 367 LauncherView* launcher_view_2nd = |
| 368 Launcher::ForWindow(root_windows[1])->GetLauncherViewForTest(); |
| 369 |
335 EXPECT_EQ(root_windows[0], p1_d1->GetRootWindow()); | 370 EXPECT_EQ(root_windows[0], p1_d1->GetRootWindow()); |
336 EXPECT_EQ(root_windows[0], p2_d1->GetRootWindow()); | 371 EXPECT_EQ(root_windows[0], p2_d1->GetRootWindow()); |
337 EXPECT_EQ(root_windows[1], p1_d2->GetRootWindow()); | 372 EXPECT_EQ(root_windows[1], p1_d2->GetRootWindow()); |
338 EXPECT_EQ(root_windows[1], p2_d2->GetRootWindow()); | 373 EXPECT_EQ(root_windows[1], p2_d2->GetRootWindow()); |
| 374 |
| 375 EXPECT_EQ(internal::kShellWindowId_PanelContainer, p1_d1->parent()->id()); |
| 376 EXPECT_EQ(internal::kShellWindowId_PanelContainer, p2_d1->parent()->id()); |
| 377 EXPECT_EQ(internal::kShellWindowId_PanelContainer, p1_d2->parent()->id()); |
| 378 EXPECT_EQ(internal::kShellWindowId_PanelContainer, p2_d2->parent()->id()); |
| 379 |
| 380 // Test a panel on 1st display. |
| 381 // Clicking on the same display has no effect. |
| 382 ClickLauncherItemForWindow(launcher_view_1st, p1_d1.get()); |
| 383 EXPECT_EQ(root_windows[0], p1_d1->GetRootWindow()); |
| 384 EXPECT_EQ(root_windows[0], p2_d1->GetRootWindow()); |
| 385 EXPECT_EQ(root_windows[1], p1_d2->GetRootWindow()); |
| 386 EXPECT_EQ(root_windows[1], p1_d2->GetRootWindow()); |
| 387 EXPECT_FALSE(root_windows[1]->GetBoundsInScreen().Contains( |
| 388 p1_d1->GetBoundsInScreen())); |
| 389 |
| 390 // Test if clicking on another display moves the panel to |
| 391 // that display. |
| 392 ClickLauncherItemForWindow(launcher_view_2nd, p1_d1.get()); |
| 393 EXPECT_EQ(root_windows[1], p1_d1->GetRootWindow()); |
| 394 EXPECT_EQ(root_windows[0], p2_d1->GetRootWindow()); |
| 395 EXPECT_EQ(root_windows[1], p1_d2->GetRootWindow()); |
| 396 EXPECT_EQ(root_windows[1], p2_d2->GetRootWindow()); |
| 397 EXPECT_TRUE(root_windows[1]->GetBoundsInScreen().Contains( |
| 398 p1_d1->GetBoundsInScreen())); |
| 399 |
| 400 // Test a panel on 2nd display. |
| 401 // Clicking on the same display has no effect. |
| 402 ClickLauncherItemForWindow(launcher_view_2nd, p1_d2.get()); |
| 403 EXPECT_EQ(root_windows[1], p1_d1->GetRootWindow()); |
| 404 EXPECT_EQ(root_windows[0], p2_d1->GetRootWindow()); |
| 405 EXPECT_EQ(root_windows[1], p1_d2->GetRootWindow()); |
| 406 EXPECT_EQ(root_windows[1], p2_d2->GetRootWindow()); |
| 407 EXPECT_TRUE(root_windows[1]->GetBoundsInScreen().Contains( |
| 408 p1_d2->GetBoundsInScreen())); |
| 409 |
| 410 // Test if clicking on another display moves the panel to |
| 411 // that display. |
| 412 ClickLauncherItemForWindow(launcher_view_1st, p1_d2.get()); |
| 413 EXPECT_EQ(root_windows[1], p1_d1->GetRootWindow()); |
| 414 EXPECT_EQ(root_windows[0], p2_d1->GetRootWindow()); |
| 415 EXPECT_EQ(root_windows[0], p1_d2->GetRootWindow()); |
| 416 EXPECT_EQ(root_windows[1], p2_d2->GetRootWindow()); |
| 417 EXPECT_TRUE(root_windows[0]->GetBoundsInScreen().Contains( |
| 418 p1_d2->GetBoundsInScreen())); |
339 } | 419 } |
340 | 420 |
341 } // namespace internal | 421 } // namespace internal |
342 } // namespace ash | 422 } // namespace ash |
OLD | NEW |