Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2021)

Unified Diff: ash/wm/workspace/phantom_window_controller_unittest.cc

Issue 101773004: Refactor PhantomWindowController so that the PhantomWindowController owns the phantom window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/wm/workspace/phantom_window_controller_unittest.cc
diff --git a/ash/wm/workspace/phantom_window_controller_unittest.cc b/ash/wm/workspace/phantom_window_controller_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fe76cd551836c948f864f8619b5591da9835ccf7
--- /dev/null
+++ b/ash/wm/workspace/phantom_window_controller_unittest.cc
@@ -0,0 +1,181 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/wm/workspace/phantom_window_controller.h"
+
+#include "ash/ash_switches.h"
+#include "ash/shell.h"
+#include "ash/test/ash_test_base.h"
+#include "ui/aura/root_window.h"
+#include "ui/aura/window.h"
+#include "ui/views/widget/widget.h"
+
+namespace ash {
+namespace internal {
+
+// Returns true if |widget| is non-NULL and is visible.
+bool IsVisible(views::Widget* widget) {
+ return widget && widget->IsVisible();
+}
+
+class PhantomWindowControllerTest : public ash::test::AshTestBase {
+ public:
+ PhantomWindowControllerTest() {
+ }
+ virtual ~PhantomWindowControllerTest() {
+ }
+
+ // ash::test::AshTestBase:
+ virtual void SetUp() OVERRIDE {
+ ash::test::AshTestBase::SetUp();
+
+ UpdateDisplay("500x400,500x400");
+ window_ = CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 50, 60));
+ controller_.reset(new PhantomWindowController(window_));
+ }
+
+ PhantomWindowController* controller() {
+ return controller_.get();
+ }
+
+ aura::Window* window() { return window_; }
+
+ views::Widget* target_widget() {
+ return controller_->target_phantom_widget_.get();
+ }
+
+ views::Widget* start_widget() {
+ return controller_->start_phantom_widget_.get();
+ }
+
+ private:
+ aura::Window* window_;
+ scoped_ptr<PhantomWindowController> controller_;
+
+ DISALLOW_COPY_AND_ASSIGN(PhantomWindowControllerTest);
+};
+
+// Test that two phantom widgets are used when animating to bounds at least
+// partially in another display.
+TEST_F(PhantomWindowControllerTest, PhantomWindowShow) {
+ if (!SupportsMultipleDisplays())
+ return;
+
+ aura::Window::Windows root_windows = Shell::GetAllRootWindows();
+ EXPECT_EQ(root_windows[0], window()->GetRootWindow());
+
+ // phantom widget only in the left screen.
+ controller()->Show(gfx::Rect(100, 100, 50, 60));
+ EXPECT_TRUE(IsVisible(target_widget()));
+ EXPECT_FALSE(IsVisible(start_widget()));
+ EXPECT_EQ(root_windows[0],
+ target_widget()->GetNativeWindow()->GetRootWindow());
+
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
+ // Move phantom widget into the right screen. Test that 2 widgets got created.
+ controller()->Show(gfx::Rect(600, 100, 50, 60));
+ EXPECT_TRUE(IsVisible(target_widget()));
+ EXPECT_TRUE(IsVisible(start_widget()));
+ EXPECT_EQ(root_windows[1],
+ target_widget()->GetNativeWindow()->GetRootWindow());
+ EXPECT_EQ(root_windows[0],
+ start_widget()->GetNativeWindow()->GetRootWindow());
+
+ // Move phantom widget only in the right screen. Start widget should close.
+ controller()->Show(gfx::Rect(700, 100, 50, 60));
+ EXPECT_TRUE(IsVisible(target_widget()));
+ EXPECT_FALSE(IsVisible(start_widget()));
+ EXPECT_EQ(root_windows[1],
+ target_widget()->GetNativeWindow()->GetRootWindow());
+
+ // Move phantom widget into the left screen. Start widget should open.
+ controller()->Show(gfx::Rect(100, 100, 50, 60));
+ EXPECT_TRUE(IsVisible(target_widget()));
+ EXPECT_TRUE(IsVisible(start_widget()));
+ EXPECT_EQ(root_windows[0],
+ target_widget()->GetNativeWindow()->GetRootWindow());
+ EXPECT_EQ(root_windows[1],
+ start_widget()->GetNativeWindow()->GetRootWindow());
+
+ // Move phantom widget while in the left screen. Start widget should close.
+ controller()->Show(gfx::Rect(200, 100, 50, 60));
+ EXPECT_TRUE(IsVisible(target_widget()));
+ EXPECT_FALSE(IsVisible(start_widget()));
+ EXPECT_EQ(root_windows[0],
+ target_widget()->GetNativeWindow()->GetRootWindow());
+
+ // Move phantom widget spanning both screens with most of the window in the
+ // right screen. Two widgets are created.
+ controller()->Show(gfx::Rect(495, 100, 50, 60));
+ EXPECT_TRUE(IsVisible(target_widget()));
+ EXPECT_TRUE(IsVisible(start_widget()));
+ EXPECT_EQ(root_windows[1],
+ target_widget()->GetNativeWindow()->GetRootWindow());
+ EXPECT_EQ(root_windows[0],
+ start_widget()->GetNativeWindow()->GetRootWindow());
+
+ // Move phantom widget back into the left screen. Phantom widgets should swap.
+ controller()->Show(gfx::Rect(200, 100, 50, 60));
+ EXPECT_TRUE(IsVisible(target_widget()));
+ EXPECT_TRUE(IsVisible(start_widget()));
+ EXPECT_EQ(root_windows[0],
+ target_widget()->GetNativeWindow()->GetRootWindow());
+ EXPECT_EQ(root_windows[1],
+ start_widget()->GetNativeWindow()->GetRootWindow());
+
+ // Hide phantom controller. Both widgets should close.
+ controller()->Hide();
+ EXPECT_FALSE(IsVisible(target_widget()));
+ EXPECT_FALSE(IsVisible(start_widget()));
+}
+
+// Test that after the phantom window is hidden that it starts animating from
+// the bounds of the window it is showing a preview for instead of the phantom
+// window's previous bounds.
+TEST_F(PhantomWindowControllerTest, PhantomWindowShowAfterHide) {
+ if (!SupportsMultipleDisplays())
+ return;
+
+ aura::Window::Windows root_windows = Shell::GetAllRootWindows();
+ EXPECT_EQ(root_windows[0], window()->GetRootWindow());
+
+ // Show phantom window in the right display. There should be two phantom
+ // widgets created because the phantom animation should start at window()'s
+ // bounds in the left display.
+ controller()->Show(gfx::Rect(600, 100, 50, 60));
+ EXPECT_TRUE(IsVisible(target_widget()));
+ EXPECT_TRUE(IsVisible(start_widget()));
+ EXPECT_EQ(root_windows[1],
+ target_widget()->GetNativeWindow()->GetRootWindow());
+ EXPECT_EQ(root_windows[0],
+ start_widget()->GetNativeWindow()->GetRootWindow());
+
+ // Show the phantom window in the left display. There should be one phantom
+ // widget visible because the phantom animation should start at window()'s
+ // bounds.
+ controller()->Hide();
+ controller()->Show(gfx::Rect(100, 100, 50, 60));
+ EXPECT_TRUE(IsVisible(target_widget()));
+ EXPECT_FALSE(IsVisible(start_widget()));
+ EXPECT_EQ(root_windows[0],
+ target_widget()->GetNativeWindow()->GetRootWindow());
+
+ // Repeat test but using StartFade() because the code path is different.
+ controller()->Show(gfx::Rect(600, 100, 50, 60));
+ EXPECT_TRUE(IsVisible(target_widget()));
+ EXPECT_TRUE(IsVisible(start_widget()));
+ EXPECT_EQ(root_windows[1],
+ target_widget()->GetNativeWindow()->GetRootWindow());
+ EXPECT_EQ(root_windows[0],
+ start_widget()->GetNativeWindow()->GetRootWindow());
+
+ controller()->StartFadeOut();
+ controller()->Show(gfx::Rect(100, 100, 50, 60));
+ EXPECT_TRUE(IsVisible(target_widget()));
+ EXPECT_FALSE(IsVisible(start_widget()));
+ EXPECT_EQ(root_windows[0],
+ target_widget()->GetNativeWindow()->GetRootWindow());
+}
+
+} // namespace internal
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698