| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "athena/wm/split_view_controller.h" | 5 #include "athena/wm/split_view_controller.h" |
| 6 | 6 |
| 7 #include "athena/common/fill_layout_manager.h" | 7 #include "athena/common/fill_layout_manager.h" |
| 8 #include "athena/test/athena_test_base.h" | 8 #include "athena/test/athena_test_base.h" |
| 9 #include "athena/wm/public/window_list_provider.h" | 9 #include "athena/wm/public/window_list_provider.h" |
| 10 #include "athena/wm/window_list_provider_impl.h" |
| 10 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 11 #include "ui/aura/test/test_window_delegate.h" | 12 #include "ui/aura/test/test_window_delegate.h" |
| 12 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 13 | 14 |
| 14 namespace athena { | 15 namespace athena { |
| 15 | 16 |
| 16 typedef test::AthenaTestBase SplitViewControllerTest; | 17 typedef test::AthenaTestBase SplitViewControllerTest; |
| 17 | 18 |
| 18 class SimpleWindowListProvider : public WindowListProvider { | |
| 19 public: | |
| 20 explicit SimpleWindowListProvider(aura::Window* container) | |
| 21 : container_(container) {} | |
| 22 virtual ~SimpleWindowListProvider() {} | |
| 23 | |
| 24 // WindowListProvider: | |
| 25 virtual aura::Window::Windows GetWindowList() const OVERRIDE { | |
| 26 return container_->children(); | |
| 27 } | |
| 28 | |
| 29 virtual void MoveToFront(aura::Window* window) OVERRIDE { | |
| 30 CHECK_EQ(container_, window->parent()); | |
| 31 container_->StackChildAtTop(window); | |
| 32 } | |
| 33 | |
| 34 private: | |
| 35 aura::Window* container_; | |
| 36 | |
| 37 DISALLOW_COPY_AND_ASSIGN(SimpleWindowListProvider); | |
| 38 }; | |
| 39 | |
| 40 // Tests that when split mode is activated, the windows on the left and right | 19 // Tests that when split mode is activated, the windows on the left and right |
| 41 // are selected correctly. | 20 // are selected correctly. |
| 42 TEST_F(SplitViewControllerTest, SplitModeActivation) { | 21 TEST_F(SplitViewControllerTest, SplitModeActivation) { |
| 43 aura::test::TestWindowDelegate delegate; | 22 aura::test::TestWindowDelegate delegate; |
| 44 ScopedVector<aura::Window> windows; | 23 ScopedVector<aura::Window> windows; |
| 45 const int kNumWindows = 6; | 24 const int kNumWindows = 6; |
| 46 for (size_t i = 0; i < kNumWindows; ++i) { | 25 for (size_t i = 0; i < kNumWindows; ++i) { |
| 47 aura::Window* window = new aura::Window(&delegate); | 26 aura::Window* window = new aura::Window(&delegate); |
| 27 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
| 48 window->Init(aura::WINDOW_LAYER_SOLID_COLOR); | 28 window->Init(aura::WINDOW_LAYER_SOLID_COLOR); |
| 49 root_window()->AddChild(window); | 29 root_window()->AddChild(window); |
| 50 windows.push_back(window); | 30 windows.push_back(window); |
| 51 } | 31 } |
| 52 | 32 |
| 53 SimpleWindowListProvider list_provider(root_window()); | 33 scoped_ptr<WindowListProvider> list_provider( |
| 54 SplitViewController controller(root_window(), &list_provider, NULL); | 34 new WindowListProviderImpl(root_window())); |
| 35 SplitViewController controller(root_window(), list_provider.get()); |
| 55 ASSERT_FALSE(controller.IsSplitViewModeActive()); | 36 ASSERT_FALSE(controller.IsSplitViewModeActive()); |
| 56 | 37 |
| 57 controller.ActivateSplitMode(NULL, NULL); | 38 controller.ActivateSplitMode(NULL, NULL); |
| 58 ASSERT_TRUE(controller.IsSplitViewModeActive()); | 39 ASSERT_TRUE(controller.IsSplitViewModeActive()); |
| 59 // The last two windows should be on the left and right, respectively. | 40 // The last two windows should be on the left and right, respectively. |
| 60 EXPECT_EQ(windows[kNumWindows - 1], controller.left_window()); | 41 EXPECT_EQ(windows[kNumWindows - 1], controller.left_window()); |
| 61 EXPECT_EQ(windows[kNumWindows - 2], controller.right_window()); | 42 EXPECT_EQ(windows[kNumWindows - 2], controller.right_window()); |
| 62 | 43 |
| 63 // Select the window that is currently on the left for the right panel. The | 44 // Select the window that is currently on the left for the right panel. The |
| 64 // windows should switch. | 45 // windows should switch. |
| 65 controller.ActivateSplitMode(NULL, windows[kNumWindows - 1]); | 46 controller.ActivateSplitMode(NULL, windows[kNumWindows - 1]); |
| 66 EXPECT_EQ(windows[kNumWindows - 2], controller.left_window()); | 47 EXPECT_EQ(windows[kNumWindows - 2], controller.left_window()); |
| 67 EXPECT_EQ(windows[kNumWindows - 1], controller.right_window()); | 48 EXPECT_EQ(windows[kNumWindows - 1], controller.right_window()); |
| 68 | 49 |
| 69 controller.ActivateSplitMode(windows[kNumWindows - 1], NULL); | 50 controller.ActivateSplitMode(windows[kNumWindows - 1], NULL); |
| 70 EXPECT_EQ(windows[kNumWindows - 1], controller.left_window()); | 51 EXPECT_EQ(windows[kNumWindows - 1], controller.left_window()); |
| 71 EXPECT_EQ(windows[kNumWindows - 2], controller.right_window()); | 52 EXPECT_EQ(windows[kNumWindows - 2], controller.right_window()); |
| 72 | 53 |
| 73 // Select one of the windows behind the stacks for the right panel. The window | 54 // Select one of the windows behind the stacks for the right panel. The window |
| 74 // on the left should remain unchanged. | 55 // on the left should remain unchanged. |
| 75 controller.ActivateSplitMode(NULL, windows[0]); | 56 controller.ActivateSplitMode(NULL, windows[0]); |
| 76 EXPECT_EQ(windows[kNumWindows - 1], controller.left_window()); | 57 EXPECT_EQ(windows[kNumWindows - 1], controller.left_window()); |
| 77 EXPECT_EQ(windows[0], controller.right_window()); | 58 EXPECT_EQ(windows[0], controller.right_window()); |
| 78 EXPECT_EQ(windows[0], *list_provider.GetWindowList().rbegin()); | 59 EXPECT_EQ(windows[0], *list_provider->GetWindowList().rbegin()); |
| 79 | 60 |
| 80 controller.ActivateSplitMode(windows[1], NULL); | 61 controller.ActivateSplitMode(windows[1], NULL); |
| 81 EXPECT_EQ(windows[1], controller.left_window()); | 62 EXPECT_EQ(windows[1], controller.left_window()); |
| 82 EXPECT_EQ(windows[0], controller.right_window()); | 63 EXPECT_EQ(windows[0], controller.right_window()); |
| 83 EXPECT_EQ(windows[1], *list_provider.GetWindowList().rbegin()); | 64 EXPECT_EQ(windows[1], *list_provider->GetWindowList().rbegin()); |
| 84 | 65 |
| 85 controller.ActivateSplitMode(windows[4], windows[5]); | 66 controller.ActivateSplitMode(windows[4], windows[5]); |
| 86 EXPECT_EQ(windows[4], controller.left_window()); | 67 EXPECT_EQ(windows[4], controller.left_window()); |
| 87 EXPECT_EQ(windows[5], controller.right_window()); | 68 EXPECT_EQ(windows[5], controller.right_window()); |
| 88 EXPECT_EQ(windows[4], *list_provider.GetWindowList().rbegin()); | 69 EXPECT_EQ(windows[4], *list_provider->GetWindowList().rbegin()); |
| 89 EXPECT_EQ(windows[5], *(list_provider.GetWindowList().rbegin() + 1)); | 70 EXPECT_EQ(windows[5], *(list_provider->GetWindowList().rbegin() + 1)); |
| 90 } | 71 } |
| 91 | 72 |
| 92 } // namespace athena | 73 } // namespace athena |
| OLD | NEW |