Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 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. | |
| 4 | |
| 5 #include "ash/wm/workspace/phantom_window_controller.h" | |
| 6 | |
| 7 #include "ash/ash_switches.h" | |
| 8 #include "ash/shell.h" | |
| 9 #include "ash/test/ash_test_base.h" | |
| 10 #include "ui/aura/root_window.h" | |
| 11 #include "ui/aura/window.h" | |
| 12 #include "ui/views/widget/widget.h" | |
| 13 | |
| 14 namespace ash { | |
| 15 namespace internal { | |
| 16 | |
| 17 // Returns true if |widget| is non-NULL and is visible. | |
| 18 bool IsVisible(views::Widget* widget) { | |
| 19 return widget && widget->IsVisible(); | |
| 20 } | |
| 21 | |
| 22 class PhantomWindowControllerTest : public ash::test::AshTestBase { | |
| 23 public: | |
| 24 PhantomWindowControllerTest() { | |
| 25 } | |
| 26 virtual ~PhantomWindowControllerTest() { | |
| 27 } | |
| 28 | |
| 29 // ash::test::AshTestBase: | |
| 30 virtual void SetUp() OVERRIDE { | |
| 31 ash::test::AshTestBase::SetUp(); | |
| 32 | |
| 33 UpdateDisplay("500x400,500x400"); | |
| 34 window_ = CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 50, 60)); | |
| 35 controller_.reset(new PhantomWindowController(window_)); | |
| 36 } | |
| 37 | |
| 38 PhantomWindowController* controller() { | |
| 39 return controller_.get(); | |
| 40 } | |
| 41 | |
| 42 aura::Window* window() { return window_; } | |
| 43 | |
| 44 views::Widget* target_widget() { | |
| 45 return controller_->target_phantom_widget_.get(); | |
| 46 } | |
| 47 | |
| 48 views::Widget* start_widget() { | |
| 49 return controller_->start_phantom_widget_.get(); | |
| 50 } | |
| 51 | |
| 52 private: | |
| 53 aura::Window* window_; | |
| 54 scoped_ptr<PhantomWindowController> controller_; | |
| 55 | |
| 56 DISALLOW_COPY_AND_ASSIGN(PhantomWindowControllerTest); | |
| 57 }; | |
| 58 | |
| 59 // Test that two phantom widgets are used when animating to bounds at least | |
| 60 // partially in another display. | |
| 61 TEST_F(PhantomWindowControllerTest, PhantomWindowShow) { | |
| 62 if (!SupportsMultipleDisplays()) | |
| 63 return; | |
| 64 | |
| 65 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | |
| 66 EXPECT_EQ(root_windows[0], window()->GetRootWindow()); | |
| 67 | |
| 68 // phantom widget only in the left screen. | |
| 69 controller()->Show(gfx::Rect(100, 100, 50, 60)); | |
| 70 EXPECT_TRUE(IsVisible(target_widget())); | |
| 71 EXPECT_FALSE(IsVisible(start_widget())); | |
| 72 EXPECT_EQ(root_windows[0], | |
| 73 target_widget()->GetNativeWindow()->GetRootWindow()); | |
| 74 | |
|
Mr4D (OOO till 08-26)
2013/12/19 17:56:55
Just wondering: Why did you get rid of the animati
pkotwicz
2013/12/19 18:18:22
I got rid of the animation completion because I am
| |
| 75 // Move phantom widget into the right screen. Test that 2 widgets got created. | |
| 76 controller()->Show(gfx::Rect(600, 100, 50, 60)); | |
| 77 EXPECT_TRUE(IsVisible(target_widget())); | |
| 78 EXPECT_TRUE(IsVisible(start_widget())); | |
| 79 EXPECT_EQ(root_windows[1], | |
| 80 target_widget()->GetNativeWindow()->GetRootWindow()); | |
| 81 EXPECT_EQ(root_windows[0], | |
| 82 start_widget()->GetNativeWindow()->GetRootWindow()); | |
| 83 | |
| 84 // Move phantom widget only in the right screen. Start widget should close. | |
| 85 controller()->Show(gfx::Rect(700, 100, 50, 60)); | |
| 86 EXPECT_TRUE(IsVisible(target_widget())); | |
| 87 EXPECT_FALSE(IsVisible(start_widget())); | |
| 88 EXPECT_EQ(root_windows[1], | |
| 89 target_widget()->GetNativeWindow()->GetRootWindow()); | |
| 90 | |
| 91 // Move phantom widget into the left screen. Start widget should open. | |
| 92 controller()->Show(gfx::Rect(100, 100, 50, 60)); | |
| 93 EXPECT_TRUE(IsVisible(target_widget())); | |
| 94 EXPECT_TRUE(IsVisible(start_widget())); | |
| 95 EXPECT_EQ(root_windows[0], | |
| 96 target_widget()->GetNativeWindow()->GetRootWindow()); | |
| 97 EXPECT_EQ(root_windows[1], | |
| 98 start_widget()->GetNativeWindow()->GetRootWindow()); | |
| 99 | |
| 100 // Move phantom widget while in the left screen. Start widget should close. | |
| 101 controller()->Show(gfx::Rect(200, 100, 50, 60)); | |
| 102 EXPECT_TRUE(IsVisible(target_widget())); | |
| 103 EXPECT_FALSE(IsVisible(start_widget())); | |
| 104 EXPECT_EQ(root_windows[0], | |
| 105 target_widget()->GetNativeWindow()->GetRootWindow()); | |
| 106 | |
| 107 // Move phantom widget spanning both screens with most of the window in the | |
| 108 // right screen. Two widgets are created. | |
| 109 controller()->Show(gfx::Rect(495, 100, 50, 60)); | |
| 110 EXPECT_TRUE(IsVisible(target_widget())); | |
| 111 EXPECT_TRUE(IsVisible(start_widget())); | |
| 112 EXPECT_EQ(root_windows[1], | |
| 113 target_widget()->GetNativeWindow()->GetRootWindow()); | |
| 114 EXPECT_EQ(root_windows[0], | |
| 115 start_widget()->GetNativeWindow()->GetRootWindow()); | |
| 116 | |
| 117 // Move phantom widget back into the left screen. Phantom widgets should swap. | |
| 118 controller()->Show(gfx::Rect(200, 100, 50, 60)); | |
| 119 EXPECT_TRUE(IsVisible(target_widget())); | |
| 120 EXPECT_TRUE(IsVisible(start_widget())); | |
| 121 EXPECT_EQ(root_windows[0], | |
| 122 target_widget()->GetNativeWindow()->GetRootWindow()); | |
| 123 EXPECT_EQ(root_windows[1], | |
| 124 start_widget()->GetNativeWindow()->GetRootWindow()); | |
| 125 | |
| 126 // Hide phantom controller. Both widgets should close. | |
| 127 controller()->Hide(); | |
| 128 EXPECT_FALSE(IsVisible(target_widget())); | |
| 129 EXPECT_FALSE(IsVisible(start_widget())); | |
| 130 } | |
| 131 | |
| 132 // Test that after the phantom window is hidden that it starts animating from | |
| 133 // the bounds of the window it is showing a preview for instead of the phantom | |
| 134 // window's previous bounds. | |
| 135 TEST_F(PhantomWindowControllerTest, PhantomWindowShowAfterHide) { | |
| 136 if (!SupportsMultipleDisplays()) | |
| 137 return; | |
| 138 | |
| 139 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | |
| 140 EXPECT_EQ(root_windows[0], window()->GetRootWindow()); | |
| 141 | |
| 142 // Show phantom window in the right display. There should be two phantom | |
| 143 // widgets created because the phantom animation should start at window()'s | |
| 144 // bounds in the left display. | |
| 145 controller()->Show(gfx::Rect(600, 100, 50, 60)); | |
| 146 EXPECT_TRUE(IsVisible(target_widget())); | |
| 147 EXPECT_TRUE(IsVisible(start_widget())); | |
| 148 EXPECT_EQ(root_windows[1], | |
| 149 target_widget()->GetNativeWindow()->GetRootWindow()); | |
| 150 EXPECT_EQ(root_windows[0], | |
| 151 start_widget()->GetNativeWindow()->GetRootWindow()); | |
| 152 | |
| 153 // Show the phantom window in the left display. There should be one phantom | |
| 154 // widget visible because the phantom animation should start at window()'s | |
| 155 // bounds. | |
| 156 controller()->Hide(); | |
| 157 controller()->Show(gfx::Rect(100, 100, 50, 60)); | |
| 158 EXPECT_TRUE(IsVisible(target_widget())); | |
| 159 EXPECT_FALSE(IsVisible(start_widget())); | |
| 160 EXPECT_EQ(root_windows[0], | |
| 161 target_widget()->GetNativeWindow()->GetRootWindow()); | |
| 162 | |
| 163 // Repeat test but using StartFade() because the code path is different. | |
| 164 controller()->Show(gfx::Rect(600, 100, 50, 60)); | |
| 165 EXPECT_TRUE(IsVisible(target_widget())); | |
| 166 EXPECT_TRUE(IsVisible(start_widget())); | |
| 167 EXPECT_EQ(root_windows[1], | |
| 168 target_widget()->GetNativeWindow()->GetRootWindow()); | |
| 169 EXPECT_EQ(root_windows[0], | |
| 170 start_widget()->GetNativeWindow()->GetRootWindow()); | |
| 171 | |
| 172 controller()->StartFadeOut(); | |
| 173 controller()->Show(gfx::Rect(100, 100, 50, 60)); | |
| 174 EXPECT_TRUE(IsVisible(target_widget())); | |
| 175 EXPECT_FALSE(IsVisible(start_widget())); | |
| 176 EXPECT_EQ(root_windows[0], | |
| 177 target_widget()->GetNativeWindow()->GetRootWindow()); | |
| 178 } | |
| 179 | |
| 180 } // namespace internal | |
| 181 } // namespace ash | |
| OLD | NEW |