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

Unified Diff: ui/aura/window_unittest.cc

Issue 1050713002: aura: Remove layerless windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: layerless: rebase Created 5 years, 9 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_tree_host.cc ('k') | ui/keyboard/keyboard_controller.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 60b113556035ef5ee3cd6ba4b7c4e1cff499ba61..9929192f2ec0946eae6e6d713e09c888f0d4a9cb 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -291,11 +291,11 @@ TEST_F(WindowTest, GetChildById) {
// and not containing NULL or parents.
TEST_F(WindowTest, Contains) {
Window parent(NULL);
- parent.Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ parent.Init(ui::LAYER_NOT_DRAWN);
Window child1(NULL);
- child1.Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ child1.Init(ui::LAYER_NOT_DRAWN);
Window child2(NULL);
- child2.Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ child2.Init(ui::LAYER_NOT_DRAWN);
parent.AddChild(&child1);
child1.AddChild(&child2);
@@ -621,7 +621,7 @@ TEST_F(WindowTest, WindowAddedToRootWindowShouldNotifyChildAndNotParent) {
AddedToRootWindowObserver child_observer;
scoped_ptr<Window> parent_window(CreateTestWindowWithId(1, root_window()));
scoped_ptr<Window> child_window(new Window(NULL));
- child_window->Init(aura::WINDOW_LAYER_TEXTURED);
+ child_window->Init(ui::LAYER_TEXTURED);
child_window->Show();
parent_window->AddObserver(&parent_observer);
@@ -670,11 +670,11 @@ TEST_F(WindowTest, OrphanedBeforeOnDestroyed) {
// Make sure StackChildAtTop moves both the window and layer to the front.
TEST_F(WindowTest, StackChildAtTop) {
Window parent(NULL);
- parent.Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ parent.Init(ui::LAYER_NOT_DRAWN);
Window child1(NULL);
- child1.Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ child1.Init(ui::LAYER_NOT_DRAWN);
Window child2(NULL);
- child2.Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ child2.Init(ui::LAYER_NOT_DRAWN);
parent.AddChild(&child1);
parent.AddChild(&child2);
@@ -697,15 +697,15 @@ TEST_F(WindowTest, StackChildAtTop) {
// Make sure StackChildBelow works.
TEST_F(WindowTest, StackChildBelow) {
Window parent(NULL);
- parent.Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ parent.Init(ui::LAYER_NOT_DRAWN);
Window child1(NULL);
- child1.Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ child1.Init(ui::LAYER_NOT_DRAWN);
child1.set_id(1);
Window child2(NULL);
- child2.Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ child2.Init(ui::LAYER_NOT_DRAWN);
child2.set_id(2);
Window child3(NULL);
- child3.Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ child3.Init(ui::LAYER_NOT_DRAWN);
child3.set_id(3);
parent.AddChild(&child1);
@@ -729,13 +729,13 @@ TEST_F(WindowTest, StackChildBelow) {
// Various assertions for StackChildAbove.
TEST_F(WindowTest, StackChildAbove) {
Window parent(NULL);
- parent.Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ parent.Init(ui::LAYER_NOT_DRAWN);
Window child1(NULL);
- child1.Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ child1.Init(ui::LAYER_NOT_DRAWN);
Window child2(NULL);
- child2.Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ child2.Init(ui::LAYER_NOT_DRAWN);
Window child3(NULL);
- child3.Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ child3.Init(ui::LAYER_NOT_DRAWN);
parent.AddChild(&child1);
parent.AddChild(&child2);
@@ -2037,7 +2037,7 @@ TEST_F(WindowTest, RecreateLayer) {
// Set properties to non default values.
Window w(new ColorTestWindowDelegate(SK_ColorWHITE));
w.set_id(1);
- w.Init(aura::WINDOW_LAYER_SOLID_COLOR);
+ w.Init(ui::LAYER_SOLID_COLOR);
w.SetBounds(gfx::Rect(0, 0, 100, 100));
ui::Layer* layer = w.layer();
@@ -2302,7 +2302,7 @@ TEST_F(WindowTest, RootWindowAttachment) {
// Test a direct add/remove from the RootWindow.
scoped_ptr<Window> w1(new Window(NULL));
- w1->Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ w1->Init(ui::LAYER_NOT_DRAWN);
w1->AddObserver(&observer);
ParentWindow(w1.get());
@@ -2317,9 +2317,9 @@ TEST_F(WindowTest, RootWindowAttachment) {
// Test an indirect add/remove from the RootWindow.
w1.reset(new Window(NULL));
- w1->Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ w1->Init(ui::LAYER_NOT_DRAWN);
Window* w11 = new Window(NULL);
- w11->Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ w11->Init(ui::LAYER_NOT_DRAWN);
w11->AddObserver(&observer);
w1->AddChild(w11);
EXPECT_EQ(0, observer.added_count());
@@ -2338,13 +2338,13 @@ TEST_F(WindowTest, RootWindowAttachment) {
// Test an indirect add/remove with nested observers.
w1.reset(new Window(NULL));
- w1->Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ w1->Init(ui::LAYER_NOT_DRAWN);
w11 = new Window(NULL);
- w11->Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ w11->Init(ui::LAYER_NOT_DRAWN);
w11->AddObserver(&observer);
w1->AddChild(w11);
Window* w111 = new Window(NULL);
- w111->Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ w111->Init(ui::LAYER_NOT_DRAWN);
w111->AddObserver(&observer);
w11->AddChild(w111);
@@ -2382,9 +2382,9 @@ class BoundsChangedWindowObserver : public WindowObserver {
TEST_F(WindowTest, RootWindowSetWhenReparenting) {
Window parent1(NULL);
- parent1.Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ parent1.Init(ui::LAYER_NOT_DRAWN);
Window parent2(NULL);
- parent2.Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ parent2.Init(ui::LAYER_NOT_DRAWN);
ParentWindow(&parent1);
ParentWindow(&parent2);
parent1.SetBounds(gfx::Rect(10, 10, 300, 300));
@@ -2392,7 +2392,7 @@ TEST_F(WindowTest, RootWindowSetWhenReparenting) {
BoundsChangedWindowObserver observer;
Window child(NULL);
- child.Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ child.Init(ui::LAYER_NOT_DRAWN);
child.SetBounds(gfx::Rect(5, 5, 100, 100));
parent1.AddChild(&child);
@@ -2423,10 +2423,10 @@ TEST_F(WindowTest, OwnedByParentFalse) {
// window will not be destroyed when its parent is.
scoped_ptr<Window> w1(new Window(NULL));
- w1->Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ w1->Init(ui::LAYER_NOT_DRAWN);
scoped_ptr<Window> w2(new Window(NULL));
w2->set_owned_by_parent(false);
- w2->Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ w2->Init(ui::LAYER_NOT_DRAWN);
w1->AddChild(w2.get());
w1.reset();
@@ -2464,13 +2464,13 @@ class OwningWindowDelegate : public TestWindowDelegate {
// bubble.
TEST_F(WindowTest, DeleteWindowFromOnWindowDestroyed) {
scoped_ptr<Window> parent(new Window(NULL));
- parent->Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ parent->Init(ui::LAYER_NOT_DRAWN);
OwningWindowDelegate delegate;
Window* c1 = new Window(&delegate);
- c1->Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ c1->Init(ui::LAYER_NOT_DRAWN);
parent->AddChild(c1);
Window* c2 = new Window(NULL);
- c2->Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ c2->Init(ui::LAYER_NOT_DRAWN);
parent->AddChild(c2);
delegate.SetOwnedWindow(c2);
parent.reset();
@@ -2838,191 +2838,6 @@ TEST_F(WindowTest, OnWindowHierarchyChange) {
}
-// Verifies SchedulePaint() on a layerless window results in damaging the right
-// thing.
-TEST_F(WindowTest, LayerlessWindowSchedulePaint) {
- Window root(NULL);
- root.Init(aura::WINDOW_LAYER_NOT_DRAWN);
- root.SetBounds(gfx::Rect(0, 0, 100, 100));
-
- Window* layerless_window = new Window(NULL); // Owned by |root|.
- layerless_window->Init(WINDOW_LAYER_NONE);
- layerless_window->SetBounds(gfx::Rect(10, 11, 12, 13));
- root.AddChild(layerless_window);
-
- root.layer()->SendDamagedRects();
- layerless_window->SchedulePaintInRect(gfx::Rect(1, 2, 100, 4));
- // Note the the region is clipped by the parent hence 100 going to 11.
- EXPECT_EQ("11,13 11x4",
- gfx::SkIRectToRect(root.layer()->damaged_region().getBounds()).
- ToString());
-
- Window* layerless_window2 = new Window(NULL); // Owned by |layerless_window|.
- layerless_window2->Init(WINDOW_LAYER_NONE);
- layerless_window2->SetBounds(gfx::Rect(1, 2, 3, 4));
- layerless_window->AddChild(layerless_window2);
-
- root.layer()->SendDamagedRects();
- layerless_window2->SchedulePaintInRect(gfx::Rect(1, 2, 100, 4));
- // Note the the region is clipped by the |layerless_window| hence 100 going to
- // 2.
- EXPECT_EQ("12,15 2x2",
- gfx::SkIRectToRect(root.layer()->damaged_region().getBounds()).
- ToString());
-}
-
-// Verifies bounds of layerless windows are correctly updated when adding
-// removing.
-TEST_F(WindowTest, NestedLayerlessWindowsBoundsOnAddRemove) {
- // Creates the following structure (all children owned by root):
- // root
- // w1ll 1,2
- // w11ll 3,4
- // w111 5,6
- // w12 7,8
- // w121 9,10
- //
- // ll: layer less, eg no layer
- Window root(NULL);
- root.Init(WINDOW_LAYER_NOT_DRAWN);
- root.SetBounds(gfx::Rect(0, 0, 100, 100));
-
- Window* w1ll = new Window(NULL);
- w1ll->Init(WINDOW_LAYER_NONE);
- w1ll->SetBounds(gfx::Rect(1, 2, 100, 100));
-
- Window* w11ll = new Window(NULL);
- w11ll->Init(WINDOW_LAYER_NONE);
- w11ll->SetBounds(gfx::Rect(3, 4, 100, 100));
- w1ll->AddChild(w11ll);
-
- Window* w111 = new Window(NULL);
- w111->Init(WINDOW_LAYER_NOT_DRAWN);
- w111->SetBounds(gfx::Rect(5, 6, 100, 100));
- w11ll->AddChild(w111);
-
- Window* w12 = new Window(NULL);
- w12->Init(WINDOW_LAYER_NOT_DRAWN);
- w12->SetBounds(gfx::Rect(7, 8, 100, 100));
- w1ll->AddChild(w12);
-
- Window* w121 = new Window(NULL);
- w121->Init(WINDOW_LAYER_NOT_DRAWN);
- w121->SetBounds(gfx::Rect(9, 10, 100, 100));
- w12->AddChild(w121);
-
- root.AddChild(w1ll);
-
- // All layers should be parented to the root.
- EXPECT_EQ(root.layer(), w111->layer()->parent());
- EXPECT_EQ(root.layer(), w12->layer()->parent());
- EXPECT_EQ(w12->layer(), w121->layer()->parent());
-
- // Ensure bounds are what we expect.
- EXPECT_EQ("1,2 100x100", w1ll->bounds().ToString());
- EXPECT_EQ("3,4 100x100", w11ll->bounds().ToString());
- EXPECT_EQ("5,6 100x100", w111->bounds().ToString());
- EXPECT_EQ("7,8 100x100", w12->bounds().ToString());
- EXPECT_EQ("9,10 100x100", w121->bounds().ToString());
-
- // Bounds of layers are relative to the nearest ancestor with a layer.
- EXPECT_EQ("8,10 100x100", w12->layer()->bounds().ToString());
- EXPECT_EQ("9,12 100x100", w111->layer()->bounds().ToString());
- EXPECT_EQ("9,10 100x100", w121->layer()->bounds().ToString());
-
- // Remove and repeat.
- root.RemoveChild(w1ll);
-
- EXPECT_TRUE(w111->layer()->parent() == NULL);
- EXPECT_TRUE(w12->layer()->parent() == NULL);
-
- // Verify bounds haven't changed again.
- EXPECT_EQ("1,2 100x100", w1ll->bounds().ToString());
- EXPECT_EQ("3,4 100x100", w11ll->bounds().ToString());
- EXPECT_EQ("5,6 100x100", w111->bounds().ToString());
- EXPECT_EQ("7,8 100x100", w12->bounds().ToString());
- EXPECT_EQ("9,10 100x100", w121->bounds().ToString());
-
- // Bounds of layers should now match that of windows.
- EXPECT_EQ("7,8 100x100", w12->layer()->bounds().ToString());
- EXPECT_EQ("5,6 100x100", w111->layer()->bounds().ToString());
- EXPECT_EQ("9,10 100x100", w121->layer()->bounds().ToString());
-
- delete w1ll;
-}
-
-// Verifies bounds of layerless windows are correctly updated when bounds
-// of ancestor changes.
-TEST_F(WindowTest, NestedLayerlessWindowsBoundsOnSetBounds) {
- // Creates the following structure (all children owned by root):
- // root
- // w1ll 1,2
- // w11ll 3,4
- // w111 5,6
- // w12 7,8
- // w121 9,10
- //
- // ll: layer less, eg no layer
- Window root(NULL);
- root.Init(WINDOW_LAYER_NOT_DRAWN);
- root.SetBounds(gfx::Rect(0, 0, 100, 100));
-
- Window* w1ll = new Window(NULL);
- w1ll->Init(WINDOW_LAYER_NONE);
- w1ll->SetBounds(gfx::Rect(1, 2, 100, 100));
-
- Window* w11ll = new Window(NULL);
- w11ll->Init(WINDOW_LAYER_NONE);
- w11ll->SetBounds(gfx::Rect(3, 4, 100, 100));
- w1ll->AddChild(w11ll);
-
- Window* w111 = new Window(NULL);
- w111->Init(WINDOW_LAYER_NOT_DRAWN);
- w111->SetBounds(gfx::Rect(5, 6, 100, 100));
- w11ll->AddChild(w111);
-
- Window* w12 = new Window(NULL);
- w12->Init(WINDOW_LAYER_NOT_DRAWN);
- w12->SetBounds(gfx::Rect(7, 8, 100, 100));
- w1ll->AddChild(w12);
-
- Window* w121 = new Window(NULL);
- w121->Init(WINDOW_LAYER_NOT_DRAWN);
- w121->SetBounds(gfx::Rect(9, 10, 100, 100));
- w12->AddChild(w121);
-
- root.AddChild(w1ll);
-
- w111->SetBounds(gfx::Rect(7, 8, 11, 12));
- EXPECT_EQ("7,8 11x12", w111->bounds().ToString());
- EXPECT_EQ("7,8 11x12", w111->GetTargetBounds().ToString());
- EXPECT_EQ("11,14 11x12", w111->layer()->bounds().ToString());
-
- // Set back.
- w111->SetBounds(gfx::Rect(5, 6, 100, 100));
- EXPECT_EQ("5,6 100x100", w111->bounds().ToString());
- EXPECT_EQ("5,6 100x100", w111->GetTargetBounds().ToString());
- EXPECT_EQ("9,12 100x100", w111->layer()->bounds().ToString());
-
- // Setting the bounds of a layerless window needs to adjust the bounds of
- // layered children.
- w11ll->SetBounds(gfx::Rect(5, 6, 100, 100));
- EXPECT_EQ("5,6 100x100", w11ll->bounds().ToString());
- EXPECT_EQ("5,6 100x100", w11ll->GetTargetBounds().ToString());
- EXPECT_EQ("5,6 100x100", w111->bounds().ToString());
- EXPECT_EQ("5,6 100x100", w111->GetTargetBounds().ToString());
- EXPECT_EQ("11,14 100x100", w111->layer()->bounds().ToString());
-
- root.RemoveChild(w1ll);
-
- w111->SetBounds(gfx::Rect(7, 8, 11, 12));
- EXPECT_EQ("7,8 11x12", w111->bounds().ToString());
- EXPECT_EQ("7,8 11x12", w111->GetTargetBounds().ToString());
- EXPECT_EQ("7,8 11x12", w111->layer()->bounds().ToString());
-
- delete w1ll;
-}
-
namespace {
// Tracks the number of times paint is invoked along with what the clip and
@@ -3063,443 +2878,6 @@ class PaintWindowDelegate : public TestWindowDelegate {
} // namespace
-// Assertions around layerless children being painted when non-layerless window
-// is painted.
-TEST_F(WindowTest, PaintLayerless) {
- // Creates the following structure (all children owned by root):
- // root
- // w1ll 1,2 40x50
- // w11ll 3,4 11x12
- // w111 5,6
- //
- // ll: layer less, eg no layer
- PaintWindowDelegate w1ll_delegate;
- PaintWindowDelegate w11ll_delegate;
- PaintWindowDelegate w111_delegate;
-
- Window root(NULL);
- root.Init(WINDOW_LAYER_NOT_DRAWN);
- root.SetBounds(gfx::Rect(0, 0, 100, 100));
-
- Window* w1ll = new Window(&w1ll_delegate);
- w1ll->Init(WINDOW_LAYER_NONE);
- w1ll->SetBounds(gfx::Rect(1, 2, 40, 50));
- w1ll->Show();
- root.AddChild(w1ll);
-
- Window* w11ll = new Window(&w11ll_delegate);
- w11ll->Init(WINDOW_LAYER_NONE);
- w11ll->SetBounds(gfx::Rect(3, 4, 11, 12));
- w11ll->Show();
- w1ll->AddChild(w11ll);
-
- Window* w111 = new Window(&w111_delegate);
- w111->Init(WINDOW_LAYER_NOT_DRAWN);
- w111->SetBounds(gfx::Rect(5, 6, 100, 100));
- w111->Show();
- w11ll->AddChild(w111);
-
- EXPECT_EQ(0, w1ll_delegate.paint_count());
- EXPECT_EQ(0, w11ll_delegate.paint_count());
- EXPECT_EQ(0, w111_delegate.paint_count());
-
- // Paint the root, this should trigger painting of the two layerless
- // descendants but not the layered descendant.
- gfx::Canvas canvas(gfx::Size(200, 200), 1.0f, true);
- static_cast<ui::LayerDelegate&>(root).OnPaintLayer(&canvas);
-
- // NOTE: SkCanvas::getClipBounds() extends the clip 1 pixel to the left and up
- // and 2 pixels down and to the right.
- EXPECT_EQ(1, w1ll_delegate.paint_count());
- EXPECT_EQ("-1,-1 42x52",
- w1ll_delegate.most_recent_paint_clip_bounds().ToString());
- EXPECT_EQ("[1 2]",
- w1ll_delegate.most_recent_paint_matrix_offset().ToString());
- EXPECT_EQ(1, w11ll_delegate.paint_count());
- EXPECT_EQ("-1,-1 13x14",
- w11ll_delegate.most_recent_paint_clip_bounds().ToString());
- EXPECT_EQ("[4 6]",
- w11ll_delegate.most_recent_paint_matrix_offset().ToString());
- EXPECT_EQ(0, w111_delegate.paint_count());
-}
-
-namespace {
-
-std::string ConvertPointToTargetString(const Window* source,
- const Window* target) {
- gfx::Point location;
- Window::ConvertPointToTarget(source, target, &location);
- return location.ToString();
-}
-
-} // namespace
-
-// Assertions around Window::ConvertPointToTarget() with layerless windows.
-TEST_F(WindowTest, ConvertPointToTargetLayerless) {
- // Creates the following structure (all children owned by root):
- // root
- // w1ll 1,2
- // w11ll 3,4
- // w111 5,6
- // w12 7,8
- // w121 9,10
- //
- // ll: layer less, eg no layer
- Window root(NULL);
- root.Init(WINDOW_LAYER_NOT_DRAWN);
- root.SetBounds(gfx::Rect(0, 0, 100, 100));
-
- Window* w1ll = new Window(NULL);
- w1ll->Init(WINDOW_LAYER_NONE);
- w1ll->SetBounds(gfx::Rect(1, 2, 100, 100));
-
- Window* w11ll = new Window(NULL);
- w11ll->Init(WINDOW_LAYER_NONE);
- w11ll->SetBounds(gfx::Rect(3, 4, 100, 100));
- w1ll->AddChild(w11ll);
-
- Window* w111 = new Window(NULL);
- w111->Init(WINDOW_LAYER_NOT_DRAWN);
- w111->SetBounds(gfx::Rect(5, 6, 100, 100));
- w11ll->AddChild(w111);
-
- Window* w12 = new Window(NULL);
- w12->Init(WINDOW_LAYER_NOT_DRAWN);
- w12->SetBounds(gfx::Rect(7, 8, 100, 100));
- w1ll->AddChild(w12);
-
- Window* w121 = new Window(NULL);
- w121->Init(WINDOW_LAYER_NOT_DRAWN);
- w121->SetBounds(gfx::Rect(9, 10, 100, 100));
- w12->AddChild(w121);
-
- root.AddChild(w1ll);
-
- // w111->w11ll
- EXPECT_EQ("5,6", ConvertPointToTargetString(w111, w11ll));
-
- // w111->w1ll
- EXPECT_EQ("8,10", ConvertPointToTargetString(w111, w1ll));
-
- // w111->root
- EXPECT_EQ("9,12", ConvertPointToTargetString(w111, &root));
-
- // w111->w12
- EXPECT_EQ("1,2", ConvertPointToTargetString(w111, w12));
-
- // w111->w121
- EXPECT_EQ("-8,-8", ConvertPointToTargetString(w111, w121));
-
- // w11ll->w111
- EXPECT_EQ("-5,-6", ConvertPointToTargetString(w11ll, w111));
-
- // w11ll->w11ll
- EXPECT_EQ("3,4", ConvertPointToTargetString(w11ll, w1ll));
-
- // w11ll->root
- EXPECT_EQ("4,6", ConvertPointToTargetString(w11ll, &root));
-
- // w11ll->w12
- EXPECT_EQ("-4,-4", ConvertPointToTargetString(w11ll, w12));
-}
-
-#if !defined(NDEBUG)
-// Verifies PrintWindowHierarchy() doesn't crash with a layerless window.
-TEST_F(WindowTest, PrintWindowHierarchyNotCrashLayerless) {
- Window root(NULL);
- root.Init(WINDOW_LAYER_NONE);
- root.SetBounds(gfx::Rect(0, 0, 100, 100));
- root.PrintWindowHierarchy(0);
-}
-#endif
-
-namespace {
-
-// See AddWindowsFromString() for details.
-aura::Window* CreateWindowFromDescription(const std::string& description,
- WindowDelegate* delegate) {
- WindowLayerType window_type = WINDOW_LAYER_NOT_DRAWN;
- std::vector<std::string> tokens;
- Tokenize(description, ":", &tokens);
- DCHECK(!tokens.empty());
- std::string name(tokens[0]);
- tokens.erase(tokens.begin());
- if (!tokens.empty()) {
- if (tokens[0] == "ll") {
- window_type = WINDOW_LAYER_NONE;
- tokens.erase(tokens.begin());
- }
- DCHECK(tokens.empty()) << "unknown tokens for creating window "
- << description;
- }
- Window* window = new Window(delegate);
- window->Init(window_type);
- window->SetName(name);
- // Window name is only propagated to layer in debug builds.
- if (window->layer())
- window->layer()->set_name(name);
- return window;
-}
-
-// Creates and adds a tree of windows to |parent|. |description| consists
-// of the following pieces:
-// X: Identifies a new window. Consists of a name and optionally ":ll" to
-// specify WINDOW_LAYER_NONE, eg "w1:ll".
-// []: optionally used to specify the children of the window. Contains any
-// number of window identifiers and their corresponding children.
-// For example: "[ a [ a1 a2:ll ] b c [ c1 ] ]" creates the tree:
-// a
-// a1
-// a2 -> WINDOW_LAYER_NONE.
-// b
-// c
-// c1
-// NOTE: you must have a space after every token.
-std::string::size_type AddWindowsFromString(aura::Window* parent,
- const std::string& description,
- std::string::size_type start_pos,
- WindowDelegate* delegate) {
- DCHECK(parent);
- std::string::size_type end_pos = description.find(' ', start_pos);
- while (end_pos != std::string::npos) {
- const std::string::size_type part_length = end_pos - start_pos;
- const std::string window_description =
- description.substr(start_pos, part_length);
- if (window_description == "[") {
- start_pos = AddWindowsFromString(parent->children().back(),
- description,
- end_pos + 1,
- delegate);
- end_pos = description.find(' ', start_pos);
- if (end_pos == std::string::npos && start_pos != end_pos)
- end_pos = description.length();
- } else if (window_description == "]") {
- ++end_pos;
- break;
- } else {
- Window* window =
- CreateWindowFromDescription(window_description, delegate);
- parent->AddChild(window);
- start_pos = ++end_pos;
- end_pos = description.find(' ', start_pos);
- }
- }
- return end_pos;
-}
-
-// Used by BuildRootWindowTreeDescription().
-std::string BuildWindowTreeDescription(const aura::Window& window) {
- std::string result;
- result += window.name();
- if (window.children().empty())
- return result;
-
- result += " [ ";
- for (size_t i = 0; i < window.children().size(); ++i) {
- if (i != 0)
- result += " ";
- result += BuildWindowTreeDescription(*(window.children()[i]));
- }
- result += " ]";
- return result;
-}
-
-// Creates a string from |window|. See AddWindowsFromString() for details of the
-// returned string. This does *not* include the layer type in the description,
-// on the name.
-std::string BuildRootWindowTreeDescription(const aura::Window& window) {
- std::string result;
- for (size_t i = 0; i < window.children().size(); ++i) {
- if (i != 0)
- result += " ";
- result += BuildWindowTreeDescription(*(window.children()[i]));
- }
- return result;
-}
-
-// Used by BuildRootWindowTreeDescription().
-std::string BuildLayerTreeDescription(const ui::Layer& layer) {
- std::string result;
- result += layer.name();
- if (layer.children().empty())
- return result;
-
- result += " [ ";
- for (size_t i = 0; i < layer.children().size(); ++i) {
- if (i != 0)
- result += " ";
- result += BuildLayerTreeDescription(*(layer.children()[i]));
- }
- result += " ]";
- return result;
-}
-
-// Builds a string for all the children of |layer|. The returned string is in
-// the same format as AddWindowsFromString() but only includes the name of the
-// layers.
-std::string BuildRootLayerTreeDescription(const ui::Layer& layer) {
- std::string result;
- for (size_t i = 0; i < layer.children().size(); ++i) {
- if (i != 0)
- result += " ";
- result += BuildLayerTreeDescription(*(layer.children()[i]));
- }
- return result;
-}
-
-// Returns the first window whose name matches |name| in |parent|.
-aura::Window* FindWindowByName(aura::Window* parent,
- const std::string& name) {
- if (parent->name() == name)
- return parent;
- for (size_t i = 0; i < parent->children().size(); ++i) {
- aura::Window* child = FindWindowByName(parent->children()[i], name);
- if (child)
- return child;
- }
- return NULL;
-}
-
-} // namespace
-
-// Direction to stack.
-enum StackType {
- STACK_ABOVE,
- STACK_BELOW,
- STACK_AT_BOTTOM,
- STACK_AT_TOP,
-};
-
-// Permutations of StackChildAt with various data.
-TEST_F(WindowTest, StackChildAtLayerless) {
- struct TestData {
- // Describes the window tree to create. See AddWindowsFromString() for
- // details.
- const std::string initial_description;
-
- // Identifies the window to move.
- const std::string source_window;
-
- // Window to move |source_window| relative to. Not used for STACK_AT_BOTTOM
- // or STACK_AT_TOP.
- const std::string target_window;
-
- StackType stack_type;
-
- // Expected window and layer results.
- const std::string expected_description;
- const std::string expected_layer_description;
- } data[] = {
- // 1 at top.
- {
- "1:ll [ 11 12 ] 2:ll [ 21 ]",
- "1",
- "",
- STACK_AT_TOP,
- "2 [ 21 ] 1 [ 11 12 ]",
- "21 11 12",
- },
-
- // 1 at bottom.
- {
- "1:ll [ 11 12 ] 2:ll [ 21 ]",
- "1",
- "",
- STACK_AT_BOTTOM,
- "1 [ 11 12 ] 2 [ 21 ]",
- "11 12 21",
- },
-
- // 2 at bottom.
- {
- "1:ll [ 11 12 ] 2:ll [ 21 ]",
- "2",
- "",
- STACK_AT_BOTTOM,
- "2 [ 21 ] 1 [ 11 12 ]",
- "21 11 12",
- },
-
- // 3 below 2.
- {
- "1:ll [ 11 12 ] 2:ll [ 21 ] 3:ll",
- "3",
- "2",
- STACK_BELOW,
- "1 [ 11 12 ] 3 2 [ 21 ]",
- "11 12 21",
- },
-
- // 2 below 1.
- {
- "1:ll [ 11 12 ] 2:ll [ 21 ]",
- "2",
- "1",
- STACK_BELOW,
- "2 [ 21 ] 1 [ 11 12 ]",
- "21 11 12",
- },
-
- // 1 above 3.
- {
- "1:ll [ 11 12 ] 2:ll [ 21 ] 3:ll",
- "1",
- "3",
- STACK_ABOVE,
- "2 [ 21 ] 3 1 [ 11 12 ]",
- "21 11 12",
- },
-
- // 1 above 2.
- {
- "1:ll [ 11 12 ] 2:ll [ 21 ]",
- "1",
- "2",
- STACK_ABOVE,
- "2 [ 21 ] 1 [ 11 12 ]",
- "21 11 12",
- },
- };
- for (size_t i = 0; i < arraysize(data); ++i) {
- test::TestWindowDelegate delegate;
- Window root(NULL);
- root.Init(WINDOW_LAYER_NOT_DRAWN);
- root.SetBounds(gfx::Rect(0, 0, 100, 100));
- AddWindowsFromString(
- &root,
- data[i].initial_description,
- static_cast<std::string::size_type>(0), &delegate);
- aura::Window* source = FindWindowByName(&root, data[i].source_window);
- ASSERT_TRUE(source != NULL) << "unable to find source window "
- << data[i].source_window << " at " << i;
- aura::Window* target = FindWindowByName(&root, data[i].target_window);
- switch (data[i].stack_type) {
- case STACK_ABOVE:
- ASSERT_TRUE(target != NULL) << "unable to find target window "
- << data[i].target_window << " at " << i;
- source->parent()->StackChildAbove(source, target);
- break;
- case STACK_BELOW:
- ASSERT_TRUE(target != NULL) << "unable to find target window "
- << data[i].target_window << " at " << i;
- source->parent()->StackChildBelow(source, target);
- break;
- case STACK_AT_BOTTOM:
- source->parent()->StackChildAtBottom(source);
- break;
- case STACK_AT_TOP:
- source->parent()->StackChildAtTop(source);
- break;
- }
- EXPECT_EQ(data[i].expected_layer_description,
- BuildRootLayerTreeDescription(*root.layer()))
- << "layer tree doesn't match at " << i;
- EXPECT_EQ(data[i].expected_description,
- BuildRootWindowTreeDescription(root))
- << "window tree doesn't match at " << i;
- }
-}
-
namespace {
class TestLayerAnimationObserver : public ui::LayerAnimationObserver {
« no previous file with comments | « ui/aura/window_tree_host.cc ('k') | ui/keyboard/keyboard_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698