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

Unified Diff: ui/aura/window_unittest.cc

Issue 115453004: Moves management of transients out of Window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove unneeded parens Created 6 years, 11 months 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
« no previous file with comments | « ui/aura/window.cc ('k') | ui/oak/oak_aura_window_display.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/window_unittest.cc
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index ce1021e99a9ebcc25dc50a19e866fea6d821742f..611748908292a1f66d8007752f17d21f438af78c 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -18,7 +18,6 @@
#include "ui/aura/client/focus_change_observer.h"
#include "ui/aura/client/visibility_client.h"
#include "ui/aura/client/window_tree_client.h"
-#include "ui/aura/layout_manager.h"
#include "ui/aura/root_window.h"
#include "ui/aura/root_window_observer.h"
#include "ui/aura/test/aura_test_base.h"
@@ -1583,41 +1582,6 @@ TEST_F(WindowTest, TransformGesture) {
EXPECT_EQ(gfx::Point(10, 10).ToString(), delegate->position().ToString());
}
-// Various assertions for transient children.
-TEST_F(WindowTest, TransientChildren) {
- scoped_ptr<Window> parent(CreateTestWindowWithId(0, root_window()));
- scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get()));
- scoped_ptr<Window> w3(CreateTestWindowWithId(3, parent.get()));
- Window* w2 = CreateTestWindowWithId(2, parent.get());
- w1->AddTransientChild(w2); // w2 is now owned by w1.
- // Stack w1 at the top (end), this should force w2 to be last (on top of w1).
- parent->StackChildAtTop(w1.get());
- ASSERT_EQ(3u, parent->children().size());
- EXPECT_EQ(w2, parent->children().back());
-
- // Destroy w1, which should also destroy w3 (since it's a transient child).
- w1.reset();
- w2 = NULL;
- ASSERT_EQ(1u, parent->children().size());
- EXPECT_EQ(w3.get(), parent->children()[0]);
-
- w1.reset(CreateTestWindowWithId(4, parent.get()));
- w2 = CreateTestWindowWithId(5, w3.get());
- w1->AddTransientChild(w2);
- parent->StackChildAtTop(w3.get());
- // Stack w1 at the top (end), this shouldn't affect w2 since it has a
- // different parent.
- parent->StackChildAtTop(w1.get());
- ASSERT_EQ(2u, parent->children().size());
- EXPECT_EQ(w3.get(), parent->children()[0]);
- EXPECT_EQ(w1.get(), parent->children()[1]);
-
- // Hiding parent should hide transient children.
- EXPECT_TRUE(w2->IsVisible());
- w1->Hide();
- EXPECT_FALSE(w2->IsVisible());
-}
-
namespace {
DEFINE_WINDOW_PROPERTY_KEY(int, kIntKey, -2);
DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish");
@@ -2056,66 +2020,6 @@ TEST_F(WindowTest, StackWindowAtBottomBelowWindowWhoseLayerHasNoDelegate) {
ui::test::ChildLayerNamesAsString(*root_window()->layer()));
}
-TEST_F(WindowTest, StackWindowsWhoseLayersHaveNoDelegate) {
- scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window()));
- window1->layer()->set_name("1");
- scoped_ptr<Window> window2(CreateTestWindowWithId(2, root_window()));
- window2->layer()->set_name("2");
- scoped_ptr<Window> window3(CreateTestWindowWithId(3, root_window()));
- window3->layer()->set_name("3");
-
- // This brings |window1| (and its layer) to the front.
- root_window()->StackChildAbove(window1.get(), window3.get());
- EXPECT_EQ("2 3 1", ChildWindowIDsAsString(root_window()));
- EXPECT_EQ("2 3 1",
- ui::test::ChildLayerNamesAsString(*root_window()->layer()));
-
- // Since |window1| does not have a delegate, |window2| should not move in
- // front of it, nor should its layer.
- window1->layer()->set_delegate(NULL);
- root_window()->StackChildAbove(window2.get(), window1.get());
- EXPECT_EQ("3 2 1", ChildWindowIDsAsString(root_window()));
- EXPECT_EQ("3 2 1",
- ui::test::ChildLayerNamesAsString(*root_window()->layer()));
-
- // It should still be possible to stack |window3| immediately below |window1|.
- root_window()->StackChildBelow(window3.get(), window1.get());
- EXPECT_EQ("2 3 1", ChildWindowIDsAsString(root_window()));
- EXPECT_EQ("2 3 1",
- ui::test::ChildLayerNamesAsString(*root_window()->layer()));
-
- // Since neither |window3| nor |window1| have a delegate, |window2| should
- // not move in front of either.
- window3->layer()->set_delegate(NULL);
- root_window()->StackChildBelow(window2.get(), window1.get());
- EXPECT_EQ("2 3 1", ChildWindowIDsAsString(root_window()));
- EXPECT_EQ("2 3 1",
- ui::test::ChildLayerNamesAsString(*root_window()->layer()));
-}
-
-TEST_F(WindowTest, StackTransientsWhoseLayersHaveNoDelegate) {
- // Create a window with several transients, then a couple windows on top.
- scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window()));
- scoped_ptr<Window> window11(CreateTransientChild(11, window1.get()));
- scoped_ptr<Window> window12(CreateTransientChild(12, window1.get()));
- scoped_ptr<Window> window13(CreateTransientChild(13, window1.get()));
- scoped_ptr<Window> window2(CreateTestWindowWithId(2, root_window()));
- scoped_ptr<Window> window3(CreateTestWindowWithId(3, root_window()));
-
- EXPECT_EQ("1 11 12 13 2 3", ChildWindowIDsAsString(root_window()));
-
- // Remove the delegates of a couple of transients, as if they are closing
- // and animating out.
- window11->layer()->set_delegate(NULL);
- window13->layer()->set_delegate(NULL);
-
- // Move window1 to the front. All transients should move with it, and their
- // order should be preserved.
- root_window()->StackChildAtTop(window1.get());
-
- EXPECT_EQ("2 3 1 11 12 13", ChildWindowIDsAsString(root_window()));
-}
-
class TestVisibilityClient : public client::VisibilityClient {
public:
explicit TestVisibilityClient(Window* root_window)
@@ -2253,240 +2157,6 @@ TEST_F(WindowTest, MouseEventsOnWindowChange) {
EXPECT_EQ("0 0 0", d11.GetMouseMotionCountsAndReset());
}
-class StackingMadrigalLayoutManager : public LayoutManager {
- public:
- explicit StackingMadrigalLayoutManager(Window* root_window)
- : root_window_(root_window) {
- root_window_->SetLayoutManager(this);
- }
- virtual ~StackingMadrigalLayoutManager() {
- }
-
- private:
- // Overridden from LayoutManager:
- virtual void OnWindowResized() OVERRIDE {}
- virtual void OnWindowAddedToLayout(Window* child) OVERRIDE {}
- virtual void OnWillRemoveWindowFromLayout(Window* child) OVERRIDE {}
- virtual void OnWindowRemovedFromLayout(Window* child) OVERRIDE {}
- virtual void OnChildWindowVisibilityChanged(Window* child,
- bool visible) OVERRIDE {
- Window::Windows::const_iterator it = root_window_->children().begin();
- Window* last_window = NULL;
- for (; it != root_window_->children().end(); ++it) {
- if (*it == child && last_window) {
- if (!visible)
- root_window_->StackChildAbove(last_window, *it);
- else
- root_window_->StackChildAbove(*it, last_window);
- break;
- }
- last_window = *it;
- }
- }
- virtual void SetChildBounds(Window* child,
- const gfx::Rect& requested_bounds) OVERRIDE {
- SetChildBoundsDirect(child, requested_bounds);
- }
-
- Window* root_window_;
-
- DISALLOW_COPY_AND_ASSIGN(StackingMadrigalLayoutManager);
-};
-
-class StackingMadrigalVisibilityClient : public client::VisibilityClient {
- public:
- explicit StackingMadrigalVisibilityClient(Window* root_window)
- : ignored_window_(NULL) {
- client::SetVisibilityClient(root_window, this);
- }
- virtual ~StackingMadrigalVisibilityClient() {
- }
-
- void set_ignored_window(Window* ignored_window) {
- ignored_window_ = ignored_window;
- }
-
- private:
- // Overridden from client::VisibilityClient:
- virtual void UpdateLayerVisibility(Window* window, bool visible) OVERRIDE {
- if (!visible) {
- if (window == ignored_window_)
- window->layer()->set_delegate(NULL);
- else
- window->layer()->SetVisible(visible);
- } else {
- window->layer()->SetVisible(visible);
- }
- }
-
- Window* ignored_window_;
-
- DISALLOW_COPY_AND_ASSIGN(StackingMadrigalVisibilityClient);
-};
-
-// This test attempts to reconstruct a circumstance that can happen when the
-// aura client attempts to manipulate the visibility and delegate of a layer
-// independent of window visibility.
-// A use case is where the client attempts to keep a window visible onscreen
-// even after code has called Hide() on the window. The use case for this would
-// be that window hides are animated (e.g. the window fades out). To prevent
-// spurious updating the client code may also clear window's layer's delegate,
-// so that the window cannot attempt to paint or update it further. The window
-// uses the presence of a NULL layer delegate as a signal in stacking to note
-// that the window is being manipulated by such a use case and its stacking
-// should not be adjusted.
-// One issue that can arise when a window opens two transient children, and the
-// first is hidden. Subsequent attempts to activate the transient parent can
-// result in the transient parent being stacked above the second transient
-// child. A fix is made to Window::StackAbove to prevent this, and this test
-// verifies this fix.
-TEST_F(WindowTest, StackingMadrigal) {
- new StackingMadrigalLayoutManager(root_window());
- StackingMadrigalVisibilityClient visibility_client(root_window());
-
- scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window()));
- scoped_ptr<Window> window11(CreateTransientChild(11, window1.get()));
-
- visibility_client.set_ignored_window(window11.get());
-
- window11->Show();
- window11->Hide();
-
- // As a transient, window11 should still be stacked above window1, even when
- // hidden.
- EXPECT_TRUE(WindowIsAbove(window11.get(), window1.get()));
- EXPECT_TRUE(LayerIsAbove(window11.get(), window1.get()));
-
- // A new transient should still be above window1. It will appear behind
- // window11 because we don't stack windows on top of targets with NULL
- // delegates.
- scoped_ptr<Window> window12(CreateTransientChild(12, window1.get()));
- window12->Show();
-
- EXPECT_TRUE(WindowIsAbove(window12.get(), window1.get()));
- EXPECT_TRUE(LayerIsAbove(window12.get(), window1.get()));
-
- // In earlier versions of the StackChildAbove() method, attempting to stack
- // window1 above window12 at this point would actually restack the layers
- // resulting in window12's layer being below window1's layer (though the
- // windows themselves would still be correctly stacked, so events would pass
- // through.)
- root_window()->StackChildAbove(window1.get(), window12.get());
-
- // Both window12 and its layer should be stacked above window1.
- EXPECT_TRUE(WindowIsAbove(window12.get(), window1.get()));
- EXPECT_TRUE(LayerIsAbove(window12.get(), window1.get()));
-}
-
-// Test for an issue where attempting to stack a primary window on top of a
-// transient with a NULL layer delegate causes that primary window to be moved,
-// but the layer order not changed to match. http://crbug.com/112562
-TEST_F(WindowTest, StackOverClosingTransient) {
- scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window()));
- scoped_ptr<Window> transient1(CreateTransientChild(11, window1.get()));
- scoped_ptr<Window> window2(CreateTestWindowWithId(2, root_window()));
- scoped_ptr<Window> transient2(CreateTransientChild(21, window2.get()));
-
- // Both windows and layers are stacked in creation order.
- Window* root = root_window();
- ASSERT_EQ(4u, root->children().size());
- EXPECT_EQ(root->children()[0], window1.get());
- EXPECT_EQ(root->children()[1], transient1.get());
- EXPECT_EQ(root->children()[2], window2.get());
- EXPECT_EQ(root->children()[3], transient2.get());
- ASSERT_EQ(4u, root->layer()->children().size());
- EXPECT_EQ(root->layer()->children()[0], window1->layer());
- EXPECT_EQ(root->layer()->children()[1], transient1->layer());
- EXPECT_EQ(root->layer()->children()[2], window2->layer());
- EXPECT_EQ(root->layer()->children()[3], transient2->layer());
- EXPECT_EQ("1 11 2 21", ChildWindowIDsAsString(root_window()));
-
- // This brings window1 and its transient to the front.
- root->StackChildAtTop(window1.get());
- EXPECT_EQ("2 21 1 11", ChildWindowIDsAsString(root_window()));
-
- EXPECT_EQ(root->children()[0], window2.get());
- EXPECT_EQ(root->children()[1], transient2.get());
- EXPECT_EQ(root->children()[2], window1.get());
- EXPECT_EQ(root->children()[3], transient1.get());
- EXPECT_EQ(root->layer()->children()[0], window2->layer());
- EXPECT_EQ(root->layer()->children()[1], transient2->layer());
- EXPECT_EQ(root->layer()->children()[2], window1->layer());
- EXPECT_EQ(root->layer()->children()[3], transient1->layer());
-
- // Pretend we're closing the top-most transient, then bring window2 to the
- // front. This mimics activating a browser window while the status bubble
- // is fading out. The transient should stay topmost.
- transient1->layer()->set_delegate(NULL);
- root->StackChildAtTop(window2.get());
-
- EXPECT_EQ(root->children()[0], window1.get());
- EXPECT_EQ(root->children()[1], window2.get());
- EXPECT_EQ(root->children()[2], transient2.get());
- EXPECT_EQ(root->children()[3], transient1.get());
- EXPECT_EQ(root->layer()->children()[0], window1->layer());
- EXPECT_EQ(root->layer()->children()[1], window2->layer());
- EXPECT_EQ(root->layer()->children()[2], transient2->layer());
- EXPECT_EQ(root->layer()->children()[3], transient1->layer());
-
- // Close the transient. Remaining windows are stable.
- transient1.reset();
-
- ASSERT_EQ(3u, root->children().size());
- EXPECT_EQ(root->children()[0], window1.get());
- EXPECT_EQ(root->children()[1], window2.get());
- EXPECT_EQ(root->children()[2], transient2.get());
- ASSERT_EQ(3u, root->layer()->children().size());
- EXPECT_EQ(root->layer()->children()[0], window1->layer());
- EXPECT_EQ(root->layer()->children()[1], window2->layer());
- EXPECT_EQ(root->layer()->children()[2], transient2->layer());
-
- // Open another window on top.
- scoped_ptr<Window> window3(CreateTestWindowWithId(3, root_window()));
-
- ASSERT_EQ(4u, root->children().size());
- EXPECT_EQ(root->children()[0], window1.get());
- EXPECT_EQ(root->children()[1], window2.get());
- EXPECT_EQ(root->children()[2], transient2.get());
- EXPECT_EQ(root->children()[3], window3.get());
- ASSERT_EQ(4u, root->layer()->children().size());
- EXPECT_EQ(root->layer()->children()[0], window1->layer());
- EXPECT_EQ(root->layer()->children()[1], window2->layer());
- EXPECT_EQ(root->layer()->children()[2], transient2->layer());
- EXPECT_EQ(root->layer()->children()[3], window3->layer());
-
- // Pretend we're closing the topmost non-transient window, then bring
- // window2 to the top. It should not move.
- window3->layer()->set_delegate(NULL);
- root->StackChildAtTop(window2.get());
-
- ASSERT_EQ(4u, root->children().size());
- EXPECT_EQ(root->children()[0], window1.get());
- EXPECT_EQ(root->children()[1], window2.get());
- EXPECT_EQ(root->children()[2], transient2.get());
- EXPECT_EQ(root->children()[3], window3.get());
- ASSERT_EQ(4u, root->layer()->children().size());
- EXPECT_EQ(root->layer()->children()[0], window1->layer());
- EXPECT_EQ(root->layer()->children()[1], window2->layer());
- EXPECT_EQ(root->layer()->children()[2], transient2->layer());
- EXPECT_EQ(root->layer()->children()[3], window3->layer());
-
- // Bring window1 to the top. It should move ahead of window2, but not
- // ahead of window3 (with NULL delegate).
- root->StackChildAtTop(window1.get());
-
- ASSERT_EQ(4u, root->children().size());
- EXPECT_EQ(root->children()[0], window2.get());
- EXPECT_EQ(root->children()[1], transient2.get());
- EXPECT_EQ(root->children()[2], window1.get());
- EXPECT_EQ(root->children()[3], window3.get());
- ASSERT_EQ(4u, root->layer()->children().size());
- EXPECT_EQ(root->layer()->children()[0], window2->layer());
- EXPECT_EQ(root->layer()->children()[1], transient2->layer());
- EXPECT_EQ(root->layer()->children()[2], window1->layer());
- EXPECT_EQ(root->layer()->children()[3], window3->layer());
-}
-
class RootWindowAttachmentObserver : public WindowObserver {
public:
RootWindowAttachmentObserver() : added_count_(0), removed_count_(0) {}
@@ -3007,50 +2677,6 @@ TEST_F(WindowTest, OnWindowHierarchyChange) {
}
-namespace {
-
-// Used by NotifyDelegateAfterDeletingTransients. Adds a string to a vector when
-// OnWindowDestroyed() is invoked so that destruction order can be verified.
-class DestroyedTrackingDelegate : public TestWindowDelegate {
- public:
- explicit DestroyedTrackingDelegate(const std::string& name,
- std::vector<std::string>* results)
- : name_(name),
- results_(results) {}
-
- virtual void OnWindowDestroyed() OVERRIDE {
- results_->push_back(name_);
- }
-
- private:
- const std::string name_;
- std::vector<std::string>* results_;
-
- DISALLOW_COPY_AND_ASSIGN(DestroyedTrackingDelegate);
-};
-
-} // namespace
-
-// Verifies the delegate is notified of destruction after transients are
-// destroyed.
-TEST_F(WindowTest, NotifyDelegateAfterDeletingTransients) {
- std::vector<std::string> destruction_order;
-
- DestroyedTrackingDelegate parent_delegate("parent", &destruction_order);
- scoped_ptr<Window> parent(new Window(&parent_delegate));
- parent->Init(ui::LAYER_NOT_DRAWN);
-
- DestroyedTrackingDelegate transient_delegate("transient", &destruction_order);
- Window* transient = new Window(&transient_delegate); // Owned by |parent|.
- transient->Init(ui::LAYER_NOT_DRAWN);
- parent->AddTransientChild(transient);
- parent.reset();
-
- ASSERT_EQ(2u, destruction_order.size());
- EXPECT_EQ("transient", destruction_order[0]);
- EXPECT_EQ("parent", destruction_order[1]);
-}
-
// Verifies SchedulePaint() on a layerless window results in damaging the right
// thing.
TEST_F(WindowTest, LayerlessWindowSchedulePaint) {
« no previous file with comments | « ui/aura/window.cc ('k') | ui/oak/oak_aura_window_display.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698